public ActionResult DatHang(FormCollection collection) { //Them Don hang DATHANG ddh = new DATHANG(); KHACHHANG kh = (KHACHHANG)Session["Taikhoan"]; List <GioHang> gh = Laygiohang(); ddh.Makh = kh.Makh; ddh.Ngaydathang = DateTime.Now; var ngaygiao = String.Format("{0:MM/dd/yyyy}", collection["Ngaygiao"]); ddh.Ngaygiahang = (ngaygiao).ToString(); ddh.Dagiaohang = false; ddh.Dathanhtoan = false; data.DATHANGs.InsertOnSubmit(ddh); data.SubmitChanges(); //Them chi tiet don hang foreach (var item in gh) { CHITIETDATHANG ctdh = new CHITIETDATHANG(); ctdh.Madh = ddh.Madh; ctdh.Masp = item.iMasach; ctdh.Soluong = item.iSoluong; ctdh.Gia = (decimal)item.dDongia; data.CHITIETDATHANGs.InsertOnSubmit(ctdh); } data.SubmitChanges(); Session["GioHang"] = null; return(RedirectToAction("Xacnhandonhang", "GioHang")); }
public ActionResult Detail(int?SoHD) { { DATHANG DH = dbo.DATHANGs.SingleOrDefault(n => n.SoHD == SoHD); return(View(DH)); } }
public ActionResult DatHang(FormCollection collection) { DATHANG dh = new DATHANG(); KHACHHANG kh = (KHACHHANG)Session["Taikhoan"]; List <Giohang> gh = Laygiohang(); try { dh.NGAYLAP = DateTime.Now; dh.MAKH = kh.MAKH; dblayer.add_dh(dh); foreach (var item in gh) { CTDH ctdh = new CTDH(); ctdh.MADH = "1"; ctdh.MAHANGHOA = item.iMAHANGHOA; ctdh.SOLUONG = item.iSOLUONG; ctdh.DONGIA = (decimal)item.dDONGIABAN; ctdh.THANHTIEN = (decimal)item.dTHANHTIEN; dblayer.add_ctdh(ctdh); } } catch (Exception ex) { @ViewBag.Error = ex.Message; return(this.DatHang()); } Session["Giohang"] = null; return(RedirectToAction("Xacnhandonhang", "Giohang")); }
public ActionResult PaymentConfirm(string billID, string voucherID, string paymentMethod) { DATHANG dathang = db.DATHANGs.Find(billID); THANHTOAN found; DATHANG billInfo = (from bill in db.DATHANGs where bill.ID_DONHANG == billID select bill).SingleOrDefault(); var voucherInfo = (from system_voucher in db.VOUCHERs where system_voucher.MACODE == voucherID join loai_voucher in db.LOAIVOUCHERs on system_voucher.LOAIVOUCHER equals loai_voucher.MALOAIVOUCHER select new { mavoucher = system_voucher.MACODE, mucgia = loai_voucher.MUCGIA, giamtoida = loai_voucher.GIAMTOIDA, uudai = loai_voucher.UUDAI }).SingleOrDefault(); if (billInfo != null) { try { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); THANHTOAN toAdd = new THANHTOAN(); DONMUA toAddDonMua = new DONMUA(); THONGTINDONHANG toAddThongTinDonHang = new THONGTINDONHANG(); THONGTINVANCHUYEN toAddThongTinVanChuyen = new THONGTINVANCHUYEN(); toAdd.ID_DONHANG = billID; toAddDonMua.MADVVC = dathang.MADVVC; toAddDonMua.ID_DONHANG = dathang.ID_DONHANG; toAddThongTinDonHang.ID_DONHANG = dathang.ID_DONHANG; toAddThongTinDonHang.THOIGIAN = DateTime.Now; toAddThongTinDonHang.TINHTRANG_DH = "Chờ xác nhận"; toAddThongTinVanChuyen.TINHTRANG_VC = "Người bán đang chuẩn bị đơn hàng"; toAddThongTinVanChuyen.THOIGIAN = DateTime.Now; var total = billInfo.TONGTIEN; toAdd.SOTIENTT = (voucherInfo != null && total - voucherInfo.mucgia > 0) ? total - Math.Min(total * voucherInfo.uudai, voucherInfo.giamtoida) : total; toAdd.NGAYTHANHTOAN = DateTime.Now; do { toAdd.SO_THANHTOAN = new string(Enumerable.Repeat(chars, 10).Select(s => s[random.Next(s.Length)]).ToArray()); toAddThongTinVanChuyen.MADONVAN = new string(Enumerable.Repeat(chars, 10).Select(s => s[random.Next(s.Length)]).ToArray()); found = db.THANHTOANs.Where(x => x.SO_THANHTOAN == toAdd.SO_THANHTOAN).SingleOrDefault(); } while (toAdd.SO_THANHTOAN == "" || toAddThongTinVanChuyen.MADONVAN == "" || found != null); toAdd.UUDAI = voucherInfo.mavoucher; toAdd.HOANTIEN = billInfo.TONGTIEN - toAdd.SOTIENTT; toAdd.LOAITHANHTOAN = paymentMethod != "Thanh toán khi nhận hàng" ? "ONL" : "COD"; toAdd.LOAITTONLINE = toAdd.LOAITHANHTOAN == "COD" ? null : paymentMethod == "Ví Airpay" ? "VDT" : paymentMethod == "Thẻ tín dụng" ? "ATM" : "DEBIT"; db.THANHTOANs.Add(toAdd); db.SaveChanges(); } catch (Exception ex) { throw ex; } } return(RedirectToAction("Success", "Checkout")); }
public ActionResult Checkout(DIACHIGH model) { var giohang = GetGioHang(); if (giohang.Total_quantity() == 0) { ModelState.AddModelError("", "Gio Hang ko duoc de trong"); } if (ModelState.IsValid) { //DIACHIGIAOHANG var diachigh = new DIACHIGH() { HOTEN = model.HOTEN, SDT = model.SDT, SONHA = model.SONHA, PHUONG = model.PHUONG, QUAN = model.QUAN, //MAKHACHHANG = model. }; _db.DIACHIGHs.Add(diachigh); _db.SaveChanges(); //DATHANG var dathang = new DATHANG() { MADIACHI = diachigh.MADIACHI, NGAY = DateTime.Now, TONGTIEN = giohang.Total_money(), }; _db.DATHANGs.Add(dathang); _db.SaveChanges(); //CT DAT HANG var ctdathang = new List <CT_MONAN_DATHANG>(); foreach (var item in giohang.Items) { var detail = new CT_MONAN_DATHANG() { MAMONAN = item._monan.MAMONAN, MADATHANG = dathang.MADATHANG, SOLUONG = item._quantity, GIABAN = item._monan.GIABAN, }; ctdathang.Add(detail); } foreach (var detail in ctdathang) { _db.CT_MONAN_DATHANG.Add(detail); } _db.SaveChanges(); return(RedirectToAction("CheckoutSuccess")); } else { ModelState.AddModelError("", "Vui Long nhap du du lieu."); } return(View(model)); }
public IHttpActionResult PostDATHANGs(DATHANG dATHANG) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } dATHANG.madathang = "DH" + (db.DATHANGs.Count() + 1); db.DATHANGs.Add(dATHANG); try { db.SaveChanges(); } catch (DbUpdateException) { if (DATHANGExists(dATHANG.madathang)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = dATHANG.madathang }, dATHANG)); }
public IHttpActionResult PutDATHANG(string id, DATHANG dATHANG) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != dATHANG.madathang) { return(BadRequest()); } db.Entry(dATHANG).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!DATHANGExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Order() { if (Session["MaKhachHang"] == null || Session["TenDangNhap"] == null) { return(RedirectToAction("Signin", "User")); } if (Session["GioHang"] == null) { return(RedirectToAction("Index", "Home")); } Chitetdathang p = new Chitetdathang(); DATHANG DH = new DATHANG(); Khach_Hang KH = (Khach_Hang)Session["TaiKhoan"]; List <Cart> GH = getCart(); DH.Ma_KhachHang = KH.Ma_Khach_Hang; DH.NgayDatHang = DateTime.Now; DH.TenNguoiNhan = KH.HoKH + " " + KH.TenKH; if (DH.TenNguoiNhan == null) { DH.TenNguoiNhan = KH.TenDangNhap; } DH.SoDienThoai = Request["Sodienthoai"]; DH.DiaChiNhan = Request["DiachiNhan"]; DH.HinhThucThanhToan = Request["Hinhthucthanhtoan"]; DH.TriGia = TongTien(); dbo.DATHANGs.Add(DH); dbo.SaveChanges(); foreach (var item in GH) { CTDATHANG CTDH = new CTDATHANG(); CTDH.SoHD = item.SoHD; CTDH.SoHD = DH.SoHD; CTDH.MaHangHoa = item.Ma_Sach; CTDH.SoLuong = item.SoLuong; CTDH.DonGia = (decimal)item.DonGia; CTDH.ThanhTien = (decimal)item.ThanhTien; Sach sl = dbo.Saches.Find(item.Ma_Sach); sl.SoLuongTon = sl.SoLuongTon - item.SoLuong; sl.SoLuongBan = 0; sl.SoLuongBan = sl.SoLuongBan + item.SoLuong; if (sl.SoLuongTon >= 0) { dbo.Entry(sl).State = EntityState.Modified; } else { sl.SoLuongTon = 0; ViewBag.sltErr = sl.SoLuongTon; dbo.Entry(sl).State = EntityState.Modified; } dbo.CTDATHANGs.Add(CTDH); } dbo.SaveChanges(); Session["GioHang"] = null; return(RedirectToAction("Index", "Home")); }
public void DonePaymentByWarehouse(string madonhang) { QLQuanAoDBContent db = new QLQuanAoDBContent(); DATHANG dathang = db.DATHANGs.SingleOrDefault(x => x.MaDonHang == madonhang); dathang.statusID = 3; db.SaveChanges(); }
// GET: CTVDonHang/Edit/5 public ActionResult Edit(int id) { if (Session["TenTK_CTV"] == null) { return(RedirectToAction("DangNhap", "CTVTaiKhoan")); } DATHANG ctv = data.DATHANGs.SingleOrDefault(i => i.ID_DatHang == id); return(View(ctv)); }
public ActionResult fillFormCustomer(string id, bool Accumulated) { List <ProductCart> productCarts = GetProductCarts(); var strimId = id.Trim(','); var listHadCheck = strimId.Split(',').Select(int.Parse).ToList(); //lấy ra sản phẩm trong giỏ hàng từ các sản phẩm đã chọn var products = productCarts.Where(x => listHadCheck.Contains(x.Id_SanPham)); // tổng tiền trong giổ hàng var sumTotal = products.Sum(x => x.soluong * x.giagiam); var customerlogin = SessionUser.GetSession(); var customer = db.KHACHHANGs.Where(x => x.Id_KhachHang == customerlogin.Id).FirstOrDefault(); var address = db.DIACHIs.Where(x => x.Id_KhachHang == customer.Id_KhachHang && x.TrangThai == true).FirstOrDefault(); DATHANG orderForm = new DATHANG { NgayDat = DateTime.Now, TrangThai = 1, DiaChiGiao = address.DiaChi, SoDienThoai = address.SoDienThoai, Id_KhachHang = customer.Id_KhachHang, TenNguoiNhan = address.TenKhachHang, // 50 tiền ship TongTien = sumTotal + 50 }; var aNewOder = db.DATHANGs.Add(orderForm); orderForm.Id_DatHang = aNewOder.Id_DatHang; // nếu nó có check thì lưu thêm cột giảm giá if (Accumulated == true) { orderForm.TongTienSauGiamGia = orderForm.TongTien - (double.Parse(customer.DiemTichLuy.ToString()) * 1000); orderForm.DiemTichLuy = customer.DiemTichLuy; customer.DiemTichLuy = 0; db.Entry(customer).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } foreach (var product in products) { CHITIETDATHANG detailOrder = new CHITIETDATHANG(); detailOrder.Id_DatHang = aNewOder.Id_DatHang; detailOrder.Id_SanPham = product.Id_SanPham; detailOrder.SoLuong = product.soluong; detailOrder.GiaBan = product.giagiam; detailOrder.ThanhTien = product.soluong * product.giagiam; detailOrder.TrangThai = true; db.CHITIETDATHANGs.Add(detailOrder); } db.SaveChanges(); return(RedirectToAction("succesBill", "PayForBill", new { idDatHang = orderForm.Id_DatHang })); }
public void add_dh(DATHANG dh) { SqlCommand com = new SqlCommand("sp_ThemDatHang", con); com.CommandType = CommandType.StoredProcedure; com.Parameters.AddWithValue("@NGAYLAP", dh.NGAYLAP); com.Parameters.AddWithValue("@MAKH", dh.MAKH); con.Open(); com.ExecuteNonQuery(); con.Close(); }
public IHttpActionResult GetDATHANG(string id) { DATHANG dATHANG = db.DATHANGs.Find(id); if (dATHANG == null) { return(NotFound()); } return(Ok(dATHANG)); }
//Cập nhật số lượng tồn private void UpdateSLTon(DATHANG datHang) { var chiTiets = datHang.CHITIETDATHANGs.Where(x => x.TrangThai != false).ToList(); foreach (var chiTiet in chiTiets) { int sl = chiTiet.SoLuong; int slTon = chiTiet.SANPHAM.SoLuongTon ?? 0; chiTiet.SANPHAM.SoLuongTon = slTon - sl; } }
public ActionResult Edit(DATHANG dh, FormCollection collection) { DATHANG ctv = data.DATHANGs.SingleOrDefault(i => i.ID_DatHang == dh.ID_DatHang); ctv.DaThanhToan = dh.DaThanhToan; ctv.TinhTrangGiao = dh.TinhTrangGiao; { UpdateModel(ctv); data.SubmitChanges(); } return(RedirectToAction("Index")); }
public IHttpActionResult DeleteDATHANG(string id) { DATHANG dATHANG = db.DATHANGs.Find(id); if (dATHANG == null) { return(NotFound()); } db.DATHANGs.Remove(dATHANG); db.SaveChanges(); return(Ok(dATHANG)); }
public List <XuatKhoDHvaCTDT> getListDatHangVaCTDH() { QLQuanAoDBContent db = new QLQuanAoDBContent(); DATHANG dh = new DATHANG(); DATHANGCHITIET dhct = new DATHANGCHITIET(); List <XuatKhoDHvaCTDT> list = new List <XuatKhoDHvaCTDT>(); List <DATHANG> listDH = db.DATHANGs.Where(x => x.statusID == 2).ToList(); List <DATHANGCHITIET> listDHCT = db.DATHANGCHITIETs.ToList(); return(db.DATHANGCHITIETs.Where(x => x.DATHANG.statusID == 2).Select(x => new XuatKhoDHvaCTDT { MaDH = x.DATHANG.MaDonHang, TenHangHoa = x.SANPHAM.tenSanPham, tenKH = x.DATHANG.TenKhachHang, SDT = x.DATHANG.SoDienThoai, DiaChi = x.DATHANG.DiaChi, Sluong = (int)x.SoLuong }).ToList()); }
public bool UpdateDHKH(DatHangKHViewModel model) { DATHANG datHang = context.DATHANGs.FirstOrDefault(t => t.Id_DatHang == model.MaDatHang && t.TrangThai == 1); if (datHang == null) { return(false); } datHang.DiaChiGiao = model.DiaChiGiao; datHang.SoDienThoai = model.SoDienThoai; context.SaveChanges(); return(true); }
public bool DeleteDatHangKH(int maDatHang) { DATHANG datHangExist = context.DATHANGs.FirstOrDefault(t => t.TrangThai == 1 && t.Id_DatHang == maDatHang); if (datHangExist == null) { return(false); } datHangExist.TrangThai = 0; if (datHangExist.DiemTichLuy != null || datHangExist.DiemTichLuy != 0) { datHangExist.KHACHHANG.DiemTichLuy += datHangExist.DiemTichLuy; } context.SaveChanges(); return(true); }
public ActionResult Huy(int?id) { if (id == null) { return(RedirectToAction("Index")); } DATHANG dathang = _db.DATHANGs.Find(id); if (dathang.TRANGTHAI == 1) { dathang.TRANGTHAI = 3; } _db.Entry(dathang).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); }
public void ThemShoppingCheque(string ten, string diachi, string sdt, string manv) { QLQuanAoDBContent db = new QLQuanAoDBContent(); DATHANG order = new DATHANG(); order.DatHangID = getNextIdOrDer(); order.DiaChi = diachi; order.MaDonHang = getNextMaDonHang(); order.MaNhanVien = manv; order.SoDienThoai = sdt; order.TenKhachHang = ten; order.statusID = 1; db.DATHANGs.Add(order); db.SaveChanges(); }
//Kiểm tra số lượng tồn private void KiemTraSLTon(DATHANG datHang) { var chiTiets = datHang.CHITIETDATHANGs.Where(x => x.TrangThai != false).ToList(); foreach (var chiTiet in chiTiets) { int sl = chiTiet.SoLuong; int slTon = chiTiet.SANPHAM.SoLuongTon ?? 0; if (sl > slTon) { throw new Exception("Số lượng sản phẩm " + chiTiet.SANPHAM.TenSanPham + " không đủ cung cấp"); } //chiTiet.SANPHAM.SoLuongTon = slTon - sl; } }
public void Add(DatHangKHViewModel model) { var dathang = new DATHANG { Id_DatHang = model.MaDatHang, Id_KhachHang = model.MaKhachHang, NgayDat = model.NgayDatHang, DiaChiGiao = model.DiaChiGiao, SoDienThoai = model.SoDienThoai, GhiChu = model.GhiChu, TongTien = model.TongTien, TrangThai = ConvertToTrangThaiInt(model.TrangThai) }; context.DATHANGs.Add(dathang); context.SaveChanges(); }
public void UpdateTrangThaiDonHang(int maDatHang) { DATHANG datHang = context.DATHANGs. Include(t => t.CHITIETDATHANGs). FirstOrDefault(t => t.Id_DatHang == maDatHang && t.TrangThai == 1); if (datHang == null) { return; } // kiem tra sl ton KiemTraSLTon(datHang); // update đặt hàng datHang.TrangThai = 2; //Xuất hoá đơn trạng thái ==2: dang giao datHang.NgayGiao = DateTime.Now; context.Entry(datHang).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); }
public ActionResult HoanTat(int?id) { if (id == null) { return(RedirectToAction("Index")); } //int temp = (int)Session["MAKH"]; DATHANG dathang = _db.DATHANGs.Find(id); if (dathang.TRANGTHAI == 1) { if (ModelState.IsValid) { var hoadon = new HOADON() { MADATHANG = dathang.MADATHANG, TONGTIEN = (double)dathang.TONGTIEN, NGAYGIO = dathang.NGAY, MAKHACHHANG = (int)Session["MAKH"] }; _db.HOADONs.Add(hoadon); _db.SaveChanges(); var mONAN_DATHANG = _db.CT_MONAN_DATHANG.Where(m => m.MADATHANG == id).ToList(); foreach (var item in mONAN_DATHANG) { var cthoadon = new CTHOADON() { MAHOADON = hoadon.MAHOADON, MADATHANG = item.MADATHANG, MAMONAN = item.MAMONAN, SOLUONG = item.SOLUONG, }; _db.CTHOADONs.Add(cthoadon); _db.SaveChanges(); } dathang.TRANGTHAI = 2; _db.Entry(dathang).State = EntityState.Modified; _db.SaveChanges(); } } return(RedirectToAction("Index")); }
public ActionResult ConfirmDelete(int?SoHD) { DATHANG DH = dbo.DATHANGs.SingleOrDefault(n => n.SoHD == SoHD); List <CTDATHANG> CTDH = dbo.CTDATHANGs.Where(n => n.SoHD == SoHD).ToList(); if (DH == null) { Response.StatusCode = 404; return(null); } foreach (var item in CTDH) { dbo.CTDATHANGs.Remove(item); } dbo.DATHANGs.Remove(DH); dbo.SaveChanges(); return(RedirectToAction("Order")); }
public ActionResult Payment(string billID, string voucherID) { DATHANG billInfo = (from bill in db.DATHANGs where bill.ID_DONHANG == billID select bill).SingleOrDefault(); var voucherInfo = (from system_voucher in db.VOUCHERs where system_voucher.MACODE == voucherID join loai_voucher in db.LOAIVOUCHERs on system_voucher.LOAIVOUCHER equals loai_voucher.MALOAIVOUCHER select new { mavoucher = system_voucher.MACODE, mucgia = loai_voucher.MUCGIA, giamtoida = loai_voucher.GIAMTOIDA, uudai = loai_voucher.UUDAI }).SingleOrDefault(); ViewBag.BILLINFO = billInfo; ViewBag.VOUCHERINFO = voucherInfo; return(View()); }
//update Không nhận hàng public bool UpdateTrangThaiKhongNhanHang(int maDatHang) { DATHANG datHang = context.DATHANGs. Include(t => t.CHITIETDATHANGs). FirstOrDefault(t => t.Id_DatHang == maDatHang && t.TrangThai == 2); if (datHang == null) { return(false); } // update đặt hàng datHang.TrangThai = 4; //Xuất hoá đơn trạng thái ==4: không nhận datHang.GhiChu = "Khách hàng không nhận sản phẩm"; if (datHang.DiemTichLuy != null || datHang.DiemTichLuy != 0) { datHang.KHACHHANG.DiemTichLuy += datHang.DiemTichLuy; datHang.DiemTichLuy = 0; } context.Entry(datHang).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); return(true); }
private void btnNhapHD_Click(object sender, RoutedEventArgs e) {// Xử lý btn nhập int test; ErrorNotice.Visibility = Visibility.Hidden; // khởi tạo lại trang thái notice error if (int.TryParse(txtBoxSoLuong.Text, out test) == true) { newOrder = new DATHANG() { MaSP = null, MaLoai = null, SoLuong = test, NgayDat = ngayDat, NgayNhan = ngayNhan, TenKH = txtBoxTenKH.Text, // Sdt = txtBoxSdtKH.Text, // TienThu = 0, MaEvent = null, DiaChi = txtBoxDiaChiKH.Text, // TraTruoc = 0, HinhThuc = cmbHinhThucThanhToan.SelectedIndex, GhiChu = txtBoxGhiChu.Text, }; // Cập nhật MaLoai if (cmbLoai.SelectedItem != null) { var t = (LOAI)cmbLoai.SelectedItem; newOrder.MaLoai = t.MaLoai; } else { ErrorNotice.Content = "*Vẫn chưa chọn loại sản phẩm"; ErrorNotice.Visibility = Visibility.Visible; return; } // Cập nhật MaSanPham if (cmbTenSP.SelectedItem != null) { var t = (SANPHAM)cmbTenSP.SelectedItem; newOrder.MaSP = t.MaSP; } else { ErrorNotice.Content = "*Vẫn chưa chọn sản phẩm"; ErrorNotice.Visibility = Visibility.Visible; return; } // Cập nhật tiền trả trước double temp = 0; if (double.TryParse(txtBoxTraTruoc.Text, out temp) == true) { newOrder.TraTruoc = temp; } else { ErrorNotice.Content = "*Định dạng số tiền trả trước không phù hợp"; ErrorNotice.Visibility = Visibility.Visible; return; } // Kiểm tra và cập nhật thông tin khách hàng if (txtBoxTenKH.Text == null || txtBoxSdtKH.Text == null || txtBoxDiaChiKH.Text == null || txtBoxTenKH.Text == "" || txtBoxSdtKH.Text == "" || txtBoxDiaChiKH.Text == "") { ErrorNotice.Content = "*Thông tin khách hàng không phù hợp"; ErrorNotice.Visibility = Visibility.Visible; return; } if (checkSoLuong(ref test) == true) { double donGia = double.Parse(txtBoxDonGia.Text); double TongTienThu = test * donGia; double luongTienGiam = 0; // Có sự kiện KHUYENMAI selected = (KHUYENMAI)cmbKhuyenMai.SelectedItem; int soLUongCanMua = 0; if (selected != null) { soLUongCanMua = selected.SoLuongCanMua.Value; if (test >= soLUongCanMua) { for (int i = 0; i < test / soLUongCanMua; i++) { luongTienGiam += ((100 - selected.PhanTram.Value) * 1.0 / 100) * soLUongCanMua * donGia; } } } TongTienThu -= luongTienGiam; // Cập nhật giao diện txtBoxTienGiam.Text = luongTienGiam.ToString(); txtBoxThanhTien.Text = TongTienThu.ToString(); // Cập nhật newBill if (selected != null) { newOrder.MaEvent = selected.MaKM; } else { newOrder.MaEvent = null; } newOrder.TienThu = TongTienThu; // Kết thúc quá trình làm hóa đơn, hiển thị cho người quản lý xem Man_che.Visibility = Visibility.Visible; btnNhapHD.Visibility = Visibility.Hidden; lblHeader.Content = "XEM LẠI HÓA ĐƠN"; } else { // Do nothing } } else { ErrorNotice.Content = "*Định dạng số lượng không phù hợp"; ErrorNotice.Visibility = Visibility.Visible; return; } }
public ActionResult CheckoutProduct(string productID, string shipping, string voucherID) { var account = Session["account"] as TAIKHOANDANGNHAP; var newCheckout = ""; try { const string chars = "0123456789"; DATHANG toAdd = new DATHANG(); DONHANG toAddDonHang = new DONHANG(); var voucherInfo = (from system_voucher in db.VOUCHERs where system_voucher.MACODE == voucherID join loai_voucher in db.LOAIVOUCHERs on system_voucher.LOAIVOUCHER equals loai_voucher.MALOAIVOUCHER select new { mucgia = loai_voucher.MUCGIA, giamtoida = loai_voucher.GIAMTOIDA, uudai = loai_voucher.UUDAI }).SingleOrDefault(); List <DATHANG> found; Random random = new Random(); toAdd.NGUOIMUA = account.ID_THANHVIEN; do { toAdd.ID_DONHANG = new string(Enumerable.Repeat(chars, 10).Select(s => s[random.Next(s.Length)]).ToArray()); toAddDonHang.ID_DONHANG = toAdd.ID_DONHANG; found = db.DATHANGs.Where(x => x.ID_DONHANG == toAdd.ID_DONHANG).ToList(); if (found.Count == 0) { break; } } while (toAdd.ID_DONHANG != ""); toAdd.NGAYDAT = DateTime.Now; var currentItem = (from GH in db.GIOHANGs where GH.ID_NGUOIMUA == account.ID_THANHVIEN && GH.MAHANGHOA == productID join HH in db.HANGHOAs on GH.MAHANGHOA equals HH.MAHANGHOA select new { id_hh = HH.MAHANGHOA, gianhang = HH.MAGIANHANG, ten = HH.TENHANGHOA, giathanh = HH.GIATHANH, soluong = GH.SOLUONG }).SingleOrDefault(); toAdd.TONGTIEN = currentItem.giathanh * currentItem.soluong; toAdd.GIANHANG = currentItem.gianhang; toAdd.MADVVC = shipping; toAddDonHang.MASANPHAM = currentItem.id_hh; toAddDonHang.SOLUONG = currentItem.soluong; toAddDonHang.DONGIA = currentItem.giathanh; db.DATHANGs.Add(toAdd); db.DONHANGs.Add(toAddDonHang); db.SaveChanges(); newCheckout = toAdd.ID_DONHANG; } catch (Exception ex) { throw ex; } return(RedirectToAction("Payment", "Checkout", new { billID = newCheckout, voucher = voucherID })); }