Shuxia Ning
2024-10-08 cf4967a0aebab18c5a37137f3e4c61b2d73a54bb
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
using DevExpress.XtraGrid.Views.Grid;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
 
namespace IStation.WinFrmUI.Analy
{
    public partial class ParallelCurvePage_bak : DocumentPage// DevExpress.XtraEditors.XtraUserControl//
    {
 
        public ParallelCurvePage_bak()
        {
            InitializeComponent();
 
            this.PageTitle.Caption = "曲线并联";
            this.gridView1.SetNormalEditView();
            this.gridView1.OptionsSelection.MultiSelect = false;//单选
            this.gridView1.OptionsBehavior.Editable = true;//
            this.gridView1.BestFitColumns();
 
            this.gridView1.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanged);
            this.gridView1.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridView_CellValueChanging);
            this.gridView1.RowCellClick += new DevExpress.XtraGrid.Views.Grid.RowCellClickEventHandler(this.GridView_RowCellClick);
 
            this.pumpCurveTreeList1.ClickAddCurveEvent += (stationName, pump, curve) =>
            {
                AddCurve(stationName, pump, curve);
                CreateConnectCurve();
            };
 
            this.mainChart.OnCalcQueryPoint += (id, pt) =>
            {
                SetQueryInfo(id, pt);
            };
        }
 
 
        public class CurrentViewModel
        {
            public long ID { get; set; }
 
            public Color DispColor
            {
                set { _dispColor = value; }
                get { return _dispColor; }
            }
            private Color _dispColor = Color.Black;
            public string StationName { get; set; }
            public string PumpName { get; set; }
            public string CurveName { get; set; }
            public string QueryPtQ { get; set; }
            public string QueryPtH { get; set; }
            public string QueryPtE { get; set; }
            public string QueryPtP { get; set; }
            public bool IsFrequency { get; set; }
            public double ConnFrequence { get; set; }
            public double ExtendRatio { get; set; } = 100;
 
            public Model.CurveExpress CurveOriginQH { get; set; }
            public Model.CurveExpress CurveOriginQE { get; set; }
            public Model.CurveExpress CurveOriginQP { get; set; }
 
            public Model.CurveExpress CurveRunQH { get; set; }
            public Model.CurveExpress CurveRunQE { get; set; }
            public Model.CurveExpress CurveRunQP { get; set; }
 
            public double RunMaxFlowByTest = 0;
 
            public void CalcRunCurve()
            {
                if (ConnFrequence > 50)
                    return;
                if (ConnFrequence < 20)
                    return;
                this.CurveRunQH = IStation.Common.CutSimuCalculer.GetSimuPointQH(CurveOriginQH, 2900, 2900 * ConnFrequence / 50);
                this.CurveRunQE = IStation.Common.CutSimuCalculer.GetSimuPointQE(CurveOriginQE, 2900, 2900 * ConnFrequence / 50);
                this.CurveRunQP = IStation.Common.CutSimuCalculer.GetSimuPointQP(CurveOriginQP, 2900, 2900 * ConnFrequence / 50);
                RunMaxFlowByTest = this.CurveRunQH.Max;
 
                this.CurveRunQH.Max = this.CurveRunQH.Max * ExtendRatio / 100;
                this.CurveRunQE.Max = this.CurveRunQE.Max * ExtendRatio / 100;
                this.CurveRunQP.Max = this.CurveRunQP.Max * ExtendRatio / 100;
            }
            public List<Model.CurvePoint> PointsQH { get; set; }
            public List<Model.CurvePoint> PointsQE { get; set; }
            public List<Model.CurvePoint> PointsQP { get; set; }
        }
 
        private BindingList<CurrentViewModel> _allBindingList = null;
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            _allBindingList = new BindingList<CurrentViewModel>();
            this.bindingSource1.DataSource = _allBindingList;
            this.pumpCurveTreeList1.SetBindingData();
        }
 
        /// <summary>
        /// 添加曲线
        /// </summary>
        /// <param name="stationName"></param>
        /// <param name="pump"></param>
        /// <param name="pumpCurve"></param>
        public void AddCurve(string stationName, Model.Equipment<Model.Pump> pump, Model.PumpCurve pumpCurve)
        {
            foreach (var it in _allBindingList)
            {
                if (it.ID == pumpCurve.ID)
                {
                    return;
                }
            }
            if (pumpCurve.CurveInfo == null || pumpCurve.CurveInfo.CurveQH == null)
                return;
            var curveInfo = pumpCurve.CurveInfo;
            if (curveInfo.CurveQH == null)
                return;
 
            var vm = new CurrentViewModel();
            vm.PumpName = pump.Name;
            vm.CurveName = pumpCurve.CurveCode;
            vm.ID = pumpCurve.ID;
 
 
            List<Model.CurvePoint> qhPoints, qePoints = null, qpPoints = null;
            if (curveInfo.CurveQH.DefinePoints != null)
                qhPoints = curveInfo.CurveQH.DefinePoints;
            else
                qhPoints = curveInfo.CurveQH.GetFitPoints(12);
 
            if (curveInfo.CurveQE != null)
                if (curveInfo.CurveQE.DefinePoints != null)
                    qePoints = curveInfo.CurveQE.DefinePoints;
                else
                    qePoints = curveInfo.CurveQE?.GetFitPoints(12);
 
            if (curveInfo.CurveQP != null)
                if (curveInfo.CurveQP?.DefinePoints != null)
                    qpPoints = curveInfo.CurveQP.DefinePoints;
                else
                    qpPoints = curveInfo.CurveQP?.GetFitPoints(12);
 
 
 
            vm.PointsQH = qhPoints;
            vm.PointsQE = qePoints;
            vm.PointsQP = qpPoints;
 
            if (qhPoints.Any())
            {
                var fitType = curveInfo.CurveQH.FitType;
                vm.CurveOriginQH = Model.FitCurveHelper.BuildCurveExpress(qhPoints, fitType);
            }
            if (qePoints.Any())
            {
                var fitType = curveInfo.CurveQE.FitType;
                vm.CurveOriginQE = Model.FitCurveHelper.BuildCurveExpress(qePoints, fitType);
            }
            if (qpPoints.Any())
            {
                var fitType = curveInfo.CurveQP.FitType;
                vm.CurveOriginQP = Model.FitCurveHelper.BuildCurveExpress(qpPoints, fitType);
            }
 
            vm.CurveRunQH = vm.CurveOriginQH;
            vm.CurveRunQE = vm.CurveOriginQE;
            vm.CurveRunQP = vm.CurveOriginQP;
 
            vm.RunMaxFlowByTest = vm.CurveOriginQH.Max;
 
            var color = GetCurveColor();
 
            vm.DispColor = color;
            vm.StationName = stationName;
            vm.IsFrequency = pump.RatedParas == null ? false : pump.RatedParas.IsBp;
            vm.ConnFrequence = 50;
            vm.ExtendRatio = 100;
 
            _allBindingList.Add(vm);
            this.bindingSource1.ResetBindings(false);
 
 
            this.mainChart.AddCurve(vm.ID, $"{stationName}-{pump.Name}", vm.CurveOriginQH, vm.CurveOriginQE, vm.CurveOriginQP, color);
        }
 
        /// <summary>
        /// 创建并联曲线
        /// </summary>
        private void CreateConnectCurve()
        {
            mainChart.DeleteCurve(-1);
            if (_allBindingList.Count < 2)
            {
                return;
            }
 
            var theConnectCurve = new Model.ConnectCurveHelper();
            // 计算并联后的曲线 
            for (int i = 0; i < _allBindingList.Count; i++)
            {
                var vm = _allBindingList[i];
                theConnectCurve.AddSinglePumpCurve(vm.CurveRunQH, vm.CurveRunQP);
            }
 
            if (!theConnectCurve.CalculateParallel(out List<IStation.Model.CurvePoint> connectCurveQH,
                                                   out List<IStation.Model.CurvePoint> connectCurveQE,
                                                   out List<IStation.Model.CurvePoint> connectCurveQP))
            {
                MessageBox.Show("这些泵不适合并联");
                return;
            }
 
            var curveExpressQH = new Model.CurveExpress(connectCurveQH);
            var curveExpressQE = new Model.CurveExpress(connectCurveQE);
            var curveExpressQP = new Model.CurveExpress(connectCurveQP);
 
            this.mainChart.AddCurve(-1, "并联曲线", curveExpressQH, curveExpressQE, curveExpressQP, System.Drawing.Color.Black);
        }
 
        /// <summary>
        /// 查询点信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="queryPt"></param>
        private void SetQueryInfo(long id, Model.GroupPoint queryPt)
        {
            if (queryPt == null || id < 0)
                return;
            var vm = _allBindingList.Where(x => x.ID == id).FirstOrDefault();
            if (vm == null)
                return;
 
            if (queryPt.Q > 0)
            {
                vm.QueryPtQ = string.Format("{0}  {1}", Math.Round(queryPt.Q, 2), Unit.UnitQHelper.GetEnUnitName(Unit.eUnitQ.M3H));
            }
            else
            {
                vm.QueryPtQ = string.Empty;
            }
 
            if (queryPt.H > 0)
            {
                vm.QueryPtH = string.Format("{0} {1}", Math.Round(queryPt.H, 2), Unit.UnitHHelper.GetEnUnitName(Unit.eUnitH.M));
            }
            else
            {
                vm.QueryPtH = string.Empty;
            }
 
            if (queryPt.E > 0)
            {
                vm.QueryPtE = string.Format("{0:N1} %", queryPt.E);
            }
            else
            {
                vm.QueryPtE = string.Empty;
            }
 
 
            if (queryPt.P > 0)
            {
                vm.QueryPtP = string.Format("{0} {1} ", Math.Round(queryPt.P, 2), Unit.UnitPHelper.GetEnUnitName(Unit.eUnitP.KW));
            }
            else
            {
                vm.QueryPtP = string.Empty;
            }
 
            this.bindingSource1.ResetBindings(false);
        }
 
        #region Color
 
        private List<Color> ColorArray = new List<Color>()
        { Color.Red, Color.Blue, Color.Green, Color.DodgerBlue,
            Color.Fuchsia, Color.MidnightBlue, Color.Maroon,
            Color.Aquamarine, Color.Bisque, Color.BurlyWood
        };
 
        /// <summary>
        /// 获取曲线颜色
        /// </summary>
        /// <returns></returns>
        private Color GetCurveColor()
        {
 
            for (int index = 0; index < 20; index++)
            {
                Color color = index < ColorArray.Count ? ColorArray[index] : GetRandomColor();
                CurrentViewModel vm = null;
                foreach (var it in _allBindingList)
                    if (it.DispColor == color)
                    {
                        vm = it;
                        break;
                    }
                if (vm == null)
                    return color;
            }
 
            return Color.Black;
        }
 
        /// <summary>
        /// 获取随机颜色
        /// </summary>
        /// <returns></returns>
        private Color GetRandomColor()
        {
            Random rdmFirst = new Random((int)DateTime.Now.Ticks);
            int red = rdmFirst.Next(256);
            Random rdmSencond = new Random((int)DateTime.Now.Ticks);
            int green = rdmSencond.Next(256);
            int blue = rdmSencond.Next(256);
            return Color.FromArgb(red, green, blue);
        }
        #endregion
 
        #region GridView 
 
        private void GridView_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            var index = e.RowHandle;
            if (index < 0)
                return;
            if (e.Value == null)
                return;
            if (e.Column == this.colConnFrequence)
            {
                var hz = Convert.ToDouble(e.Value);
                if (hz > 50)
                    return;
                if (hz < 5)
                    return;
                var vm = this.gridView1.GetRow(index) as CurrentViewModel;
                vm.CalcRunCurve();
                this.mainChart.SetCurve(vm.ID, vm.CurveRunQH, vm.CurveRunQE, vm.CurveRunQP);
                CreateConnectCurve();
 
            }
            if (e.Column == this.colExtendRatio)
            {
                var ext = Convert.ToDouble(e.Value);
                if (ext > 250)
                    return;
                var vm = this.gridView1.GetRow(index) as CurrentViewModel;
                vm.CalcRunCurve();
                this.mainChart.SetCurve(vm.ID, vm.CurveRunQH, vm.CurveRunQE, vm.CurveRunQP);
                CreateConnectCurve();
            }
 
        }
 
 
        private void GridView_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
 
            if (e.Column == colColor)
            {
                var index = e.RowHandle;
                if (index < 0)
                    return;
                var vm = _allBindingList[index];
                vm.DispColor = (Color)e.Value;
                this.mainChart.SetCurve(vm.ID, vm.DispColor);
            }
 
 
        }
        private void GridView_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            if (e.Column == colDelete)
            {
                var vm = _allBindingList[e.RowHandle];
                if (null == vm)
                {
                    return;
                }
                _allBindingList.Remove(vm);
                this.mainChart.DeleteCurve(vm.ID);
                CreateConnectCurve();
            }
        }
 
        #endregion GridView
 
 
        //计算曲线
        private void barBtnCalcuCurve_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            CreateConnectCurve();
        }
 
        //工作点
        private void barCekSearchCurve_CheckedChanged(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.mainChart.LineVisible = this.barCekSearchCurve.Checked;
        }
    }
}