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
 
namespace TProduct.WinFrmUI.TestBench
{
    public partial class SetAllInstruments4ShunCtrl : DevExpress.XtraEditors.XtraUserControl
    {
        public SetAllInstruments4ShunCtrl()
        {
            InitializeComponent();
            var list = System.IO.Ports.SerialPort.GetPortNames();
            foreach (var item in list)
            {
                this.txtComPortName.Properties.Items.Add(item, item, -1);
            }
        }
 
        private TProduct.Model.WorkBenchInstrumentShunExPort _model = null;
        private Model.WorkBenchBase _paras = null;
 
        public void SetBindingData(Model.WorkBenchBase paras)
        {
            if (paras == null)
                return;
            _paras = paras;
            _model = new TProduct.Model.WorkBenchInstrumentShunExPort();
            _model.UseStatus = Model.eUseStatus.Enable;
            imageCombo状态.SelectedIndex = 1;
            this.workBenchInstrumentShunPortAnaCtrl1.SetBindingData(paras);
            this.workBenchInstrumentShunPortRS485Ctrl1.SetBindingData(paras);
        }
 
        public void SetBindingData(Model.WorkBenchBase paras,
            Model.WorkBenchInstrumentShun instrument)
        {
            if (paras == null)
                return;
            this._paras = paras;
            this.txtLinkInstrumentNO.EditValue = instrument.SZ02NO;
            this.txtSZ02Address.Address = instrument.SZ02Address;
            this.txtComBaudRate.EditValue = instrument.ComBaudRate;
            this.txtComPortName.EditValue = instrument.ComPortName;
            this.workBenchInstrumentShunPortAnaCtrl1.SetBindingData(paras, instrument);
            this.workBenchInstrumentShunPortRS485Ctrl1.SetBindingData(paras, instrument);
            this.imageCombo状态.SelectedIndex = instrument.UseStatus == TProduct.Model.eUseStatus.Enable ? 1 : 0;
 
            this._model = new TProduct.Model.WorkBenchInstrumentShunExPort(instrument);
        }
 
        public TProduct.Model.WorkBenchInstrumentShunExPort GetData()
        {
            if (_model == null || _paras == null)
                return null;
            if (!Verify())
                return null;
            _model.SZ02NO = this.txtLinkInstrumentNO.Text.Trim();
            _model.SZ02Address = this.txtSZ02Address.Address;
            _model.ComPortName = this.txtComPortName.Text.Trim();
            _model.ComBaudRate = int.Parse(this.txtComBaudRate.Text.Trim());
            _model.BenchID = _paras.ID;
            _model.SZ02Type = TProduct.Model.eShunSZ02Type.Ana12RS485;
            _model.UseStatus = this.imageCombo状态.SelectedIndex == 0 ? TProduct.Model.eUseStatus.Disable : TProduct.Model.eUseStatus.Enable;
            _model.AnaPorts = this.workBenchInstrumentShunPortAnaCtrl1.GetData();
            _model.Rs485Ports = this.workBenchInstrumentShunPortRS485Ctrl1.GetData();
 
            return _model;
        }
 
        private bool Verify()
        {
            this.dxErrorProvider1.ClearErrors();
            if (string.IsNullOrEmpty(this.txtLinkInstrumentNO.Text))
            {
                this.dxErrorProvider1.SetError(this.txtLinkInstrumentNO, "必填项!");
                return false;
            }
            if (this.txtSZ02Address.IsInvalidValue())
            {
                this.dxErrorProvider1.SetError(this.txtSZ02Address, "必填项!");
                return false;
            }
            var address = txtSZ02Address.Address;
            if (address < 0 || address >= 255)
            {
                this.dxErrorProvider1.SetError(this.txtSZ02Address, "范围0~255!");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtComPortName.Text))
            {
                this.dxErrorProvider1.SetError(this.txtComPortName, "必填项!");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtComBaudRate.Text))
            {
                this.dxErrorProvider1.SetError(this.txtComBaudRate, "必填项!");
                return false;
            }
            if (this.workBenchInstrumentShunPortAnaCtrl1.GetData() == null)
            {
                return false;
            }
            if (this.workBenchInstrumentShunPortRS485Ctrl1.GetData() == null)
            {
                return false;
            }
            return true;
        }
    }
}