ningshuxia
2023-05-06 657c344695223f01bade2776803f719673232f81
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
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace IStation.WinFormUI.MonitorDataSet
{
    public partial class FilterDataMgrPage : DocumentPage
    {
        public FilterDataMgrPage()
        {
            InitializeComponent(); 
            _boxSelHelper = new ChartBoxSelHelper(this.chartControl1);
            _boxSelHelper.BoxSelCompletedEvent += _boxSelHelper_BoxSelCompletedEvent; 
            this.monitorPointTreeListCtrl1.SelectEvent += MonitorPointTreeListCtrl1_SelectEvent;
            this.PageTitle.Caption = "数据筛查";
        }
 
 
        #region 当前视图类
        public class CurrentViewModel
        {
            public CurrentViewModel() { }
            public CurrentViewModel(Model.SignalRecord rhs)
            {
                this.DataTime = rhs.Time;
                this.DataValue = rhs.Value;
            }
 
            public DateTime DataTime { get; set; }
            public double DataValue { get; set; }
        }
        #endregion
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public void InitialDataSource(long projectId,long sceneId, Model.LogicTree logic)
        {
            _projectId = projectId;
            _sceneId = sceneId;
            this.monitorPointTreeListCtrl1.SetBindingData(_projectId, logic.LogicType, logic.LogicId);
        }
 
        private SwiftPlotDiagram _diagram
        {
            get { return this.chartControl1.Diagram as SwiftPlotDiagram; }
        }
        private Series _series 
        {
            get
            {
                return this.chartControl1.Series[0]; 
            } 
        }
 
        private long _projectId;
        private long _sceneId;
        private Model.Signal _model = null;
        private List<CurrentViewModel> _allBindList = null;
        private ChartBoxSelHelper _boxSelHelper = null;//框选辅助类
 
        private void MonitorPointTreeListCtrl1_SelectEvent(string objectType, object model, MouseEventArgs arg3)
        {
            /*var lays = this.chartControl1.ShowOverlay();
            var monitorPointExSignalList = model as Model.MonitorPointExSignalList;
            _model = monitorPointExSignalList?.SignalList.First();
            if (_model == null)
            {
                this.labCaption.Text = "未知";
                _diagram.AxisY.Title.Text = "值";
                _allBindList = null;
            }
            else
            {
                this.labCaption.Text = _model.Name;
                _diagram.AxisY.Title.Text = UnitValueHelper.Get(_projectId,_model);
                var packet = new BLL.MonitorDataSet().GetSignalRecordPacket(_projectId,_sceneId, _model.MonitorPointId, _model.Id);
                if (packet == null|| packet.RecordList==null)
                {
                    _allBindList = new List<CurrentViewModel>();
                    lays.Close();
                    return;
                }
                else
                {
                    _allBindList = packet.RecordList.Where(x => x.Value != IStation.Default.Abnormal&&x.Value!= IStation.Default.Error)?.Select(x => new CurrentViewModel(x)).ToList();
                }
 
            }
            if (_allBindList == null)
                _allBindList = new List<CurrentViewModel>();
            this.currentViewModelBindingSource.DataSource = _allBindList;
            this.currentViewModelBindingSource.ResetBindings(false);
            lays.Close();*/
 
 
 
 
            var lays = this.chartControl1.ShowOverlay();
            var monitorPointExSignalList = model as Model.MonitorPointExSignalList;
            _model = monitorPointExSignalList?.SignalList.First();
            if (_model == null)
            {
                this.labCaption.Text = "未知";
                _diagram.AxisY.Title.Text = "值";
                _allBindList = null;
            }
            else
            {
                this.labCaption.Text = _model.Name;
                _diagram.AxisY.Title.Text = "高度/m";
                var packet = new BLL.MonitorDataSet().GetSignalRecordPacket(_projectId, _sceneId, _model.MonitorPointId, _model.Id);
                if (packet == null || packet.RecordList == null)
                {
                    _allBindList = new List<CurrentViewModel>();
                    lays.Close();
                    return;
                }
                else
                {
                    _allBindList = packet.RecordList.Where(x => x.Value != IStation.Default.Abnormal && x.Value != IStation.Default.Error)?.Select(x => new CurrentViewModel(x)).ToList();
                }
 
            }
            if (_allBindList == null)
                _allBindList = new List<CurrentViewModel>();
            this.currentViewModelBindingSource.DataSource = _allBindList;
            this.currentViewModelBindingSource.ResetBindings(false);
            lays.Close();
        }
          
        //框选完成
        private void _boxSelHelper_BoxSelCompletedEvent(MouseEventArgs e)
        {
            _boxSelSeriesPointList = _boxSelHelper?.CalcuDataTimeSelSeriesPoints(new List<Series>() { _series });
            if (_boxSelSeriesPointList == null || _boxSelSeriesPointList.Count < 1)
            {
                _boxSelHelper?.CloseBoxSel();
            }
            else
            {
                this.popBoxSel.ShowPopup(MousePosition);
            }
        }
        private List<SeriesPoint> _boxSelSeriesPointList = null;
 
        //删除
        private void barBtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_boxSelSeriesPointList == null || _boxSelSeriesPointList.Count < 1)
                return;
            var lays = this.chartControl1.ShowOverlay();
            var dataTimeList = _boxSelSeriesPointList.Select(x => x.DateTimeArgument).ToList();
            var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId,_sceneId, _model.MonitorPointId, _model.Id, dataTimeList,IStation.Default.Abnormal);
            if (!bol)
            {
                lays.Close();
                XtraMessageBox.Show("删除失败!");
                return;
            }
            _allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
            this.currentViewModelBindingSource.ResetBindings(false);
            lays.Close();
        }
 
        //关闭
        private void popBoxSel_CloseUp(object sender, EventArgs e)
        {
            _boxSelHelper?.CloseBoxSel();
        }
 
        //框选删除
        private void barBtnBoxSel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            _boxSelHelper?.StartBoxSel();
        }
 
        //区间删除
        private void barBtnRangeDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            XtraMessageBox.Show("未恢复");
            /*var dlg = new SetRangeDlg();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                var dataTimeList = _allBindList?.Where(x => x.DataValue>=dlg.MinValue&&x.DataValue<=dlg.MaxValue).Select(x => x.DataTime).ToList();
                if (dataTimeList == null || dataTimeList.Count < 1)
                {
                    XtraMessageBox.Show("未检索到区间值!");
                    return;
                }
                var lays = this.chartControl1.ShowOverlay();
                var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId,_sceneId, _model.MonitorPointId, _model.Id, dataTimeList,IStation.Default.Abnormal);
                if (!bol)
                {
                    lays.Close();
                    XtraMessageBox.Show("删除失败!");
                    return;
                }
                _allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
                this.currentViewModelBindingSource.ResetBindings(false);
                
                lays.Close();
            } */
        }
 
        //清除负值
        private void barBtnClearNegative_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show("确认清除所有负值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            var dataTimeList = _allBindList?.Where(x => x.DataValue < 0).Select(x=>x.DataTime).ToList();
            if (dataTimeList == null || dataTimeList.Count < 1)
            {
                XtraMessageBox.Show("未检索到负值!");
                return;
            }
            var lays = this.chartControl1.ShowOverlay();
            var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId,_sceneId, _model.MonitorPointId, _model.Id, dataTimeList,IStation.Default.Abnormal);
            if (!bol)
            {
                lays.Close();
                XtraMessageBox.Show("删除失败!");
                return;
            }
            _allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
            this.currentViewModelBindingSource.ResetBindings(false);
            
            lays.Close();
        }
 
        //清除零值
        private void barBtnClearZero_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (XtraMessageBox.Show("确认清除所有零值吗?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
            {
                return;
            }
            var dataTimeList = _allBindList?.Where(x => x.DataValue == 0).Select(x => x.DataTime).ToList();
            if (dataTimeList == null || dataTimeList.Count < 1)
            {
                XtraMessageBox.Show("未检索到零值!");
                return;
            }
            var lays = this.chartControl1.ShowOverlay();
            var bol = new BLL.MonitorDataSet().SetAbnormal(_projectId, _sceneId, _model.MonitorPointId, _model.Id, dataTimeList, IStation.Default.Abnormal);
            if (!bol)
            {
                lays.Close();
                XtraMessageBox.Show("删除失败!");
                return;
            }
            _allBindList.RemoveAll(x => dataTimeList.Contains(x.DataTime));
            this.currentViewModelBindingSource.ResetBindings(false);
            
            lays.Close();
        }
 
        //图标的右键菜单
        private void chartControl1_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                this.popMain.ShowPopup(MousePosition);
            }
        }
 
 
    }
}