Пример #1
0
        public void SetLoopsAmountBySpecifiedController()
        {
            List <string> lstLoopsCode = new List <string>();

            if (ProjectManager.GetInstance.Project != null && TheController != null)
            {
                SCA.Interface.IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(TheController.Type);
                short maxLoopAmount = controllerConfig.GetMaxLoopAmountValue();
                for (int i = 1; i <= maxLoopAmount; i++)
                {
                    lstLoopsCode.Add(i.ToString().PadLeft(TheController.LoopAddressLength, '0'));
                }
            }
            LoopsCode = lstLoopsCode;
        }
Пример #2
0
        public void AddMoreLines(object param)
        {
            // ObservableCollection<ManualControlBoard> ocMCB = ManualControlBoardInfoObservableCollection;
            object[] values = (object[])param;
            #region 调业务逻辑
            _manualControlBoardService.TheController = this.TheController;
            SCA.Interface.IControllerConfig config = ControllerConfigManager.GetConfigObject(this.TheController.Type);
            int totalMaxKeyNo = config.GetMaxAmountForKeyNoInManualControlBoardConfig();
            for (int i = Convert.ToInt32(values[1]); i <= Convert.ToInt32(values[2]); i++)
            {
                int maxKeyNo = 1;
                //获取当前板卡及回路下的最大"手键号"
                if (ManualControlBoardInfoObservableCollection.Count == 0)
                {
                    maxKeyNo = 1;
                }
                else
                {
                    var result = ManualControlBoardInfoObservableCollection.Where(mcb => mcb.MaxSubBoardNo == i && mcb.BoardNo == Convert.ToInt32(values[0]));
                    if (result.Count() != 0)
                    {
                        maxKeyNo = ManualControlBoardInfoObservableCollection.Where(mcb => mcb.MaxSubBoardNo == i && mcb.BoardNo == Convert.ToInt32(values[0])).Max(mcb => mcb.KeyNo);
                    }
                }
                if (maxKeyNo < totalMaxKeyNo)
                {
                    List <ManualControlBoard> lstMCB = _manualControlBoardService.Create(Convert.ToInt32(values[0]), Convert.ToInt32(values[1]), Convert.ToInt32(values[2]), maxKeyNo, Convert.ToInt32(values[3]));
                    foreach (var v in lstMCB)
                    {
                        EditableManualControlBoard mcb = new EditableManualControlBoard();
                        mcb.Controller   = v.Controller;
                        mcb.ControllerID = v.ControllerID;
                        mcb.ID           = v.ID;
                        mcb.Code         = v.Code;
                        mcb.BoardNo      = v.BoardNo;
                        mcb.SubBoardNo   = v.SubBoardNo;
                        mcb.KeyNo        = v.KeyNo;
                        ManualControlBoardInfoObservableCollection.Add(mcb);
                    }
                }
            }
            #endregion 调业务逻辑


            //SCA.WPF.Infrastructure.EventMediator.NotifyColleagues("ManualControlBoardAddMoreLinesRefreshData",null);
            this.CreateManualControlBoardVisibility = Visibility.Collapsed;
        }
Пример #3
0
        public List <string> GetPrimaryControllerLoopsAmount()
        {
            List <string> lstLoopsCode = new List <string>();

            if (ProjectManager.GetInstance.Project != null)
            {
                SCA.Model.ControllerModel       controller       = ProjectManager.GetInstance.GetPrimaryController();
                SCA.Interface.IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(controller.Type);
                short maxLoopAmount = controllerConfig.GetMaxLoopAmountValue();

                for (int i = 1; i <= maxLoopAmount; i++)
                {
                    lstLoopsCode.Add(i.ToString().PadLeft(controller.LoopAddressLength, '0'));
                }
            }
            LoopsCode = lstLoopsCode;
            return(lstLoopsCode);
        }
Пример #4
0
        public void SaveProject()
        {
            if (this.Project.IsDirty)
            {
                if (!_fileService.IsExistFile(this.Project.SaveFilePath)) //数据文件不存在
                {
                    _projectDBService.CreateLocalDBFile();
                }
                if (!IsCreatedFundamentalTableStructure) //未建立项目基础表结构
                {
                    if (_projectDBService != null)
                    {
                        _projectDBService.CreatFundamentalTableStructure();  //创建基础存储结构
                    }
                }
                //保存工程信息
                _projectDBService.AddProject(this.Project);
                //初始化“控制器类型信息”
                _projectDBService.InitializeControllerTypeInfo();

                //初始化此工程下的“器件类型”
                int projectID = _projectDBService.GetMaxID();
                IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(ControllerType.NONE);

                _deviceTypeDBService.InitializeDeviceTypeInfo(controllerConfig.GetALLDeviceTypeInfo(projectID));

                //保存此工程下的回路,器件,组态,手动盘
                foreach (var c in this.Project.Controllers)
                {
                    _deviceDBService = SCA.DatabaseAccess.DBContext.DeviceManagerDBServiceTest.GetDeviceDBContext(c.Type, _databaseService);
                    c.Project.ID     = projectID;
                    c.ProjectID      = projectID;
                    _controllerDBService.AddController(c);

                    //更新器件类型表的“匹配控制器信息”
                    controllerConfig = ControllerConfigManager.GetConfigObject(c.Type);
                    _deviceTypeDBService.UpdateMatchingController(c.Type, controllerConfig.GetDeviceTypeCodeInfo());

                    //取得当前ControllerID
                    // int controllerID = _controllerDBService.GetMaxID();
                    _deviceDBService.CreateTableStructure();
                    foreach (var loop in c.Loops)
                    {
                        loop.Controller.ID = c.ID;
                        loop.ControllerID  = c.ID;
                        _loopDBService.AddLoopInfo(loop);
                        //取得当前LoopID
                        //  int loopID = _loopDBService.GetMaxID();
                        loop.ID = loop.ID;
                        _deviceDBService.AddDevice(loop);
                        //取得当前器件最大ID号
                        //int deviceID=_deviceDBService.GetMaxID();
                    }
                    if (c.StandardConfig.Count != 0)
                    {
                        _linkageConfigStandardDBService.AddStandardLinkageConfigInfo(c.StandardConfig);
                    }
                    if (c.GeneralConfig.Count != 0)
                    {
                        _linkageConfigGeneralDBService.AddGeneralLinkageConfigInfo(c.GeneralConfig);
                    }
                    if (c.MixedConfig.Count != 0)
                    {
                        _linkageConfigMixedDBService.AddMixedLinkageConfigInfo(c.MixedConfig);
                    }
                    if (c.ControlBoard.Count != 0)
                    {
                        _manualControlBoardDBService.AddManualControlBoardInfo(c.ControlBoard);
                    }
                }
            }
            Project.IsDirty = false;
        }
Пример #5
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            ClearAllErrorMessage();
            ControllerModel controller = new ControllerModel();

            bool verifyFlag = true;

            if (ControllerTypeComboBox.SelectedItem != null)
            {
                controller.Type = (ControllerType)ControllerTypeComboBox.SelectedItem;
            }
            else
            {
                this.ErrorMessageControllerType.Text = "请选择控制器类型";
                verifyFlag = false;
            }
            if (DeviceCodeLengthComboBox.SelectedItem != null)
            {
                controller.DeviceAddressLength = Convert.ToInt32(DeviceCodeLengthComboBox.SelectedItem);
            }
            else
            {
                this.ErrorMessageControllerDeviceAddressLength.Text = "请选择器件长度";
                verifyFlag = false;
            }
            if (SerialPortNumberComboBox.SelectedItem != null)
            {
                controller.PortName = SerialPortNumberComboBox.SelectedItem.ToString();
            }
            else
            {
                this.ErrorMessageControllerPortName.Text = "请选择端口";
                verifyFlag = false;
            }
            if (this.ControllerMachineNumInputTextBox.Text == "")
            {
                this.ErrorMessageControllerDeviceAddressLength.Text = "请填写器件长度";
                verifyFlag = false;
            }
            if (verifyFlag)
            {
                controller.Name              = ControllerNameInputTextBox.Text;
                controller.MachineNumber     = ControllerMachineNumInputTextBox.Text;
                controller.LoopAddressLength = 2;//回路地址长度默认为2
                IControllerConfig config = ControllerConfigManager.GetConfigObject(controller.Type);
                int maxMachineNumber     = config.GetMaxMachineAmountValue(controller.DeviceAddressLength);
                Dictionary <string, RuleAndErrorMessage> dictRule = config.GetControllerInfoRegularExpression(controller.DeviceAddressLength);

                RuleAndErrorMessage rule = dictRule["Name"];

                Regex exminator = new Regex(rule.Rule);
                if (!string.IsNullOrEmpty(controller.Name))
                {
                    if (!exminator.IsMatch(controller.Name))
                    {
                        this.ErrorMessageControllerName.Text = rule.ErrorMessage;
                        verifyFlag = false;
                    }
                }
                else
                {
                    this.ErrorMessageControllerName.Text = "请填写控制器名称";
                    verifyFlag = false;
                }
                rule      = dictRule["MachineNumber"];
                exminator = new Regex(rule.Rule);
                if (!exminator.IsMatch(ControllerMachineNumInputTextBox.Text))
                {
                    this.ErrorMessageControllerMachineNumber.Text = rule.ErrorMessage;
                    verifyFlag = false;
                }
                else
                {
                    controller.MachineNumber = this.ControllerMachineNumInputTextBox.Text;
                }
                if (verifyFlag)
                {
                    if (Convert.ToInt16(controller.MachineNumber) > maxMachineNumber)
                    {
                        this.ErrorMessageControllerMachineNumber.Text = "机号超出范围,最大机号为" + maxMachineNumber.ToString();

                        verifyFlag = false;
                    }
                }
            }
            if (verifyFlag)
            {
                ControllerManager controllerManager = new ControllerManager();
                controllerManager.InitializeAllControllerOperation(null);
                IControllerOperation controllerOperation = controllerManager.GetController(controller.Type);
                controllerOperation.AddControllerToProject(controller);
                RaiseEvent(new RoutedEventArgs(AddButtonClickEvent));
            }
        }
Пример #6
0
 public List <int> GetDeviceCodeLength(Model.ControllerType type)
 {
     SCA.Interface.IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(type);
     DeviceCodeLength = controllerConfig.GetDeviceCodeLength();
     return(DeviceCodeLength);
 }
Пример #7
0
        //public static readonly RoutedEvent AllControllerInfoUploadedEvent = EventManager.RegisterRoutedEvent(
        //    "AllControllerInfoUploaded", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SummaryInfoView)
        //);


        //public event RoutedEventHandler AllControllerInfoUploaded
        //{
        //    add { AddHandler(AllControllerInfoUploadedEvent, value); }
        //    remove { RemoveHandler(AllControllerInfoUploadedEvent, value); }
        //}


        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            this.ErrorMessage.Text = "";
            // if (TheController != null)
            // {
            // ControllerModel controller=new ControllerModel();
            // //controller.ID = TheController.ID;

            // ControllerModel controller = ((SCA.WPF.ViewModelsRoot.ViewModels.Query.SummaryInfoViewModel)this.DataContext).TheController;
            // TheController.Name = ControllerNameInputTextBox.Text;
            // TheController.MachineNumber = MachineNumberInputTextBox.Text;

            // TheController.BaudRate = Convert.ToInt32(BaudsRateComboBox.SelectedItem);

            // TheController.PortName = ComPortComboBox.SelectedItem.ToString();
            SCA.WPF.ViewModelsRoot.ViewModels.Query.SummaryInfoViewModel vm = (SCA.WPF.ViewModelsRoot.ViewModels.Query.SummaryInfoViewModel) this.DataContext;
            ControllerModel controller = vm.TheController;

            IControllerConfig config = ControllerConfigManager.GetConfigObject(controller.Type);
            int maxMachineNumber     = config.GetMaxMachineAmountValue(controller.DeviceAddressLength);
            Dictionary <string, RuleAndErrorMessage> dictRule = config.GetControllerInfoRegularExpression(controller.DeviceAddressLength);

            RuleAndErrorMessage rule = dictRule["Name"];

            Regex  exminator    = new Regex(rule.Rule);
            string errorMessage = "";
            bool   verifyFlag   = true;

            if (!exminator.IsMatch(ControllerNameInputTextBox.Text))
            {
                errorMessage += "控制器名称:" + rule.ErrorMessage + "; ";
                //errorMessage += rule.ErrorMessage+";";
                verifyFlag = false;
            }
            rule      = dictRule["MachineNumber"];
            exminator = new Regex(rule.Rule);
            if (!exminator.IsMatch(MachineNumberInputTextBox.Text))
            {
                //errorMessage += rule.ErrorMessage+";";
                errorMessage += "控制器机号:" + rule.ErrorMessage + "; ";
                verifyFlag    = false;
            }

            if (verifyFlag)
            {
                if (Convert.ToInt16(MachineNumberInputTextBox.Text) > maxMachineNumber)
                {
                    errorMessage += "控制器机号:机号超出范围,最大机号为" + maxMachineNumber.ToString() + "; ";
                    //errorMessage += "机号超出范围,最大机号为" + maxMachineNumber.ToString();
                    verifyFlag = false;
                }
            }
            if (verifyFlag)
            {
                controller.Name          = ControllerNameInputTextBox.Text;
                controller.MachineNumber = MachineNumberInputTextBox.Text;

                controller.PortName = ComPortComboBox.SelectedItem.ToString();
                controller.BaudRate = Convert.ToInt32(BaudsRateComboBox.SelectedItem);
                vm.SaveExecute(controller);
                controller.IsDirty = true;

                EventMediator.NotifyColleagues("RefreshNavigator", controller);
                RaiseEvent(new RoutedEventArgs(AddButtonClickEvent, controller));
            }
            else
            {
                this.ErrorMessage.Text       = errorMessage;
                this.ErrorMessage.Visibility = Visibility.Visible;
            }
            // }
        }
Пример #8
0
        public void Initialize(List <ProjectModel> projects, object selectedEntity)
        {
            // 项目级别信息集合
            var projectHierarchyItemsList = new List <NavigatorItemViewModel>();

            foreach (var p in projects)
            {
                // 为项目信息创建导航节点
                var projectHierarchyItem = new NavigatorItemViewModel(p);
                projectHierarchyItemsList.Add(projectHierarchyItem);

                // 判断当前节点是否为选中节点
                if (selectedEntity != null && selectedEntity.GetType() == typeof(ProjectModel) && (selectedEntity as ProjectModel).Equals(p))
                {
                    _selectedItem = projectHierarchyItem;
                }

                // 判断项目下是否有控制器节点
                if (p.Controllers.Count != 0)
                {
                    // 创建“控制器”导航节点
                    var controllerHierarchyItemsList = new List <NavigatorItemViewModel>();

                    foreach (var c in p.Controllers)
                    {
                        // 为“控制器信息”创建导航节点
                        var controllerHierarchyItem = new NavigatorItemViewModel(c);
                        controllerHierarchyItem.Parent = projectHierarchyItem;
                        controllerHierarchyItemsList.Add(controllerHierarchyItem);

                        // 判断当前节点是否为选中节点
                        if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerModel) && (selectedEntity as ControllerModel).Equals(c))
                        {
                            _selectedItem = controllerHierarchyItem;
                        }
                        #region 根据控制器类型获取配置的节点
                        IControllerConfig     config    = ControllerConfigManager.GetConfigObject(c.Type);
                        ControllerNodeModel[] nodeModel = config.GetNodes();
                        #endregion
                        if (nodeModel.Length != 0)
                        {
                            var controllerNodeHierarchyItemList = new List <NavigatorItemViewModel>();
                            foreach (var cNode in nodeModel)
                            {
                                //为“控制器节点类型”创建导航节点
                                var nodeHierarchyItem = new NavigatorItemViewModel(cNode);
                                nodeHierarchyItem.Parent = controllerHierarchyItem;
                                controllerNodeHierarchyItemList.Add(nodeHierarchyItem);
                                if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerNodeModel) && (selectedEntity as ControllerNodeModel).Equals(cNode))
                                {
                                    _selectedItem = controllerHierarchyItem;
                                }
                                //如果节点类型为“回路”,需要为其增加“回路号”导航节点
                                if (cNode.Type == ControllerNodeType.Loop) //回路数据应该加载回路信息
                                {
                                    if (c.Loops.Count > 0)                 //加载回路数据
                                    {
                                        var loopHierarchyItemList = new List <NavigatorItemViewModel>();
                                        foreach (var l in c.Loops)
                                        {
                                            //为回路信息创建导航节点
                                            var loopHierarchyItem = new NavigatorItemViewModel(l);
                                            loopHierarchyItem.Parent = nodeHierarchyItem;
                                            loopHierarchyItemList.Add(loopHierarchyItem);
                                            if (selectedEntity != null && selectedEntity.GetType() == typeof(LoopModel) && (selectedEntity as LoopModel).Equals(l))
                                            {
                                                _selectedItem = loopHierarchyItem;
                                            }
                                        }
                                        nodeHierarchyItem.Children = new CollectionView(loopHierarchyItemList);
                                    }
                                }
                            }
                            controllerHierarchyItem.Children = new CollectionView(controllerNodeHierarchyItemList);
                        }
                    }
                    projectHierarchyItem.Children = new CollectionView(controllerHierarchyItemsList);
                }
            }

            this.Projects = new CollectionView(projectHierarchyItemsList);

            // 设置选中节点状态,并展开当前选中节点
            if (_selectedItem != null)
            {
                _selectedItem.IsSelected = true;
                NavigatorItemViewModel current = _selectedItem.Parent;

                while (current != null)
                {
                    current.IsExpanded = true;
                    current            = current.Parent;
                }
            }
        }
Пример #9
0
        public void SaveProject()
        {
            if (this.Project != null)
            {
                if (this.Project.IsDirty)
                {
                    if (!_fileService.IsExistFile(this.Project.SavePath)) //数据文件不存在
                    {
                        if (_projectDBService.CreateLocalDBFile())
                        {
                            Console.WriteLine("创建文件成功");
                        }
                        else
                        {
                            Console.WriteLine("创建文件失败");
                        }
                    }
                    if (!IsCreatedFundamentalTableStructure) //未建立项目基础表结构
                    {
                        if (_projectDBService != null)
                        {
                            if (_projectDBService.CreatFundamentalTableStructure())//;  //创建基础存储结构
                            {
                                Console.WriteLine("初始化成功");
                            }
                            else
                            {
                                Console.WriteLine("初始化失败");
                            }
                        }
                    }
                    //保存工程信息

                    if (_projectDBService.AddProject(this.Project) > 0)//;
                    {
                        Console.WriteLine("工程信息保存成功");
                    }
                    else
                    {
                        Console.WriteLine("工程信息保存失败");
                    }

                    //初始化“控制器类型信息”
                    if (_projectDBService.InitializeControllerTypeInfo())
                    {
                        Console.WriteLine("控制器类型初始化成功");
                    }
                    else
                    {
                        Console.WriteLine("控制器类型初始化失败");
                    }

                    //初始化此工程下的“器件类型”
                    int projectID = _projectDBService.GetMaxID();
                    IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(ControllerType.NONE);

                    if (_deviceTypeDBService.InitializeDeviceTypeInfo(controllerConfig.GetALLDeviceTypeInfo(projectID)))
                    {
                        Console.WriteLine("器件类型初始化成功");
                    }
                    else
                    {
                        Console.WriteLine("器件类型初始化失败");
                    }

                    //保存此工程下的回路,器件,组态,手动盘
                    foreach (var c in this.Project.Controllers)
                    {
                        _deviceDBService = SCA.DatabaseAccess.DBContext.DeviceManagerDBServiceTest.GetDeviceDBContext(c.Type, _dbFileVersionService);
                        c.Project.ID     = projectID;
                        c.ProjectID      = projectID;
                        if (_controllerDBService.AddController(c))
                        {
                            Console.WriteLine(c.Name + "控制器保存成功");
                        }
                        else
                        {
                            Console.WriteLine(c.Name + "控制器保存失败");
                        }

                        //更新器件类型表的“匹配控制器信息”
                        controllerConfig = ControllerConfigManager.GetConfigObject(c.Type);
                        if (_deviceTypeDBService.UpdateMatchingController(c.Type, controllerConfig.GetDeviceTypeCodeInfo()))
                        {
                            Console.WriteLine(c.Name + "控制器匹配信息更新成功");
                        }
                        else
                        {
                            Console.WriteLine(c.Name + "控制器匹配信息更新失败");
                        }

                        //取得当前ControllerID
                        // int controllerID = _controllerDBService.GetMaxID();
                        if (_deviceDBService.CreateTableStructure())
                        {
                            Console.WriteLine("器件结构初始化成功");
                        }
                        else
                        {
                            Console.WriteLine("器件结构初始化失败");
                        }
                        foreach (var loop in c.Loops)
                        {
                            loop.Controller.ID = c.ID;
                            loop.ControllerID  = c.ID;
                            if (_loopDBService.AddLoopInfo(loop))
                            {
                                Console.WriteLine("回路信息初始化成功");
                            }
                            else
                            {
                                Console.WriteLine("回路信息初始化失败");
                            }
                            //取得当前LoopID
                            //  int loopID = _loopDBService.GetMaxID();
                            loop.ID = loop.ID;
                            if (_deviceDBService.AddDevice(loop))
                            {
                                Console.WriteLine("器件信息保存成功");
                            }
                            else
                            {
                                Console.WriteLine("器件信息保存失败");
                            }
                            //取得当前器件最大ID号
                            //int deviceID=_deviceDBService.GetMaxID();
                        }
                        if (c.StandardConfig.Count != 0)
                        {
                            if (_linkageConfigStandardDBService.AddStandardLinkageConfigInfo(c.StandardConfig))
                            {
                                Console.WriteLine("标准组态信息保存成功");
                            }
                            else
                            {
                                Console.WriteLine("标准组态信息保存失败");
                            }
                        }
                        if (c.GeneralConfig.Count != 0)
                        {
                            if (_linkageConfigGeneralDBService.AddGeneralLinkageConfigInfo(c.GeneralConfig))
                            {
                                Console.WriteLine("通用组态信息保存成功");
                            }
                            else
                            {
                                Console.WriteLine("通用组态信息保存失败");
                            }
                        }
                        if (c.MixedConfig.Count != 0)
                        {
                            if (_linkageConfigMixedDBService.AddMixedLinkageConfigInfo(c.MixedConfig))
                            {
                                Console.WriteLine("混合组态信息保存成功");
                            }
                            else
                            {
                                Console.WriteLine("混合组态信息保存失败");
                            }
                        }
                        if (c.ControlBoard.Count != 0)
                        {
                            if (_manualControlBoardDBService.AddManualControlBoardInfo(c.ControlBoard))
                            {
                                Console.WriteLine("手控盘保存成功");
                            }
                            else
                            {
                                Console.WriteLine("手控盘保存失败");
                            }
                        }
                    }
                }
                RecentFiles.Add(Project.SavePath);
                SaveRecentFiles();
                Project.IsDirty = false;
            }
        }
Пример #10
0
        public void Initialize(List <ProjectModel> projects, object selectedEntity)
        {
            // create the top level collectionview for the customers
            var projectHierarchyItemsList = new List <HierarchyItemViewModel>();

            foreach (var p in projects)
            {
                // create the hierarchy item and add to the list
                var projectHierarchyItem = new HierarchyItemViewModel(p);

                projectHierarchyItemsList.Add(projectHierarchyItem);

                // check if this is the selected item
                if (selectedEntity != null && selectedEntity.GetType() == typeof(ProjectModel) && (selectedEntity as ProjectModel).Equals(p))
                {
                    _selectedItem = projectHierarchyItem;
                }

                // if there are any orders in projectHierarchyItem
                if (p.Controllers.Count != 0)
                {
                    // create a new list of HierarchyItems
                    var controllerHierarchyItemsList = new List <HierarchyItemViewModel>();
                    // loop through the orders and add them
                    foreach (var c in p.Controllers)
                    {
                        // create the hierarchy item and add to the list
                        var controllerHierarchyItem = new HierarchyItemViewModel(c);
                        controllerHierarchyItem.Parent = projectHierarchyItem;
                        controllerHierarchyItemsList.Add(controllerHierarchyItem);

                        // check if this is the selected item
                        if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerModel) && (selectedEntity as ControllerModel).Equals(c))
                        {
                            _selectedItem = controllerHierarchyItem;
                        }


                        IControllerConfig     config    = ControllerConfigManager.GetConfigObject(c.Type);
                        ControllerNodeModel[] nodeModel = config.GetNodes();
                        if (nodeModel.Length != 0)
                        {
                            var controllerNodeHierarchyItemList = new List <HierarchyItemViewModel>();
                            foreach (var cNode in nodeModel)
                            {
                                var nodeHierarchyItem = new HierarchyItemViewModel(cNode);
                                nodeHierarchyItem.Parent = controllerHierarchyItem;
                                controllerNodeHierarchyItemList.Add(nodeHierarchyItem);
                                if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerNodeModel) && (selectedEntity as ControllerNodeModel).Equals(cNode))
                                {
                                    _selectedItem = controllerHierarchyItem;
                                }
                                if (cNode.Type == ControllerNodeType.Loop) //回路数据应该加载回路信息
                                {
                                    if (c.Loops.Count > 0)                 //加载回路数据
                                    {
                                        var loopHierarchyItemList = new List <HierarchyItemViewModel>();
                                        foreach (var l in c.Loops)
                                        {
                                            var loopHierarchyItem = new HierarchyItemViewModel(l);
                                            loopHierarchyItem.Parent = nodeHierarchyItem;
                                            loopHierarchyItemList.Add(loopHierarchyItem);
                                            if (selectedEntity != null && selectedEntity.GetType() == typeof(LoopModel) && (selectedEntity as LoopModel).Equals(l))
                                            {
                                                _selectedItem = loopHierarchyItem;
                                            }
                                        }
                                        nodeHierarchyItem.Children = new CollectionView(loopHierarchyItemList);
                                    }
                                }
                            }
                            controllerHierarchyItem.Children = new CollectionView(controllerNodeHierarchyItemList);
                        }
                    }
                    // create the children of the customer
                    projectHierarchyItem.Children = new CollectionView(controllerHierarchyItemsList);
                }
            }

            this.Projects = new CollectionView(projectHierarchyItemsList);

            // select the selected item and expand it'type parents
            if (_selectedItem != null)
            {
                _selectedItem.IsSelected = true;
                HierarchyItemViewModel current = _selectedItem.Parent;

                while (current != null)
                {
                    current.IsExpanded = true;
                    current            = current.Parent;
                }
            }
        }
Пример #11
0
        public void ConfirmExecute()
        {
            ClearAllErrorMessage();
            RuleAndErrorMessage rule;
            Regex             exminator;
            IControllerConfig config = ControllerConfigManager.GetConfigObject(TheController.Type);
            bool verifyFlag          = true;

            if (LoopCode == null)
            {
                ErrorMessageLoopCode = "请指定回路号";
                verifyFlag           = false;
            }
            if (DeviceAmount != null)
            {
                rule      = new RuleAndErrorMessage("^[0-9]{1,3}$", "请填写数字");
                exminator = new Regex(rule.Rule);
                if (!exminator.IsMatch(DeviceAmount))
                {
                    ErrorMessageDeviceAmount = rule.ErrorMessage;
                    verifyFlag = false;
                }
                else
                {
                    int maxValue = config.GetMaxDeviceAmountValue();
                    if (Convert.ToInt32(DeviceAmount) > maxValue)
                    {
                        ErrorMessageDeviceAmount = "控制器最大节点数为:" + maxValue.ToString();
                        verifyFlag = false;
                    }
                }
            }
            if (LoopsAmount != null)
            {
                rule      = new RuleAndErrorMessage("^[0-9]{1,3}$", "请填写数字");
                exminator = new Regex(rule.Rule);
                if (!exminator.IsMatch(LoopsAmount))
                {
                    ErrorMessageLoopAmount = rule.ErrorMessage;
                    verifyFlag             = false;
                }
                else
                {
                    int maxValue = config.GetMaxLoopAmountValue();
                    if (Convert.ToInt32(LoopsAmount) > maxValue)
                    {
                        ErrorMessageLoopAmount = "控制器最大回路数为:" + maxValue.ToString();
                        verifyFlag             = false;
                    }
                }
            }
            rule      = new RuleAndErrorMessage("^[A-Za-z0-9\u4E00-\u9FFF()()]{0,8}$", "允许填写”中英文字符、阿拉伯数字、圆括号”,最大长度8个字符");
            exminator = new Regex(rule.Rule);
            if (!exminator.IsMatch(LoopName))
            {
                ErrorMessageLoopName = rule.ErrorMessage;
                verifyFlag           = false;
            }
            if (verifyFlag)
            {
                LoopModel loop = new LoopModel();
                loop.Code         = LoopCode;
                loop.DeviceAmount = Convert.ToInt32(DeviceAmount);
                loop.Name         = LoopName;
                loop.Controller   = TheController;
                loop.ControllerID = TheController.ID;
                SCA.Interface.ILoopService loopService = new SCA.BusinessLib.BusinessLogic.LoopService(loop.Controller);
                bool result = loopService.AddLoops(loop, ControllerMachineNumber, Convert.ToInt32(LoopsAmount));
                SCA.WPF.Infrastructure.EventMediator.NotifyColleagues("RefreshNavigator", result);
            }
        }
Пример #12
0
        /// <summary>
        /// 根据控制器的配置信息决定是否显示其它配置项
        /// </summary>
        /// <param name="type"></param>
        private void ToggleOtherSettingsVisibility(Model.ControllerType type)
        {
            SCA.Interface.IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(type);
            ControllerNodeModel[]           nodes            = controllerConfig.GetNodes();
            bool blnStandardFlag = false;
            bool blnMixedFlag    = false;
            bool blnGeneralFlag  = false;
            bool blnMCBFlag      = false;

            if (nodes.Length > 1)
            {
                OtherSettingsPanelVisibility = Visibility.Visible;
            }
            else
            {
                OtherSettingsPanelVisibility = Visibility.Collapsed;
            }
            for (int i = 0; i < nodes.Length; i++)
            {
                switch (nodes[i].Type)
                {
                case ControllerNodeType.Standard:
                    blnStandardFlag = true;
                    break;

                case ControllerNodeType.General:
                    blnGeneralFlag = true;
                    break;

                case ControllerNodeType.Mixed:
                    blnMixedFlag = true;
                    break;

                case ControllerNodeType.Board:
                    blnMCBFlag = true;
                    break;
                }
            }
            if (blnStandardFlag)
            {
                StandardLinkageCheckBoxVisibility = Visibility.Visible;
                StandardLinkageFlag = true;
            }
            else
            {
                StandardLinkageCheckBoxVisibility = Visibility.Collapsed;
                StandardLinkageFlag = false;
            }
            if (blnGeneralFlag)
            {
                GeneralLinkageCheckBoxVisibility = Visibility.Visible;
                GeneralLinkageFlag = true;
            }
            else
            {
                GeneralLinkageCheckBoxVisibility = Visibility.Collapsed;
                GeneralLinkageFlag = false;
            }
            if (blnMixedFlag)
            {
                MixedLinkageCheckBoxVisibility = Visibility.Visible;
                MixedLinkageFlag = true;
            }
            else
            {
                MixedLinkageCheckBoxVisibility = Visibility.Collapsed;
                MixedLinkageFlag = false;
            }
            if (blnMCBFlag)
            {
                ManualControlBoardCheckBoxVisibility = Visibility.Visible;
                ManualControlBoardFlag = true;
            }
            else
            {
                ManualControlBoardCheckBoxVisibility = Visibility.Collapsed;
                ManualControlBoardFlag = false;
            }

            return;
        }
Пример #13
0
 public void SetSelectedDeviceTypeCode(ControllerType type)
 {
     SCA.Interface.IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(type);
     SelectedDeviceTypeCode = Convert.ToInt16(controllerConfig.DefaultDeviceTypeCode);
 }
Пример #14
0
 public List <DeviceType> GetValidDeviceType(ControllerType type)
 {
     SCA.Interface.IControllerConfig controllerConfig = ControllerConfigManager.GetConfigObject(type);
     ValidDeviceType = controllerConfig.GetDeviceTypeInfo();
     return(ValidDeviceType);
 }