예제 #1
0
        public void Update()
        {
            // Updates the DBValues of the Project entry

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Projects
                .AddOrUpdate(this);

                entities.SaveChanges();
            }
        }
예제 #2
0
        public static void Delete(this Batch entry)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                Batch tempEntry = entities.Batches.First(btc => btc.ID == entry.ID);

                entities.Entry(tempEntry).State = EntityState.Deleted;
                entry.ID = 0;

                entities.SaveChanges();
            }
        }
예제 #3
0
 public static void Delete(this SpecificationVersion entry)
 {
     // Deletes SpecificationVersion entity
     {
         using (LabDbEntities entities = new LabDbEntities())
         {
             entities.SpecificationVersions.Attach(entry);
             entities.Entry(entry).State = EntityState.Deleted;
             entities.SaveChanges();
         }
     }
 }
예제 #4
0
        public void Update()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.ControlPlans.AddOrUpdate(this);
                foreach (ControlPlanItem cpi in control_plan_items_b)
                {
                    entities.ControlPlanItems.AddOrUpdate(cpi);
                }

                entities.SaveChanges();
            }
        }
예제 #5
0
파일: TaskExtension.cs 프로젝트: PiSim/LDb2
        public static void Delete(this Task entry)
        {
            // Deletes given task instance

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

                entities.SaveChanges();
            }
        }
예제 #6
0
        public void Update()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Methods.AddOrUpdate(this);

                foreach (SubMethod smtd in SubMethods)
                {
                    entities.SubMethods.AddOrUpdate(smtd);
                }

                entities.SaveChanges();
            }
        }
예제 #7
0
        public static void AddRequirement(this SpecificationVersion entry,
                                          Requirement requirementEntry)
        {
            // Adds a Requirement entity to a specificationVersion requirement list

            entry.Requirements.Add(requirementEntry);
            requirementEntry.SpecificationVersionID = entry.ID;

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Requirements.Add(requirementEntry);
                entities.SaveChanges();
            }
        }
예제 #8
0
        /// <summary>
        /// Sets the project for the material of this report to the one specified
        /// as argument
        /// </summary>
        /// <param name="projectInstance">The project instance that will be set</param>
        public void SetProject(Project projectInstance)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                Material target = entities.Reports
                                  .FirstOrDefault(rpt => rpt.ID == ID)?
                                  .Batch
                                  .Material;

                target.ProjectID = projectInstance.ID;

                entities.SaveChanges();
            }
        }
예제 #9
0
        public static void Delete(this Instrument entry)
        {
            // Deletes an Instrument entry

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

                entities.SaveChanges();

                entry.ID = 0;
            }
        }
예제 #10
0
        public static void AddMethodAssociation(this Instrument entry,
                                                Method methodEntity)
        {
            // Creates a new Instrument/method association

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Instruments.First(inst => inst.ID == entry.ID)
                .AssociatedMethods
                .Add(entities.Methods
                     .First(mtd => mtd.ID == methodEntity.ID));

                entities.SaveChanges();
            }
        }
예제 #11
0
        public static void RemoveMethodAssociation(this Instrument entry,
                                                   Method methodEntity)
        {
            // Creates a new Instrument/method association

            using (LabDbEntities entities = new LabDbEntities())
            {
                Instrument tempInstrument = entities.Instruments.First(inst => inst.ID == entry.ID);
                Method     tempMethod     = tempInstrument.AssociatedMethods.First(mtd => mtd.ID == methodEntity.ID);

                tempInstrument.AssociatedMethods.Remove(tempMethod);

                entities.SaveChanges();
            }
        }
예제 #12
0
        public static void UpdateDuration(this Report entry)
        {
            // Updates the value of the field "TotalDuration" with the sum of the report's tests individual durations

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Reports
                .First(rep => rep.ID == entry.ID)
                .TotalDuration = entities.Tests
                                 .Where(tst => tst.TestRecordID == entry.TestRecordID)
                                 .Sum(tst => tst.Duration);

                entities.SaveChanges();
            }
        }
예제 #13
0
        public void Delete()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                ControlPlan tempEntry = entities.ControlPlans.FirstOrDefault(cp => cp.ID == ID);
                if (tempEntry != null)
                {
                    entities.Entry(tempEntry)
                    .State = System.Data.Entity.EntityState.Deleted;
                    entities.SaveChanges();
                }

                ID = 0;
            }
        }
예제 #14
0
        public static void Delete(this Requirement entry)
        {
            // Deletes Requirement entry

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

                entities.SaveChanges();

                entry.ID = 0;
            }
        }
예제 #15
0
        /// <summary>
        /// Pushes the current Instance to the database updating all the values
        /// </summary>
        /// <param name="updateTests">If true all the related SubTest entities are updated too</param>
        public void Update(bool updateTests = false)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.ExternalReports.AddOrUpdate(this);

                if (updateTests)
                {
                    foreach (SubTest sts in TestRecords.SelectMany(tsr => tsr.Tests)
                             .SelectMany(tst => tst.SubTests)
                             .ToList())
                    {
                        entities.SubTests.AddOrUpdate(sts);
                    }
                }

                entities.SaveChanges();
            }
        }
예제 #16
0
        public static void AddFiles(this Instrument entry,
                                    IEnumerable <string> paths)
        {
            // Given a list of paths creates and adds a corresponding series of InstrumentFiles entities

            using (LabDbEntities entities = new LabDbEntities())
            {
                foreach (string pth in paths)
                {
                    InstrumentFiles inf = new InstrumentFiles()
                    {
                        Path         = pth,
                        InstrumentID = entry.ID
                    };

                    entities.InstrumentFiles.Add(inf);
                }

                entities.SaveChanges();
            }
        }
예제 #17
0
        /// <summary>
        /// Adds a new method to an ExternalReport entry
        /// </summary>
        /// <param name="methodEntity">The MethodVariant to Add</param>
        public void AddTestMethod(MethodVariant methodVariant)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                ExternalReport attachedExternalReport = entities.ExternalReports.First(ext => ext.ID == ID);
                MethodVariant  attachedMethodVariant  = entities.MethodVariants.First(mtd => mtd.ID == methodVariant.ID);

                attachedExternalReport.MethodVariants.Add(attachedMethodVariant);

                IEnumerable <TestRecord> recordList = attachedExternalReport.TestRecords.ToList();

                methodVariant.LoadMethod(true);

                foreach (TestRecord tstr in attachedExternalReport.TestRecords)
                {
                    tstr.Tests.Add(methodVariant.GenerateTest());
                }

                entities.SaveChanges();
            }
        }
예제 #18
0
        public ControlPlan AddControlPlan(bool asDefault = false)
        {
            // Generates a new control plan for this specification

            using (LabDbEntities entities = new LabDbEntities())
            {
                ControlPlan newEntry = new ControlPlan()
                {
                    IsDefault       = asDefault,
                    Name            = (asDefault) ? "Completo" : "Nuovo Piano di Controllo",
                    SpecificationID = ID
                };

                SpecificationVersion mainVersion = entities.SpecificationVersions
                                                   .FirstOrDefault(spv => spv
                                                                   .SpecificationID == ID &&
                                                                   spv.IsMain);

                if (mainVersion == null)
                {
                    throw new InvalidOperationException();
                }

                foreach (Requirement req in mainVersion.Requirements)
                {
                    newEntry.control_plan_items_b.Add(new ControlPlanItem()
                    {
                        IsSelected    = asDefault,
                        RequirementID = req.ID
                    });
                }

                entities.ControlPlans.Add(newEntry);

                entities.SaveChanges();

                return(newEntry);
            }
        }
예제 #19
0
        /// <summary>
        /// Removes a given methodVariant from the method associations and from every test record
        /// in the report
        /// </summary>
        /// <param name="methodEntity">The methodVariant that will be removed</param>
        public void RemoveTestMethodVariant(MethodVariant methodVariantEntity)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                ExternalReport attachedExternalReport = entities.ExternalReports.First(ext => ext.ID == ID);
                MethodVariant  attachedMethodVariant  = entities.MethodVariants.First(mtdvar => mtdvar.ID == methodVariantEntity.ID);

                attachedExternalReport.MethodVariants.Remove(attachedMethodVariant);

                IEnumerable <TestRecord> recordList = attachedExternalReport.TestRecords.ToList();

                IEnumerable <Test> testList = attachedExternalReport.TestRecords.SelectMany(tstr => tstr.Tests)
                                              .Where(tst => tst.MethodVariantID == methodVariantEntity.ID)
                                              .ToList();

                foreach (Test tst in testList)
                {
                    entities.Entry(tst).State = EntityState.Deleted;
                }

                entities.SaveChanges();
            }
        }
예제 #20
0
        public void AddMethod(Requirement requirementEntry)
        {
            // Adds a requirement to a Specification

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.SpecificationVersions
                .First(spcv => spcv.SpecificationID == ID && spcv.IsMain)
                .Requirements
                .Add(requirementEntry);

                foreach (ControlPlan cp in entities.ControlPlans.Where(cp => cp.SpecificationID == ID))
                {
                    requirementEntry.ControlPlanItems
                    .Add(new ControlPlanItem()
                    {
                        ControlPlan = cp,
                        IsSelected  = cp.IsDefault
                    });
                }

                entities.SaveChanges();
            }
        }
예제 #21
0
        public void AddBatch(Batch batchEntity)
        {
            // Adds a Batch to an ExternalReport entry

            using (LabDbEntities entities = new LabDbEntities())
            {
                ExternalReport attachedEntry = entities.ExternalReports.First(ext => ext.ID == ID);

                TestRecord recordEntry = new TestRecord()
                {
                    BatchID      = batchEntity.ID,
                    RecordTypeID = 2
                };

                foreach (MethodVariant mtdVar in attachedEntry.MethodVariants)
                {
                    recordEntry.Tests.Add(mtdVar.GenerateTest());
                }

                attachedEntry.TestRecords.Add(recordEntry);

                entities.SaveChanges();
            }
        }