using DevExpress.XtraEditors; using System.Collections.Generic; namespace TProduct.WinFrmUI.TestBench { public partial class WorkBenchInstrumentShunPortAnaCtrl : DevExpress.XtraEditors.XtraUserControl { public WorkBenchInstrumentShunPortAnaCtrl() { InitializeComponent(); this.gridView1.SetNormalEditView(); this.gridView1.SetGridMianViewColor(); this.repositoryItemImageComboBox1.Items.Clear(); //this.repositoryItemImageComboBox1.Items.AddEnum(typeof(Model.eAnalogDataType), false); this.repositoryItemImageComboBox1.Items.AddRange( new DevExpress.XtraEditors.Controls.ImageComboBoxItem[] { new DevExpress.XtraEditors.Controls.ImageComboBoxItem("4ma~20ma", Model.eAnalogDataType.I4to20ma, -1), new DevExpress.XtraEditors.Controls.ImageComboBoxItem("0ma~20ma", Model.eAnalogDataType.I0to20ma, -1)}); } private class CurrentViewModel : Model.WorkBenchInstrumentShunPortAna { public CurrentViewModel() { } public CurrentViewModel(Model.WorkBenchInstrumentShunPortAna rhs) : base(rhs) { } public bool IsChecked { get; set; } public string PortName { get; set; } } public static string PortName1 = "1号端口"; public static string PortName2 = "2号端口"; public static string PortName3 = "3号端口"; public static string PortName4 = "4号端口"; private List _bindList = null; /// /// 添加 /// public void SetBindingData(Model.WorkBenchBase paras) { if (paras == null) return; _bindList = new List(); _bindList.Add(new CurrentViewModel() { LinkID = 0, IsChecked = false, PortName = PortName1, PortIndex = 1, MonitorPointID = 0, UseStatus = Model.eUseStatus.Enable, AnalogDataType = Model.eAnalogDataType.I4to20ma }); _bindList.Add(new CurrentViewModel() { LinkID = 0, IsChecked = false, PortName = PortName2, PortIndex = 2, MonitorPointID = 0, UseStatus = Model.eUseStatus.Enable, AnalogDataType = Model.eAnalogDataType.I4to20ma }); //_bindList.Add(new CurrentViewModel() //{ // UseStatus = Model.eUseStatus.Enable, // AnalogDataType = Model.eAnalogDataType.I4to20ma, // MeasRangeMaxValue = 0, // MeasRangeMinValue = 0, // PortName = PortAna3 //}); //_bindList.Add(new CurrentViewModel() //{ // UseStatus = Model.eUseStatus.Enable, // AnalogDataType = Model.eAnalogDataType.I4to20ma, // MeasRangeMaxValue = 0, // MeasRangeMinValue = 0, // PortName = PortAna4 //}); var points = new BLL.WorkBenchMonitorPoint().Get模拟量ByBenchID(paras.ID); points?.ForEach(x => this.repositoryItemImageComboBox3.Items.Add(x.Name, x.ID, -1)); this.bindingSource1.DataSource = _bindList; this.bindingSource1.ResetBindings(false); } /// /// 编辑 /// public void SetBindingData(Model.WorkBenchBase paras, Model.WorkBenchInstrumentShun sz02) { if (sz02 == null) return; var points = new BLL.WorkBenchMonitorPoint().Get模拟量ByBenchID(paras.ID); points?.ForEach(x => this.repositoryItemImageComboBox3.Items.Add(x.Name, x.ID, -1)); var port_list = new BLL.WorkBenchInstrumentShunPortAna().GetByLinkID(sz02.ID); _bindList = new List(); //x.PortName == PortAna2); var portAna1 = port_list?.Find(x => x.PortIndex == 1); if (portAna1 == null) { _bindList.Add(new CurrentViewModel() { LinkID = sz02.ID, IsChecked = false, PortIndex = 1, MonitorPointID = 0, UseStatus = Model.eUseStatus.Enable, AnalogDataType = Model.eAnalogDataType.I4to20ma, PortName = PortName1 }); } else { _bindList.Add(new CurrentViewModel(portAna1) { IsChecked = true, PortName = PortName1 }); } var portAna2 = port_list?.Find(x => x.PortIndex == 2); if (portAna2 == null) { _bindList.Add(new CurrentViewModel() { LinkID = sz02.ID, IsChecked = false, PortIndex = 2, MonitorPointID = 0, UseStatus = Model.eUseStatus.Enable, AnalogDataType = Model.eAnalogDataType.I4to20ma, PortName = PortName2 }); } else { _bindList.Add(new CurrentViewModel(portAna2) { IsChecked = true, PortName = PortName2 }); } if (sz02.SZ02Type == Model.eShunSZ02Type.Ana1234RS485) { var portAna3 = port_list?.Find(x => x.PortIndex == 3); if (portAna3 == null) { _bindList.Add(new CurrentViewModel() { LinkID = sz02.ID, IsChecked = false, PortIndex = 3, MonitorPointID = 0, UseStatus = Model.eUseStatus.Enable, AnalogDataType = Model.eAnalogDataType.I4to20ma, PortName = PortName3 }); } else { _bindList.Add(new CurrentViewModel(portAna3) { IsChecked = true, PortName = PortName3 }); } var portAna4 = port_list?.Find(x => x.PortIndex == 4); if (portAna4 == null) { _bindList.Add(new CurrentViewModel() { LinkID = sz02.ID, IsChecked = false, PortIndex = 4, MonitorPointID = 0, UseStatus = Model.eUseStatus.Enable, AnalogDataType = Model.eAnalogDataType.I4to20ma, PortName = PortName4 }); } else { _bindList.Add(new CurrentViewModel(portAna4) { IsChecked = true, PortName = PortName4 }); } } this.bindingSource1.DataSource = _bindList; this.bindingSource1.ResetBindings(false); } /// /// 获取数据 /// public List GetData() { if (!Verify()) return null; var list = new List(); _bindList.FindAll(x => x.IsChecked).ForEach(x => list.Add(new Model.WorkBenchInstrumentShunPortAna(x))); return list; } //验证 private bool Verify() { var check_list = _bindList.FindAll(x => x.IsChecked); if (check_list != null) { var model = check_list.Find(x => x.MonitorPointID <= 0); if (model != null) { XtraMessageBox.Show("请选择测点!"); return false; } } return true; } } }