コード例 #1
0
        public static void Update(this CalibrationReport entry)
        {
            // Updates a CAlibrationReport entry

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

                entities.SaveChanges();
            }
        }
コード例 #2
0
ファイル: ReportService.cs プロジェクト: PiSim/LDb2
        /// <summary>
        /// Adds a sum to a project's ExternalCost field
        /// The addition is optimistic and assumes noone is altering the project entry
        /// </summary>
        /// <param name="projectID">The ID of the project to Update</param>
        /// <param name="sumToAdd">The amount that will be added.</param>
        public void AddToProjectExternalCost(int?projectID,
                                             double sumToAdd)
        {
            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                Project connectedEntry = entities.Projects
                                         .First(prj => prj.ID == projectID);

                connectedEntry.TotalExternalCost += sumToAdd;

                entities.SaveChanges();
            }
        }
コード例 #3
0
        public override void Run()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                IEnumerable <ExternalReport> exrepList = entities.ExternalReports.ToList();

                foreach (ExternalReport exrep in exrepList)
                {
                }

                entities.SaveChanges();
            }
        }
コード例 #4
0
ファイル: BuildTestRecords.cs プロジェクト: PiSim/LDb2
        public override void Run()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                IEnumerable <Test> testList = entities.Tests.ToList();

                foreach (Test tst in testList)
                {
                    tst.TestRecordID = tst.TBD2.TestRecordID;
                }
                entities.SaveChanges();
            }
        }
コード例 #5
0
ファイル: MaterialService.cs プロジェクト: PiSim/LDb2
        public static void Delete(this ExternalConstruction entry)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Entry(entities
                               .ExternalConstructions
                               .First(exc => exc.ID == entry.ID))
                .State = System.Data.Entity.EntityState.Deleted;
                entities.SaveChanges();

                entry.ID = 0;
            }
        }
コード例 #6
0
ファイル: OrganizationExtension.cs プロジェクト: PiSim/LDb2
        public static void Update(this IEnumerable <OrganizationRoleMapping> entries)
        {
            // updates a list of OrganizationRoleMapping entries

            using (LabDbEntities entities = new LabDbEntities())
            {
                foreach (OrganizationRoleMapping orm in entries)
                {
                    entities.OrganizationRoleMappings.AddOrUpdate(orm);
                }

                entities.SaveChanges();
            }
        }
コード例 #7
0
ファイル: SpecificationService.cs プロジェクト: PiSim/LDb2
        public void UpdateSubMethods(IEnumerable <SubMethod> methodEntries)
        {
            // Updates all the SubMethod entries

            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                foreach (SubMethod smtd in methodEntries)
                {
                    entities.SubMethods.AddOrUpdate(smtd);
                }

                entities.SaveChanges();
            }
        }
コード例 #8
0
        public static void Delete(this User entry)
        {
            // Deletes a User entry

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Entry(entities.Users
                               .First(usr => usr.ID == entry.ID))
                .State = EntityState.Deleted;

                entities.SaveChanges();

                entry.ID = 0;
            }
        }
コード例 #9
0
        public override void Run()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                foreach (ExternalReport exrep in entities.ExternalReports.ToList())
                {
                    foreach (Method mtd in exrep.Deprecated)
                    {
                        exrep.MethodVariants.Add(mtd.MethodVariants.First());
                    }
                }

                entities.SaveChanges();
            }
        }
コード例 #10
0
        public static void Delete(this InstrumentUtilizationArea entry)
        {
            // Deletes an InstrumentUtilizationArea entry

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Entry(entities
                               .InstrumentUtilizationAreas
                               .First(iua => iua.ID == entry.ID))
                .State = EntityState.Deleted;

                entities.SaveChanges();
                entry.ID = 0;
            }
        }
コード例 #11
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;
            }
        }
コード例 #12
0
        public override void Execute(LabDbEntities context)
        {
            _context = context;

            foreach (Batch batchTemplate in _batchList)
            {
                using (var transaction = _context.Database.BeginTransaction())
                {
                    Batch newBatch = new Batch();

                    context.Batches.Add(newBatch);

                    context.Entry(newBatch).CurrentValues.SetValues(batchTemplate);

                    newBatch.Material = context.Materials.First(mat => mat.Aspect.Code == batchTemplate.Material.Aspect.Code &&
                                                                mat.MaterialLine.Code == batchTemplate.Material.MaterialLine.Code &&
                                                                mat.Recipe.Code == batchTemplate.Material.Recipe.Code &&
                                                                mat.MaterialType.Code == batchTemplate.Material.MaterialType.Code);


                    if (batchTemplate.Material.ExternalConstruction != null)
                    {
                        newBatch.Material.ExternalConstructionID = batchTemplate.Material.ExternalConstruction.ID;
                    }

                    if (batchTemplate.Material.Project != null)
                    {
                        newBatch.Material.ProjectID = batchTemplate.Material.Project.ID;
                    }

                    if (batchTemplate.Material.Recipe.Colour != null)
                    {
                        newBatch.Material.Recipe.ColourID = batchTemplate.Material.Recipe.Colour.ID;
                    }

                    try
                    {
                        transaction.Commit();
                    }
                    catch
                    {
                        _failedBatches.AddLast(batchTemplate);
                    }
                }
            }
            context.SaveChanges();
        }
コード例 #13
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();
            }
        }
コード例 #14
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();
            }
        }
コード例 #15
0
        public static void AddMeasurableQuantityAssociation(this InstrumentType entry,
                                                            MeasurableQuantity quantity)
        {
            // Create a new association between an instrument Type and a quantity

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.InstrumentTypes
                .First(ist => ist.ID == entry.ID)
                .MeasurableQuantities
                .Add(entities
                     .MeasurableQuantities
                     .First(meq => meq.ID == quantity.ID));

                entities.SaveChanges();
            }
        }
コード例 #16
0
        public static void RemoveMeasurableQuantityAssociation(this InstrumentType entry,
                                                               MeasurableQuantity quantity)
        {
            // Removes an association between an instrument Type and a quantity

            using (LabDbEntities entities = new LabDbEntities())
            {
                MeasurableQuantity toBeRemoved = entities.MeasurableQuantities
                                                 .First(meq => meq.ID == quantity.ID);

                entities.InstrumentTypes
                .First(ist => ist.ID == entry.ID)
                .MeasurableQuantities
                .Remove(toBeRemoved);

                entities.SaveChanges();
            }
        }
コード例 #17
0
ファイル: SpecificationService.cs プロジェクト: PiSim/LDb2
        public void UpdateRequirements(IEnumerable <Requirement> requirementEntries)
        {
            // Updates all the Requirement entries passed as parameter

            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                foreach (Requirement req in requirementEntries)
                {
                    entities.Requirements.AddOrUpdate(req);
                    foreach (SubRequirement sreq in req.SubRequirements)
                    {
                        entities.SubRequirements.AddOrUpdate(sreq);
                    }
                }

                entities.SaveChanges();
            }
        }
コード例 #18
0
        public override void Run()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                IEnumerable <Method> methodList = entities.Methods.ToList();

                foreach (Method mtd in methodList)
                {
                    int positionCounter = 0;

                    foreach (SubMethod smtd in mtd.SubMethods)
                    {
                        smtd.Position = positionCounter++;
                    }
                }

                entities.SaveChanges();
            }
        }
コード例 #19
0
ファイル: AdminService.cs プロジェクト: PiSim/LDb2
        /// <summary>
        /// Creates and inserts in the DB the mappings between a new OrganizationRole
        /// and all the existing organization
        /// </summary>
        /// <param name="newRole">The role for which will be built the mappings</param>
        internal void CreateMappingsForNewRole(OrganizationRole newRole)
        {
            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                IEnumerable <Organization> _orgList = entities.Organizations.ToList();

                foreach (Organization org in _orgList)
                {
                    OrganizationRoleMapping tempMap = new OrganizationRoleMapping()
                    {
                        IsSelected = false,
                        RoleID     = newRole.ID
                    };

                    org.RoleMapping.Add(tempMap);
                }

                entities.SaveChanges();
            }
        }
コード例 #20
0
        public LabDbContext.User CreateNewUser(Person personInstance,
                                               string userName,
                                               string password)
        {
            LabDbContext.User output = new LabDbContext.User();
            output.FullName       = "";
            output.UserName       = userName;
            output.HashedPassword = CalculateHash(password, userName);
            output.Person         = _entities.People.First(per => per.ID == personInstance.ID);

            foreach (UserRole role in _entities.UserRoles)
            {
                UserRoleMapping tempMapping = new UserRoleMapping();
                tempMapping.UserRole   = role;
                tempMapping.IsSelected = false;

                output.RoleMappings.Add(tempMapping);
            }
            _entities.Users.Add(output);
            _entities.SaveChanges();

            return(output);
        }
コード例 #21
0
ファイル: AdminService.cs プロジェクト: PiSim/LDb2
        public PersonRole CreateNewPersonRole()
        {
            StringInputDialog addPersonRoleDialog = new StringInputDialog();

            addPersonRoleDialog.Title   = "Creazione nuovo Ruolo Persona";
            addPersonRoleDialog.Message = "Nome:";

            if (addPersonRoleDialog.ShowDialog() != true)
            {
                return(null);
            }

            PersonRole newRole = new PersonRole
            {
                Name        = addPersonRoleDialog.InputString,
                Description = ""
            };

            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                entities.PersonRoles.Add(newRole);

                foreach (Person per in entities.People)
                {
                    PersonRoleMapping newMapping = new PersonRoleMapping
                    {
                        Person     = per,
                        IsSelected = false
                    };
                    newRole.RoleMappings.Add(newMapping);
                }

                entities.SaveChanges();
            }

            return(newRole);
        }
コード例 #22
0
ファイル: ReportService.cs プロジェクト: PiSim/LDb2
        /// <summary>
        /// Process the Data input of a Report creation dialog to create a new Report instance and proceeds to insert it in the database
        /// </summary>
        /// <param name="dialogViewModelInstance">The ViewModel of the dialog used to collect data</param>
        /// <returns>The new report instance</returns>
        private Report CreateReportFromCreationDialog(ViewModels.ReportCreationDialogViewModel dialogViewModelInstance)
        {
            Report output;

            // Creates new  report instance

            output = new Report
            {
                AuthorID               = dialogViewModelInstance.Author.ID,
                BatchID                = dialogViewModelInstance.SelectedBatch.ID,
                Category               = "TR",
                Description            = (dialogViewModelInstance.SelectedControlPlan != null) ? dialogViewModelInstance.SelectedControlPlan.Name : dialogViewModelInstance.Description,
                IsComplete             = false,
                Number                 = dialogViewModelInstance.Number,
                SpecificationVersionID = dialogViewModelInstance.SelectedVersion.ID,
                StartDate              = DateTime.Now.ToShortDateString()
            };

            // Test Record is created from parent task or from the selected requirements

            output.TestRecord = new TestRecord()
            {
                BatchID      = output.BatchID,
                RecordTypeID = 1
            };

            if (dialogViewModelInstance.IsCreatingFromTask)
            {
                foreach (Test tst in dialogViewModelInstance.TaskInstance.GenerateTests())
                {
                    output.TestRecord.Tests.Add(tst);
                }
            }
            else
            {
                foreach (Test tst in GenerateTestList(dialogViewModelInstance.SelectedRequirements))
                {
                    output.TestRecord.Tests.Add(tst);
                }
            }

            // Calculates total test duration

            output.TotalDuration = output.TestRecord.Tests.Sum(tst => tst.Duration);

            //Inserts new entry in the DB

            output.Create();

            // If the tested Batch does not have a "basic" report, add reference to current instance

            if (dialogViewModelInstance.SelectedBatch.BasicReportID == null)
            {
                using (LabDbEntities entities = _dbContextFactory.Create())
                {
                    entities.Batches
                    .First(btc => btc.ID == dialogViewModelInstance.SelectedBatch.ID)
                    .BasicReportID = output.ID;

                    entities.SaveChanges();
                }
            }

            // If using Task as template, the parent is updated with the child Report ID

            if (dialogViewModelInstance.CreationMode == ViewModels.ReportCreationDialogViewModel.CreationModes.ReportFromTask)
            {
                dialogViewModelInstance.TaskInstance.ReportID = output.ID;
                dialogViewModelInstance.TaskInstance.Update();
            }

            return(output);
        }
コード例 #23
0
ファイル: SpecificationService.cs プロジェクト: PiSim/LDb2
        /// <summary>
        /// Begins the process of Modifying a Method's subMethod list
        /// </summary>
        /// <param name="toBeModified"> an instance of the method to alter</param>
        public void ModifyMethodTestList(Method toBeModified)
        {
            toBeModified.LoadSubMethods();

            Views.ModifyMethodSubMethodListDialog modificationDialog = new Views.ModifyMethodSubMethodListDialog();

            modificationDialog.OldVersion = toBeModified;

            if (modificationDialog.ShowDialog() == true)
            {
                using (LabDbEntities entities = _dbContextFactory.Create())
                {
                    /// Retrieves references to up to date entities from the Database

                    Method attachedOldMethod = entities.Methods.FirstOrDefault(mtd => mtd.ID == toBeModified.ID);

                    if (attachedOldMethod == null)
                    {
                        return;
                    }

                    /// Creates a new method Instance from the old one

                    Method newMethod = new Method()
                    {
                        Description      = attachedOldMethod.Description,
                        ShortDescription = attachedOldMethod.ShortDescription,
                        OldVersionID     = attachedOldMethod.ID,
                        PropertyID       = attachedOldMethod.PropertyID,
                        StandardID       = attachedOldMethod.StandardID
                    };

                    entities.Methods.Add(newMethod);

                    attachedOldMethod.IsOld = true;

                    /// Adds the new SubMethod list to the instance

                    int subMethodPositionCounter = 0;

                    foreach (SubMethod smtd in modificationDialog.SubMethodList)
                    {
                        smtd.Position = subMethodPositionCounter++;
                        newMethod.SubMethods.Add(smtd);
                    }

                    /// Updates all the variants

                    ICollection <MethodVariant> oldVariantList = attachedOldMethod.MethodVariants.ToList();

                    foreach (MethodVariant mtdvar in oldVariantList)
                    {
                        mtdvar.IsOld = true;

                        MethodVariant newVariant = new MethodVariant()
                        {
                            Description       = mtdvar.Description,
                            Name              = mtdvar.Name,
                            PreviousVersionID = mtdvar.ID
                        };

                        newMethod.MethodVariants.Add(newVariant);

                        BuildUpdatedRequirementsForMethodVariant(mtdvar,
                                                                 newVariant,
                                                                 newMethod,
                                                                 entities);
                    }

                    entities.SaveChanges();

                    _eventAggregator.GetEvent <BatchChanged>()
                    .Publish(new EntityChangedToken(newMethod,
                                                    EntityChangedToken.EntityChangedAction.Created));
                };
            }
        }
コード例 #24
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);
        }