private void TreeNodeRender(TreeNode treeNode, XElement element) { foreach (XElement item in element.Elements( )) { if (item.Name == "NodeClass") { TreeNode node = new TreeNode(item.Attribute("Name").Value); node.ImageKey = "usbcontroller"; node.SelectedImageKey = "usbcontroller"; NodeClass nodeClass = new NodeClass( ); nodeClass.LoadByXmlElement(item); node.Tag = nodeClass; treeNode.Nodes.Add(node); TreeNodeRender(node, item); } else if (item.Name == "RegularNode") { TreeNode node = new TreeNode(item.Attribute("Name").Value); node.ImageKey = "Operator_660"; node.SelectedImageKey = "Operator_660"; RegularNode regularNode = new RegularNode( ); regularNode.LoadByXmlElement(item); node.Tag = regularNode; treeNode.Nodes.Add(node); } } }
/// <summary> /// 从系统的xml文件中加载规则信息 /// </summary> public void LoadRegulars() { if (File.Exists(filePath)) { XElement xElement = XElement.Load(filePath); if (xElement.Name == "Regulars") { dictLock.Enter( ); sharpRegulars.Clear( ); foreach (var item in xElement.Elements("NodeClass")) { string name = item.Attribute("Name").Value; List <RegularNode> regulars = new List <RegularNode>( ); foreach (var node in item.Elements("RegularNode")) { RegularNode tmp = new RegularNode( ); tmp.LoadByXmlElement(node); regulars.Add(tmp); } if (!sharpRegulars.ContainsKey(name)) { sharpRegulars.Add(name, regulars); } } dictLock.Leave( ); } } }
public FormRegularNode(RegularNode regularNode = null) { InitializeComponent( ); RegularNode = regularNode; Icon = Util.GetWinformICon( ); }
} // 结果信息 private void userButton1_Click(object sender, EventArgs e) { // 检查数据输入 if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("名称不能为空!"); textBox1.Focus( ); return; } if (!int.TryParse(textBox3.Text, out int index)) { MessageBox.Show("索引号输入的格式有误,请重新输入。"); textBox3.Focus( ); return; } if (index < 0) { MessageBox.Show("索引号不能小于0,请重新输入。"); textBox3.Focus( ); return; } if (!int.TryParse(textBox5.Text, out int typeLength)) { MessageBox.Show("数据长度输入错误。"); textBox5.Focus( ); return; } RegularNode = new RegularNode( ) { Name = textBox1.Text, Description = textBox2.Text, Index = index, RegularCode = ((RegularNodeTypeItem)comboBox1.SelectedItem).Code, TypeLength = typeLength, }; DialogResult = DialogResult.OK; }
private void userButton1_Click(object sender, EventArgs e) { // 检查数据输入 if (string.IsNullOrEmpty(textBox1.Text)) { MessageBox.Show("名称不能为空!"); textBox1.Focus(); return; } RegularNode = new RegularNode { Name = textBox1.Text, Description = textBox2.Text }; DialogResult = DialogResult.OK; }
private void PaintLineAuxiliary(Graphics g, int paint_x, int paint_y, int every_line_count, int index, int byteLength, bool isDowm, string info, Font font, StringFormat stringFormat, RegularNode regularNode) { Point point1 = CalculatePointWithByteIndex(paint_x, paint_y, every_line_count, index); Point point2 = CalculatePointWithByteIndex(paint_x, paint_y, every_line_count, index + byteLength - 1); if (point1.Y == point2.Y) { // 同一行的情况 if (isDowm) { point1.Offset(0, 12); point2.Offset(0, 12); g.DrawLine(Pens.DimGray, point1, new Point(point1.X, point1.Y - 3)); g.DrawLine(Pens.DimGray, point2, new Point(point2.X, point2.Y - 3)); g.DrawLine(Pens.DimGray, point1, point2); Rectangle rectangle = new Rectangle(point1.X - 40, point1.Y, point2.X - point1.X + 80, 20); if (regularNode.TypeLength == 1) { g.DrawString(info, Font, Brushes.Blue, rectangle, stringFormat); } else { g.DrawString(info + "*" + regularNode.TypeLength, Font, Brushes.Blue, rectangle, stringFormat); } } else { point1.Offset(0, -11); point2.Offset(0, -11); g.DrawLine(Pens.Chocolate, point1, new Point(point1.X, point1.Y + 3)); g.DrawLine(Pens.Chocolate, point2, new Point(point2.X, point2.Y + 3)); g.DrawLine(Pens.Chocolate, point1, point2); Rectangle rectangle = new Rectangle(point1.X - 40, point1.Y - 14, point2.X - point1.X + 80, 15); if (isShowText) { g.DrawString(info, font, Brushes.Green, rectangle, stringFormat); } } } else { if (isDowm) { // 跨行的情况 point1.Offset(0, 12); point2.Offset(0, 12); Point point1_1 = CalculatePointWithByteIndex(paint_x, paint_y, every_line_count, every_line_count - 1); point1_1.Y = point1.Y; point1_1.X += 10; g.DrawLine(Pens.DimGray, point1, new Point(point1.X, point1.Y - 3)); g.DrawLine(Pens.DimGray, point1, point1_1); Point point2_2 = CalculatePointWithByteIndex(paint_x, paint_y, every_line_count, 0); point2_2.Y = point2.Y; point2_2.X -= 10; g.DrawLine(Pens.DimGray, point2, new Point(point2.X, point2.Y - 3)); g.DrawLine(Pens.DimGray, point2, point2_2); if ((point1_1.X - point1.X) > (point2.X - point2_2.X)) { Rectangle rectangle = new Rectangle(point1.X - 40, point1.Y, point1_1.X - point1.X + 80, 20); if (regularNode.TypeLength == 1) { g.DrawString(info, Font, Brushes.Blue, rectangle, stringFormat); } else { g.DrawString(info + "*" + regularNode.TypeLength, Font, Brushes.Blue, rectangle, stringFormat); } } else { Rectangle rectangle = new Rectangle(point2_2.X - 40, point2.Y, point2.X - point2_2.X + 80, 20); if (regularNode.TypeLength == 1) { g.DrawString(info, Font, Brushes.Blue, rectangle, stringFormat); } else { g.DrawString(info + "*" + regularNode.TypeLength, Font, Brushes.Blue, rectangle, stringFormat); } } } else { point1.Offset(0, -11); point2.Offset(0, -11); Point point1_1 = CalculatePointWithByteIndex(paint_x, paint_y, every_line_count, every_line_count - 1); point1_1.Y = point1.Y; point1_1.X += 10; g.DrawLine(Pens.Chocolate, point1, new Point(point1.X, point1.Y + 3)); g.DrawLine(Pens.Chocolate, point1, point1_1); Point point2_2 = CalculatePointWithByteIndex(paint_x, paint_y, every_line_count, 0); point2_2.Y = point2.Y; point2_2.X -= 10; g.DrawLine(Pens.Chocolate, point2, new Point(point2.X, point2.Y + 3)); g.DrawLine(Pens.Chocolate, point2, point2_2); if ((point1_1.X - point1.X) > (point2.X - point2_2.X)) { Rectangle rectangle = new Rectangle(point1.X - 40, point1.Y - 14, point1_1.X - point1.X + 80, 15); if (isShowText) { g.DrawString(info, Font, Brushes.Green, rectangle, stringFormat); } } else { Rectangle rectangle = new Rectangle(point2_2.X - 40, point2.Y - 14, point2.X - point2_2.X + 80, 15); if (isShowText) { g.DrawString(info, Font, Brushes.Green, rectangle, stringFormat); } } } } }
private void TreeNodeRender(TreeNode treeNode, XElement element) { foreach (var item in element.Elements()) { if (item.Name == "NodeClass") { var node = new TreeNode(item.Attribute("Name").Value); node.ImageKey = "Class_489"; node.SelectedImageKey = "Class_489"; var nodeClass = new NodeClass(); nodeClass.LoadByXmlElement(item); node.Tag = nodeClass; treeNode.Nodes.Add(node); TreeNodeRender(node, item); } else if (item.Name == "DeviceNode") { var type = int.Parse(item.Attribute("DeviceType").Value); var deviceNode = new TreeNode(item.Attribute("Name").Value); if (type == DeviceNode.ModbusTcpClient) { deviceNode.ImageKey = "Module_648"; deviceNode.SelectedImageKey = "Module_648"; var modbusNode = new NodeModbusTcpClient(); modbusNode.LoadByXmlElement(item); deviceNode.Tag = modbusNode; } else if (type == DeviceNode.ModbusTcpAlien) { deviceNode.ImageKey = "Module_648"; deviceNode.SelectedImageKey = "Module_648"; var modbusAlien = new NodeModbusTcpAline(); modbusAlien.LoadByXmlElement(item); deviceNode.Tag = modbusAlien; } else if (type == DeviceNode.MelsecMcQna3E) { deviceNode.ImageKey = "Enum_582"; deviceNode.SelectedImageKey = "Enum_582"; var node = new NodeMelsecMc(); node.LoadByXmlElement(item); deviceNode.Tag = node; } else if (type == DeviceNode.Siemens) { deviceNode.ImageKey = "Event_594"; deviceNode.SelectedImageKey = "Event_594"; var node = new NodeSiemens(); node.LoadByXmlElement(item); deviceNode.Tag = node; } else if (type == DeviceNode.DeviceNone) { deviceNode.ImageKey = "Method_636"; deviceNode.SelectedImageKey = "Method_636"; var node = new NodeEmpty(); node.LoadByXmlElement(item); deviceNode.Tag = node; } else if (type == DeviceNode.Omron) { deviceNode.ImageKey = "HotSpot_10548_color"; deviceNode.SelectedImageKey = "HotSpot_10548_color"; var node = new NodeOmron(); node.LoadByXmlElement(item); deviceNode.Tag = node; } treeNode.Nodes.Add(deviceNode); foreach (var request in item.Elements("DeviceRequest")) { var deviceRequest = new DeviceRequest(); deviceRequest.LoadByXmlElement(request); var parseCode = deviceRequest.PraseRegularCode; if (regularkeyValuePairs.ContainsKey(parseCode)) { foreach (var regularNodeItem in regularkeyValuePairs[parseCode]) { var treeNodeRegular = new TreeNode(regularNodeItem.Name); treeNodeRegular.ImageKey = "Operator_660"; treeNodeRegular.SelectedImageKey = "Operator_660"; treeNodeRegular.Tag = regularNodeItem; deviceNode.Nodes.Add(treeNodeRegular); } } } } else if (item.Name == "ServerNode") { var type = int.Parse(item.Attribute("ServerType").Value); if (type == ServerNode.ModbusServer) { var node = new TreeNode(item.Attribute("Name").Value); node.ImageKey = "server_Local_16xLG"; node.SelectedImageKey = "server_Local_16xLG"; var nodeClass = new NodeModbusServer(); nodeClass.LoadByXmlElement(item); node.Tag = nodeClass; treeNode.Nodes.Add(node); } else if (type == ServerNode.AlienServer) { var node = new TreeNode(item.Attribute("Name").Value); node.ImageKey = "server_Local_16xLG"; node.SelectedImageKey = "server_Local_16xLG"; var nodeClass = new AlienServerNode(); nodeClass.LoadByXmlElement(item); node.Tag = nodeClass; treeNode.Nodes.Add(node); TreeNodeRender(node, item); } } else if (item.Name == "RegularNode") { var node = new TreeNode(item.Attribute("Name").Value); node.ImageKey = "usbcontroller"; node.SelectedImageKey = "usbcontroller"; var nodeClass = new RegularNode(); nodeClass.LoadByXmlElement(item); node.Tag = nodeClass; treeNode.Nodes.Add(node); foreach (var regularItemXml in item.Elements("RegularItemNode")) { var treeNodeRegular = new TreeNode(regularItemXml.Attribute("Name").Value); treeNodeRegular.ImageKey = "Operator_660"; treeNodeRegular.SelectedImageKey = "Operator_660"; var regularItemNode = new RegularItemNode(); regularItemNode.LoadByXmlElement(regularItemXml); treeNodeRegular.Tag = regularItemNode; node.Nodes.Add(treeNodeRegular); } } } }