private void WizardDeleteButton_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Вы действительно хотите удалить выбранный проект?", "Подтверждение", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var dc = new ORM.FPMDataContext()) { if (dc.Project.Any(x => x.ID == _project.ID)) { var project = dc.Project.Single(x => x.ID == _project.ID); project.RowState = Convert.ToInt16(ERowState.Deleted); dc.SubmitChanges(); } ; }; ProjectWasChanged = false; _changesWasSaved = true; closeWizard(); } }
private void WizardArchiveButton_Click(object sender, RoutedEventArgs e) { var message = (_project.RowState == Convert.ToInt16(ERowState.Active)) ? "Вы действительно хотите отправить выбранный проект в архив?" : "Вы действительно хотите восстановить выбранный проект?"; if (MessageBox.Show(message, "Подтверждение", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { using (var dc = new ORM.FPMDataContext()) { if (dc.Project.Any(x => x.ID == _project.ID)) { var project = dc.Project.Single(x => x.ID == _project.ID); project.RowState = (project.RowState == Convert.ToInt16(ERowState.Active)) ? Convert.ToInt16(ERowState.Archived) : Convert.ToInt16(ERowState.Active); dc.SubmitChanges(); } ; }; ProjectWasChanged = false; _changesWasSaved = true; closeWizard(); } }
private void saveChnages() { _dc.SubmitChanges(); OnPropertyChanged("IsDataModified"); }
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"); } ; }