예제 #1
0
 public static bool UpdateCategory(string CategoryID, string CategoryName)
 {
     try
     {
         QuanLyBanHangEntities db = new QuanLyBanHangEntities();
         Category p = db.Categories.First(x => x.CategoryID == CategoryID);
         p.Name = CategoryName;
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #2
0
        public static bool DeleteProducts(string ID)
        {
            try
            {
                QuanLyBanHangEntities db = new QuanLyBanHangEntities();
                var itemToRemove         = db.Products.SingleOrDefault(x => x.ProductID == ID); //returns a single item.

                if (itemToRemove != null)
                {
                    db.Products.Remove(itemToRemove);
                    db.SaveChanges();
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
예제 #3
0
 public static bool CreateBill(List <Item> items, string CustomerName, string BillID, string Total, string tt, string CurrentCoupon = "")
 {
     try
     {
         // Insert into table Bill
         QuanLyBanHangEntities db = new QuanLyBanHangEntities();
         Bill ItemBill            = new Bill();
         ItemBill.Total        = Total;
         ItemBill.CustomerName = CustomerName;
         ItemBill.Bill_ID      = BillID;
         ItemBill.TrangThai    = tt;
         if (CurrentCoupon != "")
         {
             ItemBill.CouponID = CurrentCoupon;
             var dataset = db.Coupons.FirstOrDefault(x => x.CouponID == CurrentCoupon);
             dataset.SoLuong = dataset.SoLuong - 1;
         }
         DateTime today = DateTime.Today;
         ItemBill.Created_at = today;
         db.Bills.Add(ItemBill);
         // Insert into table BillInfo
         for (int i = 0; i < items.Count; i++)
         {
             BillInfo billInfo = new BillInfo();
             billInfo.Bill_ID   = BillID;
             billInfo.ProductID = items[i].ProductID;
             billInfo.Qty       = Int32.Parse(items[i].Qty);
             var dataset = db.Products.FirstOrDefault(x => x.ProductID == billInfo.ProductID);
             dataset.Quantity = dataset.Quantity - billInfo.Qty;
             db.BillInfoes.Add(billInfo);
         }
         int res = db.SaveChanges();
         if (res > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #4
0
 public static bool UpdateProducts(string Ten_SP, string ID_SP, string Gia_SP, string Loai_SP, int So_Luong)
 {
     try
     {
         QuanLyBanHangEntities db = new QuanLyBanHangEntities();
         var     dataset          = db.Categories.FirstOrDefault(x => x.Name == Loai_SP);
         Product p = db.Products.First(x => x.ProductID == ID_SP);
         p.Name       = Ten_SP;
         p.CategoryID = dataset.CategoryID;
         p.Cost       = Gia_SP;
         p.Quantity   = So_Luong;
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
예제 #5
0
 public static bool CreateCoupon(string ID, int phanTram, int soLuong)
 {
     try
     {
         QuanLyBanHangEntities db = new QuanLyBanHangEntities();
         Coupon coupon            = new Coupon();
         coupon.CouponID = ID;
         coupon.SoLuong  = soLuong;
         coupon.PhanTram = phanTram;
         db.Coupons.Add(coupon);
         int res = db.SaveChanges();
         if (res > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception)
     {
         return(false);
     }
 }
예제 #6
0
 public static bool AddCategory(string CategoryID, string Name)
 {
     try
     {
         QuanLyBanHangEntities db = new QuanLyBanHangEntities();
         Category category        = new Category();
         category.isDeleted  = "0";
         category.CategoryID = CategoryID;
         category.Name       = Name;
         db.Categories.Add(category);
         int res = db.SaveChanges();
         if (res > 0)
         {
             return(true);
         }
         return(false);
     }
     catch (Exception e)
     {
         return(false);
     }
 }