Esempio n. 1
0
        private bool deleteFile(ORM.StageParameter par)
        {
            var result   = true;
            var filePath = System.IO.Path.Combine(par.ProjectStage.GetStagePath(), par.StringValue);

            if (System.IO.File.Exists(filePath))
            {
                try
                {
                    System.IO.File.Delete(filePath);
                }
                catch (Exception ex)
                {
                    result = MessageBox.Show(String.Format("Файл {0} не может быть удален.Вы хотите продолжить сохранение проекта?\nОшибка:{1}", par.StringValue, ex.Message), "Ошибка удаления файла", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes;
                };
            }
            ;
            return(result);
        }
Esempio n. 2
0
        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");
            }
            ;
        }