tx
2025-04-10 2538101febc78f525945da72c7cdcb2589f9e6ea
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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
 
namespace TProduct.WinFrmUI.TPump
{
    //
    internal partial class CalcFeatTestData1Dlg : CalcFeatTestBaseDlg
    {
        public CalcFeatTestData1Dlg() : base()
        {
            InitializeComponent();
 
            btnOK.Enabled = false;
 
            this.btnCorrect.SetCalcButtonColor();
            this.btnOK.SetConfirmButtonColor();
            this.btnCancel.SetCancelButtonColor();
 
            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.CustomUnboundColumnData += new DevExpress.XtraGrid.Views.Base.CustomColumnDataEventHandler(this.GridViewMain_CustomUnboundColumnData);
 
 
            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 CalcTestData1Dlg_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; }
            public bool IsByCalc { get; set; } = false;//是否是计算得到的
        }
 
        List<CurrentViewModel> _bindingData = null;
        public override void InitialMonitorInfo(List<TProduct.Model.WorkBenchMonitorPoint> 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 == TProduct.Model.eMonitorType.转速)
                {
                    if (monitor.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
                    {
                        v.DispValue = this._pumpRatedN;
                    }
                }
                if (monitor.MonitorType == TProduct.Model.eMonitorType.电机效率)
                {
                    if (monitor.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
                    {
                        if (this._motorRatedEta > 1)
                        {
                            v.DispValue = this._motorRatedEta;
                        }
                    }
                }
                if (monitor.MonitorType == TProduct.Model.eMonitorType.电机效率)
                {
                    if (this._motorRatedEta > 1)
                    {
                        v.DispValue = this._motorRatedEta;
                    }
                }
 
                _bindingData.Add(v);
            }
        }
 
        //
        private TProduct.Model.PumpFeatTestRecordViewModel _currentRecord = null;
        //
        public override bool NewTestRecord(
            List<TProduct.Model.MonitorPointValuePure> valueList, bool isAutoCalc)
        {
            if (_bindingData == null)
                return false ;
            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;
                }
            }
 
            bindingSource1.DataSource = _bindingData;
            bindingSource1.ResetBindings(false);
            btnOK.Enabled = false;
 
            _currentRecord = new Model.PumpFeatTestRecordViewModel();
            _currentRecord.TestItemID = this._testItemID;
            _currentRecord.Time = DateTime.Now;
            _currentRecord.RecordType = this._recordType;
 
            if (isAutoCalc)
            {
               return  CalcCorrectPt(false);
            }
            else
            {
                return true;
            }
        }
 
        public override bool NewTestRecord4Save(List<TProduct.Model.MonitorPointValuePure> valueList)
        {
            if (NewTestRecord(valueList, true) == false)
                return false;
 
            if (this._testE < -0.1)
            {
                XtraMessageBox.Show("效率不正常,是否是进出口压力表搞错?");
                return false;
            }
            if (TProduct.UserSetting.Setting.PumpTest.IsCheckErrorEta100 && this._testE > 99)
            {
                XtraMessageBox.Show("效率不正常?");
                return false;
            }
            if (this._currentRecord == null)
                return false;
 
            _currentRecord.Time = DateTime.Now;
            RefreshDsRecord();// 不含时间
 
            if (this.OnSaveRecord == null)
                return false;
            var bll = new BLL.PumpFeatTestRecord();
            // operateType表示操作类型 1 表示添加  2 表示更新  3表示删除
 
            _currentRecord.ID = bll.Add(this._testItem, _currentRecord);
            OnSaveRecord(_currentRecord, 1);
 
            return true;
        }
        public override void EditTestRecord(TProduct.Model.PumpFeatTestRecordViewModel 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);
                    }
 
                    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();
            txtTestH.Text = TProduct.Common.RoundHelper.GetDispValueHead(
                    Eventech.Common.UnitHHelper.fromM(head_unit, record.TestPtH)).ToString();
            txtTestE.Text = TProduct.Common.RoundHelper.GetDispValueEta(record.TestPtE.Value).ToString();
 
            if (record.TestPtP != null)
            {
                txtTestP.Text = TProduct.Common.RoundHelper.GetDispValuePower(
                    Eventech.Common.UnitPHelper.fromKW(power_unit, record.TestPtP.Value)).ToString();
            }
 
 
            txtCorrectQ.Text = TProduct.Common.RoundHelper.GetDispValueFlow(
                   Eventech.Common.UnitQHelper.fromM3H(flow_unit, record.CorrectPtQ)).ToString();
            txtCorrectH.Text = TProduct.Common.RoundHelper.GetDispValueHead(
                   Eventech.Common.UnitHHelper.fromM(head_unit, record.CorrectPtH)).ToString();
            txtCorrectE.Text = TProduct.Common.RoundHelper.GetDispValueEta(record.CorrectPtE.Value).ToString();
            if (record.CorrectPtP != null)
            {
                txtCorrectP.Text = TProduct.Common.RoundHelper.GetDispValuePower(
                    Eventech.Common.UnitPHelper.fromKW(power_unit, record.CorrectPtP.Value)).ToString();
            }
 
 
            bindingSource1.DataSource = _bindingData;
            bindingSource1.ResetBindings(false);
            btnOK.Enabled = false;
        }
 
 
        //参数
        private double _testQ, _testH, _testE, _testP;//测量值(都是标准单位)
        private double _correctQ, _correctH, _correctE, _correctP;//修正值(都是标准单位)
        private double _rMeasureSpeed, _rMeasureHz;
 
        //计算
        private void btnCorrect_Click(object sender, EventArgs e)
        {
            CalcCorrectPt(true);
        }
        private bool CalcCorrectPt(bool isShowError)
        {
            btnOK.Enabled = false;
 
            try
            {
                if (!CalcMeasurePara(isShowError))
                    return false ;
 
                if (_testH < 0)
                {
                    if (isShowError)
                        MessageBox.Show("进出口压力测点是否搞反了");
                    return false ;
                }
                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();
                txtTestP.Text = TProduct.Common.RoundHelper.GetDispValuePower(
                    Eventech.Common.UnitPHelper.fromKW(power_unit, _testP)).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();
                txtCorrectE.Text = TProduct.Common.RoundHelper.GetDispValueEta(_correctE).ToString();
                txtCorrectP.Text = TProduct.Common.RoundHelper.GetDispValuePower(
                    Eventech.Common.UnitPHelper.fromKW(power_unit, _correctP)).ToString();
            }
            catch (Exception ex)
            {
                if (isShowError)
                    XtraMessageBox.Show(ex.Message, "Error:169");
                return false ;
            }
 
            btnOK.Enabled = true;
            return true;    
        }
 
        #region 计算
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private bool CalcMeasurePara(bool isShowError)
        {
            if (_pumpRatedParas == null)
            {
                _speedSimuMethod  = Model.eSpeedSimuMethod.不换算;
              //  if (isShowError)
              //      XtraMessageBox.Show("未设置泵额定参数?", "问题确认",
              //MessageBoxButtons.OK, MessageBoxIcon.Question);
              //  return false;
            }
 
            #region 转速,流量 
            _rMeasureHz = 0;
            var moinitor_hz = this._bindingData.Find(x => x.Entity.MonitorType == Model.eMonitorType.频率);
            if (moinitor_hz != null && moinitor_hz.DispValue != null)
            {
                this._rMeasureHz = moinitor_hz.DispValue.Value;
            }
            else if (_speedSimuMethod == Model.eSpeedSimuMethod.频率换算)
            {
                if (isShowError)
                    XtraMessageBox.Show("请输入电机频率?", "问题确认",
      MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
            //测量转速(最先获取,因为轴功率可能用到)
            var moinitor_speed = this._bindingData.Find(x => x.Entity.MonitorType == Model.eMonitorType.转速);
            if (moinitor_speed == null || moinitor_speed.DispValue == null)
            {
                if (moinitor_speed != null &&
                    moinitor_speed.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
                {
                    this._rMeasureSpeed = this._pumpRatedN;
                    this._rMeasureHz = 50;
                }
                else if (_speedSimuMethod == Model.eSpeedSimuMethod.转速换算)
                {
                    if (isShowError)
                        XtraMessageBox.Show("请输入电机转速?", "问题确认",
          MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
                else if (_speedSimuMethod == Model.eSpeedSimuMethod.频率换算)
                {
                    this._rMeasureSpeed = Math.Round(this._pumpRatedN * this._rMeasureHz / 50, 0);
                }
                else if (_speedSimuMethod == Model.eSpeedSimuMethod.不换算)
                {
                    this._rMeasureSpeed = this._pumpRatedN;
                }
                else
                {
                    this._rMeasureSpeed = this._pumpRatedN;
                }
            }
            else
            {
                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)
            {
                if (isShowError)
                    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)
                {
                    if (isShowError)
                        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 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)
                {
                    if (isShowError)
                        XtraMessageBox.Show("请输入扭矩值?", "问题确认",
                              MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
                total_axis_power = Math.Round(moinitor_扭矩.DispValue.Value * _rMeasureSpeed / 9550, 3);
            }
            else
            {//电机功率
                double motor_eff = _motorRatedEta;
                var moinitor_motor_eff = this._bindingData.Find(x =>
    x.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率);
                if (moinitor_motor_eff != null && moinitor_motor_eff.DispValue != null)
                {
                    motor_eff = moinitor_motor_eff.DispValue.Value;
                }
 
                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)
                {
                    if (isShowError)
                        XtraMessageBox.Show("请先设置电机功率测点?", "问题确认",
                              MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
 
                if (moinitor_power.DispValue == null ||
                    Eventech.Common.UnitPHelper.toKW(power_unit,
                    moinitor_power.DispValue.Value) < 0.0001 || bci自动计算电机功率.Checked)
                {
                    var calc_power = CalcPowerByUI();
                    if (calc_power != null)
                    {
                        bci自动计算电机功率.Checked = true;
                        moinitor_power.IsByCalc = true;
                        moinitor_power.DispValue = calc_power;
                        this.bindingSource1.ResetBindings(false);
                    }
                    else
                    {
                        if (isShowError)
                            XtraMessageBox.Show("请输入电机功率?", "问题确认",
                                  MessageBoxButtons.OK, MessageBoxIcon.Question);
                        return false;
                    }
                }
                double rMotorPower = Eventech.Common.UnitPHelper.toKW(power_unit,
                    moinitor_power.DispValue.Value);
 
                if (motor_eff > 1)
                    total_axis_power = rMotorPower * motor_eff / 100.0;//乘以电机效率
                else
                    total_axis_power = rMotorPower;
            }
 
            #endregion
 
            #region 计算扬程
            double OtherPressCoeff = 4 * 1000 / Math.PI / 3.6;
            double rPipeInV = 0;
 
            double p1m = 0;
            double height_inlet = 0;
            if (_isInlet清水池)
            {
                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.Elevation != null)
                {
                    height_inlet = moinitor_press_inlet.Entity.Elevation.Value;
                }
 
                if (moinitor_press_inlet != null && moinitor_press_inlet.DispValue != null)
                {
                    p1m = moinitor_press_inlet.DispValue.Value;
                }
            }
            else
            {
                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 (moinitor_press_inlet != null &&
                   moinitor_press_inlet.Entity != null &&
                   moinitor_press_inlet.Entity.Elevation != null)
                {
                    height_inlet = moinitor_press_inlet.Entity.Elevation.Value;
                }
 
                if (_pumpRatedParas != null && _pumpRatedParas.IsInletPress)
                {
                    if (moinitor_press_inlet == null || moinitor_press_inlet.DispValue == null)
                    {
                        if (isShowError)
                            XtraMessageBox.Show("请输入进口压力?", "问题确认",
                                  MessageBoxButtons.OK, MessageBoxIcon.Question);
                        return false;
                    }
 
                    double p1mpa = Eventech.Common.UnitHHelper.toMPa(press_unit,
                        moinitor_press_inlet.DispValue.Value);
                    p1m = UnitConvert_MPa2M(p1mpa);
                }
                else
                {
                    if (moinitor_press_inlet != null && moinitor_press_inlet.DispValue != null)
                    {
                        double p1mpa = Eventech.Common.UnitHHelper.toMPa(press_unit,
                            moinitor_press_inlet.DispValue.Value);
                        p1m = UnitConvert_MPa2M(p1mpa);
                    } 
                }
            }
 
 
 
 
 
            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)
            {
                if (isShowError)
                    XtraMessageBox.Show("请输入出口压力?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
 
            double p2mpa = Eventech.Common.UnitHHelper.toMPa(
                press_unit, moinitor_press_outlet.DispValue.Value);
            double p2m = UnitConvert_MPa2M(p2mpa);
            double rPipeOutV = 0;
            double height_oulet = 0;
            if (moinitor_press_outlet.Entity.PipeDia != null && moinitor_press_outlet.Entity.PipeDia > 5)
            {
                double mm_outlet_dia = moinitor_press_outlet.Entity.PipeDia.Value;
                rPipeOutV = OtherPressCoeff * total_flow_m3h / mm_outlet_dia / mm_outlet_dia;// OtherPressCoeff = 4 * 1000 / Math.PI / 3.6;
            }
            if (moinitor_press_outlet.Entity.Elevation != null)
            {
                height_oulet = moinitor_press_outlet.Entity.Elevation.Value;
            }
 
 
 
            double gc = height_oulet - height_inlet;//高差
            double rVDif = (rPipeOutV * rPipeOutV - rPipeInV * rPipeInV) / (TProduct.ConstantParas.g * 2.0);
            double total_head = Math.Round(p2m - p1m + rVDif + gc, 2);
 
            #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)
            {
                if (isShowError)
                    XtraMessageBox.Show("效率已超过100%,请确认数据是否正常?", "问题确认",
          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
 
            //计算测试修正值
            if (!CalculeCorrectPara(isShowError))
            {
                return false;
            }
 
            //温度换算
            if (!CalculeByTemperature(isShowError))
            {
                return false;
            }
 
            return true;
        }
 
        /// <summary>
        /// 根据电流电压计算功率
        /// </summary>
        /// <returns></returns>
        private double? CalcPowerByUI()
        {
            var moinitor_相电压 = this._bindingData.Find(x =>
x.Entity.MonitorType == TProduct.Model.eMonitorType.相电压
&& (string.IsNullOrEmpty(x.Entity.Property) || x.Entity.Property == TProduct.Model.MonitorTypeProperty.总));
            if (moinitor_相电压 == null || moinitor_相电压.DispValue == null)
                return null;
 
            var moinitor_相电流 = this._bindingData.Find(x =>
x.Entity.MonitorType == TProduct.Model.eMonitorType.相电流
&& (string.IsNullOrEmpty(x.Entity.Property) || x.Entity.Property == TProduct.Model.MonitorTypeProperty.总));
            if (moinitor_相电流 == null || moinitor_相电流.DispValue == null)
                return null;
            if (this._supplyCurrentType == Model.eSupplyCurrentType.直流)
            {//暂时只考虑直流
                return moinitor_相电压.DispValue.Value * moinitor_相电流.DispValue.Value;
            }
            return null;
        }
        /// <summary>
        /// 根据测试参数,计算测试修正值(输入进来的单位都是标准单位)
        /// </summary>
        /// <returns></returns>
        public bool CalculeCorrectPara(bool isShowError)
        {
            _correctQ = _correctH = _correctE = _correctP = 0;
            //测量转速 
            if (_speedSimuMethod == Model.eSpeedSimuMethod.转速换算)
            {
                if (this._rMeasureSpeed <= 20)
                {
                    if (isShowError)
                        XtraMessageBox.Show("请输入转速?", "问题确认", MessageBoxButtons.OK, MessageBoxIcon.Question);
                    return false;
                }
            }
            else if (_speedSimuMethod == Model.eSpeedSimuMethod.频率换算)
            {
                this._rMeasureSpeed = Math.Round(this._pumpRatedN * this._rMeasureHz / 50, 0);
            }
            else if (_speedSimuMethod == Model.eSpeedSimuMethod.不换算)
            {
                if (this._rMeasureSpeed <= 20)
                {
                    this._rMeasureSpeed = this._pumpRatedN;
                }
            }
 
 
 
 
            try
            {
                bool isZeroQ = false;
                if (this._pumpRatedParas == null)
                {
                    if (this._testQ < 0.1)
                    {
                        this._testQ = 0;
                        isZeroQ = true;
                    }
                }
                else
                {
                    if (this._testQ < this._pumpRatedParas.Q / 50)
                    {
                        this._testQ = 0;
                        isZeroQ = true;
                    }
                }
 
                if (_speedSimuMethod == Model.eSpeedSimuMethod.转速换算 ||
                    _speedSimuMethod == Model.eSpeedSimuMethod.频率换算)
                {
                    if (Math.Abs(this._rMeasureSpeed - this._pumpRatedN) < 3)
                    {
                        _correctQ = this._testQ;
                        _correctH = this._testH;
                        _correctE = this._testE;
                        _correctP = this._testP;
                    }
                    else
                    {
                        double rTestSpeed = this._rMeasureSpeed;
 
 
                        //得到相似换算值
                        double xshsFlow = this._testQ * this._pumpRatedN / rTestSpeed;
                        double xshsHead = this._testH * this._pumpRatedN * this._pumpRatedN / rTestSpeed / rTestSpeed;
 
                        //效率进行修正
                        double xshsEffice = GetSpeedE(this._testE, rTestSpeed, this._pumpRatedN);
 
                        //功率
                        double xshsPower = 0;
                        if (isZeroQ)
                        {//零流量点的功率
                            xshsPower = this._testP * this._pumpRatedN * this._pumpRatedN * this._pumpRatedN / rTestSpeed / rTestSpeed / rTestSpeed;
                        }
                        else
                        {//一般点的功率用效率计算
                            xshsPower = CalculateP(xshsFlow, xshsHead, xshsEffice);
                        }
 
                        _correctQ = TProduct.Common.RoundHelper.GetDispValueFlow(xshsFlow);
                        _correctH = TProduct.Common.RoundHelper.GetDispValueHead(xshsHead);
                        _correctE = TProduct.Common.RoundHelper.GetDispValueEta(xshsEffice);
                        _correctP = TProduct.Common.RoundHelper.GetDispValuePower(xshsPower);
                    }
                }
                else
                {
                    _correctQ = this._testQ;
                    _correctH = this._testH;
                    _correctE = this._testE;
                    _correctP = this._testP;
                }
 
 
            }
            catch (Exception ex)
            {
                if (isShowError)
                    XtraMessageBox.Show(ex.ToString());
                return false;
            }
            return true;
        }
 
        /// <summary>
        /// 温度换算
        /// </summary>
        /// <returns></returns>
        private bool CalculeByTemperature(bool isShowError)
        {
            //温度换算
            if (this._isTemperatureTrn && _correctQ > 0.1)
            {
                double jiezhi_wendu = 20;
                double origin_eta = _correctE;//模型效率
                double origin_wendu = 20;//模型温度
                var moinitor_jiezhi_wendu = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.介质温度);
                if (moinitor_jiezhi_wendu == null || moinitor_jiezhi_wendu.DispValue == null)
                {
                    if (_testParas == null)
                    {
                        if (isShowError)
                            XtraMessageBox.Show("请输入介质温度?", "问题确认",
              MessageBoxButtons.OK, MessageBoxIcon.Question);
                        return false;
                    }
 
                    jiezhi_wendu = _testParas.JzWenDu;
                }
                else
                {
                    jiezhi_wendu = moinitor_jiezhi_wendu.DispValue.Value;
                }
 
                if (jiezhi_wendu > -10)
                {
                    _correctE = Math.Round((origin_eta * 100 / (origin_eta * 1 + (100 - origin_eta) * Math.Pow((origin_wendu / jiezhi_wendu), -0.07))), 2);
 
                    _correctP = CalculateP(_correctH, _correctQ, _correctE);
                }
            }
 
            return true;
        }
        #endregion
 
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (this._bindingData == null)
                return;
 
            if (this._testE < -0.1)
            {
                XtraMessageBox.Show("效率不正常,是否是进出口压力表搞错?");
                return;
            }
            if (TProduct.UserSetting.Setting.PumpTest.IsCheckErrorEta100 && this._testE > 99)
            {
                XtraMessageBox.Show("效率不正常?");
                return;
            }
            if (this._currentRecord == null)
                return;
            try
            {
                _currentRecord.Time = DateTime.Now;
                RefreshDsRecord();// 不含时间
 
                if (this.OnSaveRecord == null)
                    return;
                var bll = new BLL.PumpFeatTestRecord();
                // 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 = "";
                txtCorrectE.Text = "";
                txtCorrectP.Text = "";
 
                txtTestQ.Text = "";
                txtTestH.Text = "";
                txtTestE.Text = "";
                txtTestP.Text = "";
 
                this.Hide();//不要关闭可能要再次打开
            }
        }
 
        private void RefreshDsRecord()
        {
            _currentRecord.Speed = this._rMeasureSpeed;
            //_testQ , _correctQ已经是标准单位了
            _currentRecord.TestPtQ = TProduct.Common.RoundHelper.GetDispValueFlow(this._testQ);
            _currentRecord.TestPtH = TProduct.Common.RoundHelper.GetDispValueHead(this._testH);
            _currentRecord.TestPtE = TProduct.Common.RoundHelper.GetDispValueEta(this._testE);
            _currentRecord.TestPtP = TProduct.Common.RoundHelper.GetDispValuePower(this._testP);
            _currentRecord.CorrectPtQ = TProduct.Common.RoundHelper.GetDispValueFlow(this._correctQ);
            _currentRecord.CorrectPtH = TProduct.Common.RoundHelper.GetDispValueHead(this._correctH);
            _currentRecord.CorrectPtE = TProduct.Common.RoundHelper.GetDispValueEta(this._correctE);
            _currentRecord.CorrectPtP = TProduct.Common.RoundHelper.GetDispValuePower(this._correctP);
 
            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();
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="motor"></param>
        public override void SetMotorInfo(TProduct.Model.ProductMainExMotor motor)
        {
            if (motor == null || motor.Ratedn == null || motor.Ratedn <= 1)
                return;
            if (!string.IsNullOrEmpty(motor.RatedParas))
            {
                var motor_ratedParas = TProduct.Model.RatedParas4Motor.ToModel(motor.RatedParas);
                this._motorRatedEta = motor_ratedParas.E_Self;
                if (_bindingData != null)
                {
                    var f = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率);
                    if (f != null)
                    {
                        f.Time = DateTime.Now;
                        f.DispValue = this._motorRatedEta;
                        bindingSource1.DataSource = _bindingData;
                        bindingSource1.ResetBindings(false);
                    }
                }
            }
        }
        /// <summary>
        /// 外部更新效率,并保存数据
        /// </summary>
        /// <param name="eta"></param>
        /// <returns></returns>
        public override bool RefreshMotorEta(double eta)
        {
            if (_bindingData == null)
                return false;
 
            var f = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率);
            if (f == null)
            { 
                return false;
            }
            if (f.DispValue == eta)
                return true;
            f.DispValue = eta;
            bindingSource1.DataSource = _bindingData;
            bindingSource1.ResetBindings(false);
  
 
            if (!CalcMeasurePara(false ))
                return false;
 
            RefreshDsRecord();// 不含时间
 
 
            var bll = new BLL.PumpFeatTestRecord();
            bll.Update(this._testItem, _currentRecord); 
            
            return true;
        }
        /// <summary>
        ///  外部修改了额定转速, 刷新数据
        /// </summary>
        /// <param name="eta"></param>
        /// <returns></returns>
        public override bool RefreshRatedn(double speed)
        {
            if (_bindingData == null)
                return false;
 
            this._pumpRatedN = speed;
 
 
            if (!CalcMeasurePara(false))
                return false;
 
            RefreshDsRecord();// 不含时间
 
 
            var bll = new BLL.PumpFeatTestRecord();
            bll.Update(this._testItem, _currentRecord);
 
            return true;
        }
 
        /// <summary>
        /// 设置阀门开度
        /// </summary>
        /// <param name="prop"></param>
        /// <param name="paras"></param>
        /// <returns></returns>
        public override void SetValveDegree(string prop, double paras)
        {
            if (_bindingData != null)
            {
                var f = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度 && x.Entity.Property == prop);
                if (f != null)
                {
                    f.Time = DateTime.Now;
                    f.DispValue = paras;
                }
                bindingSource1.DataSource = _bindingData;
                bindingSource1.ResetBindings(false);
            }
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (isAutoClose)
            {
                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                this.Close();
            }
            else
            {//注意:此对话框不会关闭,只是隐藏,如果要关闭需要外部关闭
                this.Hide();
            }
        }
 
 
        private void GridViewMain_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
        {
            //DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo group = e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo;
            //if (Convert.ToBoolean(group.EditValue))
            //{
            //    group.GroupText = "仪表获取";
            //}
            //else
            //{
            //    group.GroupText = "手动输入";
            //}
        }
 
        private void GridViewMain_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
        {
            //if (e.Column == colUnitName)
            //{
            //    e.Value = "";
            //    var mv = e.Row as TProduct.Model.MonitorPointValue;
            //    if (mv == null)
            //        return;
            //    e.Value = TProduct.Common.MonitorTypeHelper.GetUnitName(mv.MonitorType);
            //}
        }
 
 
        internal override void SetPumpInfo(TProduct.Model.ProductSeries series, TProduct.Model.ProductMainExPump pump)
        {
            base.SetPumpInfo(series, pump);
 
            bci转速换算.Enabled = false;
            if(pump == null)
            {
                bci转速换算.Checked = false;
                _speedSimuMethod = Model.eSpeedSimuMethod.不换算;
            }
            else
            {
                if (_speedSimuMethod == Model.eSpeedSimuMethod.不换算)
                {
                    bci转速换算.Checked = false;
                }
                else
                {
                    bci转速换算.Checked = true;
                }
            }
 
        }
 
 
 
 
 
 
    }
}