private void AddButton_Click(object sender, RoutedEventArgs e) { this.ErrorMessagePromptName.Text = ""; this.ErrorMessagePromptFilePath.Text = ""; bool verifyFlag = true; ProjectConfig projectConfig = new ProjectConfig(); Dictionary <string, RuleAndErrorMessage> dictRule = projectConfig.GetProjectInfoRegularExpression(); RuleAndErrorMessage rule = dictRule["Name"]; Regex exminator = new Regex(rule.Rule); if (!exminator.IsMatch(this.ProjectNameInputTextBox.Text)) { this.ErrorMessagePromptName.Text = rule.ErrorMessage; verifyFlag = false; } if (string.IsNullOrEmpty(this.FilePathInputTextBox.Text)) { this.ErrorMessagePromptFilePath.Text += "请选择有效路径"; verifyFlag = false; } if (verifyFlag) { SCA.Model.ProjectModel project = new Model.ProjectModel(); project.Name = this.ProjectNameInputTextBox.Text; project.SavePath = this.FilePathInputTextBox.Text + "\\" + project.Name + ".nt"; project.FileVersion = BusinessLogic.DBFileVersionManager.CurrentDBFileVersion; SCA.BusinessLib.ProjectManager.GetInstance.CreateProject(project); RaiseEvent(new RoutedEventArgs(AddButtonClickEvent)); } }
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); } }