Пример #1
0
        public static string GetFormattedNumber(this CalibrationReport entry)
        {
            // Returns a string uniquely representing a Calibration report
            // the string is generated from the report's number and year properties

            return(entry.Year.ToString() + entry.Number.ToString("D4"));
        }
        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);
        }
Пример #3
0
        public static void Create(this CalibrationReport entry)
        {
            // Inserts a calibration entry in the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.CalibrationReports.Add(entry);
                entities.SaveChanges();
            }
        }
Пример #4
0
        public static void Update(this CalibrationReport entry)
        {
            // Updates a CAlibrationReport entry

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.CalibrationReports
                .AddOrUpdate(entry);

                entities.SaveChanges();
            }
        }
Пример #5
0
        public static void Delete(this CalibrationReport entry)
        {
            // Deletes a Calibration entry from the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Entry(entities
                               .CalibrationReports
                               .First(crep => crep.ID == entry.ID))
                .State = System.Data.Entity.EntityState.Deleted;

                entities.SaveChanges();
                entry.ID = 0;
            }
        }
Пример #6
0
        public static void RemoveReference(this CalibrationReport entry,
                                           Instrument referenceEntry)
        {
            // Deletes an association between a CalibrationReport and a reference instrument

            using (LabDbEntities entities = new LabDbEntities())
            {
                CalibrationReport tempEntry = entities.CalibrationReports
                                              .First(calrep => calrep.ID == entry.ID);

                tempEntry.ReferenceInstruments
                .Remove(tempEntry.ReferenceInstruments
                        .First(inst => inst.ID == referenceEntry.ID));

                entities.SaveChanges();
            }
        }
Пример #7
0
        public static void AddReference(this CalibrationReport entry,
                                        Instrument referenceEntry)
        {
            // Adds an association with the given reference instrument

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.CalibrationReports
                .First(calrep => calrep.ID == entry.ID)
                .ReferenceInstruments
                .Add(entities
                     .Instruments
                     .First(inst => inst.ID == referenceEntry.ID));

                entities.SaveChanges();
            }
        }
Пример #8
0
        public static IEnumerable <CalibrationFiles> GetFiles(this CalibrationReport entry)
        {
            // returns all CAlibrationfiles associated with a given CalibrationReport Entry

            if (entry == null)
            {
                return(new List <CalibrationFiles>());
            }

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                return(entities.CalibrationFiles
                       .Where(calf => calf.ReportID == entry.ID)
                       .ToList());
            }
        }
Пример #9
0
        public static void Load(this CalibrationReport entry)
        {
            // Loads relevant values in a CalibrationReport instance

            if (entry == null)
            {
                return;
            }

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                CalibrationReport tempEntry = entities.CalibrationReports
                                              .Include(calr => calr.Instrument)
                                              .First(calr => calr.ID == entry.ID);

                entry.Instrument = tempEntry.Instrument;
            }
        }
Пример #10
0
        public CalibrationReport ShowNewCalibrationDialog(Instrument target)
        {
            Views.NewCalibrationDialog calibrationDialog = new Views.NewCalibrationDialog
            {
                InstrumentInstance = target
            };

            if (calibrationDialog.ShowDialog() == true)
            {
                CalibrationReport output = calibrationDialog.ReportInstance;

                _lInstData.Execute(new UpdateInstrumentCalibrationStatusCommand(target));

                _eventAggregator.GetEvent <CalibrationIssued>()
                .Publish(output);

                return(output);
            }
            else
            {
                return(null);
            }
        }
Пример #11
0
        public static IEnumerable <Instrument> GetReferenceInstruments(this CalibrationReport entry)
        {
            // Returns all Reference instruments for a given CalibrationReport entry

            if (entry == null)
            {
                return(new List <Instrument>());
            }

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                return(entities.CalibrationReports
                       .Include(calr => calr.ReferenceInstruments
                                .Select(refin => refin.InstrumentType))
                       .Include(calr => calr.ReferenceInstruments
                                .Select(refin => refin.Manufacturer))
                       .First(calr => calr.ID == entry.ID)
                       .ReferenceInstruments
                       .ToList());
            }
        }
Пример #12
0
        public CalibrationReport ShowNewCalibrationDialog(Instrument target)
        {
            Views.NewCalibrationDialog calibrationDialog = new Views.NewCalibrationDialog
            {
                InstrumentInstance = target
            };

            if (calibrationDialog.ShowDialog() == true)
            {
                CalibrationReport output = calibrationDialog.ReportInstance;

                output.Instrument.UpdateCalibrationDueDate();
                output.Instrument.Update();

                _eventAggregator.GetEvent <CalibrationIssued>()
                .Publish(output);

                return(output);
            }
            else
            {
                return(null);
            }
        }
Пример #13
0
 public ReferenceInstrumentsQuery(CalibrationReport reportInstance)
 {
     _reportInstance = reportInstance;
 }
Пример #14
0
        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);
        }
Пример #15
0
        public static IEnumerable <CalibrationReportInstrumentPropertyMapping> GetPropertyMappings(this CalibrationReport entry)
        {
            // Returns all associated CalibrationReportPropertyMapping entities

            if (entry == null)
            {
                return(null);
            }

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                return(entities.CalibrationReportInstrumentPropertyMappings
                       .Include(cripm => cripm.InstrumentMeasurableProperty.MeasurableQuantity)
                       .Include(cripm => cripm.InstrumentMeasurableProperty.UnitOfMeasurement)
                       .Where(cripm => cripm.CalibrationReportID == entry.ID)
                       .ToList());
            }
        }