From 4cac1b533e133fdc8b3def90a0f998820f51907a Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期三, 26 三月 2025 17:57:59 +0800
Subject: [PATCH] 优化UI,新增日志自动删除;

---
 WPFProject/PanuonWindow.xaml.cs |  131 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 112 insertions(+), 19 deletions(-)

diff --git a/WPFProject/PanuonWindow.xaml.cs b/WPFProject/PanuonWindow.xaml.cs
index d59e870..8f84a71 100644
--- a/WPFProject/PanuonWindow.xaml.cs
+++ b/WPFProject/PanuonWindow.xaml.cs
@@ -1,30 +1,49 @@
-锘縰sing System;
-using System.IO;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using HandyControl.Tools.Extension;
+锘縰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 WPFProject.Utils;
+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
 {
     /// <summary>
     /// PanuonWindow.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
-    public partial class PanuonWindow : WindowX
+    public partial class PanuonWindow : WindowX, IPluginContainer
     {
         public PanuonWindow()
         {
-            ToastHelper.Register(new MainToastHandler());
+            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();
+            userMenu.Header = this.lang("App.Welcome", UserInfo.User.Name);
+            ShowMenu = true; 
+            Application.Current.MainWindow = this;
+            SystemSetting.SystemSettingChanged += SystemSetting_SystemSettingChanged;
         }
 
         private void RefrshConfig()
@@ -57,19 +76,32 @@
             set { Set(ref windowLogo, value); }
         }
 
-        private void Button_Click_2(object sender, RoutedEventArgs e)
+        private bool showMenu;
+
+        public event CancelEventHandler OnCloseEvent;
+        public event EventHandler DoCloseEvent;
+        public event EventHandler LoadComplateEvent;
+
+        public bool ShowMenu
         {
-            Button btn = (Button)sender;
-            double temp = btn.RenderTransform.Value.Determinant;
-            btn.RenderTransformOrigin = new Point(0.5, 0.5);
-            ScaleTransform verticalFlipTransform = new ScaleTransform(1, temp * -1);
-            btn.RenderTransform = verticalFlipTransform;
-            menuTab.ChangeItemVisibility();
+            get { return showMenu; }
+            set
+            {
+                Set(ref showMenu, value);
+                menuTab.ChangeItemVisibility(value);
+            }
         }
 
-        private void window_Loaded(object sender, RoutedEventArgs e)
+
+        private void Button_Click_2(object sender, RoutedEventArgs e)
         {
-            SystemSetting.SystemSettingChanged += SystemSetting_SystemSettingChanged;
+            ShowMenu = !ShowMenu;
+            //Button btn = (Button)sender;
+            //double temp = btn.RenderTransform.Value.Determinant;
+            //btn.RenderTransformOrigin = new Point(0.5, 0.5);
+            //ScaleTransform verticalFlipTransform = new ScaleTransform(1, temp * -1);
+            //btn.RenderTransform = verticalFlipTransform;
+            //menuTab.ChangeItemVisibility();
         }
 
         private void SystemSetting_SystemSettingChanged(object sender, SystemSetting e)
@@ -77,6 +109,67 @@
             RefrshConfig();
         }
 
+        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)
         //{
         //    var s = (Style)this.Resources["WindowButton"];

--
Gitblit v1.9.1