Esempio n. 1
0
        public ActionResult thanhtoanthanhcong(FormCollection frmTT, DON_DAT_HANG KH, CTDON_HANG CT)
        {
            KHACH_HANG kh = db.KHACH_HANG.Find(Session["KhachHang"]);

            KH.MaKH         = Convert.ToInt32(kh.MaKH);
            KH.TenKH        = frmTT["TenKH"];
            KH.Email        = kh.Email;
            KH.DiaChi       = frmTT["diachi"];
            KH.SDT          = Convert.ToInt32(frmTT["SDT"]);
            KH.NgayDatHang  = DateTime.Now;
            KH.NgayGiaoHang = DateTime.Now.AddDays(7);
            KH.TriGiaDH     = Convert.ToInt32(frmTT["tien"]);
            db.DON_DAT_HANG.Add(KH);
            db.SaveChanges();
            List <CartItem> listSP = laygiohang();

            foreach (var item in listSP)
            {
                CTDON_HANG ctdh = new CTDON_HANG();
                ctdh.MaDH    = KH.MaDH;
                ctdh.MaSP    = Convert.ToInt32(item.MaSPham);
                ctdh.SoLuong = item.SoLuong;
                ctdh.DonGia  = (decimal)item.GiaSP;


                SANPHAM sp = db.SANPHAMs.Single(n => n.MaSP == ctdh.MaSP);
                sp.SoLuong = sp.SoLuong - ctdh.SoLuong;
                db.SANPHAMs.Add(sp);
                db.CTDON_HANG.Add(ctdh);
                db.SaveChanges();
            }

            return(RedirectToAction("thanhtoanthanhcong", "GioHang"));
        }
Esempio n. 2
0
        public ActionResult deleteDonHang(int id)
        {
            CT_DON_HANG  dev = db.CT_DON_HANGs.SingleOrDefault(n => n.MaDH == id);
            DON_DAT_HANG don = db.DON_DAT_HANGs.SingleOrDefault(n => n.MaDH == id);

            if (dev == null || don == null)
            {
                Response.StatusCode = 404;
                return(null);
            }

            try
            {
                db.CT_DON_HANGs.DeleteOnSubmit(dev);
                db.DON_DAT_HANGs.DeleteOnSubmit(don);
            }
            catch (Exception e)
            {
                Response.Write(e.Message);
            }



            db.SubmitChanges();
            return(RedirectToAction("donHang"));
        }
Esempio n. 3
0
        public ActionResult Dathang(FormCollection collection)
        {
            KHACH_HANG kh = (KHACH_HANG)Session["Taikhoan"];

            //khach hang da dang nhap
            //luu cac thong tin
            //don dat hang
            //chi tiet don hang
            //thong tin nguoi nhan
            DON_DAT_HANG ddh = new DON_DAT_HANG();

            if (kh != null)
            {
                //luu tru don dat hang

                List <Giohang> gh = Laygiohang();
                ddh.MaKH   = kh.MaKH;
                ddh.NgayDH = DateTime.Now;
                var ngaygiao = String.Format("{0:MM/dd/yyyy}", collection["Ngaygiao"]);
                ddh.NgayGiao          = DateTime.Parse(ngaygiao);
                ddh.TinhTrangGiaoHang = false;
                ddh.DaThanhToan       = false;
                ddh.Name    = collection["name"];
                ddh.Phone   = collection["phone"];
                ddh.Address = collection["address"];
                ddh.Email   = collection["email"];
                db.DON_DAT_HANGs.InsertOnSubmit(ddh);
                db.SubmitChanges();
                int temp = db.DON_DAT_HANGs.ToList().Last().MaDH;
                //Them chi tiet don hang
                foreach (var item in gh)
                {
                    CT_DON_HANG ctdh = new CT_DON_HANG();

                    ctdh.MaDH     = temp;
                    ctdh.MaDevice = item.iMasach;
                    ctdh.SoLuong  = item.iSoluong;
                    ctdh.DonGia   = (decimal)item.dDongia;
                    db.CT_DON_HANGs.InsertOnSubmit(ctdh);
                }

                db.SubmitChanges();
                //ke ca co dang nhap va khong dang nhap
            }
            //neu khong dang nhap
            //luu thong tin dia chi nguoi nhan
            //don dat hang
            else
            {
                Response.Write("<script>alert('that bai')</script>");
            }


            return(RedirectToAction("Xacnhandonhang", "Giohang", new { sdt = ddh.Phone }));
        }
Esempio n. 4
0
 public ActionResult Edit([Bind(Include = "MaDH,MaKH,TenKH,DiaChi,SDT,Email,NgayDatHang,NgayGiaoHang,TriGiaDH,PTTT,HTGH,Dagiao")] DON_DAT_HANG dON_DAT_HANG)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dON_DAT_HANG).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("dondathang", "Quanly"));
     }
     ViewBag.MaKH = new SelectList(db.KHACH_HANG, "MaKH", "TenKH", dON_DAT_HANG.MaKH);
     return(View(dON_DAT_HANG));
 }
Esempio n. 5
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DON_DAT_HANG dON_DAT_HANG = db.DON_DAT_HANG.Find(id);

            if (dON_DAT_HANG == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaKH = new SelectList(db.KHACH_HANG, "MaKH", "TenKH", dON_DAT_HANG.MaKH);
            return(View(dON_DAT_HANG));
        }
Esempio n. 6
0
        public ActionResult checkOut(FormCollection collection)
        {
            //khach hang da dang nhap
            //luu cac thong tin
            //don dat hang
            //chi tiet don hang
            //thong tin nguoi nhan
            DON_DAT_HANG ddh = new DON_DAT_HANG();


            List <Giohang> gh = Laygiohang();

            ddh.MaKH   = 2;
            ddh.NgayDH = DateTime.Now;
            var ngaygiao = String.Format("{0:MM/dd/yyyy}", collection["Ngaygiao"]);

            ddh.NgayGiao          = DateTime.Parse(ngaygiao);
            ddh.TinhTrangGiaoHang = false;
            ddh.DaThanhToan       = false;
            ddh.Name    = collection["name"];
            ddh.Phone   = collection["phone"];
            ddh.Address = collection["address"];
            ddh.Email   = collection["email"];
            db.DON_DAT_HANGs.InsertOnSubmit(ddh);
            db.SubmitChanges();
            //Them chi tiet don hang
            foreach (var item in gh)
            {
                CT_DON_HANG ctdh = new CT_DON_HANG();
                int         temp = db.DON_DAT_HANGs.ToList().Last().MaDH;
                ctdh.MaDH     = ddh.MaDH;
                ctdh.MaDevice = item.iMasach;
                ctdh.SoLuong  = item.iSoluong;
                ctdh.DonGia   = (decimal)item.dDongia;
                db.CT_DON_HANGs.InsertOnSubmit(ctdh);
            }
            //ke ca co dang nhap va khong dang nhap
            try
            {
                db.SubmitChanges();
                Session["Giohang"] = null;
            }
            catch (Exception)
            {
            }

            return(RedirectToAction("Xacnhandonhang", "Giohang", new { email = ddh.Email }));
        }