ningshuxia
2025-03-31 d321346f204a69b1929cc39098a5d88f44509e7b
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
using DevExpress.XtraEditors;
using IStation.Unit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class DataScreeningPage : DocumentPage
    {
        public DataScreeningPage()
        {
            InitializeComponent();
            PageTitle.Caption = "数据筛选";
            monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent;
            monitorPointTreeList1.FocusedChangedEvent += MonitorPointTreeList1_FocusedChangedEvent;
            timeValueEasyChartView1.BoxSelCompleteEvent += TimeValueEasyChartView1_BoxSelCompleteEvent;
        }
 
 
        private Model.MonitorDataSources _dataSource = null;
        private Model.MonitorPointExSignalWithSignalType _model = null;
        private BLL.MonitorDataSet _bll = new BLL.MonitorDataSet();
        private List<TimeValue> _allBindList = null;
        private const string delete = "delete";
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            _allBindList = new List<TimeValue>();
            timeValueEasyChartView1.InitialDefaultSeries(_allBindList);
            timeValueEasyChartView1.SetTimeAxisX(DevExpress.XtraCharts.DateTimeMeasureUnit.Minute);
            monitorDataSourcesTreeList.SetBindingData();
            monitorPointTreeList1.SetBindingData();
        }
 
        private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj)
        {
            SetBindingData(obj, _model);
        }
 
        private void MonitorPointTreeList1_FocusedChangedEvent(Model.MonitorPointExSignalWithSignalType obj)
        {
            SetBindingData(_dataSource, obj);
        }
 
        private void SetBindingData(Model.MonitorDataSources scene, Model.MonitorPointExSignalWithSignalType obj)
        {
            _dataSource = scene;
            _model = obj;
            _allBindList = new List<TimeValue>();
            if (_dataSource == null || _model == null)
            {
                timeValueEasyChartView1.SetAxisYTitle("?");
                timeValueEasyChartView1.InitialDefaultSeries(null);
            }
            else
            {
 
                if (int.TryParse(_model.UnitValue, out int unitValue))
                {
                    var dict = UnitHelper.GetEnUnitDict(_model.UnitType);
                    if (dict != null)
                        timeValueEasyChartView1.SetAxisYTitle(dict[unitValue]);
                }
                else
                {
                    timeValueEasyChartView1.SetAxisYTitle(_model.UnitValue);
                }
                var packet = _bll.GetSignalRecordPacket(_dataSource.ID, _model.MonitorPointID, _model.SignalID);
                if (packet != null && packet.RecordList != null)
                {
                    var validList = packet.RecordList.Where(x => x.Value != IStation.Error.Default && x.Value != IStation.Error.Abnormal);
                    if (validList != null && validList.Any())
                    {
                        _allBindList = validList.Select(x => new TimeValue(x.Time, x.Value)).ToList();
                    }
                }
            }
 
            timeValueEasyChartView1.InitialDefaultSeries(_allBindList);
        }
 
        private void TimeValueEasyChartView1_BoxSelCompleteEvent(string tag, List<TimeValue> timeValues)
        {
            if (timeValues == null || timeValues.Count < 1)
                return;
            var times = timeValues.Select(x => x.Time);
            switch (tag)
            {
                case delete:
                    {
                        Delete(times);
                    }
                    break;
                default:
                    break;
            }
        }
 
 
 
        //删除
        private void Delete(IEnumerable<DateTime> times)
        {
            if (_dataSource == null)
                return;
            WaitFrmHelper.ShowWaitForm("正在删除...");
            if (times == null || times.Count() < 1)
            {
                XtraMessageBox.Show("无数据!");
                return;
            }
            var bol = new BLL.MonitorDataSet().SetAbnormal(_dataSource.ID, _model.MonitorPointID, _model.SignalID, times, IStation.Error.Default);
            if (!bol)
            {
                XtraMessageBox.Show("删除失败!");
                return;
            }
            for (int i = 0; i < _allBindList.Count; i++)
            {
                var point = _allBindList[i];
                if (times.Contains(point.Time))
                {
                    _allBindList.RemoveAt(i);
                    i--;
                }
            }
            timeValueEasyChartView1.InitialDefaultSeries(_allBindList);
            WaitFrmHelper.HideWaitForm();
            XtraMessageBox.Show("删除成功!");
        }
 
 
        //框选删除
        public void Delete()
        {
            timeValueEasyChartView1.StartBoxSel(delete);
        }
 
        //区间删除
        public void RangeDelete()
        {
            var dlg = new SetRangeDlg();
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            var times = _allBindList?.Where(x => x.Value >= dlg.MinValue && x.Value <= dlg.MaxValue).Select(x => x.Time).ToList();
            if (times == null || times.Count < 1)
            {
                XtraMessageBox.Show("未检索到区间值!");
                return;
            }
            Delete(times);
        }
 
        //清除负值
        public void ClearNegativeValues()
        {
            if (XtraMessageBox.Show("确认清除所有负值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                return;
            var times = _allBindList?.Where(x => x.Value < 0).Select(x => x.Time).ToList();
            if (times == null || times.Count < 1)
            {
                XtraMessageBox.Show("未检索到负值!");
                return;
            }
            Delete(times);
        }
 
        //清除零值
        public void ClearZer0()
        {
            if (XtraMessageBox.Show("确认清除所有负值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                return;
            var times = _allBindList?.Where(x => x.Value == 0).Select(x => x.Time).ToList();
            if (times == null || times.Count < 1)
            {
                XtraMessageBox.Show("未检索到零值!");
                return;
            }
            Delete(times);
        }
 
        // 刷新数据
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var t = _allBindList?.OrderBy(x => x.Value).LastOrDefault();
            if (t != null)
            {
                XtraMessageBox.Show($"{t.Time}:{t.Value:N3}米");
                return;
            }
            InitialDataSource();
        }
 
 
 
        //修正运行状态
        private void barBtnCorrectRunStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_model == null)
            {
                return;
            }
            if (_model.SignalType != IStation.SignalType.运行状态)
            {
                XtraMessageBox.Show("请选择运行状态测点!");
                return;
            }
 
            var monitor_points = new BLL.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID
                (_model.BelongType, _model.BelongID, _model.GroupID);
            var rpm_mp = monitor_points?.Find(x => x.SignalType == IStation.SignalType.转速);
            if (rpm_mp == null)
            {
                XtraMessageBox.Show("不存在转速测点!");
                return;
            }
 
            var rpm_packet_list = _bll.GetMonitorDataSet(_dataSource.ID, rpm_mp.MonitorPointID);
            if (rpm_packet_list == null || !rpm_packet_list.Any())
            {
                XtraMessageBox.Show("不存在转速数据!");
                return;
            }
            var bol = _bll.Clear(_dataSource.ID, _model.MonitorPointID, _model.SignalID);
            if (!bol)
            {
                XtraMessageBox.Show("运行状态数据清空失败!");
                return;
            }
            foreach (var rpm_packet in rpm_packet_list)
            {
                var rpm_record_list = rpm_packet.PacketList
                    .SelectMany(x => x.RecordList).ToList();
                var rpm_run_status_record_list = rpm_record_list.Select(x => new Model.SignalRecord(x.Time, x.Value > 10 ? 1 : 0))
                    .ToList();
                _bll.Save(_dataSource.ID, _model.MonitorPointID, _model.SignalID, rpm_run_status_record_list, rpm_packet.Year, rpm_packet.Month);
            }
 
 
        }
 
        private void barBtnQueryMinAndMaxRpmFlow_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_model == null)
            {
                return;
            }
 
            if (_model.SignalType != IStation.SignalType.转速)
            {
                XtraMessageBox.Show("请选择转速测点!");
                return;
            }
            var rpm_packet_list = _bll.GetMonitorDataSet(_dataSource.ID, _model.MonitorPointID);
            if (rpm_packet_list == null || !rpm_packet_list.Any())
            {
                XtraMessageBox.Show("不存在转速数据!");
                return;
            }
 
            var monitor_points = new BLL.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongIDAndGroupID
                (_model.BelongType, _model.BelongID, _model.GroupID);
            var pressure_mp = monitor_points?.Find(x => x.SignalType == IStation.SignalType.出口压力);
            if (pressure_mp == null)
            {
                XtraMessageBox.Show("不存在压力测点!");
                return;
            }
 
 
 
 
 
        }
 
 
 
    }
}