Shuxia Ning
2025-02-13 2f1cbec203dcff25df7a5c2b51b13ec558f2c3db
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
using DevExpress.XtraEditors;
using IStation.Model;
using IStation.WinFrmUI.Curve;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Basic
{
    public partial class PumpCurveMgrPage : DocumentPage
    {
        public PumpCurveMgrPage()
        {
            InitializeComponent();
            this.PageTitle.Caption = "单泵曲线";
            this.pumpCurveTreeListCtrl1.FocusedChangedEvent += PumpCurveTreeListCtrl1_FocusedChangedEvent; ;
            this.curveExpressChart1.OnCurveCoordinateParasChanged += CurveExpressChart1_OnCurveCoordinateParasChanged;
        }
 
 
 
        private string _belongType;
        private Model.PumpCurveExMapping _pumpCurveExMapping = null;
        private Model.PumpSpeedCurve _pumpSpeedCurve = null;
        private BLL.PumpCurve _bll = new BLL.PumpCurve();
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            _pumpCurveExMapping = null;
            this.pumpCurveTreeListCtrl1.SetBindingData();
        }
 
 
        //曲线切换
        private void PumpCurveTreeListCtrl1_FocusedChangedEvent(string objectType, object obj)
        {
            _belongType = objectType;
            _pumpCurveExMapping = null;
            _pumpSpeedCurve = null;
            this.curveExpressChart1.InitialChartData();
            var isMapping = objectType == IStation.ObjectType.PumpCurveMapping;
            if (isMapping)
            {
                var mapping = obj as Model.PumpCurveMapping;
                var pumpCurve = _bll.GetByID(mapping.CurveID);
                _pumpCurveExMapping = new Model.PumpCurveExMapping(pumpCurve, mapping);
                SetBindingData(_pumpCurveExMapping.CurveInfo, _pumpCurveExMapping.CoordParas);
            }
            else
            {
                _pumpSpeedCurve = obj as Model.PumpSpeedCurve;
                SetBindingData(_pumpSpeedCurve.CurveInfo, _pumpSpeedCurve.CoordParas);
            }
            SetRibbonButton(isMapping);
        }
 
        private void SetRibbonButton(bool use)
        {
            this.barBtnEditInfo.Enabled = use;
            this.barBtnEditOtherName.Enabled = use;
            this.barBtnSetWorkCurve.Enabled = use;
            this.barBtnRefresh.Enabled = use;
            this.barBtnDeleteCurve.Enabled = use;
            this.barBtnEditCurve.Enabled = use;
            this.barBtnCopyAndExpandCurve.Enabled = use;
            this.barBtnExportYCM.Enabled = use;
            // this.barSubImport.Enabled = use;
            // this.barSubExport.Enabled = use;
        }
 
 
 
 
        //绑定数据
        private void SetBindingData(Model.FeatCurveExpressGroup curveInfo, Model.CurveCoordinateParas coordinateParas)
        {
            if (curveInfo == null || curveInfo.CurveQH == null)
                return;
            this.curveExpressChart1.SetBindingData(curveInfo.CurveQH,
                                                        curveInfo.CurveQE,
                                                        curveInfo.CurveQP,
                                                        coordinateParas);
        }
 
 
 
 
        //坐标变换修改
        private void CurveExpressChart1_OnCurveCoordinateParasChanged(Model.CurveCoordinateParas obj)
        {
            _pumpCurveExMapping.CoordParas = obj;
            if (!new BLL.PumpCurve().Update(_pumpCurveExMapping))
            {
                XtraMessageBox.Show("修改失败!");
                return;
            }
            XtraMessageBox.Show("修改成功!");
        }
 
 
        //修改泵曲线信息
        private void barBtnEditInfo_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pumpCurveExMapping == null)
                return;
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditPumpCurveInfoDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(_pumpCurveExMapping);
            dlg.ReloadDataEvent += (rhs) =>
            {
                rhs.UpdateTime = DateTime.Now;
                var result = new BLL.PumpCurve().Update(rhs);
                if (result)
                {
                    _pumpCurveExMapping.Reset(rhs);
                    SetBindingData(_pumpCurveExMapping.CurveInfo, _pumpCurveExMapping.CoordParas);
                }
                return result;
            };
            dlg.ShowDialog();
        }
 
        //修改泵曲线名称
        private void barBtnEditOtherName_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pumpCurveExMapping == null)
                return;
            WaitFrmHelper.ShowWaitForm();
            var dlg = new EditOtherNameDlg();
            dlg.Shown += delegate { WaitFrmHelper.HideWaitForm(); };
            dlg.SetBindingData(_pumpCurveExMapping.OtherName);
            dlg.ReloadDataEvent += (rhs) =>
            {
                var mapping = new BLL.PumpCurveMapping().GetByID(_pumpCurveExMapping.MappingID);
                mapping.OtherName = rhs;
                var result = new BLL.PumpCurveMapping().Update(mapping);
                if (result)
                {
                    _pumpCurveExMapping.Reset(mapping);
                    this.pumpCurveTreeListCtrl1.UpdateOtherName(rhs);
                }
                return result;
            };
            dlg.ShowDialog();
        }
 
        //设置工作曲线
        private void barBtnSetWorkCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pumpCurveExMapping == null)
                return;
            var result = new BLL.PumpCurveMapping().UpdateWorkCurve(_pumpCurveExMapping.MappingID);
            if (result)
            {
                _pumpCurveExMapping.IsWorking = true;
                this.pumpCurveTreeListCtrl1.UpdateWorkingCurve();
            }
        }
 
        //编辑曲线
        private void barBtnEditCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pumpCurveExMapping != null)
            {
                var curveInfo = _pumpCurveExMapping.CurveInfo;
                if (curveInfo == null)
                    return;
                if (curveInfo.CurveQH == null)
                    return;
                var dlg = new EditCurveExpressDlg();
                dlg.SetBindingData(curveInfo);
                dlg.ReloadDataEvent += (featCurveExpressGroup) =>
                {
                    _pumpCurveExMapping.CurveInfo = featCurveExpressGroup;
                    var bol = new BLL.PumpCurve().Update(_pumpCurveExMapping);
                    if (bol)
                    {
                        this.curveExpressChart1.SetBindingData(featCurveExpressGroup, _pumpCurveExMapping.CoordParas);
                    }
                    return bol;
                };
                dlg.ShowDialog();
            }
            else if (_pumpSpeedCurve != null)
            {
                var curveInfo = _pumpSpeedCurve.CurveInfo;
                if (curveInfo == null)
                    return;
                if (curveInfo.CurveQH == null)
                    return;
                var dlg = new EditCurveExpressDlg();
                dlg.SetBindingData(curveInfo);
                dlg.ReloadDataEvent += (featCurveExpressGroup) =>
                {
                    _pumpSpeedCurve.CurveInfo = featCurveExpressGroup;
                    var bol = new BLL.PumpSpeedCurve().Update(_pumpSpeedCurve);
                    if (bol)
                    {
                        this.curveExpressChart1.SetBindingData(featCurveExpressGroup, _pumpSpeedCurve.CoordParas);
                    }
                    return bol;
                };
                dlg.ShowDialog();
            }
        }
 
 
        //复制并延长曲线
        private void barBtnCopyAndExpandCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pumpCurveExMapping == null)
                return;
            var dlg = new CopyAndExpandCurveDlg();
            dlg.SetBindingData(_pumpCurveExMapping);
            dlg.ReloadDataEvent += (otherName, curveExpressGroup) =>
            {
                var pumpCurve = new Model.PumpCurve(_pumpCurveExMapping);
                pumpCurve.CurveInfo = curveExpressGroup;
                pumpCurve.ID = 0;
 
                var pumpCurveId = new BLL.PumpCurve().Insert(pumpCurve);
                if (pumpCurveId < 1)
                    return false;
                pumpCurve.ID = pumpCurveId;
 
                var pumpCurveMapping = new Model.PumpCurveMapping();
                pumpCurveMapping.PumpID = _pumpCurveExMapping.PumpID;
                pumpCurveMapping.CurveID = pumpCurveId;
                pumpCurveMapping.OtherName = otherName;
                pumpCurveMapping.IsWorking = false;
 
                var pumpCurveMappingId = new BLL.PumpCurveMapping().Insert(pumpCurveMapping);
                if (pumpCurveMappingId < 1)
                    return false;
                pumpCurveMapping.ID = pumpCurveMappingId;
                return true;
            };
            dlg.ShowDialog();
        }
 
        //删除曲线
        private void barBtnDeleteCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pumpCurveExMapping == null)
                return;
            if (XtraMessageBox.Show("是否删除曲线?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != DialogResult.Yes)
                return;
            var result = new BLL.PumpCurve().DeleteByID(_pumpCurveExMapping.ID, out string msg);
            if (!result)
            {
                XtraMessageBox.Show("删除失败!");
                return;
            }
            this.pumpCurveTreeListCtrl1.DeletePumpMapping(_pumpCurveExMapping.ID, _pumpCurveExMapping.MappingID);
        }
 
        //刷新
        private void barBtnReload_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            InitialDataSource();
        }
 
        //导出 inp 
        private void barBtnExportCrv_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            string fileName;
            Model.FeatCurveExpressGroup featCurveExpressGroup = null;
            //if (_belongType == IStation.ObjectType.PumpCurveExMapping)
            //{
            fileName = _pumpCurveExMapping.OtherName;
            featCurveExpressGroup = _pumpCurveExMapping.CurveInfo;
            //}
            //else
            //{
            //    fileName = _pumpSpeedCurve.HZ.ToString();
            //    featCurveExpressGroup = _pumpSpeedCurve.CurveInfo;
            //}
            ExportCurveHelper.INPFile(fileName, featCurveExpressGroup);
        }
 
        //导出ycm文件
        private void barBtnExportYCM_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (_pumpCurveExMapping == null)
                return;
            if (_pumpCurveExMapping.CurveInfo.CurveQH == null)
                return;
 
            var json = PumpCurveDtoHelper.ExportJson(_pumpCurveExMapping);
            if (string.IsNullOrEmpty(json))
            {
                XtraMessageBox.Show("无法解析!");
                return;
            }
 
            var dlg = new SaveFileDialog();
            dlg.Title = "导出 .ycm 文件";
            dlg.FileName = $"{_pumpCurveExMapping.CurveCode}.ycm";
            dlg.Filter = "ycm (*.ycm)|*.ycm";
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            var filePath = dlg.FileName;
            File.WriteAllText(filePath, json);
 
            XtraMessageBox.Show("导出成功!");
        }
 
 
        private void barBtnTemp_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var station = new BLL.Station().GetAll().Last();
            var pumps = new BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, station.ID);
            foreach (var pump in pumps)
            {
                var list = new List<Temp2ViewModel>();
                var curve = new BLL.PumpCurve().GetExMappingByPumpID(pump.ID).First();
                for (int i = 1; i <= 4; i++)
                {
                    var vm = new Temp2ViewModel(pump.RatedParas);
                    vm.ID = i;
                    vm.Name = i + "#";
                    vm.Code = pump.Name;
                    vm.CurveQH = curve.CurveInfo.CurveQH;
                    vm.CurveQE = curve.CurveInfo.CurveQE;
                    vm.CurveQP = curve.CurveInfo.CurveQP;
                    list.Add(vm);
                }
                var json = JsonHelper.Object2Json(list);
                var path = Path.Combine(Settings.File.RootDirectory, "陈行");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                File.WriteAllText(path + "\\" + pump.Name + ".json", json);
            }
 
            XtraMessageBox.Show("over");
        }
 
        public class Temp2ViewModel
        {
            public Temp2ViewModel(Model.Pump rhs)
            {
                this.Qr = rhs.Qr;
                this.Hr = rhs.Hr;
                this.Nr = rhs.Nr;
                this.Pr = rhs.Pr;
                this.Er = rhs.Er;
                this.Ic = rhs.Ic;
                this.Oc = rhs.Oc;
                this.IOd = rhs.IOd;
                this.IsBp = rhs.IsBp;
                this.IsSxp = rhs.IsSxp;
            }
 
            public long ID { get; set; }
            public string Code { get; set; }
            public string Name { get; set; }
            public double Qr { get; set; }
            public double Hr { get; set; }
            public double Nr { get; set; }
            public double Pr { get; set; }
            public double Er { get; set; }
            public double? Ic { get; set; }
            public double? Oc { get; set; }
            public double? IOd { get; set; }
            public double? Ie { get; set; }
            public double? Oe { get; set; }
            public bool IsBp { get; set; }
            public bool IsSxp { get; set; }
            public CurveExpress CurveQH { get; set; }
            public CurveExpress CurveQE { get; set; }
            public CurveExpress CurveQP { get; set; }
        }
 
        //陈行输水
        private void barBtnExportChSS_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var path = Path.Combine(Settings.File.RootDirectory, "陈行");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            var stations = new BLL.Station().GetAll();
            stations = stations?.Where(x => x.Name.Contains("输")).ToList();
            if (stations == null || !stations.Any())
                return;
            var ch1 = stations.First();
            var ch2 = stations.Last();
 
            var model = new Model.StationInfo();
            model.Station1 = new List<PumpInfo>();
            model.Station2 = new List<PumpInfo>();
 
            var pumps1 = new BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, ch1.ID);
            foreach (var pump in pumps1)
            {
                var curve = new BLL.PumpCurve().GetDefaultWorkingByPumpID(pump.ID);
                if (curve == null)
                    continue;
                var rhs = new PumpInfo();
                rhs.Flag = pump.SortCode;
                rhs.Code = pump.NO;
                rhs.Name = pump.Name;
                rhs.Qr = pump.RatedParas.Qr;
                rhs.Hr = pump.RatedParas.Hr;
                rhs.Nr = pump.RatedParas.Nr;
                rhs.Pr = pump.RatedParas.Pr;
                rhs.Er = pump.RatedParas.Er;
                rhs.Ic = pump.RatedParas.Ic;
                rhs.Oc = pump.RatedParas.Oc;
                rhs.IOd = pump.RatedParas.IOd;
                rhs.IsBp = pump.RatedParas.IsBp;
                rhs.CurveQH = curve.CurveInfo.CurveQH;
                rhs.CurveQE = curve.CurveInfo.CurveQE;
                rhs.CurveQP = curve.CurveInfo.CurveQP;
                model.Station1.Add(rhs);
            }
 
            var pumps2 = new BLL.Equipment().GetPumpListByBelongTypeAndBelongID(IStation.ObjectType.Station, ch2.ID);
            foreach (var pump in pumps2)
            {
                var curve = new BLL.PumpCurve().GetDefaultWorkingByPumpID(pump.ID);
                if (curve == null)
                    continue;
                var rhs = new PumpInfo();
                rhs.Flag = pump.SortCode;
                rhs.Code = pump.NO;
                rhs.Name = pump.Name;
                rhs.Qr = pump.RatedParas.Qr;
                rhs.Hr = pump.RatedParas.Hr;
                rhs.Nr = pump.RatedParas.Nr;
                rhs.Pr = pump.RatedParas.Pr;
                rhs.Er = pump.RatedParas.Er;
                rhs.Ic = pump.RatedParas.Ic;
                rhs.Oc = pump.RatedParas.Oc;
                rhs.IOd = pump.RatedParas.IOd;
                rhs.IsBp = pump.RatedParas.IsBp;
                rhs.CurveQH = curve.CurveInfo.CurveQH;
                rhs.CurveQE = curve.CurveInfo.CurveQE;
                rhs.CurveQP = curve.CurveInfo.CurveQP;
                model.Station2.Add(rhs);
            }
 
            var json = JsonHelper.Object2FormatJson(model);
            var jsonPath = path + "\\" + "Station" + ".json";
            File.WriteAllText(jsonPath, json);
            XtraMessageBox.Show("over");
        }
 
        private void barBtnDataValid_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
 
 
 
        }
    }
}