private void btEdit_Click(object sender, EventArgs e) { if (dgvPortCommands.CurrentCell != null && dgvPortCommands.CurrentCell.RowIndex >= 00) { int j; string field_name = "[" + m_portCommands.GetName() + " Column: " + dgvPortCommands.CurrentCell.RowIndex + "]"; PortConfig portConfig = null;// = (PortConfig)m_portCommands.m_ItemArray[dgvPortCommands.CurrentCell.RowIndex]; string temp = " "; string[] item_value = new string[m_datatable.Columns.Count]; for (int i = 0; i < m_datatable.Columns.Count; i++) { temp += m_datatable.Rows[dgvPortCommands.CurrentCell.RowIndex].ItemArray[i].ToString() + " "; } portConfig = new PortConfig(field_name, temp, m_portCommands.m_type, m_portCommands.m_nodeList); PortConfig[] tmpPortConfig = new PortConfig[] { portConfig, ((PortConfig)m_portCommands_default.m_ItemArray[0]) }; PortConfigEditForm frm = new PortConfigEditForm(tmpPortConfig); try { if (frm.ShowDialog(this) == DialogResult.OK) { //DataTable dataTable = portConfig.CreateDataTable(); for (j = 0; j < portConfig.m_value.Length /*dataTable.Rows.Count*/; j++) { m_datatable.Rows[dgvPortCommands.CurrentCell.RowIndex][j] = portConfig.m_value[j];//dataTable.Rows[j][1]; } if (portConfig.m_comment.Length > 0) { m_datatable.Rows[dgvPortCommands.CurrentCell.RowIndex][j] = '#' + portConfig.m_comment; } else { m_datatable.Rows[dgvPortCommands.CurrentCell.RowIndex][j] = ""; } } } finally { frm.Dispose(); } } }
private void SetPortConfigDisplay() { int node_id = 0; this.Text = "ConfigTool -" + m_portConfigFile.FileName; tvPortInfo.BeginUpdate(); tvPortInfo.Nodes.Add("Module Config"); tvPortInfo.Nodes[0].ContextMenuStrip = cmsPortConfig; if (m_portConfigFile.m_portConfigArray.Count > 0) { tvPortInfo.Nodes[0].Nodes.Add("Group Port Config"); for (int i = 0; i < m_portConfigFile.m_portConfigArray.Count; i++) { tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortConfig)(m_portConfigFile.m_portConfigArray[i])).GetName()); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig; PortConfig[] currentPortConfig = new PortConfig[] { (PortConfig)m_portConfigFile.m_portConfigArray[i], (PortConfig)m_portConfigFile_default.m_portConfigArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortConfig; } node_id++; } if (m_portConfigFile.m_portCommandsArray.Count > 0) { tvPortInfo.Nodes[0].Nodes.Add("Group Port Commands"); for (int i = 0; i < m_portConfigFile.m_portCommandsArray.Count; i++) { tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortCommands)(m_portConfigFile.m_portCommandsArray[i])).GetName()); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig; PortCommands[] currentPortCommands = new PortCommands[] { (PortCommands)m_portConfigFile.m_portCommandsArray[i], (PortCommands)m_portConfigFile_default.m_portCommandsArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortCommands; } node_id++; } if (m_portConfigFile.m_pcPortConfigArray.Count > 0) { tvPortInfo.Nodes[0].Nodes.Add("Modbus PC Port"); for (int i = 0; i < m_portConfigFile.m_pcPortConfigArray.Count; i++) { tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add("Modbus PC Port " + i); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig; PortConfig[] currentPortConfig = new PortConfig[] { (PortConfig)m_portConfigFile.m_pcPortConfigArray[i], (PortConfig)m_portConfigFile_default.m_pcPortConfigArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortConfig; } node_id++; } if (m_portConfigFile.m_pcPortCommandsArray.Count > 0) { tvPortInfo.Nodes[0].Nodes.Add("Modbus PC Port Commands"); for (int i = 0; i < m_portConfigFile.m_pcPortCommandsArray.Count; i++) { tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortCommands)(m_portConfigFile.m_pcPortCommandsArray[i])).GetName()); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig; PortCommands[] currentPortCommands = new PortCommands[] { (PortCommands)m_portConfigFile.m_pcPortCommandsArray[i], (PortCommands)m_portConfigFile_default.m_pcPortCommandsArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentPortCommands; } node_id++; } if (m_portConfigFile.m_etherNetPortArray.Count > 0) { tvPortInfo.Nodes[0].Nodes.Add("EtherNet"); for (int i = 0; i < m_portConfigFile.m_etherNetPortArray.Count; i++) { tvPortInfo.Nodes[0].Nodes[node_id].Nodes.Add(((PortConfig)(m_portConfigFile.m_etherNetPortArray[i])).GetName()); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].ContextMenuStrip = cmsPortConfig; PortConfig[] currentEtherNet = new PortConfig[] { (PortConfig)m_portConfigFile.m_etherNetPortArray[i], (PortConfig)m_portConfigFile_default.m_etherNetPortArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Tag = currentEtherNet; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes.Add(((PortConfig)(m_portConfigFile.m_etherNetClientConfigArray[i])).GetName()); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[0].ContextMenuStrip = cmsPortConfig; PortConfig[] curEtherNetClientCfg = new PortConfig[] { (PortConfig)m_portConfigFile.m_etherNetClientConfigArray[i], (PortConfig)m_portConfigFile_default.m_etherNetClientConfigArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[0].Tag = curEtherNetClientCfg; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes.Add(((PortCommands)(m_portConfigFile.m_etherNetClientCommandsArray[i])).GetName()); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[1].ContextMenuStrip = cmsPortConfig; PortCommands[] curEtherNetClientCmd = new PortCommands[] { (PortCommands)m_portConfigFile.m_etherNetClientCommandsArray[i], (PortCommands)m_portConfigFile_default.m_etherNetClientCommandsArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[1].Tag = curEtherNetClientCmd; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes.Add(((PortConfig)(m_portConfigFile.m_etherNetServerConfigArray[i])).GetName()); tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[2].ContextMenuStrip = cmsPortConfig; PortConfig[] curEtherNetServerCfg = new PortConfig[] { (PortConfig)m_portConfigFile.m_etherNetServerConfigArray[i], (PortConfig)m_portConfigFile_default.m_etherNetServerConfigArray[i] }; tvPortInfo.Nodes[0].Nodes[node_id].Nodes[i].Nodes[2].Tag = curEtherNetServerCfg; } node_id++; } tvPortInfo.Nodes[0].Nodes.Add(m_portConfigFile.m_dataRemap.GetName()); tvPortInfo.Nodes[0].Nodes[node_id].ContextMenuStrip = cmsPortConfig; PortCommands[] curDataRemap = new PortCommands[] { (PortCommands)m_portConfigFile.m_dataRemap, (PortCommands)m_portConfigFile_default.m_dataRemap }; tvPortInfo.Nodes[0].Nodes[node_id].Tag = curDataRemap; tvPortInfo.Nodes[0].Expand(); tvPortInfo.EndUpdate(); ShowAllContent(); }
public PortConfigEditForm(PortConfig[] portConfig) { InitializeComponent(); //m_xmlDoc = new XmlDocument(); //m_xmlDoc.LoadXml(Config.Resource.Description); //string nodeString = "PortConfig"; //XmlNodeList nodeList; m_portConfig = portConfig[0]; m_portConfig_default = portConfig[1]; m_datatable = m_portConfig.CreateDataTable(); m_datatable_default = portConfig[1].CreateDataTable(); this.Text = m_portConfig.GetName(); tbComment.Text = m_portConfig.m_comment; if (m_datatable != null) { DataSet dataset = new DataSet(); dataset.Tables.Add(m_datatable); dgvPortConfig.DataSource = dataset; dgvPortConfig.DataMember = "PortConfig"; //tbComment.Text = dgvPortConfig.CurrentRow.Cells[2].Value; //dgvPortConfig.Columns[dgvPortConfig.Columns.Count - 1].Visible = false; } /* * switch(m_portConfig.m_type) * { * case Config.EditType.EDIT_PORT_CONFIG: * nodeString = "PortConfig"; * break; * case Config.EditType.EDIT_PORT_COMMAND: * nodeString = "PortCommands"; * break; * case Config.EditType.EDIT_PCPORT_CONFIG: * nodeString = "PCPortConfig"; * break; * case Config.EditType.EDIT_PCPORT_COMMAND: * nodeString = "PCPortCommands"; * break; * case Config.EditType.EDIT_ETHERNET_CONFIG: * nodeString = "EthernetConfig"; * break; * case Config.EditType.EDIT_ETHERNET_CLIENT_CONFIG: * nodeString = "EthernetClientConfig"; * break; * case Config.EditType.EDIT_ETHERNET_CLIENT_COMMAND: * nodeString = "EthernetClientCommands"; * break; * case Config.EditType.EDIT_ETHERNET_SERVER_CONFIG: * nodeString = "EthernetServerConfig"; * break; * case Config.EditType.EDIT_DATA_REMAP: * nodeString = "DataRemap"; * break; * default: * break; * } * nodeList = m_xmlDoc.SelectSingleNode("modbus").ChildNodes; * foreach (XmlNode xn in nodeList) * { * XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型 * if (xe.Name == nodeString)//如果name属性值为tbCfgName.Text * { * m_nodeList = xe.ChildNodes; * break; * } * } */ }