ningshuxia
2025-04-16 a67da735b33be01b24845ce03ae7551cf55ddbbc
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
using DevExpress.XtraCharts;
using DevExpress.XtraEditors;
using IStation.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
 
namespace IStation.WinFrmUI.Monitor
{
    public partial class ScadaVerifyPage : DocumentPage
    {
        public ScadaVerifyPage()
        {
            InitializeComponent();
            PageTitle.Caption = "工况验证";
 
            repDateEdit.ShowToday = false;
            repDateEdit.ShowMonthHeaders = true;
            repDateEdit.CalendarView = DevExpress.XtraEditors.Repository.CalendarView.Vista;
            repDateEdit.VistaCalendarInitialViewStyle = DevExpress.XtraEditors.VistaCalendarInitialViewStyle.YearView;
            repDateEdit.VistaCalendarViewStyle = DevExpress.XtraEditors.VistaCalendarViewStyle.YearView;
            repDateEdit.Mask.EditMask = "yyyy-MM";
            repDateEdit.Mask.UseMaskAsDisplayFormat = true;
            barEditDate.EditValue = DateTime.Now.AddMonths(-1); //DateTime.Now.AddYears(-1);
 
            equipmentExTreeListCtrl1.FocusedChangedEvent += EquipmentExTreeListCtrl1_FocusedChangedEvent; ;
            monitorDataSourcesTreeList.FocusedChangedEvent += MonitorDataSourcesTreeList1_FocusedChangedEvent;
 
            gridView1.SetNormalView();
 
            repositoryItemDateEdit1.SetShowClock();
            repositoryItemDateEdit2.SetShowClock();
            barEditStartTime.EditValue = new DateTime(2024, 07, 01, 00, 00, 00);
            barEditEndTime.EditValue = new DateTime(2024, 08, 1);
            InitialChart();
        }
 
 
        public class VerifyViewModel : PumpSignalRecord
        {
 
            public VerifyViewModel(Model.PumpSignalRecord rhs) : base(rhs) { }
            public VerifyViewModel(Model.PumpSignalRecord rhs, DateTime dateTime) : base(rhs)
            {
                Time = dateTime;
            }
 
            [Display(Name = "时间", Order = 0)]
            public DateTime Time { get; set; }
 
 
            [Display(Name = "曲线功率", Order = 11)]
            public double InterPower { get; set; }
            [Display(Name = "功率差值", Order = 12)]
            public double PowerDiff { get; set; }
 
            [Display(Name = "曲线扬程", Order = 9)]
            public double InterHead { get; set; }
            [Display(Name = "扬程差值", Order = 10)]
            public double HeadDiff { get; set; }
 
            [Display(Name = "效率", Order = 8)]
            public double Eff { get; set; }
        }
 
 
        private List<VerifyViewModel> _verifyViewModelList = null;
 
        private Model.MonitorDataSources _monitorDataSources = null;
        private Model.Equipment _equipment = null;
        private readonly BLL.MonitorDataSet _bll = new BLL.MonitorDataSet();
        private readonly BLL.EquipmentMonitorMapping _bllEquipmentMonitorMapping = new BLL.EquipmentMonitorMapping();
        private readonly BLL.MonitorPoint _bllMonitorPoint = new BLL.MonitorPoint();
 
        private XYDiagram _diagram = null;
        private SecondaryAxisY _secondaryAxisYHead = null;
 
 
        /// <summary>
        /// 初始化图表
        /// </summary>
        public void InitialChart()
        {
            _diagram = chartControl1.Diagram as XYDiagram;
            _diagram.EnableAxisXScrolling = true;
            _diagram.EnableAxisYScrolling = true;
            _diagram.EnableAxisXZooming = true;
            _diagram.EnableAxisYZooming = true;
            _diagram.AxisX.CrosshairAxisLabelOptions.Visibility = DevExpress.Utils.DefaultBoolean.False;
            _diagram.AxisX.Color = System.Drawing.Color.LightCoral;
 
            _diagram.AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Second;
            _diagram.AxisX.DateTimeScaleOptions.ScaleMode = ScaleMode.Manual;
            _diagram.AxisX.GridLines.Visible = true;
            _diagram.AxisY.GridLines.Visible = false;
            _secondaryAxisYHead = _diagram.SecondaryAxesY[0];
 
 
            chartControl1.RuntimeHitTesting = true;
            chartControl1.CrosshairOptions.ShowArgumentLine = false;
            chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.True;
            chartControl1.Legend.MarkerMode = LegendMarkerMode.CheckBoxAndMarker;
            chartControl1.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right;
        }
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            chartControl1.BeginInit();
            chartControl1.Series.Clear();
            chartControl1.EndInit();
 
            equipmentExTreeListCtrl1.SetBindingData();
            monitorDataSourcesTreeList.SetBindingData();
        }
 
        private void MonitorDataSourcesTreeList1_FocusedChangedEvent(Model.MonitorDataSources obj)
        {
            _monitorDataSources = obj;
        }
 
        private bool _use = false;
        private void EquipmentExTreeListCtrl1_FocusedChangedEvent(Model.Equipment obj)
        {
            _equipment = obj;
            if (obj == null)
                return;
            if (_use)
            {
 
 
                switch (obj.SortCode)
                { //21#e172   12:47-13:10
                  //22#f173   13:20-13:36
                  //23#d171   12:22-12:32
                  //24#c170   11:56-12:10
                  //25#b169   10:43-10:58
                  //26#a168   9:59-10:31
                  //27#g174   13:54-14:07
                    case 21:
                        {
                            barEditStartTime.EditValue = new DateTime(2024, 05, 14, 12, 47, 00);
                            barEditEndTime.EditValue = new DateTime(2024, 05, 14, 13, 10, 00);
                        }
                        break;
                    case 22:
                        {
                            barEditStartTime.EditValue = new DateTime(2024, 05, 14, 13, 20, 00);
                            barEditEndTime.EditValue = new DateTime(2024, 05, 14, 13, 36, 00);
                        }
                        break;
                    case 23:
                        {
                            barEditStartTime.EditValue = new DateTime(2024, 05, 14, 12, 22, 00);
                            barEditEndTime.EditValue = new DateTime(2024, 05, 14, 12, 32, 00);
                        }
                        break;
                    case 24:
                        {
                            barEditStartTime.EditValue = new DateTime(2024, 05, 14, 11, 56, 00);
                            barEditEndTime.EditValue = new DateTime(2024, 05, 14, 12, 10, 00);
                        }
                        break;
                    case 25:
                        {
                            barEditStartTime.EditValue = new DateTime(2024, 05, 14, 10, 43, 00);
                            barEditEndTime.EditValue = new DateTime(2024, 05, 14, 10, 58, 00);
                        }
                        break;
                    case 26:
                        {
                            barEditStartTime.EditValue = new DateTime(2024, 05, 14, 09, 59, 00);
                            barEditEndTime.EditValue = new DateTime(2024, 05, 14, 10, 31, 00);
                        }
                        break;
                    case 27:
                        {
                            barEditStartTime.EditValue = new DateTime(2024, 05, 14, 13, 54, 00);
                            barEditEndTime.EditValue = new DateTime(2024, 05, 14, 14, 07, 00);
                        }
                        break;
                    default:
                        break;
                }
            }
        }
 
        //验证
        private void barBtnVerify_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barEditDate.EditValue == null)
            {
                XtraMessageBox.Show("请选择时间!");
                return;
            }
            if (_monitorDataSources == null || _equipment == null)
                return;
            var lays = chartControl1.ShowOverlay();
            chartControl1.BeginInit();
            chartControl1.Series.Clear();
            chartControl1.EndInit();
            _verifyViewModelList = new List<VerifyViewModel>();
 
            var pump = new BLL.Equipment().GetChildPumpByEnginePumpID(_equipment.ID);
 
            var date = (DateTime)barEditDate.EditValue;
            var packet = new BLL.StationSignalRecordPacket().Get(_monitorDataSources.ID, _equipment.BelongID, date.Year, date.Month);
            var stationSignalRecords = packet?.StationSignalRecords?.ToList();
            if (stationSignalRecords == null || !stationSignalRecords.Any())
            {
                lays.Close();
                XtraMessageBox.Show("无数据!");
                return;
            }
 
            foreach (var stationSignalRecord in stationSignalRecords)
            {
                foreach (var pumpSignalRecord in stationSignalRecord.PumpSignalRecords)
                {
                    if (pumpSignalRecord.Flag != pump.SortCode)
                        continue;
                    var time = stationSignalRecord.Time;
                    var rpm = pumpSignalRecord.Rpm;
                    var fre = pumpSignalRecord.Frequency;
 
 
                    var time_min = Convert.ToDateTime(barEditStartTime.EditValue);
                    var time_max = Convert.ToDateTime(barEditEndTime.EditValue);
                    if (time >= time_min && time <= time_max)
                    {
                        var vm = new VerifyViewModel(pumpSignalRecord, time);
                        _verifyViewModelList.Add(vm);
                    }
 
                }
            }
 
            var curveInfo = new BLL.PumpCurve().GetDefaultWorkingByPumpID(pump.ID)?.CurveInfo;
            if (curveInfo == null)
            {
                lays.Close();
                return;
            }
 
            var seriesViewPower = new DevExpress.XtraCharts.LineSeriesView();
            seriesViewPower.Color = System.Drawing.Color.LightCoral;
            var seriesPower = new DevExpress.XtraCharts.Series
            {
                Name = pump.SortCode + "-功率",
                View = seriesViewPower,
                LegendText = pump.SortCode + "-功率"
            };
 
            var seriesViewHead = new DevExpress.XtraCharts.LineSeriesView();
            seriesViewHead.AxisY = _secondaryAxisYHead;
            seriesViewHead.Color = System.Drawing.Color.DodgerBlue;
            var seriesHead = new DevExpress.XtraCharts.Series
            {
                Name = pump.SortCode + "-扬程",
                View = seriesViewHead,
                LegendText = pump.SortCode + "-扬程"
            };
 
            foreach (var record in _verifyViewModelList)
            {
                if (record.Flag > 18)
                {
                    if (record.FlowRate < 1)
                    {
                        continue;
                    }
                }
 
                if (record.Head == IStation.Error.Default || record.Head == 0)
                {
                    continue;
                }
                if (record.InstantaneousPower == IStation.Error.Default)
                {
                    continue;
                }
 
                var rpm = record.Rpm;
                if (rpm == IStation.Error.Default || rpm < 1)
                {
                    if (record.Frequency > 0 && record.Frequency != IStation.Error.Default)
                    {
                        rpm = (record.Frequency / 50) * pump.RatedParas.Nr;
                    }
                    else
                    {
                        continue;
                    }
                }
 
                //var hz = record.Rpm / pump.RatedParas.Nr * 50;
                //hz = Math.Round(hz);
                //if (hz != 45)
                //    continue; 
 
                var time = record.Time;
                var flowRate = record.FlowRate;
 
                Model.CurveExpress curveQH, curveQP;
                //if (record.Frequency==0|| record.Frequency==IStation.Error.Default)
                //{
                curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveInfo.CurveQH, pump.RatedParas.Nr, record.Rpm);
                curveQP = Model.CurveCalcuHelper.CalculateSimilarQP(curveInfo.CurveQP, pump.RatedParas.Nr, record.Rpm);
                //}
                //else
                //{
                //    curveQH = Model.CurveCalcuHelper.CalculateSimilarQH(curveInfo.CurveQH, 50, record.Frequency);
                //    curveQP = Model.CurveCalcuHelper.CalculateSimilarQP(curveInfo.CurveQP, 50, record.Frequency); 
                //}  
                if (curveQH == null || curveQP == null)
                    continue;
                if (flowRate < 1)
                {
                    var qhPoints = curveQH.GetFitPoints();
                    Model.FitCurveHelper.GetInterPointX(qhPoints, record.Head, out flowRate);
                }
 
                record.InterPower = Math.Round(curveQP.GetFitPointY(flowRate), 2);
                record.PowerDiff = record.InstantaneousPower - record.InterPower;
                record.PowerDiff = Math.Round(record.PowerDiff, 2);
                seriesPower.Points.Add(new SeriesPoint(time, record.PowerDiff));
 
                if (record.Flag > 19)
                {
                    record.InterHead = Math.Round(curveQH.GetFitPointY(flowRate), 2);
                    record.HeadDiff = record.Head - record.InterHead;
                    record.HeadDiff = Math.Round(record.HeadDiff, 2);
                    seriesHead.Points.Add(new SeriesPoint(time, record.HeadDiff));
                }
 
 
                record.Eff = Model.CurveCalcuHelper.CalculateE(flowRate, record.Head, record.InstantaneousPower);
            }
 
            chartControl1.Series.Add(seriesPower);
            if (pump.SortCode > 19)
            {
                chartControl1.Series.Add(seriesHead);
            }
 
            lays.Close();
 
            verifyViewModelBindingSource.DataSource = _verifyViewModelList;
            verifyViewModelBindingSource.ResetBindings(false);
        }
 
        //刷新
        private void barBtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            InitialDataSource();
        }
 
        //图表点击
        private void chartControl1_MouseClick(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (chartControl1.Series.Count < 1)
                return;
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                if (_verifyViewModelList != null && _verifyViewModelList.Any())
                {
                    var hitInfo = chartControl1.CalcHitInfo(e.Location);
                    if (hitInfo.InChart)
                    {
                        var diagramCoordinates = _diagram.PointToDiagram(e.Location);
                        var axisValue = diagramCoordinates.GetAxisValue(_diagram.AxisX);
                        if (axisValue == null)
                            return;
                        var pt_dt = axisValue.DateTimeValue;
                        var vm = _verifyViewModelList.Find(x => x.Time == pt_dt);
                        if (vm == null)
                        {
                            vm = _verifyViewModelList.FindLast(x => x.Time < pt_dt);
                        }
                        propertyGridControl1.Text = "数据";
                        propertyGridControl1.SelectedObject = vm;
                    }
                }
            }
        }
 
 
        //导出表格
        private void barBtnExportExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            gridView1.ExportExcel();
        }
 
 
        private void barBtnExportWaterDesk_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barEditDate.EditValue == null)
            {
                XtraMessageBox.Show("请选择时间!");
                return;
            }
            if (_monitorDataSources == null || _equipment == null)
                return;
 
            var start_date = (DateTime)barEditStartTime.EditValue;
            var end_date = (DateTime)barEditDate.EditValue;
 
            var dlg = new SetTimeStepDlg();
            dlg.SetBindingData(300);
            dlg.ReloadDataEvent += (timeStep) =>
            {
                //Task.Run(() =>
                //{
                //    this.Invoke(new Action(() =>
                //    {
                //        AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "开始导出!");
                //    })); 
                //    ExportWaterDeskHelper.Export(_monitorDataSources.ID,_equipment.BelongID, year,month, timeStep);
                //    this.Invoke(new Action(() =>
                //    { 
                //        AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!");
                //    })); 
                //}); 
 
                WaitFrmHelper.ShowWaitForm("正在导出");
                ExportWaterDeskHelper.Export(_monitorDataSources.ID, _equipment.BelongID, timeStep);
                WaitFrmHelper.HideWaitForm();
                AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!");
 
 
            };
            dlg.ShowDialog();
        }
 
        private void barBtnExportEapnet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (barEditDate.EditValue == null)
            {
                XtraMessageBox.Show("请选择时间!");
                return;
            }
            if (_monitorDataSources == null || _equipment == null)
                return;
 
 
            var date = (DateTime)barEditDate.EditValue;
            var year = date.Year;
            var month = date.Month;
            var dlg = new SetTimeStepDlg();
            dlg.SetBindingData(300);
            dlg.ReloadDataEvent += (timeStep) =>
            {
                WaitFrmHelper.ShowWaitForm("正在导出");
                //ExportEpanetHelper.ExportByDay(_monitorDataSources.ID, _equipment.BelongID, year, month, timeStep);
                ExportEpanetHelper.Export(_monitorDataSources.ID, _equipment.BelongID, timeStep);
 
                WaitFrmHelper.HideWaitForm();
                AlertTool.ShowInfo(System.Windows.Forms.Application.OpenForms[0], "提示", "导出完成!");
            };
            dlg.ShowDialog();
        }
    }
}