public ActionResult DatHang() { //Thêm đơn hàng bill bill = new bill(); KhachHang kh = (KhachHang)Session["TaiKhoan"]; //if (Session["TaiKhoan"] == null) //{ // return RedirectToAction("DangNhap", "Home"); //} //if (Session["GioHang"] == null) //{ // RedirectToAction("Index", "Home"); //} List <GioHang> gh = LayGioHang(); bill.MaKH = kh.MaKH; bill.MaKH = kh.MaKH; bill.date_order = DateTime.Now; db.bills.Add(bill); db.SaveChanges(); // Them chi tiết đơn hàng foreach (var item in gh) { bill_detail bill_Detail = new bill_detail(); bill_Detail.id_bill = bill.id_bill; bill_Detail.id_product = item.id_product; bill_Detail.quantity = item.quantity; bill_Detail.unit_price = (int)item.unit_price; db.bill_detail.Add(bill_Detail); } db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
private void btnThemTrai_Click(object sender, EventArgs e) { //btnLuuCT.Enabled = true; if (gvSanPham.SelectedRowsCount == 0) { return; } product p = (product)gvSanPham.GetFocusedRow(); if (busHoaDon.KiemTraTonTai(b, p)) { XtraMessageBox.Show("Sản phẩm đã tồn tại!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); return; } bill_detail bd = new bill_detail(); bd.id = b.id + p.id; bd.created = DateTime.Now; bd.quantity = (int)spSoLuong.Value; bd.monetized = (int)(spSoLuong.Value * p.price); bd.product = p; bd.bill = b; b.bill_details.Add(bd); dgvChiTietHoaDon.DataSource = busHoaDon.GetProduct(b); }
public ActionResult pay(bill ttKhachHang) { ttKhachHang.create_date = DateTime.Now.Date; db = new ToysDBContext(); db.bills.Add(ttKhachHang); cart cart = (cart)Session["cart"]; foreach (CartItem item in cart.lstcart) { bill_detail detail = new bill_detail(); detail.bill_id = ttKhachHang.id; detail.product_id = item.Id_Product; detail.amount = item.Amount; detail.price = item.Amount * item.price; db.bill_detail.Add(detail); } int stt = db.SaveChanges(); string message = "Có lỗi khi đặt hàng!"; if (stt > 0) { message = "Đặt hàng thành công"; } Session["message"] = message; Session["Cart"] = null; return(RedirectToAction("Index", "Home")); }
public ActionResult Edit([Bind(Include = "product_id,bill_id,amount,price")] bill_detail bill_detail) { if (ModelState.IsValid) { db.Entry(bill_detail).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.bill_id = new SelectList(db.bills, "id", "id", bill_detail.bill_id); ViewBag.product_id = new SelectList(db.products, "id", "name", bill_detail.product_id); return(View(bill_detail)); }
private void btnXoaTrai_Click(object sender, EventArgs e) { if (gvChiTietHoaDon.GetFocusedRow() == null) { return; } bill_detail db = (bill_detail)gvChiTietHoaDon.GetFocusedRow(); if (busHoaDon.DeleteProduct(db)) { dgvChiTietHoaDon.DataSource = busHoaDon.GetProduct(b); } }
private void btnXoaTrai_Click(object sender, EventArgs e) { if (gvCTPhieuBaoGia.GetFocusedRow() == null) { return; } bill_detail db = (bill_detail)gvCTPhieuBaoGia.GetFocusedRow(); if (busHoaDon.Save()) { dgvCTPhieuBaoGia.DataSource = busHoaDon.GetProduct(b); } }
public bool Insert(bill_detail detail) { try { db.bill_detail.Add(detail); db.SaveChanges(); return(true); } catch { return(false); } }
public bool DeleteProduct(bill_detail bd) { try { db.bill_details.DeleteOnSubmit(bd); db.SubmitChanges(); return(true); } catch (Exception ex) { throw ex; } }
private void simpleButton1_Click(object sender, EventArgs e) { double TongTien = 0; double ThanhTien = 0; for (int i = 0; i < gvChiTietHoaDon.RowCount; i++) { bill_detail pp = (bill_detail)gvChiTietHoaDon.GetRow(i); TongTien += pp.monetized; } ThanhTien = TongTien + TongTien * 0.1; txtTongTien.Text = TongTien.ToString(); txtThanhToan.Text = ThanhTien.ToString(); }
private void btnThanhToan_Click(object sender, EventArgs e) { double TongTien = 0; double ThanhTien = 0; for (int i = 0; i < gvCTPhieuBaoGia.RowCount; i++) { bill_detail pp = (bill_detail)gvCTPhieuBaoGia.GetRow(i); TongTien += pp.monetized; } ThanhTien = TongTien + TongTien * 0.1; txtTongTien.Text = TongTien.ToString(); txtThanhToan.Text = ThanhTien.ToString(); }
// GET: Admin/bills/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } bill_detail bill_detail = db.bill_detail.Find(id); if (bill_detail == null) { return(HttpNotFound()); } return(View(bill_detail)); }
// GET: Admin/bills/Edit/5 public ActionResult Edit(int?bill_id) { if (bill_id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } bill_detail bill_detail = db.bill_detail.Find(bill_id); if (bill_detail == null) { return(HttpNotFound()); } ViewBag.bill_id = new SelectList(db.bills, "id", "id", bill_detail.bill_id); ViewBag.product_id = new SelectList(db.products, "id", "name", bill_detail.product_id); return(View(bill_detail)); }
public bool saveBillDetail(string Json) { try { JavaScriptSerializer jss = new JavaScriptSerializer(); bill_detail billdt = jss.Deserialize <bill_detail>(Json); DBShopDataContext db = new DBShopDataContext(); db.bill_details.InsertOnSubmit(billdt); db.SubmitChanges(); return(true); } catch (Exception ex) { return(false); } }
public bool AddBillDetail(bill_detail bill) { var succsess = false; try { db.bill_detail.Add(bill); db.SaveChanges(); succsess = true; } catch (Exception ex) { succsess = false; throw; } return(succsess); }
public ActionResult AddCustomer(customer customer) { if (ModelState.IsValid) { var dao = new CustomerDao(); var billDao = new BillDao(); var cart = Session[CartSession]; var listProduct = (List <CartItem>)cart; var dao_product = new ProductDao(); foreach (var item in listProduct) { var product = item.Product; var soluong = item.Quantity; dao_product.Editviewcount(product, soluong); } double tongtien = 0.0f; foreach (var item in listProduct) { if (item.Product.isSale) { tongtien += item.Quantity * item.Product.promotion_price.Value; } else { tongtien += item.Quantity * item.Product.unit_price.Value; } } customer.created_at = DateTime.Now; var idCustomer = dao.AddCustomer(customer); var bill = new bill() { created_at = DateTime.Now, date_order = DateTime.Now, id_customer = idCustomer, total = (float)tongtien, }; var idBill = billDao.AddBill(bill); foreach (var item in listProduct) { var billDetail = new bill_detail() { id_bill = (int)idBill, id_product = (int)item.Product.id, quantity = item.Quantity, unit_price = item.Product.isSale ? (float)item.Product.promotion_price : item.Product.unit_price, created_at = DateTime.Now }; billDao.AddBillDetail(billDetail); } return(RedirectToAction("Index", "Bill")); } else { ModelState.AddModelError("", "dang ky khong dung"); return(RedirectToAction("Index", "Bill")); } }