1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using HMI.Core.Util;
using HMI.UI.Util;
using Panuon.WPF.UI;
using Plugin.TestResult_WPF.Model;
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
 
namespace Plugin.TestResult_WPF
{
    /// <summary>
    /// InfoWindow.xaml 的交互逻辑
    /// </summary>
    public partial class InfoWindow : WindowX
    {
 
        private string _title;
        public string title
        {
            get => _title;
            set => Set(ref _title, value);
        }
 
        private ObservableCollection<Info> _dataSource;
 
        public ObservableCollection<Info> dataSource
        {
            get => _dataSource == null ? new ObservableCollection<Info>() : _dataSource;
            set => Set(ref _dataSource, value);
        }
        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();
 
 
            UpdateProbeCount(probeCount, probeWarn);
            int row = 1;
            foreach (var chart in charts)
            {
                if (chart == null) return;
                mainGrid.Children.Add(chart);
                Grid.SetRow(chart, row++);
            }
 
            //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;
 
        private int probeCount;
        public int ProbeCount
        {
            get => probeCount;
            set
            {
                Set(ref probeCount, value);
            }
        }
 
        public int ProbeWarn
        {
            get;
            set;
        }
 
        public void UpdateProbeCount(int count, int warn)
        {
            Dispatcher.Invoke(() =>
            {
                ProbeCount = count;
                ProbeWarn = warn;
 
                if (ProbeWarn < 0)
                {
                    alarmLabel.Visibility = Visibility.Collapsed;
                    alarmValue.Visibility = Visibility.Collapsed;
                }
                else
                {
                    probeCountAlarm.Visibility = (ProbeCount >= ProbeWarn) ? 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)
        {
            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;
            //}
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (MsgBoxHelper.WarnMessage(this, this.lang("Ts.MakeSureToClearProbeCount")) == MessageBoxResult.OK)
            {
                ClearProbeCountEvent?.Invoke(this, null);
            }
        }
    }
}