From c401a2f2fd1a509cdeb33e850bb5c2827074af48 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 17 三月 2025 08:44:51 +0800
Subject: [PATCH] 完善框架,新增两个close方法;

---
 WPFProject/PanuonWindow.xaml.cs |   96 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 92 insertions(+), 4 deletions(-)

diff --git a/WPFProject/PanuonWindow.xaml.cs b/WPFProject/PanuonWindow.xaml.cs
index 717a7c8..375df69 100644
--- a/WPFProject/PanuonWindow.xaml.cs
+++ b/WPFProject/PanuonWindow.xaml.cs
@@ -1,9 +1,16 @@
-锘縰sing HMI.Core.Setting;
+锘縰sing HMI.Base;
+using HMI.Core.Api;
+using HMI.Core.Entity;
+using HMI.Core.Setting;
 using HMI.Core.Util;
+using HMI.UI.Util;
 using Panuon.WPF.UI;
 using System;
+using System.ComponentModel;
+using System.Diagnostics;
 using System.IO;
 using System.Windows;
+using System.Windows.Controls;
 using System.Windows.Media.Imaging;
 
 namespace WPFProject
@@ -11,13 +18,29 @@
     /// <summary>
     /// PanuonWindow.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
-    public partial class PanuonWindow : WindowX
+    public partial class PanuonWindow : WindowX, IPluginContainer
     {
         public PanuonWindow()
+        {
+            Loaded += PanuonWindow_Loaded;
+        }
+
+        private UserInfo currentUser;
+        public UserInfo CurrentUser
+        {
+            get => currentUser;
+            set
+            {
+                Set(ref currentUser, value);
+            }
+        }
+
+        private void PanuonWindow_Loaded(object sender, RoutedEventArgs e)
         {
             DataContext = this;
             RefrshConfig();
             InitializeComponent();
+            userMenu.Header = this.lang("App.Welcome", UserInfo.User.Name);
             ShowMenu = true;
         }
 
@@ -53,10 +76,15 @@
 
         private bool showMenu;
 
+        public event CancelEventHandler OnCloseEvent;
+        public event EventHandler DoCloseEvent;
+        public event EventHandler LoadComplateEvent;
+
         public bool ShowMenu
         {
             get { return showMenu; }
-            set { 
+            set
+            {
                 Set(ref showMenu, value);
                 menuTab.ChangeItemVisibility(value);
             }
@@ -82,7 +110,67 @@
         private void SystemSetting_SystemSettingChanged(object sender, SystemSetting e)
         {
             RefrshConfig();
-            LangUtil.LoadLang();
+        }
+
+        protected override void OnClosing(CancelEventArgs e)
+        {
+            OnCloseEvent?.Invoke(this, e);
+            base.OnClosing(e);
+        }
+
+        protected override void OnClosed(EventArgs e)
+        {
+            DoCloseEvent?.Invoke(this, e);
+            base.OnClosed(e);
+        }
+
+        private void MenuItem_Click(object sender, RoutedEventArgs e)
+        {MenuItem mi = sender as MenuItem;
+            switch (mi.Name) {
+                case "MiLogout":
+                    Logout();
+                    break;
+                case "MiRestart":
+                    RestartApp();
+                    break;
+                default:
+                    break;
+            }
+        }
+
+        private void Logout()
+        {
+            if (MsgBoxHelper.WarnMessage(this, this.lang("App.MakeSureLogout")) == MessageBoxResult.OK)
+            {
+                string path = Path.Combine(PathHelper.DatabaseFolder, "user.bin");
+                if (File.Exists(path)) { 
+                    File.Delete(path);
+                }
+                this.Closed -= window_Closed;
+                this.Close();
+                PluginLoader.Reset();
+                Login login = new Login();
+                login.Show();
+            }
+        }
+
+        private void RestartApp()
+        {
+            if (MsgBoxHelper.WarnMessage(this, this.lang("App.MakeSureRestartApp")) == MessageBoxResult.OK)
+            {
+                Application.Current.Exit += Current_Exit;
+                this.Close();
+            }
+        }
+
+        private void Current_Exit(object sender, ExitEventArgs e)
+        {
+            System.Windows.Forms.Application.Restart();
+        }
+
+        private void window_Closed(object sender, EventArgs e)
+        {
+            Application.Current.Shutdown();
         }
 
         //private void BaseWindow_Loaded(object sender, RoutedEventArgs e)

--
Gitblit v1.9.1