using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using Core.StlMes.Client.LgResMgt.Mcms.entity; using CoreFS.CA06; namespace Core.StlMes.Client.LgResMgt.Mcms { public partial class CommunicationSetting : FrmBase { public CommunicationSetting(List datas ) { InitializeComponent(); if (datas == null) { _entitys = new List(); }else { _entitys = datas.Select(p => { CommunicationEntity temp = new CommunicationEntity(); temp.PoundNo = p.PoundNo; if (p.Communication is SocketClient) { SocketClient tempS = new SocketClient { Ip = ((SocketClient) p.Communication).Ip, Port = ((SocketClient) p.Communication).Port }; temp.Communication = tempS; } else if (p.Communication is SerialPortEntity) { SerialPortEntity tempS = new SerialPortEntity { PortName = ((SerialPortEntity) p.Communication).PortName, BaudRate = ((SerialPortEntity) p.Communication).BaudRate, StrDataBits = ((SerialPortEntity) p.Communication).StrDataBits, StopBits = ((SerialPortEntity) p.Communication).StopBits, StrParity = ((SerialPortEntity) p.Communication).StrParity }; temp.Communication = tempS; } else { p.Communication = null; } return temp; }).ToList(); } communicationEntityBindingSource.DataSource = Entitys; } private List _entitys; public List Entitys { get { return _entitys; } } private void utmMain_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e) { switch (e.Tool.Key) { case "Save": // ButtonTool // Place code here matGrid.Update(); List data = communicationEntityBindingSource.DataSource as List; if(data == null) data = new List(); if ( data.Any(p=>string.IsNullOrWhiteSpace(p.PoundNo))) { MessageBox.Show("磅房不能为空!"); return; } if (data.Any(p => p.Communication==null)) { MessageBox.Show("磅房通信参数不能为空!"); return; } _entitys = data; this.DialogResult = DialogResult.OK; break; case "Close": // ButtonTool this.DialogResult = DialogResult.Cancel; break; } } private void comEdit_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { CommunicationEntity entity = matGrid.ActiveRow.ListObject as CommunicationEntity; using (CommunicationDetailSetting deatil = new CommunicationDetailSetting(entity.Communication)) { if (deatil.ShowDialog() == DialogResult.OK) { entity.Communication = deatil.Entity; } } communicationEntityBindingSource.ResetBindings(false); } } }