public NewCalibrationDialogViewModel(IEventAggregator eventAggregator, InstrumentService instrumentService, IDataService <LInstContext> lInstData) : base() { _lInstData = lInstData; _instrumentService = instrumentService; LabList = _lInstData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.CalibrationLab }) .ToList(); _eventAggregator = eventAggregator; _validationErrors = new Dictionary <string, ICollection <string> >(); CalibrationDate = DateTime.Now.Date; CancelCommand = new DelegateCommand <Window>( parentDialog => { parentDialog.DialogResult = false; }); ConfirmCommand = new DelegateCommand <Window>( parentDialog => { ReportInstance = new CalibrationReport(); ReportInstance.Date = CalibrationDate; ReportInstance.Year = DateTime.Now.Year - 2000; ReportInstance.Number = _instrumentService.GetNextCalibrationNumber(ReportInstance.Year); ReportInstance.InstrumentID = _instrumentInstance.ID; ReportInstance.LaboratoryID = _selectedLab.ID; ReportInstance.Notes = ""; ReportInstance.CalibrationResultID = 1; if (IsNotExternalLab) { ReportInstance.TechID = SelectedTech.ID; } foreach (InstrumentProperty iProperty in _lInstData.RunQuery(new InstrumentPropertiesQuery(ReportInstance.InstrumentID) { ExcludeNonCalibrationProperties = true })) { ReportInstance.CalibrationReportProperties.Add(new CalibrationReportProperty() { Name = iProperty.Name, TargetValue = iProperty.TargetValue, UpperLimit = iProperty.UpperLimit, LowerLimit = iProperty.LowerLimit, ParentPropertyID = iProperty.ID, UM = iProperty.UM }); } _lInstData.Execute(new InsertEntityCommand <LInstContext>(ReportInstance)); parentDialog.DialogResult = true; }, parentDialog => !HasErrors); }
public NewCalibrationDialogViewModel(LabDbEntities entities, IEventAggregator eventAggregator, InstrumentService instrumentService, IDataService <LabDbEntities> labDbData) : base() { _labDbData = labDbData; _entities = entities; _instrumentService = instrumentService; IsVerificationOnly = false; ReferenceList = new ObservableCollection <Instrument>(); LabList = _labDbData.RunQuery(new OrganizationsQuery() { Role = OrganizationsQuery.OrganizationRoles.CalibrationLab }) .ToList(); _eventAggregator = eventAggregator; CalibrationDate = DateTime.Now.Date; AddReferenceCommand = new DelegateCommand <string>( code => { Instrument tempRef = _entities.Instruments.FirstOrDefault(inst => inst.Code == code); if (tempRef != null) { ReferenceList.Add(tempRef); ReferenceCode = ""; } }); CancelCommand = new DelegateCommand <Window>( parentDialog => { parentDialog.DialogResult = false; }); ConfirmCommand = new DelegateCommand <Window>( parentDialog => { ReportInstance = new CalibrationReport(); ReportInstance.Date = CalibrationDate; ReportInstance.Year = DateTime.Now.Year - 2000; ReportInstance.Number = _instrumentService.GetNextCalibrationNumber(ReportInstance.Year); ReportInstance.Instrument = _instumentInstance; ReportInstance.IsVerification = IsVerificationOnly; ReportInstance.laboratoryID = _selectedLab.ID; ReportInstance.Notes = ""; ReportInstance.ResultID = 1; if (IsNotExternalLab) { ReportInstance.OperatorID = SelectedTech.ID; foreach (Instrument refInstrument in ReferenceList) { ReportInstance.ReferenceInstruments.Add(refInstrument); } } foreach (InstrumentMeasurableProperty imp in _instumentInstance.GetMeasurableProperties()) { CalibrationReportInstrumentPropertyMapping cripm = new CalibrationReportInstrumentPropertyMapping() { ExtendedUncertainty = 0, LowerRangeValue = imp.RangeLowerLimit, MeasurablePropertyID = imp.ID, MeasurementUnitID = imp.UnitID, UpperRangeValue = imp.RangeUpperLimit }; ReportInstance.InstrumentMeasurablePropertyMappings.Add(cripm); } _entities.CalibrationReports.Add(ReportInstance); _entities.SaveChanges(); parentDialog.DialogResult = true; }); RemoveReference = new DelegateCommand( () => { ReferenceList.Remove(_selectedReference); SelectedReference = null; }, () => _selectedReference != null); }