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); }
public GameModel (IPlayer player, IBallController ballController, IInputController input, ILevelConfiguration levelConfiguration, IControllerConfig controllerConfig, IGameCicle gameCicle, IBonusManager bonusManager, IFactory <Vector3, IBlock> blockFactory, IScoreController scoreController, ILifeController lifeController) { Player = player; BallController = ballController; Input = input; LevelConfiguration = levelConfiguration; ControllerConfig = controllerConfig; GameCicle = gameCicle; BonusManager = bonusManager; BlockFactory = blockFactory; ScoreController = scoreController; LifeController = lifeController; SetListeners(true); GoToStart(); }
/// <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); }
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)); } }
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); }
protected override bool GenerateExcelTemplateLoopSheet(List <string> sheetNames, IControllerConfig config, Model.BusinessModel.ExcelTemplateCustomizedInfo summaryInfo, ref IExcelService excelService) { throw new NotImplementedException(); }
//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; } // } }
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; } }
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; } } }
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); } }
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; }
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; } } }
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); }