示例#1
0
        public void Execute()
        {
            if (!viewModel.InspectionTestResults.All(x => x.Date.IsValid()))
            {
                notify.ShowInfo(Program.LanguageManager.GetString(StringResources.WrongDate),
                                Program.LanguageManager.GetString(StringResources.Message_ErrorHeader));
                log.Warn("Date limits not valid!");
                return;
            }

            var duplicateNumber = repo.GetAllActiveDuplicateEntityByNumber(viewModel.Spool.Number, viewModel.Spool.Id).Distinct(new DuplicateNumberEntityComparer()).ToList();

            String result = string.Empty;

            if (duplicateNumber != null && duplicateNumber.Count > 0)
            {
                for (int i = 0; i <= duplicateNumber.Count - 1; i++)
                {
                    DuplicateNumberEntityType translate = (DuplicateNumberEntityType)Enum.Parse(typeof(DuplicateNumberEntityType),
                                                                                                duplicateNumber[i].EntityType);
                    result = result + viewModel.localizedAllPartType[(int)((object)translate) - 1] + (i < duplicateNumber.Count - 1 ? ", " : "");
                }

                notify.ShowInfo(
                    string.Concat(Program.LanguageManager.GetString(StringResources.DuplicateEntity_Message) + result),
                    Program.LanguageManager.GetString(StringResources.DuplicateEntity_MessageHeader));
                viewModel.SpoolNumber = string.Empty;
            }
            else
            {
                if (viewModel.Spool.Length != 0)
                {
                    if (viewModel.CanCut)
                    {
                        foreach (InspectionTestResult t in viewModel.InspectionTestResults)
                        {
                            if (t.Status != PartInspectionStatus.Pending && t.Inspectors.Count <= 0)
                            {
                                numberOfOperationWithoutInspectors++;
                            }
                        }

                        if (numberOfOperationWithoutInspectors == 0)
                        {
                            try
                            {
                                viewModel.Pipe.ToExport          = true;
                                viewModel.Pipe.IsCutOnSpool      = true;
                                viewModel.Spool.Number           = viewModel.Spool.Number.ToUpper();
                                viewModel.Spool.InspectionStatus = viewModel.Spool.GetPartInspectionStatus();
                                repos.BeginTransaction();
                                repos.PipeRepo.SaveOrUpdate(viewModel.Pipe);
                                repos.SpoolRepo.SaveOrUpdate(viewModel.Spool);

                                var filesViewModel = viewModel.FilesFormViewModel;

                                //saving attached existingDocuments
                                bool fileCopySuccess = true;
                                if (null != filesViewModel)
                                {
                                    filesViewModel.FileRepo           = repos.FileRepo;
                                    viewModel.FilesFormViewModel.Item = viewModel.Spool.Id;
                                    if (!viewModel.FilesFormViewModel.TrySaveFiles(viewModel.Pipe))
                                    {
                                        fileCopySuccess = false;
                                        repos.Rollback();
                                    }
                                }

                                if (fileCopySuccess)
                                {
                                    repos.Commit();
                                }

                                repos.PipeRepo.Evict(viewModel.Pipe);
                                repos.SpoolRepo.Evict(viewModel.Spool);

                                if (fileCopySuccess)
                                {
                                    if (null != filesViewModel)
                                    {
                                        filesViewModel.DetachFileEntities();
                                    }

                                    notify.ShowNotify(
                                        Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipe),
                                        Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipeHeader));

                                    log.Info(string.Format("The entity #{0}, id:{1} has been saved in DB.",
                                                           viewModel.Spool.Number,
                                                           viewModel.Spool.Id));
                                }
                                else
                                {
                                    notify.ShowError(Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied),
                                                     Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied_Header));
                                    log.Info(string.Format("File for entity #{0}, id:{1} hasn't been saved ",
                                                           viewModel.Spool.Number,
                                                           viewModel.Spool.Id));
                                }

                                viewModel.ModifiableView.IsModified = false;

                                string oldPipeNumber = viewModel.Pipe.Number;
                                viewModel.NewSpool();
                                viewModel.ModifiableView.Id = viewModel.Spool.Id;
                                viewModel.PipeNumber        = oldPipeNumber;
                                RefreshVisualStateEvent();
                            }
                            catch (RepositoryException ex)
                            {
                                log.Error(ex.Message);
                                notify.ShowFailure(ex.InnerException.Message, ex.Message);
                            }
                        }
                        else
                        {
                            notify.ShowError(
                                Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResult),
                                Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResultHeader));
                            viewModel.ModifiableView.IsEditMode = true;
                        }
                    }
                    else
                    {
                        notify.ShowError(
                            Program.LanguageManager.GetString(StringResources.Spool_SpoolLengtBigerThenPipeLength),
                            Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipeHeader));
                        viewModel.ModifiableView.IsEditMode = true;
                        numberOfOperationWithoutInspectors  = 0;
                    }
                }
                else
                {
                    notify.ShowError(
                        Program.LanguageManager.GetString(StringResources.Spool_NullSpoolLength),
                        Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipeHeader));
                    viewModel.ModifiableView.IsEditMode = true;
                }
            }
        }
示例#2
0
        public void Execute()
        {
            if (!viewModel.InspectionTestResults.All(x => x.Date.IsValid()))
            {
                notify.ShowInfo(Program.LanguageManager.GetString(StringResources.WrongDate),
                                Program.LanguageManager.GetString(StringResources.Message_ErrorHeader));
                log.Warn("Date limits not valid!");
                return;
            }

            if (viewModel.Spool.Length != 0)
            {
                if (viewModel.CanCut)
                {
                    foreach (InspectionTestResult t in viewModel.InspectionTestResults)
                    {
                        if (t.Status != PartInspectionStatus.Pending && t.Inspectors.Count <= 0)
                        {
                            numberOfOperationWithoutInspectors++;
                        }
                    }

                    if (numberOfOperationWithoutInspectors == 0)
                    {
                        try
                        {
                            viewModel.Pipe.ToExport          = true;
                            viewModel.Pipe.IsCutOnSpool      = true;
                            viewModel.Spool.Number           = viewModel.Spool.Number.ToUpper();
                            viewModel.Spool.InspectionStatus = viewModel.Spool.GetPartInspectionStatus();
                            repos.BeginTransaction();
                            repos.PipeRepo.SaveOrUpdate(viewModel.Pipe);
                            repos.SpoolRepo.SaveOrUpdate(viewModel.Spool);

                            var filesViewModel = viewModel.FilesFormViewModel;

                            //saving attached documents
                            bool fileCopySuccess = true;
                            if (null != filesViewModel)
                            {
                                filesViewModel.FileRepo           = repos.FileRepo;
                                viewModel.FilesFormViewModel.Item = viewModel.Pipe.Id;
                                if (!viewModel.FilesFormViewModel.TrySaveFiles(viewModel.Pipe))
                                {
                                    fileCopySuccess = false;
                                    repos.Rollback();
                                }
                            }

                            repos.Commit();
                            repos.PipeRepo.Evict(viewModel.Pipe);
                            repos.SpoolRepo.Evict(viewModel.Spool);

                            if (fileCopySuccess)
                            {
                                if (null != filesViewModel)
                                {
                                    filesViewModel.DetachFileEntities();
                                }

                                notify.ShowSuccess(
                                    string.Concat(Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipe), viewModel.Spool.Id),
                                    Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipeHeader));
                            }
                            else
                            {
                                notify.ShowError(Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied),
                                                 Program.LanguageManager.GetString(StringResources.ExternalFiles_NotCopied_Header));
                            }

                            viewModel.ModifiableView.IsModified = false;

                            notify.ShowNotify(
                                Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipe),
                                Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipeHeader));

                            log.Info(string.Format("The entity #{0}, id:{1} has been saved in DB.",
                                                   viewModel.Spool.Number,
                                                   viewModel.Spool.Id));

                            string oldPipeNumber = viewModel.Pipe.Number;
                            viewModel.NewSpool();
                            viewModel.PipeNumber = oldPipeNumber;
                            RefreshVisualStateEvent();
                        }
                        catch (RepositoryException ex)
                        {
                            log.Error(ex.Message);
                            notify.ShowFailure(ex.InnerException.Message, ex.Message);
                        }
                    }
                    else
                    {
                        notify.ShowError(
                            Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResult),
                            Program.LanguageManager.GetString(StringResources.SelectInspectorsForTestResultHeader));
                        viewModel.ModifiableView.IsEditMode = true;
                    }
                }
                else
                {
                    notify.ShowError(
                        Program.LanguageManager.GetString(StringResources.Spool_SpoolLengtBigerThenPipeLength),
                        Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipeHeader));
                    viewModel.ModifiableView.IsEditMode = true;
                    numberOfOperationWithoutInspectors  = 0;
                }
            }
            else
            {
                notify.ShowError(
                    Program.LanguageManager.GetString(StringResources.Spool_NullSpoolLength),
                    Program.LanguageManager.GetString(StringResources.Spool_CutSpoolFromPipeHeader));
                viewModel.ModifiableView.IsEditMode = true;
            }
        }