From 0940f31b7eba1cf6b6a8c1fca72d97cf686e79f2 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期五, 04 七月 2025 10:43:00 +0800
Subject: [PATCH] 优化插件,完善TreeListView

---
 Plugin.TsExecution/SingleControl.xaml.cs |  134 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 102 insertions(+), 32 deletions(-)

diff --git a/Plugin.TsExecution/SingleControl.xaml.cs b/Plugin.TsExecution/SingleControl.xaml.cs
index 8b0cfff..33afb58 100644
--- a/Plugin.TsExecution/SingleControl.xaml.cs
+++ b/Plugin.TsExecution/SingleControl.xaml.cs
@@ -1,4 +1,7 @@
-锘縰sing HMI.Core.Util;
+锘縰sing HMI.Core.Manager;
+using HMI.Core.Util;
+using HMI.UI;
+using HMI.UI.Util;
 using HMI.Util;
 using NationalInstruments.TestStand.Interop.API;
 using Plugin.TsExecution.Entity;
@@ -7,6 +10,7 @@
 using System.ComponentModel;
 using System.IO;
 using System.Runtime.CompilerServices;
+using System.Threading;
 using System.Timers;
 using System.Windows;
 using System.Windows.Controls;
@@ -58,15 +62,15 @@
             }
         }
 
-        private double passNum;
-        public double PassNum
+        private int passNum;
+        public int PassNum
         {
             get => passNum;
             private set { Set(ref passNum, value); }
         }
 
-        private double failNum;
-        public double FailNum
+        private int failNum;
+        public int FailNum
         {
             get => failNum;
             private set { Set(ref failNum, value); }
@@ -135,7 +139,7 @@
         private DateTime TimeNow = new DateTime();
         private TimeSpan TimeCount = new TimeSpan();
 
-        private Timer refreshTimer;
+        private System.Timers.Timer refreshTimer;
 
         private string currentStep = "绛夊緟鎵爜";
         public string CurrentStep
@@ -198,6 +202,16 @@
 
         public int ProbeWarn { get; private set; }
 
+        private bool isAutoMode;
+        public bool IsAutoMode
+        {
+            get => isAutoMode;
+            set
+            {
+                Set(ref isAutoMode, value);
+            }
+        }
+
         public SingleControl(int Index, string CountIniPath, int probeWarn)
         {
             this.CountIniPath = CountIniPath;
@@ -205,7 +219,7 @@
             this.index = Index;
             ProbeWarn = probeWarn;
 
-            refreshTimer = new Timer()
+            refreshTimer = new System.Timers.Timer()
             {
                 Interval = 100
             };
@@ -213,6 +227,15 @@
             ReadProbeCount();
             ReadCounter();
             InitializeComponent();
+            try
+            {
+                var value = ParameterManager.GetCommonParameterByName("AutoTestMode");
+                IsAutoMode = bool.Parse(value.Value);
+            }
+            catch
+            {
+                IsAutoMode = true;
+            }
             //if (ProbeWarn > 0)
             //{
             //    probeWarnPanel.Visibility = Visibility.Visible;
@@ -328,16 +351,20 @@
             if (result == true)
             {
                 PassNum += 1;
+                //Interlocked.Increment(ref passNum);
+                //Set("PassNum");
             }
             else if (result == false)
             {
                 FailNum += 1;
+                //Interlocked.Increment(ref failNum);
+                //Set("FailNum");
             }
 
             TotalNum = PassNum + FailNum;
             if (TotalNum != 0)
             {
-                PassRate = (PassNum / TotalNum);
+                PassRate = ((double)PassNum / TotalNum);
             }
             else
             {
@@ -408,34 +435,37 @@
 
         public void WriteToCSV(string path)
         {
-            try
+            Dispatcher.BeginInvoke(new Action(() =>
             {
-
-                FileInfo fi = new FileInfo(path);
-                if (!fi.Directory.Exists)
+                try
                 {
-                    fi.Directory.Create();  //鏂囦欢涓嶅瓨鍦紝鍒涘缓鏂囦欢
-                }
 
-                using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
-                using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8))
-                {
-                    string title = "椤圭洰鍚嶇О,娴嬭瘯鍙傛暟,娴嬭瘯鍊�,涓婇檺,涓嬮檺,鍗曚綅,缁撴灉";
-                    sw.WriteLine(title);
-
-                    if (Datasource != null && Datasource.Count > 0)
+                    FileInfo fi = new FileInfo(path);
+                    if (!fi.Directory.Exists)
                     {
-                        foreach (var data in Datasource)
+                        fi.Directory.Create();  //鏂囦欢涓嶅瓨鍦紝鍒涘缓鏂囦欢
+                    }
+
+                    using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write))
+                    using (StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.UTF8))
+                    {
+                        string title = "椤圭洰鍚嶇О,娴嬭瘯鍙傛暟,娴嬭瘯鍊�,涓婇檺,涓嬮檺,鍗曚綅,缁撴灉";
+                        sw.WriteLine(title);
+
+                        if (Datasource != null && Datasource.Count > 0)
                         {
-                            sw.WriteLine($"{data.Name},{data.Step},{data.Value},{data.LimitUp},{data.LimitDown},{data.Unit},{data.Result}");
+                            foreach (var data in Datasource)
+                            {
+                                sw.WriteLine($"{data.Name},{data.Step},{data.Value},{data.LimitUp},{data.LimitDown},{data.Unit},{data.Result}");
+                            }
                         }
                     }
                 }
-            }
-            catch (Exception ex)
-            {
-                TsExecution.logger.Error("Write CSV File Failed.", ex);
-            }
+                catch (Exception ex)
+                {
+                    TsExecution.logger.Error("Write CSV File Failed.", ex);
+                }
+            }));
         }
 
         public void ShowPausePanel()
@@ -459,17 +489,57 @@
                     SequenceFileContext?.StationGlobals.SetValBoolean($"StationState.IsContinue_{index}", 1, true);
                     pausePanel.Visibility = Visibility.Collapsed;
                     break;
+                case "scannerSetting":
+                    //ScannerSetting setting = new ScannerSetting()
+                    //{
+                    //    Owner = Window.GetWindow(this)
+                    //};
+                    //setting.Open(true, $"Socket{index}", CountIniPath);
+                    ShowScannerPanel();
+                    break;
+                case "scannerOkBtn":
+                    SendSnr2Ts();
+                    break;
                 default:
                     break;
+            }
+        }
+        public void ShowScannerPanel()
+        {
+            scannerPanel.Visibility = Visibility.Visible;
+        }
+
+        private void SendSnr2Ts()
+        {
+            try
+            {
+                string snr = TbManualSnr.Text;
+                SequenceFileContext?.StationGlobals.SetValString($"StationState.SN[{index}]", 1, snr);
+                scannerPanel.Visibility = Visibility.Collapsed;
+                TbManualSnr.Text = string.Empty;
+            }
+            catch (Exception ex)
+            {
+                ToastHelper.Error(ex.Message);
             }
         }
 
         private void pausePanel_Loaded(object sender, RoutedEventArgs e)
         {
-            var can = pausePanel;
-            var modal = visualModal;
-            Canvas.SetLeft(modal, (pausePanel.ActualWidth - visualModal.ActualWidth) / 2);
-            Canvas.SetTop(modal, (pausePanel.ActualHeight - visualModal.ActualHeight) / 2);
+            if (sender == pausePanel)
+            {
+                var can = pausePanel;
+                var modal = visualModal;
+                Canvas.SetLeft(modal, (pausePanel.ActualWidth - visualModal.ActualWidth) / 2);
+                Canvas.SetTop(modal, (pausePanel.ActualHeight - visualModal.ActualHeight) / 2);
+            }
+            else
+            {
+                var can = scannerPanel;
+                var modal = scannerVisualModal;
+                Canvas.SetLeft(modal, (scannerPanel.ActualWidth - scannerVisualModal.ActualWidth) / 2);
+                Canvas.SetTop(modal, (scannerPanel.ActualHeight - scannerVisualModal.ActualHeight) / 2);
+            }
         }
     }
 }

--
Gitblit v1.9.1