//主动下置命令 private void btSend_Click(object sender, EventArgs e) { if (this.IOTreeView.SelectedNode == null) { FrmDialog.ShowDialog(this, "请在IO树中选择设备节点"); return; } if (this.IOTreeView.SelectedNode is IoDeviceTreeNode) { IoDeviceTreeNode deviceNode = this.IOTreeView.SelectedNode as IoDeviceTreeNode; IoCommunicationTreeNode communicationTreeNode = this.IOTreeView.SelectedNode.Parent as IoCommunicationTreeNode; IoServerTreeNode serverNode = this.IOTreeView.SelectedNode.Parent.Parent as IoServerTreeNode; if (serverNode.ClientEndPoint == null) { FrmDialog.ShowDialog(this, "采集站终端未上线"); return; } SendCommandForm sendCommandForm = new SendCommandForm(); sendCommandForm.InitCommand(serverNode.Server, communicationTreeNode.Communication, deviceNode.Device); if (sendCommandForm.ShowDialog(this) == DialogResult.OK) { } } else { FrmDialog.ShowDialog(this, "请在IO树中选择设备节点"); return; } }
public async void LoadTreeProject() { if (this.hsComboBox.TreeView.Nodes.Count <= 0) { await Task.Run(() => { this.BeginInvoke(new EventHandler(delegate { try { this.hsComboBox.TreeView.Nodes.Clear(); int num = IOCenterManager.IOProject.Servers.Count + IOCenterManager.IOProject.Communications.Count + IOCenterManager.IOProject.Devices.Count; TreeNode mainNode = new TreeNode(); mainNode.ImageIndex = 0; mainNode.SelectedImageIndex = 0; mainNode.Text = PubConstant.Product; ///加载采集站 for (int i = 0; i < IOCenterManager.IOProject.Servers.Count; i++) { IoServerTreeNode serverNode = new IoServerTreeNode(); serverNode.Server = IOCenterManager.IOProject.Servers[i]; serverNode.InitNode(); List <Scada.Model.IO_COMMUNICATION> serverComms = IOCenterManager.IOProject.Communications.FindAll(x => x.IO_SERVER_ID == IOCenterManager.IOProject.Servers[i].SERVER_ID); for (int c = 0; c < serverComms.Count; c++)//通道 { IoCommunicationTreeNode commNode = new IoCommunicationTreeNode(); commNode.Communication = serverComms[c]; commNode.Server = IOCenterManager.IOProject.Servers[i]; commNode.InitNode(); List <Scada.Model.IO_DEVICE> commDevices = IOCenterManager.IOProject.Devices.FindAll(x => x.IO_SERVER_ID == IOCenterManager.IOProject.Servers[i].SERVER_ID && x.IO_COMM_ID == serverComms[c].IO_COMM_ID); for (int d = 0; d < commDevices.Count; d++)//设备 { IoDeviceTreeNode deviceNode = new IoDeviceTreeNode(); deviceNode.Device = commDevices[d]; deviceNode.Server = IOCenterManager.IOProject.Servers[i]; deviceNode.Communication = serverComms[c]; //挂载右键菜单 deviceNode.InitNode(); commNode.Nodes.Add(deviceNode); } serverNode.Nodes.Add(commNode); } mainNode.Nodes.Add(serverNode); } mainNode.Expand(); this.hsComboBox.TreeView.Nodes.Add(mainNode); } catch { } })); }); } }
public void ServerStatus(EndPoint clientEndPoint, IO_SERVER server, bool status) { this.ioTree.BeginInvoke(new EventHandler(delegate { if (this.ioTree.Nodes.Count < 0) { return; } for (int i = 0; i < this.ioTree.Nodes[0].Nodes.Count; i++) { TreeNode[] tn = this.ioTree.Nodes[0].Nodes.Find(server.SERVER_ID.ToString(), false); if (tn.Length == 1) { IoServerTreeNode serverNode = tn[0] as IoServerTreeNode; if (serverNode != null) { serverNode.ClientEndPoint = clientEndPoint; if (status) { serverNode.ForeColor = Color.Green; serverNode.Tag = null; serverNode.ImageIndex = 2; serverNode.StateImageIndex = 2; serverNode.Text = clientEndPoint.ToString(); } else { serverNode.ForeColor = Color.Red; serverNode.Tag = DateTime.Now.ToString("yyyy-MM-dd"); serverNode.ImageIndex = 1; serverNode.StateImageIndex = 1; serverNode.Text = server.SERVER_NAME + "未上线"; } } } } })); }
public void LoadIOProject(TreeView tree) { if (tree.FindForm() != null) { if (tree.Parent.IsHandleCreated) { tree.BeginInvoke(new EventHandler(delegate { try { tree.Nodes.Clear(); int num = IOCenterManager.IOProject.Servers.Count + IOCenterManager.IOProject.Communications.Count + IOCenterManager.IOProject.Devices.Count; TreeNode mainNode = new TreeNode(); mainNode.ImageIndex = 0; mainNode.SelectedImageIndex = 0; mainNode.Text = PubConstant.Product; InitProgress(num); ///加载采集站 for (int i = 0; i < IOCenterManager.IOProject.Servers.Count; i++) { IoServerTreeNode serverNode = new IoServerTreeNode(); serverNode.Server = IOCenterManager.IOProject.Servers[i]; serverNode.InitNode(); List <Scada.Model.IO_COMMUNICATION> serverComms = IOCenterManager.IOProject.Communications.FindAll(x => x.IO_SERVER_ID == IOCenterManager.IOProject.Servers[i].SERVER_ID); for (int c = 0; c < serverComms.Count; c++)//通道 { IoCommunicationTreeNode commNode = new IoCommunicationTreeNode(); commNode.Communication = serverComms[c]; commNode.Server = IOCenterManager.IOProject.Servers[i]; commNode.InitNode(); List <Scada.Model.IO_DEVICE> commDevices = IOCenterManager.IOProject.Devices.FindAll(x => x.IO_SERVER_ID == IOCenterManager.IOProject.Servers[i].SERVER_ID && x.IO_COMM_ID == serverComms[c].IO_COMM_ID); for (int d = 0; d < commDevices.Count; d++)//设备 { IoDeviceTreeNode deviceNode = new IoDeviceTreeNode(); deviceNode.Device = commDevices[d]; deviceNode.Server = IOCenterManager.IOProject.Servers[i]; deviceNode.Communication = serverComms[c]; //挂载右键菜单 deviceNode.ContextMenuStrip = Mediator.IOTreeForm.contextMenuStrip; deviceNode.InitNode(); commNode.Nodes.Add(deviceNode); SetProgress(); } SetProgress(); serverNode.Nodes.Add(commNode); } mainNode.Nodes.Add(serverNode); SetProgress(); } mainNode.ExpandAll(); tree.Nodes.Add(mainNode); EndProgress(); } catch (Exception exm) { DisplyException(exm); FrmDialog.ShowDialog(MainForm, exm.Message); EndProgress(); } })); } } else { try { tree.Nodes.Clear(); int num = IOCenterManager.IOProject.Servers.Count + IOCenterManager.IOProject.Communications.Count + IOCenterManager.IOProject.Devices.Count; TreeNode mainNode = new TreeNode(); mainNode.ImageIndex = 0; mainNode.SelectedImageIndex = 0; mainNode.Text = PubConstant.Product; InitProgress(num); ///加载采集站 for (int i = 0; i < IOCenterManager.IOProject.Servers.Count; i++) { IoServerTreeNode serverNode = new IoServerTreeNode(); serverNode.Server = IOCenterManager.IOProject.Servers[i]; serverNode.InitNode(); List <Scada.Model.IO_COMMUNICATION> serverComms = IOCenterManager.IOProject.Communications.FindAll(x => x.IO_SERVER_ID == IOCenterManager.IOProject.Servers[i].SERVER_ID); for (int c = 0; c < serverComms.Count; c++)//通道 { IoCommunicationTreeNode commNode = new IoCommunicationTreeNode(); commNode.Communication = serverComms[c]; commNode.Server = IOCenterManager.IOProject.Servers[i]; commNode.InitNode(); List <Scada.Model.IO_DEVICE> commDevices = IOCenterManager.IOProject.Devices.FindAll(x => x.IO_SERVER_ID == IOCenterManager.IOProject.Servers[i].SERVER_ID && x.IO_COMM_ID == serverComms[c].IO_COMM_ID); for (int d = 0; d < commDevices.Count; d++)//设备 { IoDeviceTreeNode deviceNode = new IoDeviceTreeNode(); deviceNode.Device = commDevices[d]; deviceNode.Server = IOCenterManager.IOProject.Servers[i]; deviceNode.Communication = serverComms[c]; //挂载右键菜单 deviceNode.ContextMenuStrip = Mediator.IOTreeForm.contextMenuStrip; deviceNode.InitNode(); commNode.Nodes.Add(deviceNode); SetProgress(); } SetProgress(); serverNode.Nodes.Add(commNode); } mainNode.Nodes.Add(serverNode); SetProgress(); } mainNode.ExpandAll(); tree.Nodes.Add(mainNode); EndProgress(); } catch (Exception exm) { DisplyException(exm); FrmDialog.ShowDialog(MainForm, exm.Message); EndProgress(); } } }
public static void LoadProject(TreeView tree) { AppendLogItem("正在加载采集站工程......"); MonitorDataBaseModel.InitBaseModel(); AppendLogItem("正在加载驱动信息......"); IOMonitorManager.InitMonitor(); AppendLogItem("正在加载IO树......"); Task.Run(() => { try { if (tree.Parent.IsHandleCreated) { tree.BeginInvoke(new EventHandler(delegate { tree.Nodes.Clear(); int num = MonitorDataBaseModel.IOCommunications.Count * MonitorDataBaseModel.IODevices.Count; InitProgress(num); IoServerTreeNode serverNode = new IoServerTreeNode(); serverNode.Server = MonitorDataBaseModel.IOServer; serverNode.InitNode(); List <Scada.Model.IO_COMMUNICATION> serverComms = MonitorDataBaseModel.IOCommunications.FindAll(x => x.IO_SERVER_ID == MonitorDataBaseModel.IOServer.SERVER_ID); for (int c = 0; c < serverComms.Count; c++) //通道 { IoCommunicationTreeNode commNode = new IoCommunicationTreeNode(); commNode.Communication = serverComms[c]; commNode.Server = MonitorDataBaseModel.IOServer; commNode.InitNode(); List <Scada.Model.IO_DEVICE> commDevices = MonitorDataBaseModel.IODevices.FindAll(x => x.IO_SERVER_ID == MonitorDataBaseModel.IOServer.SERVER_ID && x.IO_COMM_ID == serverComms[c].IO_COMM_ID); for (int d = 0; d < commDevices.Count; d++) //设备 { IoDeviceTreeNode deviceNode = new IoDeviceTreeNode(); deviceNode.Device = commDevices[d]; deviceNode.Server = MonitorDataBaseModel.IOServer; deviceNode.Communication = serverComms[c]; deviceNode.InitNode(); commNode.Nodes.Add(deviceNode); SetProgress(); } SetProgress(); serverNode.Nodes.Add(commNode); } serverNode.Expand(); EndProgress(); tree.Nodes.Add(serverNode); })); } } catch (Exception exm) { DisplyException(exm); FrmDialog.ShowDialog(MainForm, exm.Message); EndProgress(); } }); }