alielie
2026-03-02 12e606635c42ea20f4b7c2bdda5204237a4b4c96
Plugin.TestResult/InfoWindow.xaml.cs
@@ -1,14 +1,9 @@
using HMI.Core.Api;
using HMI.Core.Entity;
using HMI.Core.Manager;
using HMI.Core.Util;
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.Linq;
using System.Windows;
using System.Windows.Controls;
@@ -34,41 +29,72 @@
            get => _dataSource == null ? new ObservableCollection<Info>() : _dataSource;
            set => Set(ref _dataSource, value);
        }
        private Chart electricChart;
        public InfoWindow(string title, ObservableCollection<Info> infos, Chart electricChart, int probeCount)
        private LiveChart waterChart;
        private LiveChart electricChart;
        private LiveChart vChart;
        //public InfoWindow(string title, ObservableCollection<Info> infos, Chart waterChart, Chart electricChart, Chart vChart, int probeCount, int probeWarn)
        //{
        //    this.title = title;
        //    this.dataSource = infos;
        //    DataContext = this;
        //    Topmost = false;
        //    this.ProbeWarn = probeWarn;
        //    InitializeComponent();
        //    UpdateProbeCount(probeCount,probeWarn);
        //    if (waterChart != null)
        //    {
        //        this.waterChart = waterChart;
        //        mainGrid.Children.Add(waterChart);
        //        Grid.SetRow(waterChart, 1);
        //    }
        //    this.electricChart = electricChart;
        //    mainGrid.Children.Add(electricChart);
        //    Grid.SetRow(electricChart, 2);
        //    this.vChart = vChart;
        //    mainGrid.Children.Add(vChart);
        //    Grid.SetRow(vChart, 3);
        //}
        public InfoWindow(string title, ObservableCollection<Info> infos, LiveChart[] charts, int probeCount, int probeWarn)
        {
            this.title = title;
            this.dataSource = infos;
            DataContext = this;
            Topmost = false;
            this.ProbeWarn = probeWarn;
            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);
        }
            UpdateProbeCount(probeCount, probeWarn);
            int row = 1;
            foreach (var chart in charts)
            {
                if (chart == null) return;
                mainGrid.Children.Add(chart);
                Grid.SetRow(chart, row++);
            }
        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;
            //if (waterChart != null)
            //{
            //    this.waterChart = waterChart;
            //    mainGrid.Children.Add(waterChart);
            //    Grid.SetRow(waterChart, 1);
            //}
            //this.electricChart = electricChart;
            //mainGrid.Children.Add(electricChart);
            //Grid.SetRow(electricChart, 2);
            //this.vChart = vChart;
            //mainGrid.Children.Add(vChart);
            //Grid.SetRow(vChart, 3);
        }
        public event EventHandler ClearProbeCountEvent;
@@ -85,21 +111,28 @@
        public int ProbeWarn
        {
            get => AlarmProbeCount;
            set { }
            get;
            set;
        }
        public void UpdateProbeCount(int count)
        public void UpdateProbeCount(int count, int warn)
        {
            Dispatcher.Invoke(() =>
            {
                ProbeCount = count;
                if (AlarmProbeCount >= 0)
                ProbeWarn = warn;
                if (ProbeWarn < 0)
                {
                    probeCountAlarm.Visibility = (ProbeCount >= AlarmProbeCount) ? Visibility.Visible : Visibility.Collapsed;
                    alarmLabel.Visibility = Visibility.Collapsed;
                    alarmValue.Visibility = Visibility.Collapsed;
                }
                else
                {
                    probeCountAlarm.Visibility = (ProbeCount >= ProbeWarn) ? Visibility.Visible : Visibility.Collapsed;
                }
            });
        }
        public void UpdateSource(ObservableCollection<Info> infos)
        {
@@ -118,22 +151,24 @@
        protected override void OnClosed(EventArgs e)
        {
            waterChart = null;
            electricChart = null;
            vChart = null;
            mainGrid.Children.Clear();
            base.OnClosed(e);
        }
        private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (electricChart != null)
            {
                electricChart.Height = this.ActualHeight * 0.3;
            }
            //if (electricChart != null)
            //{
            //    electricChart.Height = this.ActualHeight * 0.3;
            //}
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (MsgBoxHelper.WarnMessage(this, "确定要清空探针使用次数吗?") == MessageBoxResult.OK)
            if (MsgBoxHelper.WarnMessage(this, this.lang("Ts.MakeSureToClearProbeCount")) == MessageBoxResult.OK)
            {
                ClearProbeCountEvent?.Invoke(this, null);
            }