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); }
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); } }