예제 #1
0
 public void  ServerStatus(EndPoint clientEndPoint, IO_SERVER server, bool status, string mac)
 {
     if (this.IsHandleCreated && IOTreeView.InvokeRequired)
     {
         IOTreeView.BeginInvoke(new EventHandler(delegate
         {
             if (this.IOTreeView.Nodes.Count < 0)
             {
                 return;
             }
             for (int i = 0; i < this.IOTreeView.Nodes.Count; i++)
             {
                 TreeNode[] tn = this.IOTreeView.Nodes[i].Nodes.Find(server.SERVER_ID.ToString(), false);
                 if (tn.Length == 1)
                 {
                     Controls.IoServerTreeNode serverNode = tn[0] as Controls.IoServerTreeNode;
                     if (serverNode != null)
                     {
                         serverNode.MAC            = mac;
                         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 + "未上线";
                         }
                     }
                 }
             }
         }));
     }
     IOCenterManager.QueryFormManager.Mediator.IOTreeForm.ServerStatus(clientEndPoint, server, status);
 }
예제 #2
0
파일: Search.cs 프로젝트: nxzzkj/lazyiot
        /// <summary>
        /// 首先要加载树结构
        /// </summary>
        public async void LoadTreeProject()
        {
            if (this.hsComboBoxDevices.TreeView.Nodes.Count <= 0)
            {
                await Task.Run(() =>
                {
                    if (this.IsHandleCreated)
                    {
                        this.BeginInvoke(new EventHandler(delegate
                        {
                            try
                            {
                                this.hsComboBoxDevices.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.hsComboBoxDevices.TreeView.Nodes.Add(mainNode);
                            }
                            catch
                            {
                            }
                        }));
                    }
                });
            }
        }