From 9d1660270272180cd71147d6ddd53d1382643d2e Mon Sep 17 00:00:00 2001
From: wenxiangchao <wenxiangchao@ihengxin.com.cn>
Date: 星期一, 02 十一月 2026 18:00:14 +0800
Subject: [PATCH] merge: 并入远程 Initial commit 作为历史根节点

---
 Plugin.TestResult/Cooler.xaml.cs |  218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 218 insertions(+), 0 deletions(-)

diff --git a/Plugin.TestResult/Cooler.xaml.cs b/Plugin.TestResult/Cooler.xaml.cs
new file mode 100644
index 0000000..e4edc93
--- /dev/null
+++ b/Plugin.TestResult/Cooler.xaml.cs
@@ -0,0 +1,218 @@
+锘縰sing HMI.Core.Manager;
+using HMI.UI.Util;
+using PLCHelper;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using System.Timers;
+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.Navigation;
+using System.Windows.Shapes;
+
+namespace Plugin.TestResult
+{
+    /// <summary>
+    /// Cooler.xaml 鐨勪氦浜掗�昏緫
+    /// </summary>
+    public partial class Cooler : UserControl, INotifyPropertyChanged
+    {
+        #region ...
+        public virtual event PropertyChangedEventHandler PropertyChanged;
+
+        protected virtual void Set([CallerMemberName] string name = null)
+        {
+
+            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
+        }
+
+        protected void Set<T>(ref T old, T @new, [CallerMemberName] string propertyName = null)
+        {
+            old = @new;
+            if (propertyName != null)
+            {
+                Set(propertyName);
+            }
+        }
+        #endregion
+
+        public int index { get; private set; }
+
+        public string Title { get; set; }
+
+        private Timer timer;
+
+        public Cooler(int index)
+        {
+            DataContext = this;
+            this.index = index;
+            this.Title = $"绗瑊index + 1}璺按鍐锋満";
+            InitializeComponent();
+        }
+
+        private ushort status;
+        public ushort Status
+        {
+            get => status;
+            set
+            {
+                Set(ref status, value);
+            }
+        }
+
+        private int totalTime;
+
+        private string labelContent = "鍚规按涓�";
+        public string LabelContent
+        {
+            get => labelContent;
+            set
+            {
+                Set(ref labelContent, value);
+            }
+        }
+
+        private void InitTimer(int time)
+        {
+            if (time <= 0)
+            {
+                time = 240;
+            }
+            totalTime = time;
+            LabelContent = $"鍚规按涓璡r\n鍓﹞totalTime}s...";
+            timer = new Timer();
+            timer.Interval = 1000;
+            timer.Elapsed += Timer_Elapsed;
+            timer.Enabled = true;
+        }
+
+        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
+        {
+            try
+            {
+                timer.AutoReset = false;
+                if (totalTime > 0)
+                {
+                    totalTime -= 1;
+                    LabelContent = $"鍚规按涓璡r\n鍓﹞totalTime}s...";
+                }
+                else
+                {
+                    if (S7Context.WriteData("", $"Cooler{index + 1}_Status", 0, out string errMsg))
+                    {
+                        Status = 0;
+                        Dispatcher.Invoke(() =>
+                        {
+                            startBtn.IsEnabled = true;
+                        });
+                    }
+                    else
+                    {
+                        Dispatcher.Invoke(() =>
+                        {
+                            ToastHelper.Error(errMsg);
+                        });
+                    }
+                    Release();
+                }
+            }
+            catch (Exception ex)
+            {
+            }
+            finally
+            {
+                if (timer?.Enabled == true) timer.AutoReset = true;
+            }
+        }
+
+        private void Start_Click(object sender, RoutedEventArgs e)
+        {
+            if (timer != null) return;
+            var btn = sender as Button;
+
+            int totalTime = 240;
+
+            try
+            {
+                var p = ParameterManager.GetCommonParameterByName("鍚规按鏃堕棿")?.Value;
+                if (!string.IsNullOrEmpty(p)) totalTime = int.Parse(p);
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+            if (MsgBoxHelper2.WarnChoose($"绗� [{index + 1}] 璺按鍐锋満纭畾瑕亄btn.Content}鍚�?") == MessageBoxResult.OK)
+            {
+                try
+                {
+                    if (S7Context.WriteData("", $"Cooler{index + 1}_Status", 2, out string errMsg))
+                    {
+                        Status = 2;
+                        InitTimer(totalTime);
+                        btn.IsEnabled = false;
+                    }
+                    else
+                    {
+                        ToastHelper.Error(errMsg);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    ToastHelper.Error(ex.Message);
+                }
+            }
+        }
+
+        private void Stop_Click(object sender, RoutedEventArgs e)
+        {
+            var btn = sender as Button;
+
+            if (MsgBoxHelper2.WarnChoose($"绗� [{index + 1}] 璺按鍐锋満纭畾瑕亄btn.Content}鍚�?") == MessageBoxResult.OK)
+            {
+                try
+                {
+                    if (timer != null)
+                    {
+                        timer.Enabled = false;
+                        timer.Dispose();
+                        timer = null;
+                    }
+
+                    if (S7Context.WriteData("", $"Cooler{index + 1}_Status", 0, out string errMsg))
+                    {
+                        Status = 0;
+                        startBtn.IsEnabled = true;
+                    }
+                    else
+                    {
+                        ToastHelper.Error(errMsg);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    ToastHelper.Error(ex.Message);
+                }
+            }
+        }
+
+        public void Release()
+        {
+            if (timer != null)
+            {
+                timer.Enabled = false;
+                timer.Dispose();
+                timer = null;
+            }
+        }
+    }
+}

--
Gitblit v1.9.1