예제 #1
0
        public void Load()
        {
            // Explicitly loads a Project and all related entities

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

                Project tempEntry = entities.Projects.Include(prj => prj.ExternalReports
                                                              .Select(extr => extr.ExternalLab))
                                    .Include(prj => prj.Leader)
                                    .Include(prj => prj.Oem)
                                    .First(prj => prj.ID == ID);

                Description         = tempEntry.Description;
                ExternalReports     = tempEntry.ExternalReports;
                Leader              = tempEntry.Leader;
                Name                = tempEntry.Name;
                Oem                 = tempEntry.Oem;
                OemID               = tempEntry.OemID;
                ProjectLeaderID     = tempEntry.ProjectLeaderID;
                TotalExternalCost   = tempEntry.TotalExternalCost;
                TotalReportDuration = tempEntry.TotalReportDuration;
            }
        }
예제 #2
0
파일: TaskExtension.cs 프로젝트: PiSim/LDb2
        /// <summary>
        /// Generates a list of tests based on the taskItems loading all values from the DB
        /// </summary>
        /// <param name="includeMethods">If true the related Method entities are loaded</param>
        /// <returns>An IList containing the generated test entitites</returns>
        public IList <Test> GenerateTests(bool includeMethods = false)
        {
            List <Test> output = new List <Test>();

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

                IEnumerable <TaskItem> _itemList;

                if (includeMethods)
                {
                    _itemList = entities.TaskItems
                                .Include(tski => tski.Method.Property)
                                .Include(tski => tski.Method.Standard)
                                .Include(tski => tski.SubTaskItems)
                                .Where(tski => tski.TaskID == ID)
                                .ToList();
                }
                else
                {
                    _itemList = entities.TaskItems
                                .Include(tski => tski.SubTaskItems)
                                .Where(tski => tski.TaskID == ID)
                                .ToList();
                }

                foreach (TaskItem currentItem in _itemList)
                {
                    output.Add(currentItem.GetTest());
                }

                return(output);
            }
        }
예제 #3
0
        /// <summary>
        /// Deletes the entry from the database if no Test or requirement is associated with it, otherwise sets it as obsolete
        /// </summary>
        public void RemoveOrSetObsolete()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                MethodVariant attachedInstance = entities.MethodVariants.FirstOrDefault(mtdvar => mtdvar.ID == ID);
                if (attachedInstance == null)
                {
                    return;
                }

                if (attachedInstance.Requirements.Count == 0 &&
                    attachedInstance.Tests.Count == 0)
                {
                    entities.Entry(attachedInstance)
                    .State = EntityState.Deleted;
                }
                else
                {
                    attachedInstance.IsOld = true;
                    IsOld = true;
                }

                entities.SaveChanges();
            }
        }
예제 #4
0
        /// <summary>
        /// Returns the report which uses this TestRecord
        /// </summary>
        /// <returns></returns>
        public object GetReport()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                if (RecordTypeID == 1)
                {
                    return(entities.TestRecords
                           .Include(tstr => tstr.Reports).First(tsr => tsr.ID == ID)
                           .Reports
                           .FirstOrDefault());
                }
                else if (RecordTypeID == 2)
                {
                    return(entities.TestRecords
                           .Include(tstr => tstr.ExternalReports)
                           .First(tsr => tsr.ID == ID)
                           .ExternalReports
                           .FirstOrDefault());
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Returns all Task entities in the DB
        /// </summary>
        /// <param name="includeComplete">If true complete tasks will be included</param>
        /// <param name="includeAssigned">If true assigned tasks will be included</param>
        /// <returns>IEnumerable containing all the found entries</returns>
        public IEnumerable <Task> GetTasks(bool includeComplete = true,
                                           bool includeAssigned = true)
        {
            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                IQueryable <Task> queryBase = entities.Tasks.Include(tsk => tsk.Batch.Material.Aspect)
                                              .Include(tsk => tsk.Batch.Material.Project)
                                              .Include(tsk => tsk.Batch.Material.MaterialLine)
                                              .Include(tsk => tsk.Batch.Material.MaterialType)
                                              .Include(tsk => tsk.Batch.Material.Recipe.Colour)
                                              .Include(tsk => tsk.Requester)
                                              .Include(tsk => tsk.SpecificationVersion.Specification.Standard);

                if (includeComplete)
                {
                    return(queryBase.ToList());
                }

                if (includeAssigned)
                {
                    return(queryBase.Where(tsk => tsk.Report == null || !tsk.Report.IsComplete)
                           .ToList());
                }
                else
                {
                    return(queryBase.Where(tsk => tsk.Report == null)
                           .ToList());
                }
            }
        }
예제 #6
0
파일: TaskExtension.cs 프로젝트: PiSim/LDb2
        /// <summary>
        /// Reads and stores the entity property values from the DB
        /// Children collections are not loaded
        /// </summary>
        public void Load()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                Task tempEntry = entities.Tasks.Include(tsk => tsk.Batch.Material.Aspect)
                                 .Include(tsk => tsk.Batch.Material.ExternalConstruction)
                                 .Include(tsk => tsk.Batch.Material.MaterialLine)
                                 .Include(tsk => tsk.Batch.Material.MaterialType)
                                 .Include(tsk => tsk.Batch.Material.Project.Oem)
                                 .Include(tsk => tsk.Batch.Material.Recipe.Colour)
                                 .Include(tsk => tsk.Batch.Material.Recipe.Master)
                                 .Include(tsk => tsk.Report)
                                 .Include(tsk => tsk.Requester)
                                 .Include(tsk => tsk.SpecificationVersion.Specification.Standard.Organization)
                                 .First(tsk => tsk.ID == ID);

                Batch                  = tempEntry.Batch;
                BatchID                = tempEntry.BatchID;
                EndDate                = tempEntry.EndDate;
                Notes                  = tempEntry.Notes;
                PipelineOrder          = tempEntry.PipelineOrder;
                PriorityModifier       = tempEntry.PriorityModifier;
                Progress               = tempEntry.Progress;
                Report                 = tempEntry.Report;
                Requester              = tempEntry.Requester;
                RequesterID            = tempEntry.RequesterID;
                SpecificationVersion   = tempEntry.SpecificationVersion;
                SpecificationVersionID = tempEntry.SpecificationVersionID;
                StartDate              = tempEntry.StartDate;
            }
        }
예제 #7
0
        public static void Load(this SpecificationVersion entry)
        {
            // Loads relevant RelatedEntities for given SpecificationVersion entry

            if (entry == null)
            {
                return;
            }

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

                SpecificationVersion tempEntry = entities.SpecificationVersions.Include(specv => specv.ExternalConstructions)
                                                 .Include(specv => specv.Requirements
                                                          .Select(req => req.SubRequirements))
                                                 .Include(specv => specv.Requirements
                                                          .Select(req => req.Overridden))
                                                 .Include(specv => specv.Requirements
                                                          .Select(req => req.MethodVariant.Method.Property))
                                                 .Include(specv => specv.Requirements
                                                          .Select(req => req.MethodVariant.Method.Standard.Organization))
                                                 .Include(req => req.Specification.Standard.Organization)
                                                 .First(specv => specv.ID == entry.ID);

                entry.ExternalConstructions = tempEntry.ExternalConstructions;
                entry.IsMain          = tempEntry.IsMain;
                entry.Name            = tempEntry.Name;
                entry.Reports         = tempEntry.Reports;
                entry.Requirements    = tempEntry.Requirements;
                entry.Specification   = tempEntry.Specification;
                entry.SpecificationID = tempEntry.SpecificationID;
                entry.Tasks           = tempEntry.Tasks;
            }
        }
예제 #8
0
 public static void Create(this Method entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Methods.Add(entry);
         entities.SaveChanges();
     }
 }
예제 #9
0
 public void Create()
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.ControlPlans.Add(this);
         entities.SaveChanges();
     }
 }
예제 #10
0
 public void Create()
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Projects.Add(this);
         entities.SaveChanges();
     }
 }
예제 #11
0
 public static void CreateTests(this IEnumerable <Test> testList)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Tests.AddRange(testList);
         entities.SaveChanges();
     }
 }
예제 #12
0
 /// <summary>
 /// Inserts the entity in the database
 /// </summary>
 public void Create()
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.MethodVariants.Add(this);
         entities.SaveChanges();
     }
 }
예제 #13
0
 public static void Update(this Report entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Reports.AddOrUpdate(entry);
         entities.SaveChanges();
     }
 }
예제 #14
0
 public static void Create(this Batch entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Batches.Add(entry);
         entities.SaveChanges();
     }
 }
예제 #15
0
 public static void Update(this Specification entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Specifications.AddOrUpdate(entry);
         entities.SaveChanges();
     }
 }
예제 #16
0
 public static void Delete(this Specification entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Entry(entities.Specifications.First(spec => spec.ID == entry.ID))
         .State = EntityState.Deleted;
         entities.SaveChanges();
     }
 }
예제 #17
0
        public Requirement GetRequirement(int ID)
        {
            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                return(entities.Requirements.First(req => req.ID == ID));
            }
        }
예제 #18
0
 public static void Delete(this Method entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.Methods.Attach(entry);
         entities.Entry(entry).State = System.Data.Entity.EntityState.Deleted;
         entities.SaveChanges();
     }
 }
예제 #19
0
        /// <summary>
        /// Returns all PersonRole Entities
        /// </summary>
        /// <returns>An IEnumerable containing all PersonRole entities</returns>
        public IEnumerable <PersonRole> GetPersonRoles()
        {
            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                return(entities.PersonRoles.ToList());
            }
        }
예제 #20
0
파일: TaskExtension.cs 프로젝트: PiSim/LDb2
        public static void Update(this Task entry)
        {
            // Updates the DB values of a Task entry

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Tasks.AddOrUpdate(entry);
                entities.SaveChanges();
            }
        }
예제 #21
0
        public static void Delete(this Report entry)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Entry(entities.Reports.First(rep => rep.ID == entry.ID)).State = EntityState.Deleted;
                entities.SaveChanges();

                entry.ID = 0;
            }
        }
예제 #22
0
        public static void Create(this Report entry)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                entities.Reports.Add(entry);
                entities.SaveChanges();
            }
        }
예제 #23
0
        public void Create()
        {
            // Inserts the report in the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.ExternalReports.Add(this);
                entities.SaveChanges();
            }
        }
예제 #24
0
        public static void Create(this Requirement entry)
        {
            // Insert new Requirement entry in the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Requirements.Add(entry);
                entities.SaveChanges();
            }
        }
예제 #25
0
파일: TaskExtension.cs 프로젝트: PiSim/LDb2
        public static void Create(this Task entry)
        {
            // Deletes given task instance

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Tasks.Add(entry);
                entities.SaveChanges();
            }
        }
예제 #26
0
        /// <summary>
        /// Calculates the total external cost of the project and stores the result in the
        /// TotalExternalCost field
        /// </summary>
        /// <returns>The calculated value</returns>
        public double GetExternalReportCost()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                IQueryable <ExternalReport> externalReportList = entities.ExternalReports
                                                                 .Where(extr => extr.ProjectID == ID);

                return((externalReportList.Count() == 0) ? 0 : externalReportList.Sum(extr => extr.OrderTotal));
            }
        }
예제 #27
0
        public IEnumerable <MeasurementUnit> GetMeasurementUnits()
        {
            // Returns all measurement units

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

                return(entities.MeasurementUnits.ToList());
            }
        }
예제 #28
0
        public CalibrationReport GetCalibrationReport(int ID)
        {
            // Returns a calibration report with the given ID, or null if none is found

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

                return(entities.CalibrationReports.FirstOrDefault(calrep => calrep.ID == ID));
            }
        }
예제 #29
0
        /// <summary>
        /// Removes the ExternalConstruction Association from the material
        /// </summary>
        public void UnsetConstruction()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                Material attachedEntry = entities.Materials.First(mat => mat.ID == ID);

                attachedEntry.ExternalConstruction.Materials.Remove(attachedEntry);

                entities.SaveChanges();
            }
        }
예제 #30
0
        /// <summary>
        /// Returns all the StandardFiles related to this standard
        /// </summary>
        /// <returns>An IEnumerable of StandardFiles entities</returns>
        public IEnumerable <StandardFile> GetFiles()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Configuration.LazyLoadingEnabled = false;

                return(entities.StandardFiles
                       .Where(stf => stf.StandardID == ID)
                       .ToList());
            }
        }