コード例 #1
0
        public bool AddLoops(LoopModel loop, string machineNumber, int loopsAmount)
        {
            try
            {
                ControllerOperationCommon controllerBase = new ControllerOperationCommon();
                int loopID = controllerBase.GetMaxLoopID();
                //ControllerModel controller = ProjectManager.GetInstance.GetPrimaryController();
                int[]             loopsCode          = GetAllLoopCode(_controller, null);
                int               currentMaxLoopCode = loopsCode.Max();
                IControllerConfig config             = ControllerConfigManager.GetConfigObject(_controller.Type);
                short             allowMaxLoopValue  = config.GetMaxLoopAmountValue();
                if (loopsAmount > allowMaxLoopValue)
                {
                    //超出最大数回数
                    return(false);
                }
                if ((allowMaxLoopValue - currentMaxLoopCode) < loopsAmount)
                {
                    //剩余回路空间无法创建指定回路数量的回路
                    return(false);
                }

                string strLoopLengthFormat = "#";

                for (int i = 0; i < _controller.LoopAddressLength; i++)
                {
                    strLoopLengthFormat += "0";
                }

                for (int i = 1; i <= loopsAmount; i++)
                {
                    LoopModel l = new LoopModel();
                    l.ID   = ++loopID;
                    l.Code = _controller.MachineNumber + (currentMaxLoopCode + i).ToString().PadLeft(_controller.LoopAddressLength, '0');
                    l.Name = _controller.MachineNumber + (currentMaxLoopCode + i).ToString().PadLeft(_controller.LoopAddressLength, '0');
                    //l.Code = (currentMaxLoopCode + i).ToString().PadLeft(_controller.LoopAddressLength, '0');
                    //l.Name = loop.Name+i.ToString();
                    l.DeviceAmount = loop.DeviceAmount;
                    l.Controller   = _controller;
                    _controller.Loops.Add(l);
                    //   SetDataDirty();
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
 protected override bool GenerateExcelTemplateLoopSheet(List <string> sheetNames, IControllerConfig config, Model.BusinessModel.ExcelTemplateCustomizedInfo summaryInfo, ref IExcelService excelService)
 {
     try
     {
         #region 生成所有回路页签模板
         int                   currentLoopStartIndex       = 2;
         int                   defaultLoopCodeLength       = 2;                                 //默认回路编码长度
         string                loopSheetNamePrefix         = "";                                //回路页签名称前缀
         short                 maxDeviceAmount             = config.GetMaxDeviceAmountValue();
         int                   maxLoopAmount               = config.GetMaxLoopAmountValue();    //允许最大回路数量
         int                   defaultDeviceTypeCode       = summaryInfo.DefaultDeviceTypeCode; //默认器件编码
         DeviceType            defaultDeviceType           = config.GetDeviceTypeViaDeviceCode(defaultDeviceTypeCode);
         ColumnConfigInfo[]    deviceColumnDefinitionArray = config.GetDeviceColumns();         //取得器件的列定义信息
         List <MergeCellRange> lstMergeCellRange           = new List <MergeCellRange>();
         ControllerNodeModel[] nodes = config.GetNodes();
         for (int i = 0; i < nodes.Length; i++)
         {
             switch (nodes[i].Type)
             {
             case ControllerNodeType.Loop:
                 loopSheetNamePrefix = nodes[i].Name;
                 break;
             }
         }
         for (int i = currentLoopStartIndex; i <= summaryInfo.LoopSheetAmount + 1; i++)
         {
             lstMergeCellRange.Clear();
             for (int j = 0; j < summaryInfo.LoopAmountPerSheet; j++)
             {
                 if (maxLoopAmount < (j + 1 + (i - currentLoopStartIndex) * summaryInfo.LoopAmountPerSheet))//已经超出最大回路编号,退出循环
                 {
                     break;
                 }
                 string loopCode  = summaryInfo.MachineNumberFormatted + (j + 1 + (i - currentLoopStartIndex) * summaryInfo.LoopAmountPerSheet).ToString().PadLeft(defaultLoopCodeLength, '0');
                 int    extraLine = 0;
                 if (j != 0)
                 {
                     extraLine = 2;
                 }
                 //回路标题:回路1
                 excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + j * extraLine, 0, loopSheetNamePrefix + ":" + loopCode, CellStyleType.SubCaption);
                 for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++)
                 {
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + 1 + j * extraLine, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead);
                 }
                 //回路标题行合并
                 MergeCellRange mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + j * extraLine;
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + j * extraLine;
                 mergeCellRange.FirstColumnIndex = 0;
                 mergeCellRange.LastColumnIndex  = deviceColumnDefinitionArray.Length - 1;
                 lstMergeCellRange.Add(mergeCellRange);
                 //回路默认器件信息
                 for (int k = 0; k < maxDeviceAmount; k++)
                 {
                     string deviceCode = (k + 1).ToString().PadLeft(summaryInfo.SelectedDeviceCodeLength - defaultLoopCodeLength - summaryInfo.MachineNumberFormatted.Length, '0');
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 0, loopCode + deviceCode, CellStyleType.Data);  //器件编码
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 1, defaultDeviceType.Name, CellStyleType.Data); //器件类型
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 2, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 3, "0", CellStyleType.Data);                    //屏蔽
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 4, "2", CellStyleType.Data);                    //灵敏度
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 5, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 6, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 7, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 8, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 9, null, CellStyleType.Data);
                 }
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 1;
                 mergeCellRange.LastColumnIndex  = 1;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.DeviceType.ToString(), mergeCellRange);
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 2;
                 mergeCellRange.LastColumnIndex  = 2;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.Feature.ToString(), mergeCellRange);
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 3;
                 mergeCellRange.LastColumnIndex  = 3;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.Disable.ToString(), mergeCellRange);
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 4;
                 mergeCellRange.LastColumnIndex  = 4;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.SensitiveLevel.ToString(), mergeCellRange);
             }
             excelService.SetColumnWidth(sheetNames[i], 1, 15f);
             excelService.SetColumnWidth(sheetNames[i], 9, 50f);
             excelService.SetMergeCells(sheetNames[i], lstMergeCellRange);//设置"回路页签"合并单元格
         }
         #endregion
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
コード例 #3
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);
            }
        }
コード例 #4
0
ファイル: LoopService.cs プロジェクト: A1X71/twilight
        public bool AddLoops(LoopModel loop, string machineNumber, int loopsAmount)
        {
            try
            {
                ControllerOperationCommon controllerBase = new ControllerOperationCommon();
                int loopID = controllerBase.GetMaxLoopID();
                //ControllerModel controller = ProjectManager.GetInstance.GetPrimaryController();
                int[] loopsCode          = GetAllLoopCode(_controller, null);
                int   currentMaxLoopCode = loopsCode.Max();
                int   specifiedLoopCode  = 0;     //指定的回路号
                bool  loopCodeExistFlag  = false; //回路号已经存在标志

                //if (loop.Code != "")
                //{
                //    specifiedLoopCode=Convert.ToInt32(loop.Code);
                //    if (specifiedLoopCode > currentMaxLoopCode)
                //    {
                //        currentMaxLoopCode = specifiedLoopCode;
                //    }
                //}

                for (int i = 0; i < loopsCode.Length; i++)
                {
                    if (loopsCode[i] == specifiedLoopCode)
                    {
                        loopCodeExistFlag = true;
                        break;
                    }
                }


                IControllerConfig config            = ControllerConfigManager.GetConfigObject(_controller.Type);
                short             allowMaxLoopValue = config.GetMaxLoopAmountValue();
                if (loopsAmount == 0)
                {
                    return(false);
                }
                if (loopsAmount > allowMaxLoopValue)
                {
                    //超出最大数回数
                    return(false);
                }
                if ((allowMaxLoopValue - currentMaxLoopCode) < loopsAmount)
                {
                    //剩余回路空间无法创建指定回路数量的回路
                    return(false);
                }

                string strLoopLengthFormat = "#";

                for (int i = 0; i < _controller.LoopAddressLength; i++)
                {
                    strLoopLengthFormat += "0";
                }

                for (int i = 1; i <= loopsAmount; i++)
                {
                    LoopModel l = new LoopModel();
                    l.ID = ++loopID;
                    if (!loopCodeExistFlag)
                    {
                        if (i == 1) //减少复杂性,只对指定的回路号使用一次
                        {
                            l.Code = _controller.MachineNumber + loop.Code.ToString().PadLeft(_controller.LoopAddressLength, '0');
                        }
                        else
                        {
                            l.Code = _controller.MachineNumber + (currentMaxLoopCode + i - 1).ToString().PadLeft(_controller.LoopAddressLength, '0');
                        }
                    }
                    else
                    {
                        l.Code = _controller.MachineNumber + (currentMaxLoopCode + i).ToString().PadLeft(_controller.LoopAddressLength, '0');
                    }

                    l.Name = loop.Name + "(" + l.Code + ")";// _controller.MachineNumber + (currentMaxLoopCode + i).ToString().PadLeft(_controller.LoopAddressLength, '0');
                    //l.Code = (currentMaxLoopCode + i).ToString().PadLeft(_controller.LoopAddressLength, '0');
                    //l.Name = loop.Name+i.ToString();
                    l.DeviceAmount = loop.DeviceAmount;
                    l.Controller   = _controller;
                    l.ControllerID = _controller.ID;
                    InitializeDevicesToLoop(_controller.Type, l);
                    _controller.Loops.Add(l);
//                  SetDataDirty();
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }