public InstrumentEditViewModel(IDataService <LInstContext> lInstData, IEventAggregator aggregator, InstrumentService instrumentService) : base() { _lInstData = lInstData; _editMode = false; _eventAggregator = aggregator; _instrumentService = instrumentService; AreaList = _lInstData.RunQuery(new InstrumentUtilizationAreasQuery()).ToList(); InstrumentTypeList = _lInstData.RunQuery(new InstrumentTypesQuery()).ToList(); ManufacturerList = _lInstData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.Manufacturer }) .ToList(); CalibrationLabList = _lInstData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.CalibrationLab }) .ToList(); PropertiesToAdd = new List <InstrumentProperty>(); PropertiesToRemove = new List <InstrumentProperty>(); PropertyList = new ObservableCollection <InstrumentProperty>(); AddCalibrationCommand = new DelegateCommand( () => { if (_instrumentService.ShowNewCalibrationDialog(_instance) != null) { RefreshCalibrations(); } }, () => IsInstrumentAdmin); AddFileCommand = new DelegateCommand( () => { OpenFileDialog fileDialog = new OpenFileDialog { Multiselect = true }; if (fileDialog.ShowDialog() == DialogResult.OK) { IEnumerable <InstrumentFile> fileList = fileDialog.FileNames.Select(pt => new InstrumentFile() { Path = pt }); _lInstData.Execute(new BulkInsertEntitiesCommand <LInstContext>(fileList)); RaisePropertyChanged("FileList"); } }); AddMaintenanceEventCommand = new DelegateCommand( () => { _instrumentService.ShowNewMaintenanceDialog(_instance); RefreshMaintenanceEventList(); }, () => IsInstrumentAdmin); DeleteCalibrationCommand = new DelegateCommand( () => { DialogResult confirmation = MessageBox.Show("Il Report selezionato verrà eliminato, continuare?", "Conferma Eliminazione", MessageBoxButtons.YesNo); if (confirmation == DialogResult.Yes) { _lInstData.Execute(new DeleteEntityCommand <LInstContext>(_selectedCalibration)); RefreshCalibrations(); } }, () => Thread.CurrentPrincipal.IsInRole(UserRoleNames.InstrumentAdmin) && _selectedCalibration != null); OpenFileCommand = new DelegateCommand( () => { try { System.Diagnostics.Process.Start(_selectedFile.Path); } catch (Exception) { _eventAggregator.GetEvent <StatusNotificationIssued>().Publish("File non trovato"); } }, () => _selectedFile != null); RemoveFileCommand = new DelegateCommand( () => { _lInstData.Execute(new DeleteEntityCommand <LInstContext>(_selectedFile)); RaisePropertyChanged("FileList"); SelectedFile = null; }, () => _selectedFile != null); SaveCommand = new DelegateCommand( () => { _lInstData.Execute(new UpdateEntityCommand <LInstContext>(_instance)); _lInstData.Execute(new BulkInsertEntitiesCommand <LInstContext>(PropertiesToAdd)); _lInstData.Execute(new BulkDeleteEntitiesCommand <LInstContext>(PropertiesToRemove)); _lInstData.Execute(new BulkUpdateEntitiesCommand <LInstContext>(PropertyList)); ClearPropertyPendingUpdates(); EditMode = false; _eventAggregator.GetEvent <InstrumentListUpdateRequested>() .Publish(); }, () => _editMode); StartEditCommand = new DelegateCommand( () => { EditMode = true; }, () => IsInstrumentAdmin && !_editMode); #region Event Subscriptions _eventAggregator.GetEvent <CalibrationIssued>() .Subscribe( report => { if (report.InstrumentID == _instance?.ID) { RaisePropertyChanged("CalibrationReportList"); } }); #endregion Event Subscriptions }
public InstrumentEditViewModel(IDataService <LabDbEntities> labDbdata, IEventAggregator aggregator, InstrumentService instrumentService) : base() { _labDbData = labDbdata; _editMode = false; _eventAggregator = aggregator; _instrumentService = instrumentService; AreaList = _labDbData.RunQuery(new InstrumentUtilizationAreasQuery()).ToList(); InstrumentTypeList = _labDbData.RunQuery(new InstrumentTypesQuery()).ToList(); ManufacturerList = _labDbData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.Manufacturer }) .ToList(); CalibrationLabList = _labDbData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.CalibrationLab }) .ToList(); AddCalibrationCommand = new DelegateCommand( () => { _instrumentService.ShowNewCalibrationDialog(_instance); }, () => IsInstrumentAdmin); AddFileCommand = new DelegateCommand( () => { OpenFileDialog fileDialog = new OpenFileDialog { Multiselect = true }; if (fileDialog.ShowDialog() == DialogResult.OK) { IEnumerable <string> fileList = fileDialog.FileNames; _instance.AddFiles(fileList); RaisePropertyChanged("FileList"); } }); AddMaintenanceEventCommand = new DelegateCommand( () => { _instrumentService.ShowNewMaintenanceDialog(_instance); RaisePropertyChanged("MaintenanceEventList"); }, () => IsInstrumentAdmin); AddMethodAssociationCommand = new DelegateCommand( () => { _instance.AddMethodAssociation(_selectedUnassociated); SelectedUnassociatedMethod = null; RaisePropertyChanged("AssociatedMethods"); RaisePropertyChanged("UnassociatedMethods"); }, () => IsInstrumentAdmin && _selectedUnassociated != null); AddPropertyCommand = new DelegateCommand( () => { Views.AddPropertyDialog propertyDialog = new Views.AddPropertyDialog(); if (propertyDialog.ShowDialog() == true) { InstrumentMeasurableProperty newIMP = new InstrumentMeasurableProperty() { CalibrationRangeLowerLimit = 0, CalibrationRangeUpperLimit = 0, Description = "", InstrumentID = _instance.ID, MeasurableQuantityID = propertyDialog.QuantityInstance.ID, RangeLowerLimit = 0, RangeUpperLimit = 0, Resolution = 0, TargetUncertainty = 0, UnitID = propertyDialog.QuantityInstance.GetMeasurementUnits().First().ID }; newIMP.Create(); RaisePropertyChanged("InstrumentMeasurablePropertyList"); } }, () => IsInstrumentAdmin); OpenFileCommand = new DelegateCommand( () => { try { System.Diagnostics.Process.Start(_selectedFile.Path); } catch (Exception) { _eventAggregator.GetEvent <StatusNotificationIssued>().Publish("File non trovato"); } }, () => _selectedFile != null); RemoveFileCommand = new DelegateCommand( () => { _selectedFile.Delete(); RaisePropertyChanged("FileList"); SelectedFile = null; }, () => _selectedFile != null); RemoveMethodAssociationCommand = new DelegateCommand( () => { _instance.RemoveMethodAssociation(_selectedAssociated); SelectedAssociatedMethod = null; RaisePropertyChanged("AssociatedMethods"); RaisePropertyChanged("UnassociatedMethods"); }, () => IsInstrumentAdmin && _selectedAssociated != null); SaveCommand = new DelegateCommand( () => { _instance.Update(); foreach (InstrumentMeasurablePropertyWrapper impw in InstrumentMeasurablePropertyList.Where(imp => imp.IsModified)) { impw.PropertyInstance.Update(); } EditMode = false; _eventAggregator.GetEvent <InstrumentListUpdateRequested>() .Publish(); }, () => _editMode); StartEditCommand = new DelegateCommand( () => { EditMode = true; }, () => IsInstrumentAdmin && !_editMode); #region Event Subscriptions _eventAggregator.GetEvent <MaintenanceEventCreated>() .Subscribe( maint => { if (maint.InstrumentID == _instance?.ID) { RaisePropertyChanged("MaintenanceEventList"); } }); _eventAggregator.GetEvent <CalibrationIssued>() .Subscribe( report => { if (report.instrumentID == _instance?.ID) { RaisePropertyChanged("CalibrationReportList"); } }); #endregion Event Subscriptions }