//ArrayList arr; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request.QueryString["id"] == null) { ViewCart(); } else { String proid = Request.QueryString["id"].ToString(); //ArrayList arr = new ArrayList();//(ArrayList)Session["Cart"]; ArrayList arr = (ArrayList)Session["Cart"]; objPro.proID = proid; String sname = objData.ProductName(objPro); double sprice = objData.ProductPrice(objPro); double stotal; bool availabe = false; try { foreach (SCartItems item in arr) { if (item.proID == proid) { item.quantity += 1; item.total = sprice * item.quantity; availabe = true; } } if (availabe == false) { int count = 1; stotal = sprice * count; SCartItems sitem = new SCartItems(proid, sname, count, sprice, stotal); arr.Add(sitem); Session["Cart"] = arr; } } catch (Exception ex) { MessageBox.Show("Your cart is empty."); } ViewCart(); // TotalBill(); } } }
public void AddItem(SCartItems item) { chose.Add(item); }
protected void Page_Load(object sender, EventArgs e) { Panel1.Visible = false; if (!IsPostBack) { if (Request.QueryString["id"] == null) { //ViewCart(); //TotalPay(); Response.Redirect("Home.aspx"); } else { String sID = Request.QueryString["id"].ToString(); objPro.proID = sID; ArrayList arr = null; if (Session["Cart"] != null) { arr = (ArrayList)Session["Cart"]; } else { arr = new ArrayList(); } String sName = objGetData.ProductName(objPro); double sPrice = objGetData.ProductPrice(objPro); double sTotal; bool available = false; try { foreach (SCartItems item in arr) { if (item.proID == sID) { item.quantity += 1; item.total = sPrice * item.quantity; available = true; } } if (available == false) { int sl = 1; sTotal = sPrice * sl; SCartItems item = new SCartItems(sID, sName, sl, sPrice, sTotal); arr.Add(item); } } catch (Exception ex) { MessageBox.Show(ex.Message); } Session["Cart"] = arr; ViewCart(); TotalPay(); } } }