Esempio n. 1
0
        public void Luudonhang(DonHangTongQuan a, long maKH, GioHang giohang)
        {
            try
            {
                using (Shopbanhang db = new Shopbanhang())
                {
                    DONHANG dhkh = new DONHANG();
                    dhkh.MADONHANG = RandomMa();
                    dhkh.MAKH      = maKH;

                    dhkh.DIACHI       = a.address;
                    dhkh.DIENTHOAI    = a.phoneNumber;
                    dhkh.GHICHU       = a.Note;
                    dhkh.NGAYDATMUA   = DateTime.Now;
                    dhkh.TINHTRANGDH  = 1;
                    dhkh.TONGTIEN     = giohang.Tinhtongtiensanpham();
                    dhkh.PHIVANCHUYEN = 0;

                    dhkh = db.DONHANGs.Add(dhkh);
                    db.SaveChanges();
                    Luuchitietdonhang(giohang, db, dhkh.MADONHANG);
                }
            }
            catch (Exception) { }
        }
Esempio n. 2
0
 public bool Updatetinhtrangdh(string madh, int?tt)
 {
     if (tt == null)
     {
         return(false);
     }
     try {
         Shopbanhang db = new Shopbanhang();
         DONHANG     dh = db.DONHANGs.Find(madh);
         if (dh.TINHTRANGDH == 4 || dh.TINHTRANGDH == 3)
         {
             return(false);
         }
         if (dh.TINHTRANGDH == 1)
         {
             if (tt == 2 || tt == 3)
             {
                 foreach (var item in db.CTDONHANGs)
                 {
                     SanphamModel sp = new SanphamModel();
                     sp.UpdateSoluong(item.MASP, item.SOLUONG, false);
                 }
             }
         }
         if (dh.TINHTRANGDH == 2)
         {
             if (tt == 4)
             {
                 foreach (var item in db.CTDONHANGs)
                 {
                     SanphamModel sp = new SanphamModel();
                     sp.UpdateSoluong(item.MASP, item.SOLUONG, false);
                 }
             }
             if (tt == 1)
             {
                 return(false);
             }
         }
         string query = "update DONHANG set TINHTRANGDH = " + tt + " where MADONHANG ='" + madh + "'";
         db.Database.ExecuteSqlCommand(query);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }