From e3868d4d61ded0e76fc8fe3fdacdd9e6d9113cf1 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期一, 13 十月 2025 08:50:15 +0800
Subject: [PATCH] 优化HMI;

---
 Plugin.JarUI/JarUI.xaml.cs |  159 ++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 146 insertions(+), 13 deletions(-)

diff --git a/Plugin.JarUI/JarUI.xaml.cs b/Plugin.JarUI/JarUI.xaml.cs
index cdaea7c..6ee24d7 100644
--- a/Plugin.JarUI/JarUI.xaml.cs
+++ b/Plugin.JarUI/JarUI.xaml.cs
@@ -14,7 +14,6 @@
 using System.IO;
 using System.IO.Ports;
 using System.Linq;
-using System.Reflection;
 using System.Windows;
 using System.Windows.Controls;
 
@@ -29,8 +28,8 @@
         {
             DataContext = this;
             InitializeComponent();
-            InitProducts();
             InitTsEngine();
+            InitProducts();
         }
 
         public override void InitFinish()
@@ -97,8 +96,21 @@
             get { return _selectedProduct; }
             set
             {
-                SetTestSeqFile(value);
                 Set(ref _selectedProduct, value);
+                SetTestSeqFile(value);
+            }
+        }
+
+        private bool _enableMes;
+        public bool EnableMes
+        {
+            get => _enableMes;
+            set
+            {
+                if (WriteConfig("EnableMes", value))
+                {
+                    Set(ref _enableMes, value);
+                }
             }
         }
 
@@ -156,17 +168,130 @@
                 if (!string.IsNullOrEmpty(lastModel))
                 {
                     var product = Products.FirstOrDefault(p => p.Name == lastModel);
-                    if (product != null) SelectedProduct = product;
-                    goto Write;
+                    if (product != null)
+                    {
+                        SelectedProduct = product;
+                        RefershUI();
+                        return;
+                    }
                 }
-                goto Write;
-
-            Write:
                 SelectedProduct = Products[0];
-                engine?.Globals.SetValString("StationState.ProductModel", 1, Products[0].Name);
-
                 RefershUI();
             }
+        }
+
+        private bool WriteConfig(string name, bool value)
+        {
+            //IniFileHelper.WriteIniData("Config", name, value.ToString(), CountIniPath);
+            try
+            {
+                if (ParameterManager.UpdateCommonParameter(name, value, out string errMsg))
+                {
+                    SequenceContext?.StationGlobals.SetValBoolean($"SystemSetting.{name}", 1, value);
+                    return true;
+                }
+                else
+                {
+                    throw new Exception(errMsg);
+                }
+            }
+            catch (Exception ex)
+            {
+                MsgBoxHelper2.Error(ex.Message);
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 璇诲彇閰嶇疆鏂囦欢閲岀殑鍑犱釜灞炴��
+        /// </summary>
+        /// <param name="pass"></param>
+        /// <param name="fail"></param>
+        private void ReadConfig()
+        {
+            ParameterData value;
+            try
+            {
+                value = ParameterManager.GetCommonParameterByName("EnableMes");
+                _enableMes = bool.Parse(value.Value);
+                Set("EnableMes");
+            }
+            catch
+            {
+                _enableMes = false;
+                Set("EnableMes");
+            }
+
+            //try
+            //{
+            //    value = ParameterManager.GetCommonParameterByName("EnableNGPause");
+            //    _enableNGPause = bool.Parse(value.Value);
+            //    Set("EnableNGPause");
+            //}
+            //catch
+            //{
+            //    _enableNGPause = false;
+            //    Set("EnableNGPause");
+            //}
+
+            //try
+            //{
+            //    value = ParameterManager.GetCommonParameterByName("EnableCanLog");
+            //    _enableCanLog = bool.Parse(value.Value);
+            //    Set("EnableCanLog");
+            //}
+            //catch
+            //{
+            //    _enableCanLog = false;
+            //    Set("EnableCanLog");
+            //}
+
+            //try
+            //{
+            //    value = ParameterManager.GetCommonParameterByName("EnableDebugMode");
+            //    _enableDebugMode = bool.Parse(value.Value);
+            //    Set("EnableDebugMode");
+            //}
+            //catch
+            //{
+            //    _enableDebugMode = false;
+            //    Set("EnableDebugMode");
+            //}
+
+            //try
+            //{
+            //    value = ParameterManager.GetCommonParameterByName("EnableSimpleMode");
+            //    EnableSimpleMode = bool.Parse(value.Value);
+            //}
+            //catch
+            //{
+            //    EnableSimpleMode = false;
+            //}
+
+            //try
+            //{
+            //    value = ParameterManager.GetCommonParameterByName("UI_ShowInfoDock");
+            //    UI_ShowInfoDock = bool.Parse(value.Value);
+            //}
+            //catch
+            //{
+            //    UI_ShowInfoDock = false;
+            //}
+
+            //try
+            //{
+
+            //    value = ParameterManager.GetCommonParameterByName("TestReportFolder");
+            //    csvDir = value.Value;
+            //    if (!Directory.Exists(csvDir))
+            //    {
+            //        Directory.CreateDirectory(csvDir);
+            //    }
+            //}
+            //catch
+            //{
+            //    csvDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TestReport");
+            //}
         }
 
         #region 鎵爜鏋浉鍏�
@@ -203,7 +328,10 @@
             catch (Exception ex)
             {
                 log.Error("Init Scan Gun Failed.", ex);
-                MsgBoxHelper.Error(this, $"{this.lang("Tr.InitGunFailed")}: {ex.StackTrace}");
+                Dispatcher.Invoke(() =>
+                {
+                    MsgBoxHelper.Error(this, $"{this.lang("Tr.InitGunFailed")}: {ex.StackTrace}");
+                });
             }
         }
         private string ReadDataFrom(SerialPort sp)
@@ -343,7 +471,10 @@
                     catch (Exception ex)
                     {
                         log.Error("TsExecution Loaded Failed.", ex);
-                        MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.UserControlLoadFailed")}: {ex.Message}");
+                        Dispatcher.Invoke(() =>
+                        {
+                            MsgBoxHelper.Error(this, $"{LangUtil.Get("Ts.UserControlLoadFailed")}: {ex.Message}");
+                        });
                     }
                     Dispatcher.Invoke(() =>
                     {
@@ -362,6 +493,8 @@
             try
             {
                 if (!isLoadOk) return;
+                engine?.Globals.SetValString("StationState.ProductModel", 1, SelectedProduct?.Name);
+                engine?.CommitGlobalsToDisk(promptOnSaveConflicts: false);
                 this.modeSeq = this.engine.GetSequenceFileEx(@"C:\Program Files\National Instruments\TestStand 2020\Components\Models\TestStandModels\ParallelModel.seq");
                 this.testSeq = this.engine.GetSequenceFileEx(this.testSeqFile, 0, TypeConflictHandlerTypes.ConflictHandler_UseGlobalType);
                 this.execution = this.engine.NewExecution(this.testSeq, "Test UUTs", this.modeSeq, false, 0, null, null, null);
@@ -458,7 +591,7 @@
 
                 try
                 {
-                    log.Info($"Event: {EventCase}, NumericData: {MethodCode}, StringData: {strData}");
+                    //log.Info($"Event: {EventCase}, NumericData: {MethodCode}, StringData: {strData}");
                 }
                 catch
                 {

--
Gitblit v1.9.1