/// <summary> /// line save button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void line_save_button_Click(object sender, EventArgs e) { try { if (!LineCheck()) { MessageBoxEx.Show("界面参数不能为空,请检查!"); return; } if (xi.Name == line_name_textBox.Text) { xi.Name = line_name_textBox.Text; xi.Index = int.Parse(line_index_textBox.Text); xi.HeartBeatAddr = line_heartAddress_textBox.Text; xi.IP = line_ip_textBox.Text; xi.PLCSlot = int.Parse(line_plcSolt_textBox.Text); xi.ThreaCount = int.Parse(line_threadCount_textBox.Text); xi.UpdateRate = int.Parse(line_updateRate_textBox.Text); xi.PLCType = line_plcBrand_comboBox.Text; xi.AddrType = line_addressType_label.Text; XML_Tool.Save(); MessageBoxEx.Show("line层修改成功!"); } else { Xml_InfoConfig xInfo = new Xml_InfoConfig(); xInfo.Name = line_name_textBox.Text; xInfo.Index = int.Parse(line_index_textBox.Text); xInfo.HeartBeatAddr = line_heartAddress_textBox.Text; xInfo.IP = line_ip_textBox.Text; xInfo.PLCSlot = int.Parse(line_plcSolt_textBox.Text); xInfo.ThreaCount = int.Parse(line_threadCount_textBox.Text); xInfo.UpdateRate = int.Parse(line_updateRate_textBox.Text); xInfo.PLCType = line_plcBrand_comboBox.Text; xi.AddrType = line_addressType_label.Text; List <Xml_InfoConfig_Station> xisList = new List <Xml_InfoConfig_Station>(); Xml_InfoConfig_Station xml_InfoConfig_Station = new Xml_InfoConfig_Station(); xml_InfoConfig_Station.Name = "OP00"; xisList.Add(xml_InfoConfig_Station); xInfo.STATION = xisList; XML_Tool.xml.LINE.Add(xInfo); XML_Tool.Save(); MessageBoxEx.Show("line层添加成功!"); } PageFrush(treeNode); } catch (Exception ex) { MessageBox.Show("line层添加异常:" + ex.Message); } }
/// <summary> /// tree select event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void plcAddress_tree_advTree_AfterSelect(object sender, TreeViewEventArgs e) { try { if (e.Node.Level == 0) { ShowPanel(0); var line = XML_Tool.xml.LINE.Single(n => n.Name == e.Node.Text); xi = line; line_name_textBox.Text = xi.Name; line_index_textBox.Text = xi.Index.ToString(); line_heartAddress_textBox.Text = xi.HeartBeatAddr; line_ip_textBox.Text = xi.IP; line_plcSolt_textBox.Text = xi.PLCSlot.ToString(); line_threadCount_textBox.Text = xi.ThreaCount.ToString(); line_updateRate_textBox.Text = xi.UpdateRate.ToString(); line_plcBrand_comboBox.Text = xi.PLCType; line_addressType_textBox.Text = xi.AddrType; treeNode = plcAddress_tree_advTree.Nodes[e.Node.Index]; } else if (e.Node.Level == 1) { ShowPanel(1); var line = XML_Tool.xml.LINE.Single(n => n.Name == e.Node.Parent.Text); xi = line; var station = line.STATION.Single(n => n.Name == e.Node.Text); xis = station; station_name_textBox.Text = station.Name; station_desc_textBox.Text = station.Desc; station_planTime_textBox.Text = station.PlanTime; station_alarmAddress_textBox.Text = station.AlarmAddr; station_addressType_textBox.Text = station.AddrType; treeNode = plcAddress_tree_advTree.Nodes[e.Node.Parent.Index]; } else if (e.Node.Level == 2) { ShowPanel(2); var station = XML_Tool.xml.LINE.Single(n => n.Name == e.Node.Parent.Parent.Text).STATION. Single(n => n.Name == e.Node.Parent.Text); xis = station; var opc = station.Opcitem.Single(n => n.Name == e.Node.Text); xio = opc; opcitem_name_textBox.Text = opc.Name; opcitem_address_textBox.Text = opc.Addr; opcitem_backAddress_textBox.Text = opc.BackAddr; opcitem_addressType_textBox.Text = opc.AddrType; opcitem_operationDesc_textBox.Text = opc.OperationDesc; treeNode = plcAddress_tree_advTree.Nodes[e.Node.Parent.Parent.Index]; } else if (e.Node.Level == 3) { ShowPanel(3); var opc = XML_Tool.xml.LINE.Single(n => n.Name == e.Node.Parent.Parent.Parent.Text).STATION. Single(n => n.Name == e.Node.Parent.Parent.Text).Opcitem. Single(n => n.Name == e.Node.Parent.Text); xio = opc; var tag = opc.Tag.Single(n => n.Name == e.Node.Text); xit = tag; tag_name_textBox.Text = xit.Name; tag_tag_textBox.Text = xit.Tag.ToString(); tag_tableName_textBox.Text = xit.TableName; treeNode = plcAddress_tree_advTree.Nodes[e.Node.Parent.Parent.Parent.Index]; } else if (e.Node.Level == 4) { ShowPanel(4); var tag = XML_Tool.xml.LINE.Single(n => n.Name == e.Node.Parent.Parent.Parent.Parent.Text). STATION.Single(n => n.Name == e.Node.Parent.Parent.Parent.Text).Opcitem. Single(n => n.Name == e.Node.Parent.Parent.Text).Tag.Single(n => n.Name == e.Node.Parent.Text); xit = tag; var dataitem = tag.Dataitem.Single(n => n.Name == e.Node.Text); xid = dataitem; dataitem_name_textBox.Text = xid.Name; dataitem_address_textBox.Text = xid.Addr; dataitem_columnName_textBox.Text = xid.ColmnName; dataitem_addressType_textBox.Text = xid.AddrType; dataitem_addressLength_textBox.Text = xid.AddrLength; treeNode = plcAddress_tree_advTree.Nodes[e.Node.Parent.Parent.Parent.Parent.Index]; } } catch (Exception ex) { MessageBoxEx.Show("树点击事件出现异常:" + ex.Message); } }