tangxu
2024-04-24 1c5fa983ae3506c2edaa88c51a959d46685c1ba1
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
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using IStation.Unit;
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.WinFrmUI.Monitor
{
    public partial class DataScreeningChartCtrl : XtraUserControl
    {
        public DataScreeningChartCtrl()
        {
            InitializeComponent();
            this.monitorPointTreeListCtrl1.FocusedChangedEvent += MonitorPointTreeListCtrl1_FocusedChangedEvent;
            this.timeValueEasyChartView1.BoxSelCompleteEvent += TimeValueEasyChartView1_BoxSelCompleteEvent;
        }
 
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            _allBindList = new List<TimeValue>();
            this.timeValueEasyChartView1.InitialDefaultSeries(_allBindList);
            this.monitorPointTreeListCtrl1.SetBindingData();
        }
 
        private Model.MonitorPointExSignalExSignalType _model = null;
        private List<TimeValue> _allBindList = null;
 
        private const string delete = "delete";
 
 
        //框选返回事件
        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 MonitorPointTreeListCtrl1_FocusedChangedEvent(Model.MonitorPointExSignalExSignalType obj)
        {
            _model = obj;
            _allBindList = new List<TimeValue>();
            if (_model == null)
            {
                this.timeValueEasyChartView1.SetAxisYTitle("?");
                this.timeValueEasyChartView1.InitialDefaultSeries(null);
            }
            else
            {
 
                if (int.TryParse(_model.UnitValue, out int unitValue))
                {
                    var dict = UnitHelper.GetEnUnitDict(_model.UnitType);
                    if (dict != null)
                        this.timeValueEasyChartView1.SetAxisYTitle(dict[unitValue]);
                }
                else
                {
                    this.timeValueEasyChartView1.SetAxisYTitle(_model.UnitValue);
                }
                var packet = new BLL.MonitorDataSet().GetSignalRecordPacket(_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();
                    }
                }
            }
 
            this.timeValueEasyChartView1.InitialDefaultSeries(_allBindList);
        }
 
 
        //删除
        private void Delete(IEnumerable<DateTime> times)
        {
            WaitFrmHelper.ShowWaitForm("正在删除...");
            if (times == null || times.Count() < 1)
            {
                XtraMessageBox.Show("无数据!");
                return;
            }
            var bol = new BLL.MonitorDataSet().SetAbnormal(_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--;
                }
            }
            this.timeValueEasyChartView1.InitialDefaultSeries(_allBindList);
            WaitFrmHelper.HideWaitForm();
            XtraMessageBox.Show("删除成功!");
        }
 
 
        //框选删除
        public void Delete()
        {
            this.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 barBtnCaclu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
             if (_model == null)
                 return;
             if (_allBindList == null || _allBindList.Count < 1)
                 return;
 
             switch (_model.Identifier)
             {
                 case IStation.SignalType.瞬时流量:
                     {
                         SuperpositionCalcu();
                     }
                     break;
                 case IStation.SignalType.有功功率:
                     {
                         SuperpositionCalcu();
                     }
                     break;
                 case IStation.SignalType.有功电度:
                     {
                         SuperpositionCalcu();
                     }
                     break;
                 default:
                     {
                         XtraMessageBox.Show("暂不支持计算!");
                         return;
                     }
             }
         }
 
 
         private void SuperpositionCalcu()
         {
             if (_allBindList == null || _allBindList.Count < 1)
                 return;
             double value = 0;
             var count = 0;
 
             for (int i = 0; i < _allBindList.Count - 1; i++)
             {
                 var n = _allBindList[i];
                 var n1 = _allBindList[i + 1];
                 var second = (n1.Time - n.Time).TotalSeconds;
                 value += n1.Value / 3600 * second;
                 count++;
             }
 
 
             var str = new StringBuilder();
             str.AppendLine($"点数量:{count}");
             str.AppendLine($"叠加值:{Math.Round(value, 0)}");
             XtraMessageBox.Show(str.ToString());
         }
 
         private void barBtnExport_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
             if (_model == null)
                 return;
             var monitorPointExSignalList = this.monitorPointTreeListCtrl1.GetMonitorPointExSignalList();
             monitorPointExSignalList = monitorPointExSignalList?.Where(x => x.SignalList.First().SignalType == IStation.Scatl.SignalType.累积流量 || x.SignalList.First().SignalType == IStation.Scatl.SignalType.有功电度).ToList();
             if (monitorPointExSignalList == null || monitorPointExSignalList.Count < 1)
                 return;
 
             var monitorPointGroups = this.monitorPointTreeListCtrl1.GetMonitorPointGroups();
 
             WaitFrmHelper.ShowWaitForm();
             var dlg = new SuperpositionCalcuDlg();
             dlg.SetBindingData(_projectId, monitorPointGroups, monitorPointExSignalList);
             dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
             dlg.ShowDialog();
 
         }
 
         private void barBtnPumpDataCompare_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
         {
             if (_model == null)
                 return;
             var monitorPointExSignalList = this.monitorPointTreeListCtrl1.GetMonitorPointExSignalList();
             if (monitorPointExSignalList == null || monitorPointExSignalList.Count < 1)
                 return;
 
             var monitorPointGroups = this.monitorPointTreeListCtrl1.GetMonitorPointGroups();
 
             WaitFrmHelper.ShowWaitForm();
             var dlg = new PumpDataCompareDlg2();
             dlg.SetBindingData(_projectId, monitorPointGroups, monitorPointExSignalList);
             dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
             dlg.ShowDialog();
         }*/
 
 
 
 
    }
 
}