Exemple #1
0
        private int DeleteTblFamily(TblFamily row)
        {
            using (var context = new WorkFlowManagerDBEntities())
            {
                var oldRow = (from e in context.TblFamilies
                              where e.Iserial == row.Iserial
                              select e).SingleOrDefault();
                if (oldRow != null)
                {
                    context.DeleteObject(oldRow);
                }

                context.SaveChanges();
            }
            return(row.Iserial);
        }
Exemple #2
0
 private TblFamily UpdateOrInsertTblFamily(TblFamily newRow, bool save, int index, out int outindex)
 {
     outindex = index;
     using (var context = new WorkFlowManagerDBEntities())
     {
         if (save)
         {
             context.TblFamilies.AddObject(newRow);
         }
         else
         {
             var oldRow = (from e in context.TblFamilies
                           where e.Iserial == newRow.Iserial
                           select e).SingleOrDefault();
             if (oldRow != null)
             {
                 SharedOperation.GenericUpdate(oldRow, newRow, context);
             }
         }
         context.SaveChanges();
         return(newRow);
     }
 }
Exemple #3
0
        private int CreateClasses(Brand brand, TblLkpBrandSection tblLkpBrandSection1, TblFamily family, TblSubFamily subFamily)
        {
            var class1Iserial = FindOrCreate("TblClass1", new GenericTable {
                Iserial = 0, Ename = brand.Brand_Ename, Code = brand.Brand_Code, Aname = brand.Brand_Ename
            });

            using (var context = new ccnewEntities())
            {
                var class2Code = brand.Brand_Code + tblLkpBrandSection1.Code;
                var class3Code = class2Code + family.Code;
                var class4Code = class3Code + subFamily.Code;

                var class2MaxIserial = GetMaxIserial("TblCLASS2");
                var class3MaxIserial = GetMaxIserial("TblCLASS3");
                var class4MaxIserial = GetMaxIserial("TblCLASS4");

                var class2Row = context.TblCLASS2.FirstOrDefault(x => x.Code == class2Code);

                if (class2Row == null)
                {
                    context.TblCLASS2.AddObject(new TblCLASS2
                    {
                        ISerial   = class2MaxIserial,
                        Code      = class2Code,
                        EName     = tblLkpBrandSection1.Ename,
                        AName     = tblLkpBrandSection1.Aname,
                        TblClass1 = class1Iserial,
                    });
                }
                else
                {
                    class2MaxIserial = class2Row.ISerial;
                }

                var class3Row = context.TblCLASS3.FirstOrDefault(x => x.Code == class3Code);

                if (class3Row == null)
                {
                    context.TblCLASS3.AddObject(new TblCLASS3
                    {
                        ISerial   = class3MaxIserial,
                        Code      = class3Code,
                        EName     = family.Ename,
                        AName     = family.Aname,
                        TblClass2 = class2MaxIserial,
                    });
                }
                else
                {
                    class3MaxIserial = class3Row.ISerial;
                }

                var class4Row = context.TblCLASS4.FirstOrDefault(x => x.Code == class4Code);

                if (class4Row == null)
                {
                    class4Row = (new TblCLASS4
                    {
                        ISerial = class4MaxIserial,
                        Code = class4Code,
                        Ename = subFamily.Ename,
                        Aname = subFamily.Aname,
                        TblClass3 = class3MaxIserial,
                    });
                    context.TblCLASS4.AddObject(class4Row);
                }

                context.SaveChanges();

                return(class4Row.ISerial);
            }
        }