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; } } }