From 6bcafc823e836ecd5790f87178a906333699f868 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期四, 10 四月 2025 10:46:47 +0800
Subject: [PATCH] 优化插件结构;

---
 WPFProject/PanuonWindow.xaml.cs |  105 ++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 93 insertions(+), 12 deletions(-)

diff --git a/WPFProject/PanuonWindow.xaml.cs b/WPFProject/PanuonWindow.xaml.cs
index 0c162fe..8f84a71 100644
--- a/WPFProject/PanuonWindow.xaml.cs
+++ b/WPFProject/PanuonWindow.xaml.cs
@@ -1,28 +1,49 @@
-锘縰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;
 using System.Windows.Media.Imaging;
-using WPFProject.Utils;
 
 namespace WPFProject
 {
     /// <summary>
     /// PanuonWindow.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
-    public partial class PanuonWindow : WindowX
+    public partial class PanuonWindow : WindowX, IPluginContainer
     {
         public PanuonWindow()
+        {
+            this.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();
-            ShowMenu = true;
+            userMenu.Header = this.lang("App.Welcome", UserInfo.User.Name);
+            ShowMenu = true; 
+            Application.Current.MainWindow = this;
+            SystemSetting.SystemSettingChanged += SystemSetting_SystemSettingChanged;
         }
 
         private void RefrshConfig()
@@ -57,10 +78,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);
             }
@@ -78,15 +104,70 @@
             //menuTab.ChangeItemVisibility();
         }
 
-        private void window_Loaded(object sender, RoutedEventArgs e)
-        {
-            SystemSetting.SystemSettingChanged += SystemSetting_SystemSettingChanged;
-        }
-
         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