public void Luudonhang(Donhangtongquan a, string maKH, Giohang giohang)
        {
            try
            {
                using (Entities db = new Entities())
                {
                    DonHangKH dhkh = new DonHangKH();
                    dhkh.MaDH = RandomMa();
                    dhkh.MaKH = maKH;

                    dhkh.Diachi      = a.address;
                    dhkh.Dienthoai   = a.phoneNumber;
                    dhkh.Ghichu      = a.Note;
                    dhkh.NgayDatMua  = DateTime.Now;
                    dhkh.TinhTrangDH = 1;
                    if (giohang.Tinhtongtiensanpham() > 500000)
                    {
                        dhkh.PhiVanChuyen = 0;
                    }
                    else
                    {
                        dhkh.PhiVanChuyen = 30000;
                    }
                    dhkh.Tongtien = giohang.Tinhtongtiensanpham() + (double)dhkh.PhiVanChuyen;

                    dhkh = db.DonHangKHs.Add(dhkh);
                    db.SaveChanges();

                    Luuchitietdonhang(giohang, db, dhkh.MaDH);
                }
            }
            catch (Exception e) { }
        }
 internal void DeleteDH(string maDH)
 {
     using (Entities db = new Entities())
     {
         DonHangKH donhang = db.DonHangKHs.Find(maDH);
         db.DonHangKHs.Remove(donhang);
         db.SaveChanges();
     }
 }
 internal bool UpdateTinhTrang(string madh, int?tt)
 {
     if (tt == null)
     {
         return(false);
     }
     try
     {
         Entities  db = new Entities();
         DonHangKH dh = db.DonHangKHs.Find(madh);
         if (dh.TinhTrangDH == 4 || dh.TinhTrangDH == 3)
         {
             return(false);
         }
         if (dh.TinhTrangDH == 1)
         {
             if (tt == 2 || tt == 3)
             {
                 foreach (var item in dh.ChiTietDonHangs)
                 {
                     SanPhamModel spm = new SanPhamModel();
                     spm.UpdateSL(item.MaSP, item.SoLuong, false);
                 }
             }
         }
         if (dh.TinhTrangDH == 2)
         {
             if (tt == 4)
             {
                 foreach (var item in dh.ChiTietDonHangs)
                 {
                     SanPhamModel spm = new SanPhamModel();
                     spm.UpdateSL(item.MaSP, item.SoLuong, true);
                 }
             }
             if (tt == 1)
             {
                 return(false);
             }
         }
         string query = "update DonHangKH set TinhTrangDH = " + tt + " where MaDH ='" + madh + "'";
         db.Database.ExecuteSqlCommand(query);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }