Exemple #1
0
 public bool deleteBranchImport(string id)
 {
     db = new CMART1Entities1();
     try
     {
         BranchImport             branchImport = db.BranchImports.Single(st => st.IDBranchImport.Equals(id));
         List <BranchImport_List> branchlist   = branchImport.BranchImport_List.ToList();
         foreach (BranchImport_List a in branchlist)
         {
             db.BranchImport_List.Remove(a);
         }
         db.BranchImports.Remove(branchImport);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #2
0
 public bool deleteHeadImport(string id)
 {
     db = new CMART1Entities1();
     try
     {
         HeadImport             headimport = db.HeadImports.Single(st => st.IDHeadImport.Equals(id));
         List <HeadImport_List> headlist   = headimport.HeadImport_List.ToList();
         foreach (HeadImport_List a in headlist)
         {
             db.HeadImport_List.Remove(a);
         }
         db.HeadImports.Remove(headimport);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #3
0
 public bool editPriceHT(int id, DateTime date, string price1, DateTime date1)
 {
     db = new CMART1Entities1();
     try
     {
         PriceHistory pricer = db.PriceHistories.Single(st => st.IDProduct.Equals(id) && st.Date.Equals(date));
         db.PriceHistories.Remove(pricer);
         PriceHistory priceht = new PriceHistory();
         float        b       = float.Parse(price1);
         priceht.IDProduct = id;
         priceht.Price     = b;
         priceht.Date      = date1;
         db.PriceHistories.Add(priceht);
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #4
0
        public bool editPromotion(string idPromotion, int idProduct, string price, string image, DateTime start, DateTime end, string content)
        {
            db = new CMART1Entities1();
            try
            {
                Promotion promotion = db.Promotions.Single(st => st.IDPromotion.Equals(idPromotion));
                promotion.IDProduct = idProduct;
                promotion.Price     = float.Parse(price);
                promotion.Image     = image;
                promotion.Contents  = content;
                promotion.StartDate = start;
                promotion.EndDate   = end;
                db.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #5
0
 public bool addBranchList(string idBI, int[] idpro, int[] quantity, string[] status)
 {
     db = new CMART1Entities1();
     try
     {
         for (int i = 0; i < quantity.Length; i++)
         {
             BranchImport_List branchList = new BranchImport_List();
             branchList.IDBranchImport = idBI;
             branchList.IDProduct      = idpro[i];
             branchList.Quantity       = quantity[i];
             branchList.Status         = status[i];
             db.BranchImport_List.Add(branchList);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #6
0
        public bool deletePromotion(string id, DataGridView list)
        {
            db = new CMART1Entities1();
            Promotion promotion;

            try
            {
                if (list.SelectedRows.Count == 1)
                {
                    var    row  = list.SelectedRows[0];
                    var    cell = row.Cells["IDPromotion"];
                    string idd  = (string)cell.Value;
                    promotion = db.Promotions.Single(st => st.IDPromotion == idd);
                    db.Promotions.Remove(promotion);
                    db.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemple #7
0
 public bool addHeadList(string idHI, int[] idpro, int[] quantity, double[] price, DateTime[] date, string[] status)
 {
     db = new CMART1Entities1();
     try
     {
         for (int i = 0; i < idpro.Length; i++)
         {
             HeadImport_List head = new HeadImport_List();
             head.IDHeadImport = idHI;
             head.IDProduct    = idpro[i];
             head.Quantity     = quantity[i];
             head.Status       = status[i];
             head.Price        = price[i];
             head.Expiration   = date[i];
             db.HeadImport_List.Add(head);
             db.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemple #8
0
        public bool addHeadImport(string idRe, DateTime date, float Total, string IDAcc, int[] idpro, int[] quantity, double[] price, DateTime[] dateti, string[] status)
        {
            db = new CMART1Entities1();
            HeadImport        Head = null;
            List <HeadImport> lst  = db.HeadImports.ToList();

            foreach (HeadImport he in lst)
            {
                Head = he;
            }
            if (Head != null)
            {
                int    t     = int.Parse(Head.IDHeadImport.Substring(8, 3)) + 1;
                string Month = date.Month.ToString();
                string Date  = date.Day.ToString();
                if (Month.Length < 2)
                {
                    Month = "0" + Month;
                }
                if (Date.Length < 2)
                {
                    Date = "0" + Date;
                }
                string idnew = date.Year.ToString() + Month + Date;
                idnew = "HI" + idnew.Substring(2, 6);
                if (idnew == Head.IDHeadImport.Substring(0, 8))
                {
                    for (int i = t.ToString().Length; i < 3; i++)
                    {
                        idnew = idnew + "0";
                    }
                    idnew = idnew + t;
                }
                else
                {
                    idnew = idnew + "001";
                }
                HeadImport head = new HeadImport();
                try
                {
                    head.IDrequestImport = idRe;
                    head.IDHeadImport    = idnew;
                    head.IDAcc           = IDAcc;
                    head.HeadDate        = date;
                    head.TotalAmount     = Total;
                    db.HeadImports.Add(head);
                    db.SaveChanges();
                    addHeadList(idnew, idpro, quantity, price, dateti, status);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                HeadImport head  = new HeadImport();
                string     Month = date.Month.ToString();
                string     Date  = date.Day.ToString();
                if (Month.Length < 2)
                {
                    Month = "0" + Month;
                }
                if (Date.Length < 2)
                {
                    Date = "0" + Date;
                }
                string idnew = date.Year.ToString() + Month + Date;
                idnew = "HI" + idnew.Substring(2, 6) + "001";
                try
                {
                    head.IDrequestImport = idRe;
                    head.IDHeadImport    = idnew;
                    head.IDAcc           = IDAcc;
                    head.HeadDate        = date;
                    head.TotalAmount     = Total;
                    db.HeadImports.Add(head);
                    db.SaveChanges();
                    addHeadList(idnew, idpro, quantity, price, dateti, status);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemple #9
0
        public bool addBill(string id, DateTime date, string totalAmount, string Recieved, string returned, int totalQuantity, string POS, string IDAcc, int[] idpro, string[] quantity, string[] unitprice)
        {
            db = new CMART1Entities1();
            Bill        billl = null;
            List <Bill> lst   = db.Bills.ToList();

            foreach (Bill bi in lst)
            {
                billl = bi;
            }
            if (billl != null)
            {
                int    t     = int.Parse(id.Substring(6, 6)) + 1;
                string Month = date.Month.ToString();
                string Date  = date.Day.ToString();
                if (Month.Length < 2)
                {
                    Month = "0" + Month;
                }
                if (Date.Length < 2)
                {
                    Date = "0" + Date;
                }
                string idnew = date.Year.ToString() + Month + Date;
                idnew = idnew.Substring(2, 6);
                if (idnew == id.Substring(0, 6))
                {
                    for (int i = t.ToString().Length; i < 6; i++)
                    {
                        idnew = idnew + "0";
                    }
                    idnew = idnew + t;
                }
                else
                {
                    idnew = idnew + "000001";
                }
                Bill bill = new Bill();
                try
                {
                    bill.IDBill        = idnew;
                    bill.BillDate      = date;
                    bill.TotalAmount   = totalAmount;
                    bill.TotalQuantity = totalQuantity;
                    bill.Recieved      = Recieved;
                    bill.Returned      = returned;
                    bill.POS           = POS;
                    bill.IDAcc         = IDAcc;
                    db.Bills.Add(bill);
                    db.SaveChanges();
                    addBillList(idnew, idpro, quantity, unitprice);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                Bill   bill  = new Bill();
                string Month = date.Month.ToString();
                string Date  = date.Day.ToString();
                if (Month.Length < 2)
                {
                    Month = "0" + Month;
                }
                if (Date.Length < 2)
                {
                    Date = "0" + Date;
                }
                string idnew = date.Year.ToString() + Month + Date;
                idnew = idnew.Substring(2, 6);
                idnew = idnew + "000001";
                try
                {
                    bill.IDBill        = idnew;
                    bill.BillDate      = date;
                    bill.TotalAmount   = totalAmount;
                    bill.TotalQuantity = totalQuantity;
                    bill.Recieved      = Recieved;
                    bill.Returned      = returned;
                    bill.POS           = POS;
                    bill.IDAcc         = IDAcc;
                    db.Bills.Add(bill);
                    db.SaveChanges();
                    addBillList(idnew, idpro, quantity, unitprice);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
Exemple #10
0
        public bool addPromotion(int idProduct, float price, string image, DateTime start, DateTime end, string content)
        {
            db = new CMART1Entities1();
            Promotion        promotion  = new Promotion();
            List <Promotion> lst        = db.Promotions.ToList();
            Promotion        promotion1 = null;

            foreach (Promotion a in lst)
            {
                promotion1 = a;
            }
            if (promotion1 != null)
            {
                string idold    = promotion1.IDPromotion;
                int    changeID = int.Parse(idold.Substring(1, 6)) + 1;
                string idnew    = "P";
                for (int i = changeID.ToString().Length; i < 6; i++)
                {
                    idnew = idnew + "0";
                }
                idnew = idnew + changeID.ToString();

                try
                {
                    promotion.IDPromotion = idnew;
                    promotion.IDProduct   = idProduct;
                    promotion.Price       = price;
                    promotion.Image       = image;
                    promotion.Contents    = content;
                    promotion.StartDate   = start;
                    promotion.EndDate     = end;
                    db.Promotions.Add(promotion);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                try
                {
                    promotion.IDPromotion = "P000001";
                    promotion.IDProduct   = idProduct;
                    promotion.Price       = price;
                    promotion.Image       = image;
                    promotion.Contents    = content;
                    promotion.StartDate   = start;
                    promotion.EndDate     = end;
                    db.Promotions.Add(promotion);
                    db.SaveChanges();
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }
        public bool addBranchImport(string idHI, DateTime date, int branch, string IDAcc, int[] idpro, int[] quantity, string[] status)
        {
            db = new CMART1Entities1();
            BranchImport        bran = null;
            List <BranchImport> lst  = db.BranchImports.ToList();

            foreach (BranchImport b in lst)
            {
                bran = b;
            }
            if (bran != null)
            {
                int    t     = int.Parse(bran.IDBranchImport.Substring(8, 3)) + 1;
                string Month = date.Month.ToString();
                string Date  = date.Day.ToString();
                if (Month.Length < 2)
                {
                    Month = "0" + Month;
                }
                if (Date.Length < 2)
                {
                    Date = "0" + Date;
                }
                string idnew = date.Year.ToString() + Month + Date;
                idnew = "BI" + idnew.Substring(2, 6);
                if (idnew == bran.IDBranchImport.Substring(0, 8))
                {
                    for (int i = t.ToString().Length; i < 3; i++)
                    {
                        idnew = idnew + "0";
                    }
                    idnew = idnew + t;
                }
                else
                {
                    idnew = idnew + "001";
                }
                BranchImport branchImport = new BranchImport();
                try
                {
                    branchImport.IDBranchImport = idnew;
                    branchImport.IDHeadImport   = idHI;
                    branchImport.BranchDate     = date;
                    branchImport.Branch         = branch;
                    branchImport.IDAcc          = IDAcc;
                    db.BranchImports.Add(branchImport);
                    db.SaveChanges();
                    addBranchList(idnew, idpro, quantity, status);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
            else
            {
                BranchImport branchImport = new BranchImport();
                string       Month        = date.Month.ToString();
                string       Date         = date.Day.ToString();
                if (Month.Length < 2)
                {
                    Month = "0" + Month;
                }
                if (Date.Length < 2)
                {
                    Date = "0" + Date;
                }
                string idnew = date.Year.ToString() + Month + Date;
                idnew = "BI" + idnew.Substring(2, 6) + "001";
                try
                {
                    branchImport.IDBranchImport = idnew;
                    branchImport.IDHeadImport   = idHI;
                    branchImport.BranchDate     = date;
                    branchImport.Branch         = branch;
                    branchImport.IDAcc          = IDAcc;
                    db.BranchImports.Add(branchImport);
                    db.SaveChanges();
                    addBranchList(idnew, idpro, quantity, status);
                    return(true);
                }
                catch (Exception)
                {
                    return(false);
                }
            }
        }