public ActionResult DatHang(FormCollection collection)
        {
            DonDatHang     ddh         = new DonDatHang();
            KhachHang      kh          = (KhachHang)Session["TaiKhoan"];
            List <GioHang> listGioHang = LayGioHang();

            ddh.MaKhachHang = kh.MaKhachHang;
            ddh.NgayDatHang = DateTime.Now;
            var ngaygiao = String.Format("{0:MM/dd/yyyy}", collection["NgayGiao"]);

            ddh.NgayGiaoHang      = DateTime.Parse(ngaygiao);
            ddh.TinhTrangGiaoHang = false;
            ddh.DatThanhToan      = false;
            data.DonDatHangs.InsertOnSubmit(ddh);

            data.SubmitChanges();

            foreach (var item in listGioHang)
            {
                ChiTietDatHang ctdh = new ChiTietDatHang();
                ctdh.MaDonHang = ddh.MaDonHang;
                ctdh.MaSach    = item.iMaSach;
                ctdh.SoLuong   = item.iSoLuong;
                ctdh.DonGia    = (decimal)item.dDonGia;
                data.ChiTietDatHangs.InsertOnSubmit(ctdh);
            }
            data.SubmitChanges();
            Session["GioHang"] = null;


            return(RedirectToAction("XacNhanDonHang", "GioHang"));
        }
Example #2
0
        public ActionResult DatHang(FormCollection collection)
        {
            DonHang        ddh = new DonHang();
            KhachHang      kh  = (KhachHang)Session["UserName"];
            List <Giohang> gh  = Laygiohang();

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

            ddh.NgayGiao      = DateTime.Parse(ngaygiao);
            ddh.TinhTrangGiao = false;
            ddh.DaThanhToan   = false;
            db.DonHangs.InsertOnSubmit(ddh);
            db.SubmitChanges();
            //them chi tiet don hang
            foreach (var item in gh)
            {
                ChiTietDatHang ctdh = new ChiTietDatHang();
                ctdh.IdDonHang = ddh.IdDonHang;
                ctdh.IdWatch   = item.iIdDongho;
                ctdh.Number    = item.iSoluong;
                ctdh.Cost      = (decimal)item.dDongia;
                db.ChiTietDatHangs.InsertOnSubmit(ctdh);
            }
            db.SubmitChanges();
            Session["Giohang"] = null;
            return(RedirectToAction("Xacnhandonhang", "Giohang"));
        }
        public bool ChiTietDatHang_Update(ChiTietDatHang Data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("sp_ChiTietDatHang_Update", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@id_hoadon", Data.Id_hoadon));
                    dbCmd.Parameters.Add(new SqlParameter("@id_hang", Data.Id_hang));
                    dbCmd.Parameters.Add(new SqlParameter("@SoLuongMua", Data.SoLuongMua));
                    dbCmd.Parameters.Add(new SqlParameter("@ThanhTien", Data.ThanhTien));
                    dbCmd.Parameters.Add(new SqlParameter("@Size", Data.Size));
                    dbCmd.Parameters.Add(new SqlParameter("@Gia", Data.Gia));



                    dbCmd.ExecuteNonQuery();
                }
                //Clear cache
                System.Web.HttpContext.Current.Cache.Remove("ChiTietDatHang");
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #4
0
 public ActionResult DatHang(FormCollection collection)
 {
     DatHang ddh = new DatHang();            
     TaiKhoan tk = (TaiKhoan)Session["Username"];
     List<GioHang> gh = LayGioHang();
     ddh.IDUser = tk.IDUser;
     ddh.ThoiGianDatHang = DateTime.Now;            
     ddh.DaGiaoHang = false;
     var diachigiaohang = collection["DiaChiGiaoHang"];            
         ddh.DiaChiGiaoHang = diachigiaohang;
     double iTongTien = 0;           
     List<GioHang> lstGiohang = Session["GioHang"] as List<GioHang>;
     if (lstGiohang != null)
     {
         iTongTien = lstGiohang.Sum(n => n.dThanhTien);
     }
     ddh.ThanhTien = decimal.Parse( iTongTien.ToString());
     data.DatHangs.InsertOnSubmit(ddh);
         data.SubmitChanges();            
     foreach (var item in gh)
         {
             ChiTietDatHang ctdn = new ChiTietDatHang();
             ctdn.ID = ddh.ID;
             
             ctdn.IDThucDon = item.iIDThucDon;
             ctdn.SoLuong = item.iSoLuong;  
             data.ChiTietDatHangs.InsertOnSubmit(ctdn);
         }            
         data.SubmitChanges();
         Session["GioHang"] = null;
         return RedirectToAction("Xacnhandonhang", "GioHang");           
 }
Example #5
0
        public ActionResult CheckOut(FormCollection form)
        {
            // Add bill
            DonDatHang  bill     = new DonDatHang();
            KhachHang   customer = (KhachHang)Session["TaiKhoan"];
            List <Cart> cart     = GetCart();

            bill.MaKH   = customer.MaKH;
            bill.NgayDH = DateTime.Now;
            var deliveryDate = String.Format("{0:dd/MM/yyyy}", form["NgayGiao"]);

            bill.NgayGiao          = DateTime.Parse(deliveryDate);
            bill.TinhTrangGiaoHang = false;
            bill.DaThanhToan       = false;
            db.DonDatHangs.Add(bill);
            if (bill.MaKH > 0)
            {
                db.SaveChanges();
            }
            // Add details order
            foreach (var item in cart)
            {
                ChiTietDatHang orderDetails = new ChiTietDatHang();
                orderDetails.SoDH    = bill.SoDH;
                orderDetails.MaSach  = item.maSach;
                orderDetails.SoLuong = item.soLuong;
                orderDetails.DonGia  = (decimal)item.donGia;
                db.ChiTietDatHangs.Add(orderDetails);
            }
            db.SaveChanges();
            Session["Cart"] = null;
            return(RedirectToAction("ConfirmCart", "Cart"));
        }
 private void btnLuuTour_Click(object sender, EventArgs e)
 {
     using (DataClasses1DataContext data = new DataClasses1DataContext())
     {
         if (trangThai2 == "them")
         {
             string         maDH = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaDatHang").ToString();
             ChiTietDatHang ctdh = new ChiTietDatHang();
             ctdh.MaDatHang = int.Parse(maDH);
             ctdh.MaSoTour  = int.Parse(cboTour.EditValue.ToString());
             ctdh.SoLuongVe = int.Parse(txtSoLuongVe.Value.ToString());
             ctdh.ThanhTien = int.Parse(txtThanhTienTour.Text.ToString());
             data.ChiTietDatHangs.InsertOnSubmit(ctdh);
             data.SubmitChanges();
             loadDgvChiTietDatHangTheoMa(int.Parse(maDH));
             //ClearAll();
             MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             CapNhapTongThanhTien(int.Parse(maDH));
         }
         if (trangThai2 == "sua")
         {
             string         maDH   = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaDatHang").ToString();
             string         maTour = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "MaSoTour").ToString();
             ChiTietDatHang ctdh   = data.ChiTietDatHangs.Where(t => t.MaDatHang == int.Parse(maDH) && t.MaSoTour == int.Parse(maTour)).FirstOrDefault();
             ctdh.SoLuongVe = int.Parse(txtSoLuongVe.Value.ToString());
             ctdh.ThanhTien = int.Parse(txtThanhTienTour.Text);
             data.SubmitChanges();
             loadDgvChiTietDatHangTheoMa(int.Parse(maDH));
             //ClearAll();
             MessageBox.Show("Sửa thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             CapNhapTongThanhTien(int.Parse(maDH));
         }
     }
 }
Example #7
0
        public ActionResult DeleteConfirmed(string id)
        {
            ChiTietDatHang chiTietDatHang = db.ChiTietDatHangs.Find(id);

            db.ChiTietDatHangs.Remove(chiTietDatHang);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult payment(string shipName, string mobile, string address, string email)
        {
            var order = new DonDatHang();

            order.NgayDat        = DateTime.Now;
            order.DiaChiGiaoHang = address;
            order.SoDienThoai    = mobile;
            order.TenNguoiDat    = shipName;
            order.Email          = email;
            order.TrangThai      = 1;

            try
            {
                var     id        = new OrderDao().Insert(order);
                var     cart      = (List <CartItem>)Session[CommonConstants.CART_SEDSSION];
                var     detailDao = new OrderDetailDao();
                decimal total     = 0;
                foreach (var item in cart)
                {
                    var orderDetail = new ChiTietDatHang();
                    orderDetail.MaDon = id;
                    orderDetail.MaSP  = item.Product.MaSP;

                    if (item.Product.GiaKhuyenMai != null)
                    {
                        orderDetail.DonGia = item.Product.GiaKhuyenMai;
                    }
                    else
                    {
                        orderDetail.DonGia = item.Product.DonGia;
                    }

                    orderDetail.SoLuong = item.Quantity;
                    detailDao.Insert(orderDetail);

                    //total += (item.Product.DonGia.GetValueOrDefault(0) * item.Quantity);
                }
                Session[CommonConstants.CART_SEDSSION] = null;
                //string content = System.IO.File.ReadAllText(Server.MapPath("~/assets/client/template/neworder.html"));

                //content = content.Replace("{{CustomerName}}", shipName);
                //content = content.Replace("{{Phone}}", mobile);
                //content = content.Replace("{{Email}}", email);
                //content = content.Replace("{{Address}}", address);
                //content = content.Replace("{{Total}}", total.ToString("N0"));
                //var toEmail = ConfigurationManager.AppSettings["ToEmailAddress"].ToString();

                //new MailHelper().SendMail(email, "Đơn hàng mới từ Shop", content);
                //new MailHelper().SendMail(toEmail, "Đơn hàng mới từ Shop", content);
            }
            catch (Exception ex)
            {
                //ghi log
                return(Redirect("/loi-thanh-toan"));
            }
            return(Redirect("/hoan-thanh"));
        }
Example #9
0
        public ActionResult Suachitietdonhang(FormCollection f)
        {
            ChiTietDatHang ctdh = db.ChiTietDatHangs.First(d => d.IdDonHang == int.Parse(f["IdDonHang"]));

            if (ModelState.IsValid)
            {
                UpdateModel(ctdh);
                db.SubmitChanges();
            }
            return(RedirectToAction("QLDonhang"));
        }
Example #10
0
 public ActionResult Edit([Bind(Include = "SoHoaDon,MaSanPham,MaKhachHang,SoLuong,DonGia,ThanhTien,NgayDatHang,NgayGiaoHang")] ChiTietDatHang chiTietDatHang)
 {
     if (ModelState.IsValid)
     {
         db.Entry(chiTietDatHang).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaKhachHang = new SelectList(db.KhachHangs, "MaKhachHang", "TenKhachHang", chiTietDatHang.MaKhachHang);
     ViewBag.MaSanPham   = new SelectList(db.SanPhams, "MaSanPham", "TenSanPham", chiTietDatHang.MaSanPham);
     return(View(chiTietDatHang));
 }
Example #11
0
 public bool Them(ChiTietDatHang ctdhang)
 {
     try
     {
         db.ChiTietDatHangs.Add(ctdhang);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 public bool Insert(ChiTietDatHang orderDetail)
 {
     try
     {
         db.ChiTietDatHang.Add(orderDetail);
         db.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #13
0
        public ActionResult Create([Bind(Include = "SoHoaDon,MaSanPham,MaKhachHang,MaHoaDon,SoLuong,DonGia,ThanhTien,NgayDatHang,NgayGiaoHang")] ChiTietDatHang chiTietDatHang)
        {
            if (ModelState.IsValid)
            {
                db.ChiTietDatHangs.Add(chiTietDatHang);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.MaHoaDon    = new SelectList(db.DatHangs, "MaHoaDon", "MaKhachHang", chiTietDatHang.MaHoaDon);
            ViewBag.MaKhachHang = new SelectList(db.KhachHangs, "MaKhachHang", "TenKhachHang", chiTietDatHang.MaKhachHang);
            ViewBag.MaSanPham   = new SelectList(db.SanPhams, "MaSanPham", "TenSanPham", chiTietDatHang.MaSanPham);
            return(View(chiTietDatHang));
        }
Example #14
0
        // GET: Administrator/ChiTietDatHangs/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDatHang chiTietDatHang = db.ChiTietDatHangs.Find(id);

            if (chiTietDatHang == null)
            {
                return(HttpNotFound());
            }
            return(View(chiTietDatHang));
        }
Example #15
0
 public ActionResult Chitietdonhang(int id)
 {
     if (Session["Taikhoanadmin"] != null)
     {
         ChiTietDatHang ctdh = db.ChiTietDatHangs.SingleOrDefault(n => n.IdDonHang == id);
         if (ctdh == null)
         {
             Response.StatusCode = 404;
             return(null);
         }
         return(View(ctdh));
     }
     return(RedirectToAction("Login", "Admin"));
 }
Example #16
0
        public ActionResult DatHang(KhachHang kh)
        {
            if (Session["GioHang"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            KhachHang kh1 = new KhachHang();

            if (Session["ThanhVien"] == null)
            {
                kh1 = kh;
                db.KhachHang.Add(kh1);
            }
            else
            {
                ThanhVien tv = Session["ThanhVien"] as ThanhVien;
                kh1.TenKH     = tv.HoTen;
                kh1.DiaChi    = tv.DiaChi;
                kh1.DienThoai = tv.SoDienThoai;
                kh1.Email     = tv.Email;
                db.KhachHang.Add(kh1);
            }

            DatHang dh = new DatHang();

            dh.MaKH          = kh1.MaKH;
            dh.NgayDat       = DateTime.Now;
            dh.TinhTrangGiao = false;
            dh.DaThanhToan   = false;
            dh.UuDai         = 0;
            dh.DaHuy         = false;
            db.DatHang.Add(dh);

            List <itemGioHang> lstGH = LayGioHang();

            foreach (var item in lstGH)
            {
                ChiTietDatHang ctdh = new ChiTietDatHang();
                ctdh.MaDH    = dh.MaDH;
                ctdh.MaSP    = item.MaSP;
                ctdh.TenSP   = item.TenSP;
                ctdh.SoLuong = item.SoLuong;
                ctdh.DonGia  = item.DonGia;
                db.ChiTietDatHang.Add(ctdh);
            }
            db.SaveChanges();
            Session["GioHang"] = null;
            return(RedirectToAction("XemChiTiet"));
        }
Example #17
0
        // GET: Administrator/ChiTietDatHang/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ChiTietDatHang chiTietDatHang = db.ChiTietDatHangs.Find(id);

            if (chiTietDatHang == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaKhachHang = new SelectList(db.KhachHangs, "MaKhachHang", "TenKhachHang", chiTietDatHang.MaKhachHang);
            ViewBag.MaSanPham   = new SelectList(db.SanPhams, "MaSanPham", "TenSanPham", chiTietDatHang.MaSanPham);
            return(View(chiTietDatHang));
        }
 private void btnXoaTour_Click(object sender, EventArgs e)
 {
     using (DataClasses1DataContext data = new DataClasses1DataContext())
     {
         string         maDH   = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MaDatHang").ToString();
         string         maTour = gridView2.GetRowCellValue(gridView2.FocusedRowHandle, "MaSoTour").ToString();
         ChiTietDatHang ctdh   = data.ChiTietDatHangs.Where(t => t.MaDatHang == int.Parse(maDH) && t.MaSoTour == int.Parse(maTour)).FirstOrDefault();
         DialogResult   r;
         r = MessageBox.Show("Bạn có muốn xóa tour này khỏi đơn", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (r == DialogResult.Yes)
         {
             data.ChiTietDatHangs.DeleteOnSubmit(ctdh);
             data.SubmitChanges();
             loadDgvChiTietDatHangTheoMa(int.Parse(maDH));
             CapNhapTongThanhTien(int.Parse(maDH));
         }
     }
 }