public InstrumentMeasurablePropertyWrapper(InstrumentMeasurableProperty instance) : base() { IsSelected = false; IsModified = false; PropertyInstance = instance; UMList = PropertyInstance.GetMeasurementUnits(); }
public static void Create(this InstrumentMeasurableProperty entry) { // Inserts a new InstrumentMeasurableProperty entry in the DB using (LabDbEntities entities = new LabDbEntities()) { entities.InstrumentMeasurableProperties.Add(entry); entities.SaveChanges(); } }
public InstrumentCreationDialogViewModel(IDataService <LabDbEntities> labDbData) : base() { _labDbData = labDbData; ControlPeriod = 12; Notes = ""; Model = ""; SerialNumber = ""; CalibrationLabList = _labDbData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.CalibrationLab }) .ToList(); CancelCommand = new DelegateCommand <Window>( parent => { parent.DialogResult = false; }); ConfirmCommand = new DelegateCommand <Window>( parent => { InstrumentInstance = new Instrument(); InstrumentInstance.Code = _code; InstrumentInstance.Description = Notes; InstrumentInstance.InstrumentTypeID = SelectedType.ID; InstrumentInstance.IsInService = true; InstrumentInstance.IsUnderControl = _isUnderControl; InstrumentInstance.CalibrationInterval = ControlPeriod; InstrumentInstance.UtilizationAreaID = SelectedArea.ID; InstrumentInstance.CalibrationDueDate = (_isUnderControl) ? DateTime.Now : (DateTime?)null; InstrumentInstance.CalibrationResponsibleID = _selectedCalibrationLab?.ID; InstrumentInstance.manufacturerID = SelectedManufacturer.ID; InstrumentInstance.Model = Model; InstrumentInstance.SerialNumber = SerialNumber; foreach (MeasurableQuantity meq in SelectedType.GetAssociatedMeasurableQuantities()) { InstrumentMeasurableProperty tempIMP = new InstrumentMeasurableProperty() { MeasurableQuantityID = meq.ID, UnitID = meq.UnitsOfMeasurement.First().ID }; InstrumentInstance.InstrumentMeasurableProperties.Add(tempIMP); } InstrumentInstance.Create(); parent.DialogResult = true; }, parent => !HasErrors); SelectedCalibrationLab = null; }
public static void Update(this InstrumentMeasurableProperty entry) { // Updates an InstrumentMeasurableProperty entry using (LabDbEntities entities = new LabDbEntities()) { entities.InstrumentMeasurableProperties.AddOrUpdate(entry); entities.SaveChanges(); } }
public static CalibrationReport GetLastCalibration(this InstrumentMeasurableProperty entry) { // Returns the most recent CalibrationReport for this entry, or null if none exist using (LabDbEntities entities = new LabDbEntities()) { entities.Configuration.LazyLoadingEnabled = false; return(entities.CalibrationReports .Where(calrep => calrep .InstrumentMeasurablePropertyMappings .Any(impm => impm.MeasurablePropertyID == entry.ID)) .OrderByDescending(calrep => calrep.Date) .FirstOrDefault()); } }
public static IEnumerable <MeasurementUnit> GetMeasurementUnits(this InstrumentMeasurableProperty entry) { // Returns a list of possible UM for a given property if (entry == null) { return(new List <MeasurementUnit>()); } using (LabDbEntities entities = new LabDbEntities()) { entities.Configuration.LazyLoadingEnabled = false; return(entities.MeasurementUnits .Where(um => entities .InstrumentMeasurableProperties .FirstOrDefault(imp => imp.ID == entry.ID) .MeasurableQuantityID == um.MeasurableQuantityID) .ToList()); } }
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 }