//xóa hoặc giảm số lượng sản phẩm từ cart void DeleteCart() { string delete = (string)Request.Form["delete"]; ExportBill eb = (ExportBill)Session["cart"]; string rawDeleteId = (string)Request.Form["id"]; int deleteId = Convert.ToInt32(rawDeleteId); for (int i = 0; i < eb.Lines.Count; i++) { DetailExportBill detail = eb.Lines[i]; if (deleteId == detail.Product.Id) { if (detail.Quantity > 1) { detail.Quantity = (detail.Quantity - 1); detail.Discount = 0; } else { eb.Lines.RemoveAt(i); } break; } } Session["cart"] = eb; }
public void ViewDetailOrder() { string rawId = (string)Request.Form["id"]; int detailID = Convert.ToInt32(rawId); ExportBillDAO exDAO = new ExportBillDAO(); ExportBill ex = new ExportBill(); DetailExportBill de = new DetailExportBill(); Session["detailInfo"] = exDAO.GetExportBillByID(detailID); Session["detailOrder"] = exDAO.GetDetailExportBillByID(detailID); }
//thêm sản phẩm vào giỏ hàng void AddProductToCart() { string rawId = (string)Request.Form["productId"]; ExportBill eb = (ExportBill)Session["cart"]; if (eb == null) { eb = new ExportBill(); } int productId = Convert.ToInt32(rawId); pdao = new ProductDAO(); Product p = pdao.GetProductById(productId); int indexExisting = -1; for (int i = 0; i < eb.Lines.Count; i++) { DetailExportBill detail = eb.Lines[i]; if (p.Id == detail.Product.Id) { indexExisting = i; break; } } if (indexExisting != -1) { DetailExportBill detail = eb.Lines[indexExisting]; detail.Quantity = (detail.Quantity + 1); } else { DetailExportBill detail = new DetailExportBill(); detail.Product = p; detail.ExportBill = eb; detail.ToTalPrice = p.PriceSale; detail.Quantity = 1; detail.Discount = 0; eb.Lines.Add(detail); } Session["cart"] = eb; }