Пример #1
0
        private void NewDevice()
        {
            TreeListNode         node       = trees.CurrentNode();
            TreeListNode         parentNode = null;
            ProductionLineEntity parent     = null;

            if (node.Tag is Guid id)
            {
                BaseEntity entity = DataHelper.Instance.AllEntities[id];
                if (entity is ProductionLineEntity line)
                {
                    parentNode = node;
                    parent     = line;
                }
                else if (entity is DeviceEntity device)
                {
                    parentNode = node.ParentNode;
                    parent     = device.Parent;
                }
            }

            if (parentNode != null && parent != null)
            {
                DeviceEntity newDevice = new DeviceEntity(parent);
                parent.Devices.Add(newDevice, null);
                DataHelper.Instance.AllEntities.Add(newDevice);

                newDevice.Node = trees.AppendNode(newDevice.Name, newDevice.ID, parentNode);
            }
        }
Пример #2
0
        private void NewProductionLine()
        {
            ProductionLineEntity line = new ProductionLineEntity()
            {
                Name = $"Known[{Guid.NewGuid().ToString("N")}]",
            };

            DataHelper.Instance.AllEntities.Add(line);
            DataHelper.Instance.Lines.Add(line, null);

            line.Node = trees.AppendNode(line.Name, line.ID, null);
        }
Пример #3
0
        private void ImportDeviceParams()
        {
            #region 获取设备导入的文件名
            OpenFileDialog dialogOpenFile = new OpenFileDialog()
            {
                Title           = "选择导入设备PLC的配置文件",
                Filter          = "设备PLC配置文件(*.xml)|*.xml|所有文件(*.*)|*.*",
                CheckFileExists = true,
            };
            string importPath = "";
            if (dialogOpenFile.ShowDialog(FindForm()) == DialogResult.OK)
            {
                importPath = dialogOpenFile.FileName;
            }
            #endregion

            if (File.Exists(importPath))
            {
                TreeListNode         node   = trees.CurrentNode();
                ProductionLineEntity parent = null;

                if (node.Tag is Guid id)
                {
                    BaseEntity entity = DataHelper.Instance.AllEntities[id];
                    if (entity is ProductionLineEntity line)
                    {
                        parent = line;
                    }
                }

                if (parent != null)
                {
                    List <DeviceEntity> devices = parent.ImportDevice(importPath);
                    foreach (DeviceEntity device in devices)
                    {
                        device.Node = trees.AppendNode(device.Name, device.ID, node);
                    }
                }
            }
        }