private bool DeleteDeviceFromDB(int id) { try { IFileService _fileService = new SCA.BusinessLib.Utility.FileService(); ILogRecorder logger = null; DBFileVersionManager dbFileVersionManager = new DBFileVersionManager(TheLoop.Controller.Project.SavePath, logger, _fileService); IDBFileVersionService dbFileVersionService = dbFileVersionManager.GetDBFileVersionServiceByVersionID(DBFileVersionManager.CurrentDBFileVersion); IDeviceDBServiceTest deviceDBService = SCA.DatabaseAccess.DBContext.DeviceManagerDBServiceTest.GetDeviceDBContext(TheLoop.Controller.Type, dbFileVersionService); if (deviceDBService.DeleteDeviceByID(id)) { if (BusinessLib.ProjectManager.GetInstance.MaxDeviceIDInController8001 == id) //如果最大ID等于被删除的ID,则重新赋值 { ControllerOperation8001 controllerOperation = new ControllerOperation8001(); BusinessLib.ProjectManager.GetInstance.MaxDeviceIDInController8001 = controllerOperation.GetMaxDeviceID(); } } ILoopDBService loopDBService = new SCA.DatabaseAccess.DBContext.LoopDBService(dbFileVersionService); //更新回路中存储的器件数量 loopDBService.AddLoopInfo(TheLoop); } catch (Exception ex) { return(false); } return(true); }
public void ImportDataFromExcelExecute() { if (ExcelFilePath != "") { FileService fileService = new FileService(); ControllerOperation8001 operation = new ControllerOperation8001(); operation.ReadEXCELTemplate(ExcelFilePath, fileService); } }
public void DownloadExcelTemplateExecute() { VistaFolderBrowserDialog dialog = new VistaFolderBrowserDialog(); dialog.Description = "选择存储的文件夹"; dialog.UseDescriptionForTitle = true; // This applies to the Vista style dialog only, not the old dialog. dialog.ShowDialog(); string strFilePath = dialog.SelectedPath; FileService fileService = new FileService(); if (DefaultTemplateState) { ControllerOperation8001 operation = new ControllerOperation8001(); operation.DownloadDefaultEXCELTemplate(strFilePath + "//" + "默认(" + SelectedControllerType.ToString() + ")模板文件.xls", fileService, null); } else if (CustomizedTemplateState) { ExcelTemplateCustomizedInfo customizedInfo = new ExcelTemplateCustomizedInfo(); customizedInfo.ControllerType = SelectedControllerType; customizedInfo.ControllerName = ControllerName;//应该限制此控制器名称的长度 customizedInfo.MachineNumber = MachineNumber; customizedInfo.SelectedDeviceCodeLength = SelectedDeviceCodeLength; customizedInfo.SerialPortNumber = SerialPortNumber; customizedInfo.LoopAmount = LoopAmount; customizedInfo.LoopGroupAmount = LoopGroupAmount; customizedInfo.StandardLinkageFlag = StandardLinkageFlag; customizedInfo.MixedLinkageFlag = MixedLinkageFlag; customizedInfo.GeneralLinkageFlag = GeneralLinkageFlag; customizedInfo.ManualControlBoardFlag = ManualControlBoardFlag; ControllerOperation8001 operation = new ControllerOperation8001(); string fileName = ""; if (ControllerName.Length > 10) { fileName = fileName + ControllerName.Substring(0, 10) + "控制器(" + SelectedControllerType.ToString() + ")模板文件.xls"; } else { fileName = fileName + ControllerName + "控制器(" + SelectedControllerType.ToString() + ")模板文件.xls"; } operation.DownloadDefaultEXCELTemplate(strFilePath + "//" + fileName, fileService, customizedInfo); } }
public void ComfirmExecute() { this.ErrorMessagePromptImportFilePath = ""; this.ErrorMessagePromptName = ""; this.ErrorMessagePromptSaveFilePath = ""; bool verifyFlag = true; ProjectConfig projectConfig = new ProjectConfig(); Dictionary <string, RuleAndErrorMessage> dictRule = projectConfig.GetProjectInfoRegularExpression(); RuleAndErrorMessage rule = dictRule["Name"]; Regex exminator = new Regex(rule.Rule); if (!string.IsNullOrEmpty(ProjectName)) { if (!exminator.IsMatch(ProjectName)) { ErrorMessagePromptName = rule.ErrorMessage; verifyFlag = false; } } else { ErrorMessagePromptName = "请输入工程名称"; verifyFlag = false; } if (string.IsNullOrEmpty(ImportedFilePath)) { ErrorMessagePromptImportFilePath = "请选择有效导入文件路径"; verifyFlag = false; } if (string.IsNullOrEmpty(SavedFilePath)) { ErrorMessagePromptSaveFilePath = "请选择有效文件存储路径"; verifyFlag = false; } if (verifyFlag) { IFileService _fileService = new FileService(); ILogRecorder _logRecorder = null; string strImportedFilePath = this.ImportedFilePath; string strExtentionName = strImportedFilePath.Substring(strImportedFilePath.LastIndexOf(".") + 1); DBFileVersionManager dbFileVersionManager = new DBFileVersionManager(this.ImportedFilePath, _logRecorder, _fileService); //取得某一系列的数据文件操作服务(4,5,6 系列没有项目,7开始有项目信息,以文件扩展名作为划分依据) IDBFileVersionService dbFileVersionService = dbFileVersionManager.GetDBFileVersionServiceByExtentionName(strExtentionName); //取得文件版本 int fileVersion = dbFileVersionService.GetFileVersion(); dbFileVersionService = dbFileVersionManager.GetDBFileVersionServiceByVersionID(fileVersion); //取得项目信息 ProjectModel project = dbFileVersionService.GetProject(1); project.Name = this.ProjectName; //以当前设置的名称作为项目名 project.SavePath = this.SavedFilePath + "\\" + project.Name + ".nt"; //以当前设置的路径作为项目的存储路径 IControllerOperation controllerOperation = null; //取得项目下所有控制器信息 List <ControllerModel> lstController = dbFileVersionService.GetControllersByProject(project); int dataFileVersion = 0; //数据文件版本 ControllerModel controller = null; foreach (var controllerInfo in lstController) //取得控制器操作服务 { if (project.FileVersion == -1) //4,5,6版本文件无项目信息 { project.FileVersion = controllerInfo.FileVersion; } switch (controllerInfo.Type) { case ControllerType.FT8000: controllerOperation = new ControllerOperation8000(); break; case ControllerType.FT8003: controllerOperation = new ControllerOperation8003(); break; case ControllerType.NT8001: controllerOperation = new ControllerOperation8001(); break; case ControllerType.NT8007: controllerOperation = new ControllerOperation8007(); break; case ControllerType.NT8021: controllerOperation = new ControllerOperation8021(); break; case ControllerType.NT8036: controllerOperation = new ControllerOperation8036(); break; } if (controllerOperation != null) //合法控制器类型 { dataFileVersion = Convert.ToInt32(project.FileVersion); //取得当前项目文件版本号 dbFileVersionService = dbFileVersionManager.GetDBFileVersionServiceByVersionID(dataFileVersion); //取得当前文件的数据文件服务 //controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService); controller = controllerOperation.OrganizeControllerInfoFromSpecifiedDBFileVersion(dbFileVersionService, controllerInfo); //取得组织完成的控制器信息 } if (controller != null) //将组织完成的信息增加至项目中 { project.Controllers.Add(controllerInfo); } } if (dataFileVersion != 0)//将所有数据转换为当前软件应用的数据版本 { project = dbFileVersionManager.VersionConverter(dataFileVersion, DBFileVersionManager.CurrentDBFileVersion, project); } SCA.BusinessLib.ProjectManager.GetInstance.CreateProject(project); EventMediator.NotifyColleagues("DisplayTheOpenedProject", null); } }
public void ConvertOldVersionSoftwareDataFileToCurrentModel8001() { _databaseService = new MSAccessDatabaseAccess(@"E:\2016\6 软件优化升级\4 实际工程数据\工程数据111\连城心怡都城_文件版本5.mdb", _logRecorder, _fileService); IOldVersionSoftwareDBService oldVersionService = new OldVersionSoftware8001DBService(_databaseService); IControllerOperation controllerOperation = null; string[] strFileInfo = oldVersionService.GetFileVersionAndControllerType(); ControllerModel controllerInfo = null; if (strFileInfo.Length > 0) { switch (strFileInfo[0]) { case "8001": controllerOperation = new ControllerOperation8001(); break; } if (controllerOperation != null) { controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService); } //strFileInfo[1]; } Assert.That(controllerInfo.Type, Is.EqualTo(ControllerType.NT8001), "控制器类型不正确"); Assert.That(controllerInfo.DeviceAddressLength, Is.EqualTo(7), "器件长度为7"); Assert.That(controllerInfo.Loops.Count, Is.EqualTo(10), "回路数量不正确"); Assert.That(controllerInfo.Loops[0].Code, Is.EqualTo("0001"), "回路名称不正确"); Assert.That(controllerInfo.Loops[0].DeviceAmount, Is.EqualTo(46), "01回路器件数量不正确"); Assert.That(controllerInfo.Loops[0].GetDevices <Model.DeviceInfo8001>()[0].Code, Is.EqualTo("0001001"), "器件编码不正确"); Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].Code, Is.EqualTo("0003001"), "器件编码不正确"); Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].TypeCode, Is.EqualTo(4), "器件类型不正确"); Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].Disable, Is.EqualTo(0), "隔离不正确"); Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].SensitiveLevel, Is.EqualTo(2), "灵敏度不正确"); Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].Location, Is.EqualTo("A2三层306店"), "地点不正确"); Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].BuildingNo, Is.EqualTo(1), "楼号不正确"); //区号可以为0 Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].ZoneNo, Is.EqualTo(2), "区号不正确"); Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].FloorNo, Is.EqualTo(3), "层号不正确"); //房间可以为0 Assert.That(controllerInfo.Loops[2].GetDevices <Model.DeviceInfo8001>()[0].RoomNo, Is.EqualTo(null), "房间号不正确"); Assert.That(controllerInfo.Loops[1].Code, Is.EqualTo("0002"), "回路名称不正确"); Assert.That(controllerInfo.StandardConfig.Count, Is.EqualTo(20), "标准组态数量为20"); Assert.That(controllerInfo.StandardConfig[13].Code, Is.EqualTo("0014"), "标准组态编号为0014"); Assert.That(controllerInfo.StandardConfig[13].DeviceNo4, Is.EqualTo("0007102"), "编号4的编号为0007102"); Assert.That(controllerInfo.StandardConfig[13].LinkageNo2, Is.EqualTo("0020"), "联动组2的编号为0020"); Assert.That(controllerInfo.MixedConfig.Count, Is.EqualTo(53), "混合组态数量为53"); Assert.That(controllerInfo.MixedConfig[13].Code, Is.EqualTo("0014"), "混合组态编号为0014"); Assert.That(controllerInfo.MixedConfig[13].ActionCoefficient, Is.EqualTo("1"), "编号14的动作常数为1"); Assert.That(controllerInfo.MixedConfig[13].ActionType, Is.EqualTo(LinkageActionType.AND), "编号14的动作类型为与"); Assert.That(controllerInfo.MixedConfig[13].DeviceTypeCodeA, Is.EqualTo(13), "编号14的类型A为13"); Assert.That(controllerInfo.MixedConfig[29].TypeC, Is.EqualTo(LinkageType.ZoneLayer), "编号30的类型c为区层"); Assert.That(controllerInfo.MixedConfig[29].BuildingNoC, Is.EqualTo(6), "编号30的楼号为6"); Assert.That(controllerInfo.MixedConfig[29].ZoneNoC, Is.EqualTo(5), "编号30的区号为5"); Assert.That(controllerInfo.MixedConfig[29].LayerNoC, Is.EqualTo(-1), "编号30的层号为-1"); Assert.That(controllerInfo.MixedConfig[30].TypeC, Is.EqualTo(LinkageType.Address), "编号31的类型c为地址"); Assert.That(controllerInfo.MixedConfig[30].MachineNoC, Is.EqualTo("00"), "编号31的机号为00"); Assert.That(controllerInfo.MixedConfig[30].LoopNoC, Is.EqualTo("07"), "编号31的路号为07"); Assert.That(controllerInfo.MixedConfig[30].DeviceCodeC, Is.EqualTo("075"), "编号31的地编号为075"); Assert.That(controllerInfo.GeneralConfig.Count, Is.EqualTo(37), "通用组态数量为37"); Assert.That(controllerInfo.GeneralConfig[13].Code, Is.EqualTo("0014"), "通用组态编号为0014"); Assert.That(controllerInfo.GeneralConfig[13].ActionCoefficient, Is.EqualTo("1"), "编号14的动作常数为1"); Assert.That(controllerInfo.GeneralConfig[13].BuildingNoA, Is.EqualTo(6), "编号14的楼号为6"); Assert.That(controllerInfo.GeneralConfig[13].ZoneNoA, Is.EqualTo(5), "编号14的区号为5"); Assert.That(controllerInfo.GeneralConfig[13].LayerNoA1, Is.EqualTo(0), "编号14的层号A1为0"); Assert.That(controllerInfo.GeneralConfig[13].LayerNoA2, Is.EqualTo(0), "编号14的层号A2为0"); Assert.That(controllerInfo.GeneralConfig[13].DeviceTypeCodeA, Is.EqualTo(13), "编号14的类型A为13"); Assert.That(controllerInfo.GeneralConfig[13].TypeC, Is.EqualTo(LinkageType.ZoneLayer), "编号14的分类C为区层"); Assert.That(controllerInfo.GeneralConfig[13].BuildingNoC, Is.EqualTo(6), "编号14的楼号为6"); Assert.That(controllerInfo.GeneralConfig[13].ZoneNoC, Is.EqualTo(5), "编号14的区号C为5"); Assert.That(controllerInfo.GeneralConfig[13].LayerNoC, Is.EqualTo(-1), "编号14的层号C为-1"); Assert.That(controllerInfo.GeneralConfig[13].DeviceTypeCodeC, Is.EqualTo(36), "编号14的层号C为36"); Assert.That(controllerInfo.GeneralConfig[14].TypeC, Is.EqualTo(LinkageType.Address), "编号15的分类C为地址"); Assert.That(controllerInfo.GeneralConfig[14].MachineNoC, Is.EqualTo("00"), "编号15的机号为0"); Assert.That(controllerInfo.GeneralConfig[14].LoopNoC, Is.EqualTo("01"), "编号15的路号为1"); Assert.That(controllerInfo.GeneralConfig[14].DeviceCodeC, Is.EqualTo("001"), "编号15的层号C为001"); Assert.That(controllerInfo.GeneralConfig[14].DeviceTypeCodeC, Is.EqualTo(null), "编号14的层号C为null"); }
public HierarchyViewModel() { IProjectManager projManager = ProjectManager.GetInstance; IFileService _fileService = new FileService(); IDatabaseService _databaseService = new MSAccessDatabaseAccess(@"C:\Users\Administrator\Desktop\foo\8036.mdb", null, _fileService); IOldVersionSoftwareDBService oldVersionService = new OldVersionSoftware8036DBService(_databaseService); IControllerOperation controllerOperation = null; string[] strFileInfo = oldVersionService.GetFileVersionAndControllerType(); ControllerModel controllerInfo = null; if (strFileInfo.Length > 0) { switch (strFileInfo[0]) { case "8036": controllerOperation = new ControllerOperation8036(_databaseService); break; } if (controllerOperation != null) { controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService); } //strFileInfo[1]; } ProjectModel proj = new ProjectModel() { ID = 1, Name = "尼特智能" }; proj.Controllers.Add(controllerInfo); _databaseService = new MSAccessDatabaseAccess(@"E:\2016\6 软件优化升级\4 实际工程数据\工程数据111\连城心怡都城_文件版本5.mdb", null, _fileService); oldVersionService = new OldVersionSoftware8001DBService(_databaseService); strFileInfo = oldVersionService.GetFileVersionAndControllerType(); controllerInfo = null; if (strFileInfo.Length > 0) { switch (strFileInfo[0]) { case "8001": controllerOperation = new ControllerOperation8001(null); break; } if (controllerOperation != null) { controllerInfo = controllerOperation.OrganizeControllerInfoFromOldVersionSoftwareDataFile(oldVersionService); } //strFileInfo[1]; } proj.Controllers.Add(controllerInfo); projManager.CreateProject(proj); List <ProjectModel> lstProjects = new List <ProjectModel>(); lstProjects.Add(proj); Initialize(lstProjects, null); }
private int GetMaxID() { ControllerOperation8001 controllerOperation = new ControllerOperation8001(); return(controllerOperation.GetMaxDeviceID()); }