From dedcf4174c8540ee3a912daad2ff13e014e495b1 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 28 三月 2025 16:28:30 +0800
Subject: [PATCH] 优化UI组件;

---
 Plugin.TestResult/Scanner.xaml.cs |   64 ++++++++++++-------------------
 1 files changed, 25 insertions(+), 39 deletions(-)

diff --git a/Plugin.TestResult/Scanner.xaml.cs b/Plugin.TestResult/Scanner.xaml.cs
index 7e80db7..72c0bd4 100644
--- a/Plugin.TestResult/Scanner.xaml.cs
+++ b/Plugin.TestResult/Scanner.xaml.cs
@@ -1,19 +1,10 @@
-锘縰sing System;
-using System.Collections.Generic;
+锘縰sing HMI.Core.Util;
+using HMI.UI.Util;
+using Panuon.WPF.UI;
+using System;
 using System.ComponentModel;
 using System.IO.Ports;
-using System.Linq;
-using System.Runtime.CompilerServices;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Shapes;
 
 namespace Plugin.TestResult_WPF
 {
@@ -34,29 +25,14 @@
     /// <summary>
     /// Scanner.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
-    public partial class Scanner : Window, INotifyPropertyChanged
+    public partial class Scanner : WindowX
     {
-        #region ...
-        public event PropertyChangedEventHandler PropertyChanged;
-
-        public virtual void RaisePropertyChanged(string name)
-        {
-            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
-        }
-
-        public void RaiseAndSetIfchanged<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
-        {
-            old = @new;
-            if (propertyName != null) RaisePropertyChanged(propertyName);
-        }
-        #endregion
-
         private string _title;
 
         public string title
         {
             get { return _title; }
-            set => RaiseAndSetIfchanged(ref _title, value);
+            set => Set(ref _title, value);
         }
 
         public event EventHandler<BarcodeEventArg> FinishBarcode;
@@ -68,7 +44,13 @@
             this.title = title;
             this.DataContext = this;
             InitializeComponent();
+            Loaded += Scanner_Loaded;
+        }
+
+        private void Scanner_Loaded(object sender, RoutedEventArgs e)
+        {
             InitScanner();
+            Loaded -= Scanner_Loaded;
         }
 
         /// <summary>
@@ -78,7 +60,7 @@
         {
             string comStr = "";
             if (serialPort != null) return;
-            if (this.title == "涓�鍖烘壂鐮�")
+            if (this.Tag == "Zone1")
             {
                 comStr = "COM1";
             }
@@ -112,7 +94,8 @@
             }
             catch (Exception ex)
             {
-                MessageBox.Show($"鍒濆鍖栨壂鐮佹灙澶辫触锛亄ex.StackTrace}");
+                ViewControl.Logger.Error("Init Scan Gun Failed.", ex);
+                MsgBoxHelper.Error(this, $"{this.lang("Tr.InitGunFailed")}: {ex.StackTrace}");
             }
         }
 
@@ -142,7 +125,8 @@
             }
             catch (Exception ex)
             {
-                MessageBox.Show($"鑾峰彇鎵爜鏋暟鎹け璐ワ紒{ex.StackTrace}");
+                ViewControl.Logger.Error("Get Scan Gun Data Failed.", ex);
+                MessageBox.Show($"{this.lang("Tr.GetGunData")}: {ex.StackTrace}");
             }
         }
 
@@ -153,19 +137,20 @@
                 string position = positionText.Text, snr = snrText.Text;
                 if (string.IsNullOrEmpty(position) || string.IsNullOrEmpty(snr))
                 {
-                    MessageBox.Show("璇疯緭鍏ュ偍浣嶆潯鐮佸拰浜у搧鏉$爜");
+                    ToastHelper.Warning(this, this.lang("Tr.PleaseInputSnrs"));
                     return;
                 }
                 try
                 {
-                    FinishBarcode.Invoke(this, new BarcodeEventArg(title, position, snr));
+                    FinishBarcode.Invoke(this, new BarcodeEventArg(Tag.ToString(), position, snr));
                     //positionText.Text = "";
                     //snrText.Text = "";
                     positionText.Focus();
                 }
                 catch (Exception ex)
                 {
-                    MessageBox.Show(ex.Message);
+                    ViewControl.Logger.Error("Con_Click Failed.", ex);
+                    ToastHelper.Warning(this, ex.Message);
                 }
             });
         }
@@ -175,17 +160,18 @@
             string position = positionText.Text, snr = snrText.Text;
             if (string.IsNullOrEmpty(position) || string.IsNullOrEmpty(snr))
             {
-                MessageBox.Show("璇疯緭鍏ュ偍浣嶆潯鐮佸拰浜у搧鏉$爜");
+                ToastHelper.Warning(this, this.lang("Tr.PleaseInputSnrs"));
                 return;
             }
             try
             {
-                FinishBarcode.Invoke(this, new BarcodeEventArg(title, position, snr));
+                FinishBarcode.Invoke(this, new BarcodeEventArg(Tag.ToString(), position, snr));
                 this.Close();
             }
             catch (Exception ex)
             {
-                MessageBox.Show(ex.Message);
+                ViewControl.Logger.Error("Con_Click Failed.", ex);
+                ToastHelper.Warning(this, ex.Message);
             }
         }
 

--
Gitblit v1.9.1