private bool checkDirectory(ORM.ProjectStage stage, out string stageFolder) { bool result = false; stageFolder = stage.GetStagePath(); var projectFolder = stage.Project.GetProjectPath(); try { if (!System.IO.Directory.Exists(projectFolder)) { System.IO.Directory.CreateDirectory(projectFolder); } ; if (!System.IO.Directory.Exists(stageFolder)) { System.IO.Directory.CreateDirectory(stageFolder); } ; result = true; } catch (Exception ex) { MessageBox.Show(String.Format("Ошибка доступа к папке проекта:\n{0}", ex.Message), "Ошибка доступа к папке проекта", MessageBoxButton.OK, MessageBoxImage.Error); }; return(result); }
private void WizardApplyButton_Click(object sender, RoutedEventArgs e) { if (ValidateWizard()) { var saveData = true; var newProjectID = -1; using (var dc = new ORM.FPMDataContext()) { #region ProjectInfo changes var findProject = new Func <ORM.Project, bool>(x => x.ID == _project.ID); ORM.Project project = null; if (dc.Project.Any(findProject)) { project = dc.Project.Single(findProject); newProjectID = project.ID; } else { project = new ORM.Project(); }; project.Type = _project.Type; project.ResponsiblePerson = _project.ResponsiblePerson; project.Progress = getProjectProgress(); project.Priority = _project.Priority; project.Note = _project.Note; project.IsInWork = _project.IsInWork; project.ContactID = _project.ContactID; project.Caption = _project.Caption; project.CrtDate = _project.CrtDate; project.RowState = _project.RowState; #endregion if (_project.ID <= 0) { dc.Project.InsertOnSubmit(project); } else { #region ProjectStage changes var stages = dc.ProjectStage.Where(x => x.ProjectID == _project.ID); foreach (var itm in stages) { if (!saveData) { break; } ; if (StageTileView.Stages.Any(x => x.ID == itm.ID)) { /*измененные стадии*/ var stg = StageTileView.Stages.Single(x => x.ID == itm.ID); itm.IsPublic = stg.IsPublic; itm.SortIndex = stg.SortIndex; itm.Name = stg.Name; itm.Note = stg.Note; itm.ResponsibleRole = stg.ResponsibleRole; itm.StageState = stg.StageState; /*Изменение параметров стадии*/ var parameters = dc.StageParameter.Where(x => x.ProjectStageID == itm.ID); foreach (var par in parameters) { if (stg.StageParameter.Any(x => x.ID == par.ID)) { var srcPar = stg.StageParameter.Single(x => x.ID == par.ID); par.NumberValue = srcPar.NumberValue; par.StringValue = srcPar.StringValue; par.DateTimeValue = srcPar.DateTimeValue; } else { dc.StageParameter.DeleteOnSubmit(par); if (ParameterRepository.GetParameterValueType(par.ParameterID) == EParameterValueType.Path) { if (!stg.StageParameter.Any(x => x.StringValue == par.StringValue)) { saveData = deleteFile(par); } ; } ; }; } ; if (saveData) { /*Новые параметры*/ foreach (var nStg in stg.StageParameter.Where(x => x.ID < 0)) { var newParameter = new ORM.StageParameter() { CrtDate = nStg.CrtDate, DateTimeValue = nStg.DateTimeValue, NumberValue = nStg.NumberValue, StringValue = nStg.StringValue, ParameterID = nStg.ParameterID, ProjectStageID = nStg.ProjectStageID }; dc.StageParameter.InsertOnSubmit(newParameter); } ; } ; } else { /*удаленные стадии*/ itm.RowState = Convert.ToInt16(ERowState.Deleted); }; } ; #endregion }; if (saveData) { if (StageTileView.Stages.Any(x => x.ID == 0)) { /*новые стадии*/ foreach (var itm in StageTileView.Stages.Where(x => x.ID == 0)) { var stage = new ORM.ProjectStage() { CrtDate = itm.CrtDate, IsPublic = itm.IsPublic, Name = itm.Name, Note = itm.Note, Project = project, ResponsibleRole = itm.ResponsibleRole, RowState = 1, SortIndex = itm.SortIndex, StageState = itm.StageState, StageParameter = itm.StageParameter }; dc.ProjectStage.InsertOnSubmit(stage); } ; } ; } ; #region Upload Files if (project.ID > 0) { saveData = UploadFiles(); if (saveData) { dc.SubmitChanges(); } ; } else { dc.SubmitChanges(); newProjectID = project.ID; UploadFiles(); }; #endregion }; if (saveData) { var focusedStage = StageTileView.Stages.Single(x => x.IsFocused); Load(newProjectID); StageTileView.FocusedStage = focusedStage; } ; ProjectWasChanged = !saveData; _changesWasSaved = saveData; OnPropertyChanged("AllowDeleteAndArchieveProject"); } ; }