tx
2025-04-09 fa7510e1ed63df0366787fa4ed1b3db6426d2b46
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
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
namespace TProduct.WinFrmUI.TValve
{
    //
    internal partial class CalcFeatTestData1Dlg : CalcFeatTestBaseDlg
    {
        public CalcFeatTestData1Dlg()
        {
            InitializeComponent();
 
            btnOK.Enabled = false;
            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;
 
            flow_unit = TProduct.UserSetting.Setting.ValveTest.UnitFlow;
            press_unit = TProduct.UserSetting.Setting.ValveTest.UnitPress;
 
            lblCorrectQ.Text = string.Format("流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
            labelYaCha.Text = string.Format("压差({0})", Eventech.Common.UnitHHelper.GetEnUnitName(press_unit));
 
            this.btnCorrect.SetCalcButtonColor();
            this.btnOK.SetConfirmButtonColor();
            this.btnCancel.SetCancelButtonColor();
        }
 
        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; }
        }
        //
        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;
 
                _bindingData.Add(v);
            }
        }
 
        //
        private TProduct.Model.ValveFeatTestRecordViewModel _currentRecord = null;
        public override void NewTestRecord(List<TProduct.Model.MonitorPointValuePure> valueList)
        {
            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 = 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 = f.Time;
 
                }
            }
 
            bindingSource1.DataSource = _bindingData;
            bindingSource1.ResetBindings(false);
            btnOK.Enabled = false;
 
            _currentRecord = new TProduct.Model.ValveFeatTestRecordViewModel();
            _currentRecord.TestItemID = this._testItemID;
            _currentRecord.Time = DateTime.Now;
            _currentRecord.RecordType = this._recordType;
        }
 
        public override void EditTestRecord(TProduct.Model.ValveFeatTestRecordViewModel 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;
                }
 
                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;
 
            txt流量.Text = record.Flow.ToString();
            textBoxP1.Text = TProduct.Common.RoundHelper.GetDispValuePress(
                Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P1)).ToString();
            textBoxP2.Text = TProduct.Common.RoundHelper.GetDispValuePress(
                Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P2)).ToString();
            textBoxP3.Text = TProduct.Common.RoundHelper.GetDispValuePress(
                Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P3)).ToString();
 
 
            textBox压差.Text = TProduct.Common.RoundHelper.GetDispValuePress(
                Eventech.Common.UnitHHelper.fromMPa(press_unit, record.DeltaP)).ToString(); //Math.Round(record.DeltaP, 4).ToString();
            textBox流量系数.Text = Math.Round(record.Kv, 2).ToString();
            textBox流阻系数.Text = Math.Round(record.Rc, 4).ToString();
            textBox流速.Text = Math.Round(record.V, 3).ToString();
 
 
            bindingSource1.DataSource = _bindingData;
            bindingSource1.ResetBindings(false);
            btnOK.Enabled = false;
        }
 
        //参数 都是标准单位
        private double Degree;//开度 
        protected double Density;//密度
        private double Viscosity;
        private double Flow;//流量
        private double P1, P2, P3;
        private double Re;//雷诺数
        private double V;//流速
        private double DeltaP;//压差 
        private double Kv;//流量系数
        private double Rc;//流阻系数
 
        //计算
        private void btnCorrect_Click(object sender, EventArgs e)
        {
            btnOK.Enabled = false;
 
            try
            {
                if (!CalcMeasurePara())
                    return;
 
                //计算测试修正值
                if (!CalculePara())
                    return;
 
 
                txt流量.Text = TProduct.Common.RoundHelper.GetDispValueFlow(
                    Eventech.Common.UnitQHelper.fromM3H(flow_unit, Flow)).ToString();
                textBoxP1.Text = TProduct.Common.RoundHelper.GetDispValuePress(
                    Eventech.Common.UnitHHelper.fromMPa(press_unit, P1)).ToString();
                textBoxP2.Text = TProduct.Common.RoundHelper.GetDispValuePress(
                    Eventech.Common.UnitHHelper.fromMPa(press_unit, P2)).ToString();
                textBoxP3.Text = TProduct.Common.RoundHelper.GetDispValuePress(
                    Eventech.Common.UnitHHelper.fromMPa(press_unit, P3)).ToString();
 
                this.textBox雷诺数.Text = Math.Round(Re, 5).ToString();
                this.textBox压差.Text = Math.Round(DeltaP * 1000, 1).ToString();//DeltaP * 1000;//换算成KPa
                this.textBox流量系数.Text = Math.Round(Kv, 4).ToString();
                this.textBox流阻系数.Text = Math.Round(Rc, 5).ToString();
                this.textBox流速.Text = Math.Round(this.V, 3).ToString();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Error:169");
                return;
            }
 
            btnOK.Enabled = true;
        }
        //
        private bool CalcMeasurePara()
        {
            #region  P1
            var moinitor_p1_list = this._bindingData.Where(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.压力 &&
             x.Entity.Property == TProduct.Model.MonitorTypeProperty.P1);
            if (moinitor_p1_list == null || moinitor_p1_list.Count() == 0)
            {
                XtraMessageBox.Show("请输入P1?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            List<Double> p1_list = new List<double>();
            foreach (var m in moinitor_p1_list)
            {
                if (m.DispValue.HasValue)
                {
                    p1_list.Add(
                        Eventech.Common.UnitHHelper.toMPa(press_unit, m.DispValue.Value) +
                        Eventech.Common.UnitHHelper.toMPa(Eventech.Model.UnitH.M, m.Entity.GetElevationValve()));
                }
            }
            if (p1_list.Count == 0)
            {
                XtraMessageBox.Show("请输入P1?", "问题确认",
          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            else if (p1_list.Count == 1)
            {
                this.P1 = p1_list.First();
            }
            else
            {
                this.P1 = p1_list.Average();
            }
 
 
            #endregion
 
 
            #region  P2
            var moinitor_p2_list = this._bindingData.Where(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.压力 &&
             x.Entity.Property == TProduct.Model.MonitorTypeProperty.P2);
            if (moinitor_p2_list == null || moinitor_p2_list.Count() == 0)
            {
                XtraMessageBox.Show("请输入P2?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            List<Double> p2_list = new List<double>();
            foreach (var m in moinitor_p2_list)
            {
                if (m.DispValue.HasValue)
                {
                    p2_list.Add(
                        Eventech.Common.UnitHHelper.toMPa(press_unit, m.DispValue.Value) +
                        Eventech.Common.UnitHHelper.toMPa(Eventech.Model.UnitH.M, m.Entity.GetElevationValve()));
                }
            }
            if (p2_list.Count == 0)
            {
                XtraMessageBox.Show("请输入P2?", "问题确认",
          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            else if (p2_list.Count == 1)
            {
                this.P2 = p2_list.First();
            }
            else
            {
                this.P2 = p2_list.Average();
            }
 
            #endregion
 
 
            #region  P3
            var moinitor_p3_list = this._bindingData.Where(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.压力 &&
             x.Entity.Property == TProduct.Model.MonitorTypeProperty.P3);
            if (moinitor_p3_list == null || moinitor_p3_list.Count() == 0)
            {
                XtraMessageBox.Show("请输入P2?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            List<Double> p3_list = new List<double>();
            foreach (var m in moinitor_p3_list)
            {
                if (m.DispValue.HasValue)
                {
                    p3_list.Add(
                        Eventech.Common.UnitHHelper.toMPa(press_unit, m.DispValue.Value) +
                        Eventech.Common.UnitHHelper.toMPa(Eventech.Model.UnitH.M, m.Entity.GetElevationValve()));
                }
            }
            if (p3_list.Count == 0)
            {
                XtraMessageBox.Show("请输入P3?", "问题确认",
          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            else if (p3_list.Count == 1)
            {
                this.P3 = p3_list.First();
            }
            else
            {
                this.P3 = p3_list.Average();
            }
 
            #endregion
 
 
            #region 流量
            //测量流量
            var moinitor_flow = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.流量);
            if (moinitor_flow == null || moinitor_flow.DispValue == null)
            {
                XtraMessageBox.Show("请输入流量?", "问题确认",
                          MessageBoxButtons.OK, MessageBoxIcon.Question);
                return false;
            }
            this.Flow = Eventech.Common.UnitQHelper.toM3H(flow_unit, moinitor_flow.DispValue.Value);
 
            #endregion
 
 
 
            #region 开度
            //测量流量
            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;
            }
            this.Degree = moinitor_开度.DispValue.Value;
            #endregion
 
 
 
            return true;
        }
 
        //根据测试参数,计算测试修正值 
        public bool CalculePara()
        {
            try
            {
                var dia_m = this._dia / 1000;//口径(m)
                var flow_m3s = this.Flow / 3600;//流量 m3/s
                this.V = Math.Round(4 * flow_m3s / (Math.PI * dia_m * dia_m), 4);//流速
 
                this.Viscosity = 1;//水的运动黏度 单位m2/s 实际和温度也有关系 暂时固定
                this.Density = TProduct.ConstantParas.WaterDensity;//测试时水密度 实际和温度也有关系 暂时固定
 
                this.Re = this.V * dia_m / this.Viscosity;//雷诺数
 
                double deta_p1 = this.P2 - this.P3;//阀门前后取压点压差(MPa) 
                double deta_pt = this.P1 - this.P2;//阀门前管道差压(MPa) 
 
                this.DeltaP = deta_p1 - deta_pt;//MPa
                if (this.DeltaP < 0.0001)
                {
                    MessageBox.Show("压差值不合理,请问是否是数据正常");
                    return false;
                }
 
 
 
                double midu_15度 = TProduct.ConstantParas.WaterDensity;// 15度时的水密度
                double kpa_DeltaP = DeltaP * 1000;//换算成KPa
 
                this.Kv = 10 * this.Flow * Math.Sqrt(this.Density / (midu_15度 * kpa_DeltaP));
                this.Rc = 2000 * kpa_DeltaP / (this.Density * this.V * this.V);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.ToString());
                return false;
            }
            return true;
        }
 
 
        //
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (_bindingData == null)
                return;
 
            if (_currentRecord == null)
                return;
            try
            {
                _currentRecord.Time = DateTime.Now;
                _currentRecord.Degree = this.Degree;
 
                _currentRecord.Density = this.Density;
                _currentRecord.Viscosity = this.Viscosity;
                _currentRecord.Flow = TProduct.Common.RoundHelper.GetDispValueFlow(this.Flow);
                _currentRecord.P1 = TProduct.Common.RoundHelper.GetDispValuePress(this.P1);
                _currentRecord.P2 = TProduct.Common.RoundHelper.GetDispValuePress(this.P2);
                _currentRecord.P3 = TProduct.Common.RoundHelper.GetDispValuePress(this.P3);
                _currentRecord.V = Math.Round(this.V, 2);
                _currentRecord.Re = Math.Round(this.Re, 5);
                _currentRecord.DeltaP = TProduct.Common.RoundHelper.GetDispValuePress(this.DeltaP);
                _currentRecord.Kv = Math.Round(this.Kv, 2);
                _currentRecord.Rc = Math.Round(this.Rc, 4);
 
 
                TProduct.Model.MonitorRecord4DsList monitorRecord4Ds = new TProduct.Model.MonitorRecord4DsList();
                foreach (var bd in _bindingData)
                {
                    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.ValveFeatTestRecord();
                // 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
            {//注意:此对话框不会关闭,只是隐藏,如果要关闭需要外部关闭
                txt流量.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 void gridView1_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 GridView_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);
            //}
        }
 
 
 
 
 
 
 
 
    }
}