From 99df058a665ea04065a23e729ec79a2f23f79881 Mon Sep 17 00:00:00 2001
From: alielie <alielie@git.com>
Date: 星期二, 20 五月 2025 16:59:43 +0800
Subject: [PATCH] 优化

---
 Plugin.TestResult/InfoWindow.xaml.cs |  132 ++++++++++++++++++++++++++++++++++++--------
 1 files changed, 108 insertions(+), 24 deletions(-)

diff --git a/Plugin.TestResult/InfoWindow.xaml.cs b/Plugin.TestResult/InfoWindow.xaml.cs
index bb085f8..58b265e 100644
--- a/Plugin.TestResult/InfoWindow.xaml.cs
+++ b/Plugin.TestResult/InfoWindow.xaml.cs
@@ -1,37 +1,30 @@
-锘縰sing Plugin.TestResult_WPF.Model;
+锘縰sing HMI.Core.Api;
+using HMI.Core.Entity;
+using HMI.Core.Manager;
+using HMI.Core.Util;
+using HMI.UI.Util;
+using Panuon.WPF.UI;
+using Plugin.TestResult_WPF.Model;
+using System;
+using System.Collections.Generic;
 using System.Collections.ObjectModel;
-using System.ComponentModel;
-using System.Runtime.CompilerServices;
+using System.Linq;
 using System.Windows;
+using System.Windows.Controls;
 
 namespace Plugin.TestResult_WPF
 {
     /// <summary>
     /// InfoWindow.xaml 鐨勪氦浜掗�昏緫
     /// </summary>
-    public partial class InfoWindow : Window, INotifyPropertyChanged
+    public partial class InfoWindow : 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 => _title;
-            set => RaiseAndSetIfchanged(ref _title, value);
+            set => Set(ref _title, value);
         }
 
         private ObservableCollection<Info> _dataSource;
@@ -39,20 +32,111 @@
         public ObservableCollection<Info> dataSource
         {
             get => _dataSource == null ? new ObservableCollection<Info>() : _dataSource;
-            set => RaiseAndSetIfchanged(ref _dataSource, value);
+            set => Set(ref _dataSource, value);
         }
-
-        public InfoWindow(string title, ObservableCollection<Info> infos)
+        private Chart electricChart;
+        public InfoWindow(string title, ObservableCollection<Info> infos, Chart electricChart, int probeCount)
         {
             this.title = title;
             this.dataSource = infos;
-            this.DataContext = this;
+            DataContext = this;
+            Topmost = false;
             InitializeComponent();
+
+            if (AlarmProbeCount < 0)
+            {
+                alarmLabel.Visibility = Visibility.Collapsed;
+                alarmValue.Visibility = Visibility.Collapsed;
+            }
+            UpdateProbeCount(probeCount);
+
+            this.electricChart = electricChart;
+            mainGrid.Children.Add(electricChart);
+            Grid.SetRow(electricChart, 1);
         }
+
+        private static int AlarmProbeCount;
+        static InfoWindow()
+        {
+            int probeWarn = -1;
+            try
+            {
+                probeWarn = Convert.ToInt32(ParameterManager.GetCommonParameter<List<ParameterData>>()
+                    .FirstOrDefault(x => x.Name == "ProbeWarn")?.Value);
+            }
+            catch (Exception ex)
+            {
+                probeWarn = -1;
+            }
+            AlarmProbeCount = probeWarn;
+        }
+
+        public event EventHandler ClearProbeCountEvent;
+
+        private int probeCount;
+        public int ProbeCount
+        {
+            get => probeCount;
+            set
+            {
+                Set(ref probeCount, value);
+            }
+        }
+
+        public int ProbeWarn
+        {
+            get => AlarmProbeCount;
+            set { }
+        }
+        public void UpdateProbeCount(int count)
+        {
+            Dispatcher.Invoke(() =>
+            {
+                ProbeCount = count;
+                if (AlarmProbeCount >= 0)
+                {
+                    probeCountAlarm.Visibility = (ProbeCount >= AlarmProbeCount) ? Visibility.Visible : Visibility.Collapsed;
+                }
+            });
+        }
+
 
         public void UpdateSource(ObservableCollection<Info> infos)
         {
             this.dataSource = infos;
         }
+
+        private void Window_Loaded(object sender, RoutedEventArgs e)
+        {
+            DataContext = this;
+        }
+
+        private void Window_Unloaded(object sender, RoutedEventArgs e)
+        {
+            DataContext = null;
+        }
+
+        protected override void OnClosed(EventArgs e)
+        {
+            electricChart = null;
+            mainGrid.Children.Clear();
+            base.OnClosed(e);
+        }
+
+        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
+        {
+            if (electricChart != null)
+            {
+                electricChart.Height = this.ActualHeight * 0.3;
+            }
+        }
+
+        private void Button_Click(object sender, RoutedEventArgs e)
+        {
+            if (MsgBoxHelper.WarnMessage(this, "纭畾瑕佹竻绌烘帰閽堜娇鐢ㄦ鏁板悧锛�") == MessageBoxResult.OK)
+            {
+                ClearProbeCountEvent?.Invoke(this, null);
+            }
+        }
     }
 }

--
Gitblit v1.9.1