tx
10 天以前 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
using System;
using System.Collections.Generic;
using System.Windows.Forms;
 
 
namespace TProduct.WinFrmUI.TestBench
{
    public partial class SetSingleBenchMonitorPointInoCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SetSingleBenchMonitorPointInoCtrl()
        {
            InitializeComponent();
            this.imgComMonitorType.Properties.Items.AddEnum(typeof(Model.eMonitorType), false);
            this.imgComUserStatus.Properties.Items.AddEnum(typeof(Model.eUseStatus), false);
        }
 
        private Model.WorkBenchMonitorPoint _model = null;
        private string _oldName = string.Empty;
 
        /// <summary>
        /// 添加
        /// </summary>
        public void SetBindingData( )
        {
            //_model = new Model.WorkBenchMonitorPoint();
            //_model.CreateTime = DateTime.Now;
            //_model.CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
            //_model.UpdateTime = DateTime.Now;
            //_model.BenchID = benchID;
            //_model.UseStatus = Model.eUseStatus.Enable;
            //var sortCode = new BLL.WorkBenchMonitorPoint().GetMaxSortCode(benchID);
            //this.txtSortCode.EditValue = ++sortCode;
            //this.imgComUserStatus.EditValue = Model.eUseStatus.Enable;
            //this.checkEditDispInPanel.Checked = true;
        }
 
        public void SetBindingData(Model.WorkBenchMonitorPoint model)
        {
            if (model == null)
                return;
            _model = model;
            _oldName = _model.Name;
            this.txtName.EditValue = _model.Name;
            this.textEditTag.Text = _model.Tag;
           // this.txtPipeDia.EditValue = _model.PipeDia;
            this.imgComMonitorType.EditValue = _model.MonitorType;
           // this.txtElevation.EditValue = _model.Elevation;
 
            this.txtSortCode.EditValue = _model.SortCode;
            this.imgComUserStatus.EditValue = _model.UseStatus;
            this.checkEditDispInPanel.Checked = model.DispInPanel == 0 ? false : true;
            this.check在实时曲线界面中显示.Checked = model.DispInRealChart  == 0 ? false : true;
 
 
            this.comboBoxSource.EditValue = (int)model.SourceType;
            this.textEditIStationID.Text = _model.IStationID;
 
            var list_propte = Model.MonitorTypeProperty.GetPropertyList(_model.MonitorType);
            this.txtProperty.Properties.Items.Clear();
            list_propte?.ForEach(x => this.txtProperty.Properties.Items.Add(x));
            this.txtProperty.Text = _model.Property;
 
            spinEditSumCalcCoeff.Text = model.SumCalcCoeff.ToString();
 
            if (model.ValueCoeffParas != null)
            {
                simpleLabelItem数据修正.Text = "数据已设置修正";
            }
 
            if (model.PointParas != null)
            {
                checkEdit是否可以出现负值.Checked = model.PointParas.IsHaveNavigateValue;
            }
            if (model.SourceType == Model.eMonitorPointSourceType.数字量)
            {
                if (model.DigitalParas != null)
                {
                    //textEditRegisterAddress.Text = model.DigitalParas.RegisterAddress.ToString();
                    //spinEditDataLength.Text = model.DigitalParas.DataLength.ToString();
                    //spinEditDecimalPointPosition.Text = model.DigitalParas.DecimalPointPosition.ToString();
 
                    //if (model.DigitalParas.ValueType == 0)
                    //{
                    //    imageComboBoxDtype.SelectedIndex = 0;
                    //    layoutControlGroup模拟量.Enabled = false;
                    //}
                    //else if (model.DigitalParas.ValueType == 1)
                    //{
                    //    imageComboBoxDtype.SelectedIndex = 1;
                    //    layoutControlGroup模拟量.Enabled = true;
                    //    if (model.AnalogParas != null)
                    //    {
                    //        spinEditRangeMax.Text = model.AnalogParas.RangeMax.ToString();
                    //        spinEditRangeMin.Text = model.AnalogParas.RangeMin.ToString();
                    //    }
                    //} 
                }
            }
            else if (model.SourceType == Model.eMonitorPointSourceType.模拟量)
            {
                //if (model.AnalogParas != null)
                //{
                //    spinEditRangeMax.Text = model.AnalogParas.RangeMax.ToString();
                //    spinEditRangeMin.Text = model.AnalogParas.RangeMin.ToString();
                //}
 
            }
 
        }
 
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public Model.WorkBenchMonitorPoint GetData()
        {
            if (_model == null)
                return null;
            if (!Verify())
                return null;
 
            _model.Name = this.txtName.Text.Trim();
            _model.Property = this.txtProperty.Text.Trim();
            _model.Tag = this.textEditTag.Text;
            _model.MonitorType = (Model.eMonitorType)this.imgComMonitorType.EditValue;
            //if (!string.IsNullOrEmpty(this.txtPipeDia.Text))
            //    _model.PipeDia = double.Parse(this.txtPipeDia.Text.Trim());
            //else
            //    _model.PipeDia = null;
            //if (!string.IsNullOrEmpty(this.txtElevation.Text))
            //    _model.Elevation = double.Parse(this.txtElevation.Text.Trim());
            //else
            //    _model.Elevation = null;
            //if (!string.IsNullOrEmpty(this.txtValueCoefficient.Text))
            //    _model.ValueCoefficient = double.Parse(this.txtValueCoefficient.Text.Trim());
            //if (!string.IsNullOrEmpty(this.txtValueAdditional.Text))
            //    _model.ValueAdditional = double.Parse(this.txtValueAdditional.Text.Trim());
            if (!string.IsNullOrEmpty(this.txtSortCode.Text))
                _model.SortCode = int.Parse(this.txtSortCode.Text.Trim());
 
            _model.SumCalcCoeff = Convert.ToDouble(spinEditSumCalcCoeff.Text);
 
            if (_model.PointParas == null)
                _model.PointParas = new Model.MonitorPointParas();
            _model.PointParas.IsHaveNavigateValue = checkEdit是否可以出现负值.Checked;
            _model.IStationID = this.textEditIStationID.Text;
 
            if (this.comboBoxSource.SelectedIndex == 0)
            {
                _model.DigitalParas = null;
                _model.AnalogParas = null;
                _model.SourceType = Model.eMonitorPointSourceType.未知;
            }
            else if (this.comboBoxSource.SelectedIndex == 1)
            {
                _model.DigitalParas = null;
                _model.SourceType = Model.eMonitorPointSourceType.模拟量;
                //_model.AnalogParas = new Model.AnalogMonitorPointParas();
                //_model.AnalogParas.RangeMax = Convert.ToDouble(spinEditRangeMax.Text);
                //_model.AnalogParas.RangeMin = Convert.ToDouble(spinEditRangeMin.Text);
            }
            else if (this.comboBoxSource.SelectedIndex == 2)
            { 
                _model.SourceType = Model.eMonitorPointSourceType.数字量;
                _model.DigitalParas = new Model.DigitalMonitorPointParas();
                //if (string.IsNullOrEmpty(textEditRegisterAddress.Text))
                //{
                //    _model.DigitalParas.RegisterAddress = 0;
                //}
                //else if (textEditRegisterAddress.Text.ToLower().Contains("0x"))
                //{
                //    _model.DigitalParas.RegisterAddress = Convert.ToByte(textEditRegisterAddress.Text, 16);
                //}
                //else
                //{
                //    _model.DigitalParas.RegisterAddress = Convert.ToInt32(textEditRegisterAddress.Text);
                //}
                //_model.DigitalParas.DataLength = Convert.ToInt32(spinEditDataLength.Text);
                //_model.DigitalParas.DecimalPointPosition = Convert.ToInt32(spinEditDecimalPointPosition.Text);
 
                _model.DigitalParas.ValueType = Convert.ToInt32(imageComboBoxDtype.EditValue);
                if (_model.DigitalParas.ValueType == 0)
                {
                    _model.AnalogParas = null;
                }
                else
                {
                    //_model.AnalogParas = new Model.AnalogMonitorPointParas();
                    //_model.AnalogParas.RangeMax = Convert.ToDouble(spinEditRangeMax.Text);
                    //_model.AnalogParas.RangeMin = Convert.ToDouble(spinEditRangeMin.Text);
                }
            }
            else if (this.comboBoxSource.SelectedIndex == 3)
            {
                _model.SourceType = Model.eMonitorPointSourceType.额定参数;
            }
            _model.DispInPanel = this.checkEditDispInPanel.Checked ? 1 : 0;
 
            _model.DispInRealChart = this.check在实时曲线界面中显示.Checked ? 1 : 0;
 
 
            return _model;
        }
 
        private bool Verify()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtName.Text))
            {
                this.dxErrorProvider1.SetError(this.txtName, "必填项!");
                return false;
            }
            if (string.IsNullOrEmpty(_oldName) || _oldName != this.txtName.Text.Trim())
            {
                if (new BLL.WorkBenchMonitorPoint().IsExistName( this.txtName.Text.Trim()))
                {
                    this.dxErrorProvider1.SetError(this.txtName, "该名称已存在!");
                    return false;
                }
            }
            //if (string.IsNullOrEmpty(this.txtTag.Text))
            //{
            //    this.dxErrorProvider1.SetError(this.txtTag, "必填项!");
            //    return false;
            //}
            if (string.IsNullOrEmpty(this.imgComMonitorType.Text))
            {
                this.dxErrorProvider1.SetError(this.imgComMonitorType, "必选项!");
                return false;
            }
 
            //if (string.IsNullOrEmpty(this.txtValueCoefficient.Text))
            //{
            //    this.dxErrorProvider1.SetError(this.txtValueCoefficient, "必选项!");
            //    return false;
            //}
            //if (string.IsNullOrEmpty(this.txtValueAdditional.Text))
            //{
            //    this.dxErrorProvider1.SetError(this.txtValueAdditional, "必选项!");
            //    return false;
            //}
            return true;
        }
 
        private void imgComMonitorType_SelectedValueChanged(object sender, EventArgs e)
        {
            if (this.imgComMonitorType.EditValue == null)
                return;
            this.txtProperty.Properties.Items.Clear();
            this.txtProperty.Text = null;
            var monitorType = (Model.eMonitorType)this.imgComMonitorType.EditValue;
            List<string> list = null;
            int default_index = -1;
            if (monitorType == Model.eMonitorType.水位)
            {
                list = new List<string>()
                    {
                        Model.MonitorTypeProperty.进口, Model.MonitorTypeProperty.出口
                    };
                default_index = 0;
            }
            else if (monitorType == Model.eMonitorType.压力)
            {
                if (TProduct.UserSetting.Setting.PumpTest.IsHaveParappelTest)
                {
                    list = new List<string>()
                    {
                        Model.MonitorTypeProperty.进口,
                        Model.MonitorTypeProperty.出口,
                        Model.MonitorTypeProperty.并联泵进口,
                        Model.MonitorTypeProperty.并联泵出口
                    };
                }
                else
                {
                    list = new List<string>()
                    {
                        Model.MonitorTypeProperty.进口, Model.MonitorTypeProperty.出口
                    };
                }
            }
            else if (monitorType == Model.eMonitorType.功率)
            {
                if (TProduct.UserSetting.Setting.PumpTest.IsHaveParappelTest)
                {
                    list = new List<string>()
                    {
                        Model.MonitorTypeProperty.总,
                        Model.MonitorTypeProperty.A,
                        Model.MonitorTypeProperty.B,
                        Model.MonitorTypeProperty.C, 
                        //Model.MonitorTypeProperty.并联泵总功率,//暂时不行,需要指定仪器时,分区对应哪台泵,暂时没发区分
                    };
                }
                else
                {
                    list = new List<string>()
                    {
                        Model.MonitorTypeProperty.总,
                        Model.MonitorTypeProperty.A,
                        Model.MonitorTypeProperty.B,
                        Model.MonitorTypeProperty.C,
                    };
                }
                default_index = 0;
            }
            else
            {
                list = Model.MonitorTypeProperty.GetPropertyList(monitorType);
            }
            if (list != null && list.Count > 0)
            {
                list.ForEach(x => this.txtProperty.Properties.Items.Add(x));
                if (default_index >= 0)
                {
                    this.txtProperty.SelectedIndex = default_index;
                }
            }
 
        }
 
        private void comboBoxSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxSource.SelectedIndex == 0)
            {
                //layoutControlGroup模拟量.Enabled = false;
                layoutControlGroup数字量.Enabled = false;
            }
            if (comboBoxSource.SelectedIndex == 1)
            {
                //layoutControlGroup模拟量.Enabled = true;
                layoutControlGroup数字量.Enabled = false;
            }
            if (comboBoxSource.SelectedIndex == 2)
            { 
                layoutControlGroup数字量.Enabled = true;
                //if (Convert.ToInt32(imageComboBoxDtype.EditValue) == 0)
                //{
                //   // layoutControlGroup模拟量.Enabled = false;
                //}
                //else
                //{
                //   // layoutControlGroup模拟量.Enabled = true;
                //}
            }
        }
 
        private void imageComboBoxDtype_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (Convert.ToInt32(imageComboBoxDtype.EditValue) == 0)
            //{
            //    layoutControlGroup模拟量.Enabled = false;
            //}
            //else
            //{
            //    layoutControlGroup模拟量.Enabled = true;
            //}
        }
 
        private void simpleLabelItem数据修正_Click(object sender, EventArgs e)
        {
            if (_model == null)
                return;
            SethMonitorPointValueCoeffParasDlg frm = new SethMonitorPointValueCoeffParasDlg();
            frm.SetBindingData(_model.ValueCoeffParas);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                _model.ValueCoeffParas = frm.GetBindingData();
 
                if (_model.ValueCoeffParas != null)
                {
                    simpleLabelItem数据修正.Text = "数据已设置修正";
                }
                else
                {
                    simpleLabelItem数据修正.Text = "数据无需修正";
                }
            }
        }
 
 
    }
}