tx
8 天以前 e0b138b3e057de6f57021e6c8963868f5c5acc5a
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
 
namespace TProduct.WinFrmUI.TPump
{
    internal partial class CalcNpshTestDataByEDlg : CalcNpshTestBaseDlg
    {
        public CalcNpshTestDataByEDlg()
        {
            InitializeComponent();
 
            this.btnCorrect.SetCalcButtonColor();
            this.btnOK.SetConfirmButtonColor();
            this.btnCancel.SetCancelButtonColor();
            //设置默认温度
            _jzTemplate = 20;
            txtTemperature.Value = 20;
            RefreshWaterProperty(20);
 
            this.gridViewMain.OptionsDetail.ShowDetailTabs = false;//不显示TAB名
            this.gridViewMain.OptionsView.ShowGroupPanel = false;//隐藏最上面的GroupPanel
            this.gridViewMain.OptionsSelection.MultiSelect = false;//单选
            //this.gridViewMain.OptionsBehavior.Editable = false;//只读
            this.gridViewMain.BestFitColumns();
            this.gridViewMain.IndicatorWidth = 2;
            this.gridViewMain.RowHeight = 25;
            //this.gridViewMain.CustomDrawGroupRow += new DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventHandler(this.GridViewMain_CustomDrawGroupRow);
            this.gridViewMain.CellValueChanged += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridViewMain_CellValueChanged);
 
 
            power_unit = TProduct.UserSetting.Setting.PumpTest.UnitPower;
            flow_unit = TProduct.UserSetting.Setting.PumpTest.UnitFlow;
            head_unit = TProduct.UserSetting.Setting.PumpTest.UnitHead;
            press_unit = TProduct.UserSetting.Setting.PumpTest.UnitPress;
 
            lblCorrectQ.Text = string.Format("修正流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
            lblTestQ.Text = string.Format("测量流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
 
            lblCorrectH.Text = string.Format("修正扬程({0})", Eventech.Common.UnitHHelper.GetEnUnitName(head_unit));
            lblTestH.Text = string.Format("测量扬程({0})", Eventech.Common.UnitHHelper.GetEnUnitName(head_unit));
 
            //lblCorrectP.Text = string.Format("修正功率({0})", Eventech.Common.UnitPHelper.GetEnUnitName(power_unit));
            //lblTestP.Text = string.Format("测量功率({0})", Eventech.Common.UnitPHelper.GetEnUnitName(power_unit));
 
        }
 
        private void CalcNpshTestDataDlg_Load(object sender, EventArgs e)
        {
        }
 
        public class CurrentViewModel
        {
            public CurrentViewModel() { }
            public TProduct.Model.WorkBenchMonitorPoint Entity { get; set; }
            public long ID { get; set; }
            public string MonitorName { get; set; }
            public string UnitName { get; set; }//单位
            public double? DispValue { get; set; }//单位换算后的
            public DateTime Time { get; set; }
        }
        private long _jzTemperatureMonitorID = 0;
        private List<CurrentViewModel> _bindingData = null;
        public override void InitialMonitorInfo(
            List<TProduct.Model.WorkBenchMonitorPoint> allMonitorList)
        {
            this._allMonitorList = allMonitorList;
 
            this._bindingData = new List<CurrentViewModel>();
            foreach (var monitor in allMonitorList)
            {
                CurrentViewModel v = new CurrentViewModel();
                v.Entity = monitor;
                v.ID = monitor.ID;
                v.MonitorName = monitor.Name;
                v.UnitName = GetUnitName(monitor);
                v.DispValue = null;
 
                if (monitor.MonitorType == Model.eMonitorType.介质温度)
                {
                    this._jzTemperatureMonitorID = monitor.ID;
                }
                if (monitor.MonitorType == Model.eMonitorType.转速)
                {
                    if (monitor.SourceType == Model.eMonitorPointSourceType.额定参数)
                    {
                        v.DispValue = this._ratedN;
                    }
                }
                if (monitor.MonitorType == Model.eMonitorType.电机效率)
                {
                    v.DispValue = _motorRatedEta;
                }
 
                _bindingData.Add(v);
            }
        }
 
 
 
        //
        private TProduct.Model.PumpNpshTestRecordViewModel _currentRecord = null;
        public override void NewTestRecord(
            List<TProduct.Model.MonitorPointValuePure> valueList, bool isAutoCalc)
        {
            txtCorrectQ.Text = "";
            txtCorrectH.Text = "";
            txtCorrectNPSH.Text = "";
 
            txtTestQ.Text = "";
            txtTestH.Text = "";
            txtTestNPSH.Text = "";
            if (_bindingData == null)
                return;
            if (valueList == null || valueList.Count() == 0)
            {
 
                foreach (var bd in _bindingData)
                {
                    if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.计算量)
                        continue;
                    if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
                        continue;
                    if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度)
                        continue;
                    if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率)
                        continue;
                    if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.介质温度)
                        continue;
                    bd.DispValue = null;
                }
            }
            else
            {
                foreach (var bd in _bindingData)
                {
                    var f = valueList.Find(x => x.ID == bd.ID);
                    if (f == null || f.Value == null)
                    {
                        if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.计算量)
                            continue;
                        if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
                            continue;
                        if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度)
                            continue;
                        if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率)
                            continue;
                        if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.介质温度)
                            continue;
                        bd.DispValue = null;
                        continue;
                    }
 
                    double rMeasureValue = f.Value.Value;
                    if (bd.Entity.MonitorType == Model.eMonitorType.功率)
                    {
                        rMeasureValue = Eventech.Common.UnitPHelper.fromKW(
                            power_unit, rMeasureValue);
                    }
                    else if (bd.Entity.MonitorType == Model.eMonitorType.流量)
                    {
                        rMeasureValue = Math.Round(Eventech.Common.UnitQHelper.fromM3H(
                            flow_unit, rMeasureValue), 4);
                    }
                    else if (bd.Entity.MonitorType == Model.eMonitorType.压力)
                    {
                        rMeasureValue = Eventech.Common.UnitHHelper.fromMPa(
                            press_unit, rMeasureValue);
                    }
 
                    bd.DispValue = rMeasureValue;
                    bd.Time = f.Time;
 
                }
            }
            //介质温度没有值 就用默认
            var jz_item = _bindingData.Find(x => x.Entity.MonitorType == Model.eMonitorType.介质温度);
            if (jz_item != null)
            {
                if (jz_item.DispValue == null)
                {
                    jz_item.DispValue = this._jzTemplate;
                    txtTemperature.Value = Convert.ToDecimal(this._jzTemplate);
                    this.RefreshWaterProperty(_jzTemplate);
                }
            }
 
            if (this._jzTemperatureMonitorID > 0 && valueList != null)
            {
                var vTemperature = valueList.Find(x => x.ID == this._jzTemperatureMonitorID);
                if (vTemperature != null && vTemperature.Value.HasValue)
                {
                    this._jzTemplate = vTemperature.Value.Value;
                    this.txtTemperature.Text = vTemperature.Value.Value.ToString();
                    this.RefreshWaterProperty(vTemperature.Value.Value);
                }
            }
 
 
            bindingSource1.DataSource = _bindingData;
            bindingSource1.ResetBindings(false);
            btnOK.Enabled = false;
 
            _currentRecord = new Model.PumpNpshTestRecordViewModel();
            _currentRecord.TestItemID = this._testItemID;
            _currentRecord.Time = DateTime.Now;
            _currentRecord.RecordType = this._recordType;
        }
 
 
        public override void EditTestRecord(TProduct.Model.PumpNpshTestRecordViewModel record)
        {
            if (record == null)
                return;
            foreach (var bd in _bindingData)
            {
                var f = record.MonitorRecordList.Find(x => x.ID == bd.ID);
                if (f == null || string.IsNullOrEmpty(f.Value))
                {
                    if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.计算量)
                        continue;
                    if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
                        continue;
                    if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度)
                        continue;
                    if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率)
                        continue;
                    if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.介质温度)
                        continue;
                    bd.DispValue = null;
                }
                else
                {
                    double rMeasureValue = Convert.ToDouble(f.Value);
                    if (bd.Entity.MonitorType == Model.eMonitorType.功率)
                    {
                        rMeasureValue = Eventech.Common.UnitPHelper.fromKW(
                            power_unit, rMeasureValue);
                    }
                    else if (bd.Entity.MonitorType == Model.eMonitorType.流量)
                    {
                        rMeasureValue = Eventech.Common.UnitQHelper.fromM3H(
                            flow_unit, rMeasureValue);
                    }
                    else if (bd.Entity.MonitorType == Model.eMonitorType.压力)
                    {
                        rMeasureValue = Eventech.Common.UnitHHelper.fromMPa(
                            press_unit, rMeasureValue);
                    }
                    else if (bd.Entity.MonitorType == Model.eMonitorType.介质温度)
                    {
                        _jzTemplate = rMeasureValue;
                        this.txtTemperature.Text = rMeasureValue.ToString();
                        this.RefreshWaterProperty(_jzTemplate);
                    }
                    bd.DispValue = rMeasureValue;
                    bd.Time = record.Time;
                }
            }
            this._currentRecord = record;
            txtTestQ.Text = TProduct.Common.RoundHelper.GetDispValueFlow(
                    Eventech.Common.UnitQHelper.fromM3H(flow_unit, record.TestPtQ)).ToString();
            txtTestE.Text = TProduct.Common.RoundHelper.GetDispValueHead(
                    Eventech.Common.UnitHHelper.fromM(head_unit, record.TestPtAccord)).ToString();
            txtTestNPSH.Text = TProduct.Common.RoundHelper.GetDispValueEta(record.TestPtNpsh).ToString();
 
            txtCorrectQ.Text = TProduct.Common.RoundHelper.GetDispValueFlow(
                   Eventech.Common.UnitQHelper.fromM3H(flow_unit, record.CorrectPtQ)).ToString();
            txtCorrectE.Text = TProduct.Common.RoundHelper.GetDispValueHead(
                   Eventech.Common.UnitHHelper.fromM(head_unit, record.CorrectPtAccord)).ToString();
            txtCorrectNPSH.Text = TProduct.Common.RoundHelper.GetDispValueEta(record.CorrectPtNpsh).ToString();
 
 
 
            bindingSource1.DataSource = _bindingData;
            bindingSource1.ResetBindings(false);
            btnOK.Enabled = false;
        }
 
        //参数
        private double _testQ, _testH, _testE, _testP, _testNpsh;//测量值(都是标准单位)
        private double _correctQ, _correctH, _correctE, _correctP, _correctNpsh;//修正值(都是标准单位)
        private double _rMeasureSpeed;
 
        //计算
        private void btnCorrect_Click(object sender, EventArgs e)
        {
            btnOK.Enabled = false;
 
            try
            {
                if (!CalcMeasurePara())
                    return;
                if (_testH < 0)
                {
                    MessageBox.Show("进出口压力测点是否搞反了");
                    return;
                }
 
                txtTestQ.Text = TProduct.Common.RoundHelper.GetDispValueFlow(
                    Eventech.Common.UnitQHelper.fromM3H(flow_unit, _testQ)).ToString();
                txtTestH.Text = TProduct.Common.RoundHelper.GetDispValueHead(
                    Eventech.Common.UnitHHelper.fromM(head_unit, _testH)).ToString();
                txtTestE.Text = TProduct.Common.RoundHelper.GetDispValueEta(_testE).ToString();
 
                txtTestNPSH.Text = TProduct.Common.RoundHelper.GetDispValueHead(_testNpsh).ToString();
 
                txtCorrectE.Text = TProduct.Common.RoundHelper.GetDispValueEta(_correctE).ToString();
 
                txtCorrectQ.Text = TProduct.Common.RoundHelper.GetDispValueFlow(
                    Eventech.Common.UnitQHelper.fromM3H(flow_unit, _correctQ)).ToString();
                txtCorrectH.Text = TProduct.Common.RoundHelper.GetDispValueHead(
                    Eventech.Common.UnitHHelper.fromM(head_unit, _correctH)).ToString();
                txtCorrectNPSH.Text = TProduct.Common.RoundHelper.GetDispValueHead(_correctNpsh).ToString();
 
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Error:169");
                return;
            }
 
            btnOK.Enabled = true;
        }
        #region 计算
 
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private bool CalcMeasurePara()
        {
            if (_ratedParas == null)
            {
                XtraMessageBox.Show("未设置泵额定参数?", "问题确认",
          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            #region 转速,流量
            //测量转速
            var moinitor_speed = this._bindingData.Find(x => x.Entity.MonitorType == Model.eMonitorType.转速);
            if (moinitor_speed == null || moinitor_speed.DispValue == null)
            {
                XtraMessageBox.Show("请输入电机转速?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            this._rMeasureSpeed = moinitor_speed.DispValue.Value;
 
            //测量流量
            double total_flow_m3h = 0;
            var moinitor_flows = this._bindingData.Where(x => x.Entity.MonitorType == Model.eMonitorType.流量);
            if (moinitor_flows == null || moinitor_flows.Count() == 0)
            {
                XtraMessageBox.Show("请输入流量?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            else if (moinitor_flows.Count() == 1)
            {
                var moinitor_flow = moinitor_flows.First();
                if (moinitor_flow == null || moinitor_flow.DispValue == null)
                {
                    XtraMessageBox.Show("请输入流量?", "问题确认",
                              MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
                total_flow_m3h = Eventech.Common.UnitQHelper.toM3H(flow_unit, moinitor_flow.DispValue.Value);
            }
            else
            {//多个流量计
                total_flow_m3h = 0;
                foreach (var moinitor_flow in moinitor_flows)
                {
                    if (moinitor_flow == null || moinitor_flow.DispValue == null)
                    {
                        continue;
                    }
                    total_flow_m3h = total_flow_m3h + moinitor_flow.DispValue.Value * moinitor_flow.Entity.SumCalcCoeff;
                }
                total_flow_m3h = Eventech.Common.UnitQHelper.toM3H(flow_unit, total_flow_m3h);
            }
 
            #endregion
 
            #region 计算扬程 
 
            double OtherPressCoeff = 4 * 1000 / Math.PI / 3.6;
            double rPipeInV = 0;
            double p1m = 0;
            CurrentViewModel moinitor_press_inlet =
                this._bindingData.Find(x => x.Entity.MonitorType == Model.eMonitorType.压力 && x.Entity.Property == TProduct.Model.MonitorTypeProperty.进口);
            //if (moinitor_press_inlet != null &&
            //    moinitor_press_inlet.Entity != null &&
            //    moinitor_press_inlet.Entity.PipeDia != null &&
            //    moinitor_press_inlet.Entity.PipeDia > 10)
            //{
            //    double mm_inlet_dia = moinitor_press_inlet.Entity.PipeDia.Value;
            //    rPipeInV = OtherPressCoeff * total_flow_m3h / mm_inlet_dia / mm_inlet_dia;
            //}
 
            if (_ratedParas.IsInletPress)
            {//可能测点有,配有标高
                if (moinitor_press_inlet == null || moinitor_press_inlet.DispValue == null)
                {
                    XtraMessageBox.Show("请输入进口压力?", "问题确认",
                              MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
 
                p1m = Eventech.Common.UnitHHelper.toMPa(press_unit, moinitor_press_inlet.DispValue.Value);
            }
 
            var moinitor_press_outlet = this._bindingData.Find(x => x.Entity.MonitorType == Model.eMonitorType.压力 && x.Entity.Property == TProduct.Model.MonitorTypeProperty.出口);
            if (moinitor_press_outlet == null || moinitor_press_outlet.DispValue == null)
            {
                XtraMessageBox.Show("请输入出口压力?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
 
            double p2m = Eventech.Common.UnitHHelper.toMPa(press_unit, moinitor_press_outlet.DispValue.Value);
 
            double rPipeOutV = 0;
            //if (moinitor_press_outlet.Entity.PipeDia != null && moinitor_press_outlet.Entity.PipeDia > 10)
            //{
            //    double mm_outlet_dia = moinitor_press_outlet.Entity.PipeDia.Value;
            //    rPipeOutV = OtherPressCoeff * total_flow_m3h / mm_outlet_dia / mm_outlet_dia;
            //}
 
            //高差
            double gc = 0;
            //if (moinitor_press_outlet.Entity.Elevation != null)
            //{
            //    gc += moinitor_press_outlet.Entity.Elevation.Value;
            //}
            //if (moinitor_press_inlet != null &&
            //    moinitor_press_inlet.Entity != null &&
            //    moinitor_press_inlet.Entity.Elevation != null)
            //{
            //    gc -= moinitor_press_inlet.Entity.Elevation.Value;
            //}
 
            double rVDif = (rPipeOutV * rPipeOutV - rPipeInV * rPipeInV) / (TProduct.ConstantParas.g * 2.0);
            double total_head = Math.Round(UnitConvert_MPa2M(p2m - p1m) + rVDif + gc, 2);
 
            #endregion
 
            #region  功率/扭矩
            double total_axis_power = 0;
            if (_powerTestMethod == TProduct.Model.ePowerTestMethod.扭矩)
            {
                var moinitor_扭矩 = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.扭矩);
                if (moinitor_扭矩 == null || moinitor_扭矩.DispValue == null)
                {
                    XtraMessageBox.Show("请输入扭矩值?", "问题确认",
                              MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
                total_axis_power = Math.Round(moinitor_扭矩.DispValue.Value * _rMeasureSpeed / 9550, 3);
            }
            else
            {//电机功率
                var moinitor_power = this._bindingData.Find(x =>
    x.Entity.MonitorType == TProduct.Model.eMonitorType.功率
    && (string.IsNullOrEmpty(x.Entity.Property) || x.Entity.Property == TProduct.Model.MonitorTypeProperty.总));
                if (moinitor_power == null || moinitor_power.DispValue == null)
                {
                    XtraMessageBox.Show("请输入电机功率?", "问题确认",
                              MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
                double rMotorPower = Eventech.Common.UnitPHelper.toKW(power_unit,
                    moinitor_power.DispValue.Value);
                if (rMotorPower <= 0.0001)
                {
                    XtraMessageBox.Show("请输入电机功率?", "问题确认",
                              MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
 
                total_axis_power = rMotorPower * _motorRatedEta / 100.0;//乘以电机效率
            }
 
            #endregion
 
            this._testQ = TProduct.Common.RoundHelper.GetDispValueFlow(total_flow_m3h);
            this._testH = TProduct.Common.RoundHelper.GetDispValueHead(total_head);
            this._testP = TProduct.Common.RoundHelper.GetDispValuePower(total_axis_power);
            this._testE = CalculateE(_testQ, _testH, _testP);
 
            if (TProduct.UserSetting.Setting.PumpTest.IsCheckErrorEta100 && this._testE > 99)
            {
                XtraMessageBox.Show("效率已超过100%,请确认数据是否正常??", "问题确认",
                      MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
 
            //依照设计手册P220页
            //NPSH = Pa/pg+ Ps/pg + Vs^2/2g - Pv/pg + Zd;
            // Pa = 大气压  Ps 进口表压  Pv气化压力  Vs 流速 Zd 泵进口基准面与NPSH基准面的高差
            // pg 密度和重力加速度
            _testNpsh =
                  UnitConvert_KPa2M(this._atmospherePressure)//大气压(Kp)
                - UnitConvert_KPa2M(this._qiHuaYaLi)//汽化压力(Kp)
                + UnitConvert_MPa2M(p1m)
                + this._ratedParas.NpshGaoChaZd//Zd 泵进口基准面与NPSH基准面的高差
                + rPipeInV * rPipeInV / TProduct.ConstantParas.g / 2.0
                ;//计算水泵汽蚀
 
            //计算测试修正值
            if (!CalculeCorrectPara())
            {
                return false;
            }
 
 
            //温度换算
            if (!CalculeByTemperature())
            {
                return false;
            }
 
            return true;
        }
 
 
 
        //根据测试参数,计算测试修正值(输入进来的单位都是标准单位)
        public bool CalculeCorrectPara()
        {
            _correctQ = _correctH = _correctE = _correctP = _correctNpsh = 0;
            //测量转速
            if (_rMeasureSpeed <= 20)
            {
                XtraMessageBox.Show("请输入转速?", "问题确认", MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
 
            try
            {
                bool isZeroQ = false;
                if (this._ratedParas == null)
                {
                    if (this._testQ < 0.1)
                    {
                        this._testQ = 0;
                        isZeroQ = true;
                    }
                }
                else
                {
                    if (this._testQ < this._ratedParas.Q / 50)
                    {
                        this._testQ = 0;
                        isZeroQ = true;
                    }
                }
                double rTestSpeed = this._rMeasureSpeed;
 
                //得到相似换算值
                double xshsFlow = _testQ * this._ratedN / _rMeasureSpeed;
                double xshsHead = _testH * this._ratedN * this._ratedN / _rMeasureSpeed / _rMeasureSpeed;
 
                //效率进行修正
                double xshsEffice = GetSpeedE(this._testE, rTestSpeed, this._ratedN);
 
                //功率
                double xshsPower = 0;
                if (isZeroQ)
                {//零流量点的功率
                    xshsPower = this._testP * this._ratedN * this._ratedN * this._ratedN / rTestSpeed / rTestSpeed / rTestSpeed;
                }
                else
                {//一般点的功率用效率计算
                    xshsPower = CalculateP(xshsFlow, xshsHead, xshsEffice);
                }
 
                //汽蚀 根据手册P79页为速度的平方
                double xshsNPSH = _testNpsh * this._ratedN * this._ratedN / _rMeasureSpeed / _rMeasureSpeed;
 
                _correctQ = TProduct.Common.RoundHelper.GetDispValueFlow(xshsFlow);
                _correctH = TProduct.Common.RoundHelper.GetDispValueHead(xshsHead);
                _correctE = TProduct.Common.RoundHelper.GetDispValueEta(xshsEffice);
                _correctP = TProduct.Common.RoundHelper.GetDispValuePower(xshsPower);
 
                _correctNpsh = Math.Round(xshsNPSH, 2);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString());
                return false;
            }
            return true;
        }
 
 
        /// <summary>
        /// 温度换算
        /// </summary>
        /// <returns></returns>
        private bool CalculeByTemperature()
        {
            //温度换算
            if (this._isTemperatureTrn && _correctQ > 0.1)
            {
                double origin_eta = _correctE;//模型效率
                double origin_wendu = 20;//模型温度
                if (this._jzTemplate > -10)
                {
                    _correctE = Math.Round((origin_eta * 100 / (origin_eta * 1 + (100 - origin_eta) * Math.Pow((origin_wendu / _jzTemplate), -0.07))), 2);
 
                    _correctP = CalculateP(_correctH, _correctQ, _correctE);
                }
            }
 
            return true;
        }
        #endregion
        //
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_bindingData == null)
                return;
            if (this._ratedParas == null)
            {
                XtraMessageBox.Show("未设置泵的额定参数");
                return;
            }
            if (this._testNpsh < 0)
            {
                XtraMessageBox.Show("汽蚀为负数,请确认");
                return;
            }
            if (this._testH < 0.1)
            {
                XtraMessageBox.Show("扬程数据不正常?");
                return;
            }
            if (this._currentRecord == null)
                return;
            try
            {
                _currentRecord.Time = DateTime.Now;
                _currentRecord.Speed = this._rMeasureSpeed;
                //_testQ , _correctQ已经是标准单位了
                _currentRecord.TestPtQ = TProduct.Common.RoundHelper.GetDispValueFlow(this._testQ);
                _currentRecord.TestPtAccord = TProduct.Common.RoundHelper.GetDispValueHead(this._testE);
                _currentRecord.TestPtNpsh = TProduct.Common.RoundHelper.GetDispValueHead(this._testNpsh);
 
                _currentRecord.CorrectPtQ = TProduct.Common.RoundHelper.GetDispValueFlow(this._correctQ);
                _currentRecord.CorrectPtAccord = TProduct.Common.RoundHelper.GetDispValueHead(this._correctE);
                _currentRecord.CorrectPtNpsh = TProduct.Common.RoundHelper.GetDispValueHead(this._correctNpsh);
 
                TProduct.Model.MonitorRecord4DsList monitorRecord4Ds = new TProduct.Model.MonitorRecord4DsList();
                foreach (var bd in _bindingData)
                {
                    if (bd.DispValue != null)
                    {
                        double rMeasureValue = bd.DispValue.Value;
                        if (bd.Entity.MonitorType == Model.eMonitorType.功率)
                        {
                            rMeasureValue = Eventech.Common.UnitPHelper.toKW(
                                power_unit, rMeasureValue);
                        }
                        else if (bd.Entity.MonitorType == Model.eMonitorType.流量)
                        {
                            rMeasureValue = Eventech.Common.UnitQHelper.toM3H(
                                flow_unit, rMeasureValue);
                        }
                        else if (bd.Entity.MonitorType == Model.eMonitorType.压力)
                        {
                            rMeasureValue = Eventech.Common.UnitHHelper.toMPa(
                                press_unit, rMeasureValue);
                        }
                        monitorRecord4Ds.Add(new TProduct.Model.MonitorRecord4Ds(bd.ID, rMeasureValue.ToString()));
                    }
                }
                _currentRecord.MonitorRecordList = monitorRecord4Ds;
                _currentRecord.MonitorRecords = monitorRecord4Ds.ToDsString();
 
                if (this.OnSaveRecord == null)
                    return;
                var bll = new BLL.PumpNpshTestRecord();
                // operateType表示操作类型 1 表示添加  2 表示更新  3表示删除
                if (_currentRecord.ID == 0)
                {
                    _currentRecord.ID = bll.Add(this._testItem, _currentRecord);
                    OnSaveRecord(_currentRecord, 1);
                }
                else
                {
                    bll.Update(this._testItem, _currentRecord);
                    OnSaveRecord(_currentRecord, 2);
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Error:184");
                return;
            }
            if (isAutoClose)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {//注意:此对话框不会关闭,只是隐藏,如果要关闭需要外部关闭
                txtCorrectQ.Text = "";
                txtCorrectH.Text = "";
                txtCorrectNPSH.Text = "";
 
                txtTestQ.Text = "";
                txtTestH.Text = "";
                txtTestNPSH.Text = "";
 
                this.Hide();//不要关闭可能要再次打开
            }
 
        }
 
        //
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (isAutoClose)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                this.Close();
            }
            else
            {//注意:此对话框不会关闭,只是隐藏,如果要关闭需要外部关闭
                this.Hide();
            }
        }
 
        //
        private double _motorRatedEta = 100;
        public override void SetMotorInfo(double ratedEta, Eventech.Model.CurveExpress eatCurve)
        {
            if (ratedEta > 1)
            {
                if (_bindingData != null)
                {
                    var f = this._bindingData.Find(x => x.Entity.MonitorType == Model.eMonitorType.电机效率);
                    if (f != null)
                    {
                        f.Time = DateTime.Now;
                        f.DispValue = ratedEta;
                        bindingSource1.DataSource = _bindingData;
                        bindingSource1.ResetBindings(false);
                    }
 
                }
 
                _motorRatedEta = ratedEta;
            }
        }
 
 
        private void GridViewMain_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            var rec = gridViewMain.GetRow(e.RowHandle) as CurrentViewModel;
            if (rec == null)
                return;
            if (rec.Entity.MonitorType == Model.eMonitorType.介质温度 && rec.DispValue != null)
            {
                this._jzTemplate = rec.DispValue.Value;
                this.txtTemperature.Text = this._jzTemplate.ToString();
                this.RefreshWaterProperty(rec.DispValue.Value);
            }
        }
 
 
 
        //根据温度计算汽化压力
        double _qiHuaYaLi = 2.334;// (Kp) 
        private void RefreshWaterProperty(double temperature)
        {
            TProduct.Model.WaterProperty prop = TProduct.Common.WaterPropertyHelper.GetByTemperature(temperature);
            if (prop == null)
                return;
 
            this._qiHuaYaLi = prop.BHZQYkpa;
 
            text密度.Text = prop.MD.ToString();
            text重度.Text = prop.ZD.ToString();
            text运动粘度.Text = prop.YDND.ToString();
            text饱和蒸汽压kgf.Text = prop.BHZQYkgf.ToString();
            text饱和蒸汽压kpa.Text = prop.BHZQYkpa.ToString();
        }
 
        private void btnHelpNpshCalc_Click(object sender, EventArgs e)
        {
            //new TPump.WinFrmUI.CalcNpshHelplDlg().Show();
        }
 
    }
}