Exemplo n.º 1
0
        private void simplifyNetToolStripMenuItem_Click(object sender, EventArgs e)
        {
            TreeNode node = treeView1.SelectedNode;

            if (node.Tag is NodeClass nodeClass)
            {
                if (nodeClass.NodeType == NodeClassInfo.NodeClass)
                {
                    // 允许添加SimplifyNet设备
                    using (NodeSettings.FormSimplifyNet formNode = new NodeSettings.FormSimplifyNet(null))
                    {
                        if (formNode.ShowDialog( ) == DialogResult.OK)
                        {
                            formNode.NodeSimplifyNet.Name = GetUniqueName(node, formNode.NodeSimplifyNet.Name);

                            TreeNode nodeNew = new TreeNode(formNode.NodeSimplifyNet.Name);
                            nodeNew.ImageKey         = "FlagRed_16x";
                            nodeNew.SelectedImageKey = "FlagRed_16x";
                            nodeNew.Tag = formNode.NodeSimplifyNet;
                            node.Nodes.Add(nodeNew);
                            node.Expand( );
                            isNodeSettingsModify = true;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void 编辑类别editClassToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // 节点被选择的时候
            TreeNode node = treeView1.SelectedNode;

            if (node.ImageKey == "VirtualMachine_16xLG")
            {
                MessageBox.Show("无法编辑系统节点!");
                return;
            }

            if (node.Tag is NodeClass nodeClass)
            {
                if (nodeClass.NodeType == NodeClassInfo.NodeClass)
                {
                    // 编辑了节点
                    using (NodeSettings.FormNodeClass formNode = new NodeSettings.FormNodeClass(nodeClass))
                    {
                        if (formNode.ShowDialog( ) == DialogResult.OK)
                        {
                            node.Text            = formNode.SelectedNodeClass.Name;
                            node.Tag             = formNode.SelectedNodeClass;
                            isNodeSettingsModify = true;
                        }
                    }
                }
                else if (nodeClass.NodeType == NodeClassInfo.AlienServer)
                {
                    if (node.Tag is AlienNode alienNode)
                    {
                        // 编辑了异形服务器节点信息
                        using (NodeSettings.FormAlienNode formNode = new NodeSettings.FormAlienNode(alienNode))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.AlienNode.Name;
                                node.Tag             = formNode.AlienNode;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                }
                else if (nodeClass.NodeType == NodeClassInfo.ModbusServer)
                {
                    if (node.Tag is NodeModbusServer serverNode)
                    {
                        // 编辑了异形服务器节点信息
                        using (NodeSettings.FormModbusServer formNode = new NodeSettings.FormModbusServer(serverNode))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.ModbusServer.Name;
                                node.Tag             = formNode.ModbusServer;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                }
                else
                {
                    if (node.Tag is NodeModbusTcpClient modbusTcpNode)
                    {
                        // 编辑了Modbus-tcp节点
                        using (NodeSettings.FormModbusTcp formNode = new NodeSettings.FormModbusTcp(modbusTcpNode))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.ModbusTcpNode.Name;
                                node.Tag             = formNode.ModbusTcpNode;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                    else if (node.Tag is NodeModbusTcpAline modbusTcpAline)
                    {
                        // 编辑了Modbus-aline节点
                        using (NodeSettings.FormModbusTcpAlien formNode = new NodeSettings.FormModbusTcpAlien(modbusTcpAline))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.ModbusTcpAline.Name;
                                node.Tag             = formNode.ModbusTcpAline;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                    else if (node.Tag is DeviceRequest deviceRequest)
                    {
                        // 编辑了Request节点
                        using (RequestSettings.FormRequest formRequest = new RequestSettings.FormRequest(deviceRequest))
                        {
                            if (formRequest.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formRequest.DeviceRequest.Name;
                                node.Tag             = formRequest.DeviceRequest;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                    else if (node.Tag is NodeMelsecMc nodeMelsecMc)
                    {
                        // 编辑了三菱的节点数据
                        using (NodeSettings.FormMelsec3E formNode = new NodeSettings.FormMelsec3E(nodeMelsecMc))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.MelsecMc.Name;
                                node.Tag             = formNode.MelsecMc;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                    else if (node.Tag is NodeOmron nodeOmron)
                    {
                        // 编辑了欧姆龙的节点数据
                        using (NodeSettings.FormOmron formNode = new NodeSettings.FormOmron(nodeOmron))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.NodeOmron.Name;
                                node.Tag             = formNode.NodeOmron;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                    else if (node.Tag is NodeSiemens nodeSiemens)
                    {
                        // 编辑了欧姆龙的节点数据
                        using (NodeSettings.FormSiemens formNode = new NodeSettings.FormSiemens(nodeSiemens))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.NodeSiemens.Name;
                                node.Tag             = formNode.NodeSiemens;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                    else if (node.Tag is NodeEmpty nodeEmpty)
                    {
                        // 编辑了欧姆龙的节点数据
                        using (NodeSettings.FormEmpty formNode = new NodeSettings.FormEmpty(nodeEmpty))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.NodeEmpty.Name;
                                node.Tag             = formNode.NodeEmpty;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                    else if (node.Tag is NodeSimplifyNet nodeSimplify)
                    {
                        // 编辑了欧姆龙的节点数据
                        using (NodeSettings.FormSimplifyNet formNode = new NodeSettings.FormSimplifyNet(nodeSimplify))
                        {
                            if (formNode.ShowDialog( ) == DialogResult.OK)
                            {
                                node.Text            = formNode.NodeSimplifyNet.Name;
                                node.Tag             = formNode.NodeSimplifyNet;
                                isNodeSettingsModify = true;
                            }
                        }
                    }
                }
            }
        }