public ProjectModel UpgradeToDestinationVersion(ProjectModel project) { if (project != null) { int deviceCodeLength = 0; foreach (var c in project.Controllers) { foreach (var l in c.Loops) { if (l.DeviceAmount != 0) { deviceCodeLength = GetDeviceCodeLength(c.Type, l); break; } } //更新器件长度信息 if (deviceCodeLength == 0)//无器件信息,无法判定当前控制器长度,采用默认值 { IControllerConfig config = ControllerConfigManager.GetConfigObject(c.Type); c.DeviceAddressLength = config.GetDeviceCodeLength()[0]; } else { c.DeviceAddressLength = deviceCodeLength; } } } return(project); }
/// <summary> /// 将回路数据写入指定的EXCEL工作表 /// </summary> /// <param name="excelService"></param> /// <param name="models"></param> /// <param name="sheetName"></param> /// <returns></returns> public bool ExportLoopDataToExcel(ref IExcelService excelService, List <LoopModel> models, string sheetName) { try { if (models.Count > 0) { IControllerConfig config = ControllerConfigManager.GetConfigObject(ControllerType.FT8000); ColumnConfigInfo[] deviceColumnDefinitionArray = config.GetDeviceColumns(); //取得器件的列定义信息 List <MergeCellRange> lstMergeCellRange = new List <MergeCellRange>(); int startRowIndex = 0; int currentRowIndex = 0; foreach (var loop in models) { startRowIndex = currentRowIndex; currentRowIndex++; //回路标题 excelService.SetCellValue(sheetName, startRowIndex, 0, "回路:" + loop.Name, CellStyleType.SubCaption); for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++) { excelService.SetCellValue(sheetName, currentRowIndex, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead); } //回路标题行合并 MergeCellRange mergeCellRange = new MergeCellRange(); mergeCellRange.FirstRowIndex = startRowIndex; mergeCellRange.LastRowIndex = startRowIndex; mergeCellRange.FirstColumnIndex = 0; mergeCellRange.LastColumnIndex = deviceColumnDefinitionArray.Length - 1; lstMergeCellRange.Add(mergeCellRange); //写入器件信息 foreach (var device in loop.GetDevices <DeviceInfo8000>()) { currentRowIndex++; excelService.SetCellValue(sheetName, currentRowIndex, 0, device.Code, CellStyleType.Data); //器件编码 excelService.SetCellValue(sheetName, currentRowIndex, 1, config.GetDeviceTypeViaDeviceCode(device.TypeCode).Name, CellStyleType.Data); //器件类型 excelService.SetCellValue(sheetName, currentRowIndex, 2, device.Feature == null?null:device.Feature.ToString(), CellStyleType.Data); //特性 excelService.SetCellValue(sheetName, currentRowIndex, 3, device.Disable == null?null:device.Disable.ToString(), CellStyleType.Data); //屏蔽 excelService.SetCellValue(sheetName, currentRowIndex, 4, device.SensitiveLevel == null?null:device.SensitiveLevel.ToString(), CellStyleType.Data); //灵敏度 excelService.SetCellValue(sheetName, currentRowIndex, 5, device.LinkageGroup1, CellStyleType.Data); //输出组1 excelService.SetCellValue(sheetName, currentRowIndex, 6, device.LinkageGroup2, CellStyleType.Data); //输出组2 excelService.SetCellValue(sheetName, currentRowIndex, 7, device.LinkageGroup3, CellStyleType.Data); //输出组3 excelService.SetCellValue(sheetName, currentRowIndex, 8, device.DelayValue == null?null:device.DelayValue.ToString(), CellStyleType.Data); //延时 excelService.SetCellValue(sheetName, currentRowIndex, 9, device.sdpKey, CellStyleType.Data); //手操号 excelService.SetCellValue(sheetName, currentRowIndex, 10, device.ZoneNo == null?null:device.ZoneNo.ToString(), CellStyleType.Data); //分区 excelService.SetCellValue(sheetName, currentRowIndex, 11, device.BroadcastZone, CellStyleType.Data); //广播分区 excelService.SetCellValue(sheetName, currentRowIndex, 12, device.Location, CellStyleType.Data); //安装地点 } currentRowIndex++; } excelService.SetMergeCells(sheetName, lstMergeCellRange);//设置"回路页签"合并单元格 excelService.SetColumnWidth(sheetName, 1, 15f); excelService.SetColumnWidth(sheetName, 12, 50f); } } catch (Exception ex) { return(false); } return(true); }
/// <summary> /// 将回路数据写入指定的EXCEL工作表 /// </summary> /// <param name="excelService"></param> /// <param name="models"></param> /// <param name="sheetName"></param> /// <returns></returns> public bool ExportLoopDataToExcel(ref IExcelService excelService, List <LoopModel> models, string sheetName) { try { if (models.Count > 0) { IControllerConfig config = ControllerConfigManager.GetConfigObject(ControllerType.NT8021); ColumnConfigInfo[] deviceColumnDefinitionArray = config.GetDeviceColumns(); //取得器件的列定义信息 List <MergeCellRange> lstMergeCellRange = new List <MergeCellRange>(); int startRowIndex = 0; int currentRowIndex = 0; foreach (var loop in models) { startRowIndex = currentRowIndex; currentRowIndex++; //回路标题 excelService.SetCellValue(sheetName, startRowIndex, 0, "回路:" + loop.Name, CellStyleType.SubCaption); for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++) { excelService.SetCellValue(sheetName, currentRowIndex, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead); } //回路标题行合并 MergeCellRange mergeCellRange = new MergeCellRange(); mergeCellRange.FirstRowIndex = startRowIndex; mergeCellRange.LastRowIndex = startRowIndex; mergeCellRange.FirstColumnIndex = 0; mergeCellRange.LastColumnIndex = deviceColumnDefinitionArray.Length - 1; lstMergeCellRange.Add(mergeCellRange); //写入器件信息 foreach (var device in loop.GetDevices <DeviceInfo8021>()) { currentRowIndex++; excelService.SetCellValue(sheetName, currentRowIndex, 0, device.Code, CellStyleType.Data); //器件编码 excelService.SetCellValue(sheetName, currentRowIndex, 1, config.GetDeviceTypeViaDeviceCode(device.TypeCode).Name, CellStyleType.Data); //器件类型 excelService.SetCellValue(sheetName, currentRowIndex, 2, device.Disable == null?null:device.Disable.ToString(), CellStyleType.Data); //屏蔽 excelService.SetCellValue(sheetName, currentRowIndex, 3, device.CurrentThreshold == null?null:device.CurrentThreshold.ToString(), CellStyleType.Data); //电流报警值 excelService.SetCellValue(sheetName, currentRowIndex, 4, device.TemperatureThreshold == null?null:device.TemperatureThreshold.ToString(), CellStyleType.Data); //温度报警值 excelService.SetCellValue(sheetName, currentRowIndex, 5, device.BuildingNo == null?null:device.BuildingNo.ToString(), CellStyleType.Data); //楼号 excelService.SetCellValue(sheetName, currentRowIndex, 6, device.ZoneNo == null?null:device.ZoneNo.ToString(), CellStyleType.Data); //区号 excelService.SetCellValue(sheetName, currentRowIndex, 7, device.FloorNo == null?null:device.FloorNo.ToString(), CellStyleType.Data); //层号 excelService.SetCellValue(sheetName, currentRowIndex, 8, device.RoomNo == null?null:device.RoomNo.ToString(), CellStyleType.Data); //房间号 excelService.SetCellValue(sheetName, currentRowIndex, 9, device.Location, CellStyleType.Data); //安装地点 } } excelService.SetMergeCells(sheetName, lstMergeCellRange);//设置"回路页签"合并单元格 excelService.SetColumnWidth(sheetName, 1, 15f); excelService.SetColumnWidth(sheetName, 9, 50f); } } catch (Exception ex) { return(false); } return(true); }
public bool ExportStandardLinkageDataToExcel(ref IExcelService excelService, List <LinkageConfigStandard> models, string sheetName) { try { if (models.Count > 0) { #region 标准组态表头 IControllerConfig config = ControllerConfigManager.GetConfigObject(ControllerType.FT8000); ColumnConfigInfo[] deviceColumnDefinitionArray = config.GetStandardLinkageConfigColumns(); //取得标准组态的列定义信息 List <MergeCellRange> lstMergeCellRange = new List <MergeCellRange>(); int currentRowIndex = 0; excelService.SetCellValue(sheetName, currentRowIndex, 0, sheetName, CellStyleType.SubCaption); currentRowIndex++; for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++) { excelService.SetCellValue(sheetName, currentRowIndex, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead); } MergeCellRange mergeCellRange = new MergeCellRange(); mergeCellRange.FirstRowIndex = 0; mergeCellRange.LastRowIndex = 0; mergeCellRange.FirstColumnIndex = 0; mergeCellRange.LastColumnIndex = deviceColumnDefinitionArray.Length - 1; lstMergeCellRange.Add(mergeCellRange); excelService.SetMergeCells(sheetName, lstMergeCellRange); foreach (var model in models) { currentRowIndex++; excelService.SetCellValue(sheetName, currentRowIndex, 0, model.Code, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 1, model.DeviceNo1, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 2, model.DeviceNo2, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 3, model.DeviceNo3, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 4, model.DeviceNo4, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 5, model.DeviceNo5, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 6, model.DeviceNo6, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 7, model.DeviceNo7, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 8, model.DeviceNo8, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 9, model.ActionCoefficient.ToString(), CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 10, model.LinkageNo1, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 11, model.LinkageNo2, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 12, model.LinkageNo3, CellStyleType.Data); excelService.SetCellValue(sheetName, currentRowIndex, 13, model.Memo, CellStyleType.Data); } excelService.SetColumnWidth(sheetName, 13, 50f); #endregion } } catch (Exception ex) { return(false); } return(true); }
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); }
protected override bool GenerateExcelTemplateStandardSheet(List <string> sheetNames, int currentIndex, int loopSheetAmount, int maxLinkageAmount, ref IExcelService excelService) { try { #region 标准组态表头 List <MergeCellRange> lstMergeCellRange = new List <MergeCellRange>(); IControllerConfig config = ControllerConfigManager.GetConfigObject(ControllerType.FT8003); ColumnConfigInfo[] deviceColumnDefinitionArray = config.GetStandardLinkageConfigColumns(); //取得标准组态的列定义信息 excelService.SetCellValue(sheetNames[loopSheetAmount + currentIndex], 0, 0, sheetNames[loopSheetAmount + currentIndex], CellStyleType.SubCaption); for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++) { excelService.SetCellValue(sheetNames[loopSheetAmount + currentIndex], 1, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead); } MergeCellRange mergeCellRange = new MergeCellRange(); mergeCellRange.FirstRowIndex = 0; mergeCellRange.LastRowIndex = 0; mergeCellRange.FirstColumnIndex = 0; mergeCellRange.LastColumnIndex = deviceColumnDefinitionArray.Length - 1; lstMergeCellRange.Add(mergeCellRange); excelService.SetMergeCells(sheetNames[loopSheetAmount + currentIndex], lstMergeCellRange);//设置"标准组态页签"合并单元格 for (int i = 2; i < maxLinkageAmount + 3; i++) { for (int j = 0; j < deviceColumnDefinitionArray.Length; j++) { excelService.SetCellValue(sheetNames[loopSheetAmount + currentIndex], i, j, null, CellStyleType.Data); } } mergeCellRange = new MergeCellRange(); mergeCellRange.FirstRowIndex = 2; mergeCellRange.LastRowIndex = maxLinkageAmount + 2; mergeCellRange.FirstColumnIndex = 5; mergeCellRange.LastColumnIndex = 5; excelService.SetSheetValidationForListConstraint(sheetNames[loopSheetAmount + currentIndex], RefereceRegionName.ActionCoefficient.ToString(), mergeCellRange); #endregion } catch (Exception ex) { return(false); } return(true); }
public List <ManualControlBoard> Create(int boardNo, int subBoardStartNo, int subBoardEndNo, int amount) { List <ManualControlBoard> lstMCB = new List <ManualControlBoard>(); if (DataRecordAlreadySet) //如果数据已经填写完成,则可获取最大编号 { _maxCode = GetMaxCode(); _maxID = GetMaxID(); } int tempCode = _maxCode; if (tempCode >= MaxManualControlBoardAmount) //如果已经达到上限,则不添加任何行 { amount = 0; } if ((tempCode + amount) > MaxManualControlBoardAmount) //如果需要添加的行数将达上限,则增加剩余的行数 { amount = MaxManualControlBoardAmount - tempCode; } for (int j = subBoardStartNo; j <= subBoardEndNo; j++) { SCA.Interface.IControllerConfig config = ControllerConfigManager.GetConfigObject(this.TheController.Type); int totalMaxKeyNo = config.GetMaxAmountForKeyNoInManualControlBoardConfig(); int maxKeyNo = 0; //获取当前板卡及回路下的最大"手键号" if (TheController.ControlBoard.Count == 0) { maxKeyNo = 0; } else { var result = TheController.ControlBoard.Where(mcb => mcb.SubBoardNo == j && mcb.BoardNo == boardNo); if (result.Count() != 0) { maxKeyNo = TheController.ControlBoard.Where(mcb => mcb.SubBoardNo == j && mcb.BoardNo == boardNo).Max(mcb => mcb.KeyNo); } } if (maxKeyNo < totalMaxKeyNo) { for (int i = 1; i <= amount; i++) { tempCode++; _maxID++; maxKeyNo++; ManualControlBoard mcb = new ManualControlBoard(); mcb.BoardNo = boardNo; mcb.SubBoardNo = j; mcb.KeyNo = maxKeyNo; mcb.Controller = _controller; mcb.ControllerID = _controller.ID; mcb.Code = tempCode;//.ToString().PadLeft(MaxManualControlBoardAmount.ToString().Length, '0'); mcb.ID = _maxID; mcb.IsDirty = true; lstMCB.Add(mcb); } } } _maxCode = tempCode; DataRecordAlreadySet = false; foreach (var singleItem in lstMCB) { Update(singleItem); } return(lstMCB); }
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); }