public override void Run()
        {
            using (LabDbEntities context = new LabDbEntities())
            {
                Material lastMaterial;
                List <List <Material> > duplicates = new List <List <Material> >();
                List <Material>         currentGroup;

                IList <Material> matList = context.Materials.AsNoTracking()
                                           .OrderBy(mat => mat.AspectID)
                                           .ThenBy(mat => mat.LineID)
                                           .ThenBy(mat => mat.TypeID)
                                           .ThenBy(mat => mat.RecipeID)
                                           .ToList();
                {
                    lastMaterial = matList[0];
                    currentGroup = new List <Material>();

                    foreach (Material mat in matList.Skip(1))
                    {
                        if (mat.AspectID == lastMaterial.AspectID &&
                            mat.LineID == lastMaterial.LineID &&
                            mat.TypeID == lastMaterial.TypeID &&
                            mat.RecipeID == lastMaterial.RecipeID)
                        {
                            currentGroup.Add(mat);
                        }
                        else
                        {
                            if (currentGroup.Count > 1)
                            {
                                duplicates.Add(currentGroup);
                            }
                            currentGroup = new List <Material>()
                            {
                                mat
                            };
                        }

                        lastMaterial = mat;
                    }

                    foreach (List <Material> duplicateGroup in duplicates)
                    {
                        Material parent = duplicateGroup[0];
                        foreach (Material toSubstitute in duplicateGroup.Skip(1))
                        {
                            foreach (Batch btc in toSubstitute.Batches)
                            {
                                btc.MaterialID = parent.ID;
                            }

                            context.Entry(toSubstitute).State = System.Data.Entity.EntityState.Deleted;
                        }
                    }

                    context.SaveChanges();
                }
            }
        }
Esempio n. 2
0
        public List <entSalesTrx> GetSalesTrx()
        {
            try
            {
                LabDbEntities db = new LabDbEntities();

                List <entSalesTrx> list = (from sales in db.tt_WCF_Lab1_SalesTrx
                                           join prod in db.tt_WCF_Lab1_Products on sales.ProdSysId equals prod.ProdSysId
                                           where prod.IsActive == true
                                           select new entSalesTrx
                {
                    TrsSysId = sales.TrsSysId,
                    TrxDateTime = sales.TrxDateTime,
                    CustId = sales.CustId,
                    Qnt = sales.Qnt,
                    ProdSysId = prod.ProdSysId,
                    ProdName = prod.Name.Trim(),
                    ProdImg = GenericCode.ImgPath + prod.Img.Trim(),
                    ProdPrice = prod.Price,
                }).ToList();

                return(list);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
        public void AddOrganizationRole(string name)
        {
            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                OrganizationRole newRole = new OrganizationRole
                {
                    Name        = name,
                    Description = ""
                };

                entities.OrganizationRoles.Add(newRole);

                foreach (Organization org in entities.Organizations)
                {
                    OrganizationRoleMapping newMapping = new OrganizationRoleMapping
                    {
                        Role         = newRole,
                        Organization = org,
                        IsSelected   = false
                    };
                    entities.OrganizationRoleMappings.Add(newMapping);
                }

                entities.SaveChanges();
            }
        }
Esempio n. 4
0
 public static void Update(this ExternalConstruction entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.ExternalConstructions.AddOrUpdate(entry);
         entities.SaveChanges();
     }
 }
Esempio n. 5
0
 public static void Create(this ExternalConstruction entry)
 {
     using (LabDbEntities entities = new LabDbEntities())
     {
         entities.ExternalConstructions.Attach(entry);
         entities.Entry(entry).State = System.Data.Entity.EntityState.Added;
         entities.SaveChanges();
     }
 }
Esempio n. 6
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();
            }
        }
Esempio n. 7
0
        public static void Create(this Organization entry)
        {
            //Inserts a new Organization entry

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Organizations.Add(entry);
                entities.SaveChanges();
            }
        }
Esempio n. 8
0
        public int GetNextReportNumber()
        {
            // Returns the next available ReportNumber

            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                return(entities.Reports
                       .Max(rep => rep.Number) + 1);
            }
        }
Esempio n. 9
0
        public static void Create(this UserRole entry)
        {
            // Inserts a new UserRole in the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.UserRoles.Add(entry);
                entities.SaveChanges();
            }
        }
Esempio n. 10
0
        public static void Create(this InstrumentMeasurableProperty entry)
        {
            // Inserts a new InstrumentMeasurableProperty entry in the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.InstrumentMeasurableProperties.Add(entry);
                entities.SaveChanges();
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Runs the Command Routine over a given context
        /// </summary>
        /// <param name="context">A LabDbEntities context</param>
        public override void Execute(LabDbEntities context)
        {
            _context = context;

            Batch attachedBatch = _context.Batches.Find(_batchInstance.ID);

            _context.Entry(attachedBatch).CurrentValues.SetValues(_batchInstance);
            attachedBatch.Material = GetOrCreateMaterial(_materialTemplate);
            _context.SaveChanges();
        }
Esempio n. 12
0
        public static void Create(this InstrumentType entry)
        {
            // Inserts a new InstrumentType in the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.InstrumentTypes.Add(entry);
                entities.SaveChanges();
            }
        }
Esempio n. 13
0
        public void AddCalibrationFiles(IEnumerable <CalibrationFiles> fileList)
        {
            // inserts a set of CalibrationFiles entries in the DB

            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                entities.CalibrationFiles.AddRange(fileList);
                entities.SaveChanges();
            }
        }
Esempio n. 14
0
        public static void Update(this InstrumentMeasurableProperty entry)
        {
            // Updates an InstrumentMeasurableProperty entry

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

                entities.SaveChanges();
            }
        }
Esempio n. 15
0
        public static void Update(this CalibrationReportInstrumentPropertyMapping entry)
        {
            // Updates a CAlibrationReportInstrumentPropertyMapping entry

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

                entities.SaveChanges();
            }
        }
Esempio n. 16
0
        public static void AddMaterial(this ExternalConstruction entry,
                                       Material toBeAdded)
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.Materials.First(mat => mat.ID == toBeAdded.ID)
                .ExternalConstructionID = entry.ID;

                entities.SaveChanges();
            }
        }
Esempio n. 17
0
        public static void Update(this User entry)
        {
            // Updates a User Entry

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

                entities.SaveChanges();
            }
        }
Esempio n. 18
0
        public static void Update(this Organization entry)
        {
            // Updates the db values for a given Organization entry

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

                entities.SaveChanges();
            }
        }
Esempio n. 19
0
        public static void Create(this MeasurementUnit entry)
        {
            // Inserts a MeasurementUnit entry in the DB

            using (LabDbEntities entities = new LabDbEntities())
            {
                entities.MeasurementUnits.Add(entry);

                entities.SaveChanges();
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Inserts a list of MethodVariants in the database, or updates the values if the entry already exists
        /// </summary>
        /// <param name="variantList">An IEnumerable containing the MethodVariant instances to update/insert</param>
        public void UpdateMethodVariantRange(IEnumerable <MethodVariant> variantList)
        {
            using (LabDbEntities entities = _dbContextFactory.Create())
            {
                foreach (MethodVariant mtdvar in variantList)
                {
                    entities.MethodVariants.AddOrUpdate(mtdvar);
                }

                entities.SaveChanges();
            }
        }
Esempio n. 21
0
        public IEnumerable <CalibrationResult> GetCalibrationResults()
        {
            // Returns all CalibrationResult entities

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

                return(entities.CalibrationResults
                       .ToList());
            }
        }
Esempio n. 22
0
        public static void Update(this CalibrationReport entry)
        {
            // Updates a CAlibrationReport entry

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

                entities.SaveChanges();
            }
        }
        public override void Run()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                foreach (Test test in entities.Tests.Where(tst => tst.MethodVariantID == null).ToList())
                {
                    test.MethodVariantID = test.Deprecated.MethodVariants.First().ID;
                }

                entities.SaveChanges();
            }
        }
Esempio n. 24
0
        public override void Run()
        {
            using (LabDbEntities entities = new LabDbEntities())
            {
                IEnumerable <ExternalReport> exrepList = entities.ExternalReports.ToList();

                foreach (ExternalReport exrep in exrepList)
                {
                }

                entities.SaveChanges();
            }
        }
Esempio n. 25
0
        /// <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();
            }
        }
Esempio n. 26
0
        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;
            }
        }
Esempio n. 27
0
        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();
            }
        }
Esempio n. 28
0
        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();
            }
        }
Esempio n. 29
0
        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();
            }
        }
Esempio n. 30
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;
            }
        }