private void cmsAddThietBi_Click(object sender, EventArgs e) { var ports = SerialPort.GetPortNames(); splitContainer.Panel2.Controls.Clear(); ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(this); protocolConfiguration.Dock = DockStyle.Fill; protocolConfiguration.btnEditProtocol.Visible = false; protocolConfiguration.btnAddNewProtocol.Visible = true; protocolConfiguration.cbCOM.DataSource = ports; //protocolConfiguration.dgvDataProtocol.DataSource = null; protocolConfiguration.SetThietBiAndSlave(null, null); protocolConfiguration.SetDsThietBi(ThietBiGiamSatService.GetDsThietBi("Quang Ninh")); protocolConfiguration.HideTabDuLieu(); protocolConfiguration.HideTabSlave(); splitContainer.Panel2.Controls.Add(protocolConfiguration); formProtocolConfiguration = protocolConfiguration;//lưu vào biến toàn cục isInFormEdit = true; formProtocolConfiguration.isTabConfigHaveAnyChanged = false; formProtocolConfiguration.isTabDataHaveAnyChanged = false; formProtocolConfiguration.isTabSlaveChanged = false; /*formProtocolConfiguration = protocolConfiguration; * isInFormEdit = false;*/ }
private void cms_Them_SlaveAddress(object sender, EventArgs e) { TreeNode node = rightClickNode; splitContainer.Panel2.Controls.Clear(); ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(this); protocolConfiguration.Dock = DockStyle.Fill; protocolConfiguration.dgvDataProtocol.DataSource = null; protocolConfiguration.HideTabCauHinh(); protocolConfiguration.isAddSlave = true; // get Thiet Bi string thietBi_name = node.Name == TreeName.Name.ThietBi.ToString() ? node.Text : ""; if (!String.IsNullOrEmpty(thietBi_name)) { ThietBiModel thietBi_model = ThietBiGiamSatService.GetThietBiGiamSat("Quang Ninh", thietBi_name); protocolConfiguration.SetThietBiAndSlave(thietBi_model, null); } protocolConfiguration.SetDsThietBi(ThietBiGiamSatService.GetDsThietBi("Quang Ninh")); // splitContainer.Panel2.Controls.Add(protocolConfiguration); formProtocolConfiguration = protocolConfiguration;//lưu vào biến toàn cục isInFormEdit = true; formProtocolConfiguration.isTabConfigHaveAnyChanged = false; formProtocolConfiguration.isTabDataHaveAnyChanged = false; formProtocolConfiguration.isTabSlaveChanged = false; /*formProtocolConfiguration = protocolConfiguration; * isInFormEdit = false;*/ }
private void tvMain_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { e.Node.Expand(); TreeNode node = tvMain.SelectedNode; //use for in ProtocolConfiguration selectedNodeDouble = tvMain.SelectedNode; var ports = SerialPort.GetPortNames(); if (node != null && (node.Name == TreeName.Name.SlaveAddress.ToString() || node.Name == TreeName.Name.ThietBi.ToString())) { splitContainer.Panel2.Controls.Clear(); ProtocolConfiguration protocolConfiguration = new ProtocolConfiguration(this); protocolConfiguration.Dock = DockStyle.Fill; protocolConfiguration.cbCOM.DataSource = ports; protocolConfiguration.btnEditProtocol.Visible = true; protocolConfiguration.btnAddNewProtocol.Visible = false; string thietBi_name = node.Name == TreeName.Name.ThietBi.ToString() ? node.Text : node.Parent.Text; string slave_name = node.Name == TreeName.Name.SlaveAddress.ToString() ? node.Text : null; protocolConfiguration.txtTenGiaoThuc.Text = thietBi_name; protocolConfiguration.txtSlaveAddress.Text = slave_name; ThietBiModel thietBi_model = ThietBiGiamSatService.GetThietBiGiamSat("Quang Ninh", thietBi_name); SlaveModel slave_model = ThietBiGiamSatService.GetDsSlave("Quang Ninh", thietBi_name, slave_name); if (node.Name == TreeName.Name.SlaveAddress.ToString()) { protocolConfiguration.txtScanRate.Text = slave_model.ScanRate.ToString(); } protocolConfiguration.SetThietBiAndSlave(thietBi_model, slave_name); protocolConfiguration.SetDsThietBi(ThietBiGiamSatService.GetDsThietBi("Quang Ninh")); if (node.Name == TreeName.Name.SlaveAddress.ToString()) { protocolConfiguration.LoadDuLieuLenDgv(); } if (node.Name == TreeName.Name.ThietBi.ToString()) { protocolConfiguration.HideTabDuLieu(); protocolConfiguration.HideTabSlave(); } try { ThietBiTCPIP deviceTemp = (ThietBiTCPIP)thietBi_model; protocolConfiguration.txtIPAdress.Text = deviceTemp.IP; protocolConfiguration.txtPort.Text = deviceTemp.Port.ToString(); protocolConfiguration.cbProtocol.Text = deviceTemp.Protocol.ToString(); } catch { ThietBiCOM deviceTemp = (ThietBiCOM)thietBi_model; protocolConfiguration.cbCOM.Text = deviceTemp.Com; protocolConfiguration.cbBaud.Text = deviceTemp.Baud.ToString(); protocolConfiguration.cbParity.Text = deviceTemp.Parity.ToString(); protocolConfiguration.cbDataBit.Text = deviceTemp.Databit.ToString(); protocolConfiguration.cbStopBit.Text = deviceTemp.StopBits.ToString(); protocolConfiguration.cbProtocol.Text = deviceTemp.Protocol.ToString(); } splitContainer.Panel2.Controls.Add(protocolConfiguration); formProtocolConfiguration = protocolConfiguration;//lưu vào biến toàn cục isInFormEdit = true; formProtocolConfiguration.isTabConfigHaveAnyChanged = false; formProtocolConfiguration.isTabDataHaveAnyChanged = false; formProtocolConfiguration.isTabSlaveChanged = false; } }