Example #1
0
        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 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();
                }
            }
        }
Example #3
0
        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();
                }
            });
        }