Пример #1
0
        public MethodEditViewModel(IEventAggregator aggregator,
                                   IDataService <LabDbEntities> labDbData,
                                   ISpecificationService specificationService) : base()
        {
            _labDbData            = labDbData;
            _editMode             = false;
            _eventAggregator      = aggregator;
            _specificationService = specificationService;

            OrganizationList = _labDbData.RunQuery(new OrganizationsQuery()
            {
                Role = OrganizationsQuery.OrganizationRoles.StandardPublisher
            })
                               .ToList();;
            PropertyList = _labDbData.RunQuery(new PropertiesQuery()).ToList();

            Measurements = new List <SubMethod>();

            AddFileCommand = new DelegateCommand(
                () =>
            {
                OpenFileDialog fileDialog = new OpenFileDialog
                {
                    Multiselect = true
                };

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    foreach (string pth in fileDialog.FileNames)
                    {
                        StandardFile temp = new StandardFile
                        {
                            Path        = pth,
                            Description = "",
                            StandardID  = _methodInstance.StandardID
                        };

                        temp.Create();
                    }

                    RaisePropertyChanged("FileList");
                }
            },
                () => CanModify);

            CancelEditCommand = new DelegateCommand(
                () =>
            {
                EditMode = false;
            },
                () => EditMode);

            OpenFileCommand = new DelegateCommand(
                () =>
            {
                System.Diagnostics.Process.Start(_selectedFile.Path);
            },
                () => _selectedFile != null);

            OpenReportCommand = new DelegateCommand <Test>(
                tst =>
            {
                NavigationToken token = new NavigationToken((tst.TestRecord.RecordTypeID == 1) ? ReportViewNames.ReportEditView : ReportViewNames.ExternalReportEditView,
                                                            tst.TestRecord.Reports.First());

                _eventAggregator.GetEvent <NavigationRequested>()
                .Publish(token);
            });

            OpenSpecificationCommand = new DelegateCommand <Specification>(
                spec =>
            {
                NavigationToken token = new NavigationToken(SpecificationViewNames.SpecificationEdit,
                                                            spec);
                _eventAggregator.GetEvent <NavigationRequested>().Publish(token);
            });

            RemoveFileCommand = new DelegateCommand(
                () =>
            {
                _selectedFile.Delete();
                SelectedFile = null;
            },
                () => EditMode && _selectedFile != null);

            SaveCommand = new DelegateCommand(
                () =>
            {
                _methodInstance.Update();

                _specificationService.UpdateSubMethods(Measurements);
                _specificationService.UpdateMethodVariantRange(_methodVariantList);

                if (_selectedOrganization.ID != _methodInstance.Standard.OrganizationID)
                {
                    _methodInstance.Standard.OrganizationID = _selectedOrganization.ID;
                    _methodInstance.Standard.Update();
                }

                EditMode = false;
            },
                () => _editMode);

            StartEditCommand = new DelegateCommand(
                () =>
            {
                EditMode = true;
            },
                () => CanModify && !_editMode);

            UpdateCommand = new DelegateCommand(
                () =>
            {
                _specificationService.ModifyMethodTestList(_methodInstance);
            },
                () => CanModify);
        }
Пример #2
0
        public SpecificationEditViewModel(IDataService <LabDbEntities> labDbData,
                                          IEventAggregator aggregator,
                                          IReportService reportService)
        {
            _labDbData       = labDbData;
            _eventAggregator = aggregator;
            _reportService   = reportService;

            AddControlPlanCommand = new DelegateCommand(
                () =>
            {
                ControlPlan temp = _instance.AddControlPlan();

                RaisePropertyChanged("ControlPlanList");
            });

            AddFileCommand = new DelegateCommand(
                () =>
            {
                OpenFileDialog fileDialog = new OpenFileDialog
                {
                    Multiselect = true
                };

                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    foreach (string pth in fileDialog.FileNames)
                    {
                        StandardFile temp = new StandardFile
                        {
                            Path        = pth,
                            Description = "",
                            StandardID  = _instance.StandardID
                        };

                        temp.Create();
                    }

                    RaisePropertyChanged("FileList");
                }
            },
                () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.SpecificationEdit));

            AddTestCommand = new DelegateCommand <MethodVariant>(
                mtd =>
            {
                Requirement newReq = _reportService.GenerateRequirement(mtd);
                _instance.AddMethod(newReq);

                _eventAggregator.GetEvent <SpecificationMethodListChanged>()
                .Publish(_instance);
            },
                mtd => CanEdit);

            AddVersionCommand = new DelegateCommand(
                () =>
            {
                SpecificationVersion temp = new SpecificationVersion
                {
                    IsMain          = false,
                    Name            = "Nuova versione",
                    SpecificationID = _instance.ID
                };

                temp.Create();

                RaisePropertyChanged("VersionList");
            },
                () => CanEdit);

            CloseAddMethodViewCommand = new DelegateCommand(
                () =>
            {
                NavigationToken token = new NavigationToken(SpecificationViewNames.SpecificationVersionList,
                                                            null,
                                                            RegionNames.SpecificationVersionTestListEditRegion);

                _eventAggregator.GetEvent <NavigationRequested>()
                .Publish(token);
            });

            OpenFileCommand = new DelegateCommand(
                () =>
            {
                try
                {
                    System.Diagnostics.Process.Start(_selectedFile.Path);
                }
                catch (Exception)
                {
                    _eventAggregator.GetEvent <StatusNotificationIssued>().Publish("File non trovato");
                }
            },
                () => _selectedFile != null);

            OpenReportCommand = new DelegateCommand(
                () =>
            {
                NavigationToken token = new NavigationToken(Reports.ViewNames.ReportEditView,
                                                            SelectedReport);
                _eventAggregator.GetEvent <NavigationRequested>().Publish(token);
            },
                () => _selectedReport != null);

            RemoveControlPlanCommand = new DelegateCommand(
                () =>
            {
                _selectedControlPlan.Delete();
                RaisePropertyChanged("ControlPlanList");
                SelectedControlPlan = null;
            },
                () => CanEdit &&
                _selectedControlPlan != null &&
                !_selectedControlPlan.IsDefault);

            RemoveFileCommand = new DelegateCommand(
                () =>
            {
                _selectedFile.Delete();
                SelectedFile = null;
            },
                () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.SpecificationEdit) && _selectedFile != null);

            SaveCommand = new DelegateCommand(
                () =>
            {
                _instance.Update();
                _instance.Standard.Update();
                EditMode = false;
            },
                () => _editMode && !HasErrors);

            StartEditCommand = new DelegateCommand(
                () =>
            {
                EditMode = true;
            },
                () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.SpecificationEdit) && !_editMode);

            // Event Subscriptions

            _eventAggregator.GetEvent <MethodChanged>()
            .Subscribe(
                tkn =>
            {
                _methodVariantList = null;
                RaisePropertyChanged("MethodVariantList");
            });

            _eventAggregator.GetEvent <ReportCreated>().Subscribe(
                report => RaisePropertyChanged("ReportList"));
        }