protected void ItemsList_ItemCommand(object source, DataListCommandEventArgs e) { if (e.CommandName == "btnPurchase") { var ItemsInfo = e.CommandArgument.ToString().Split('^'); TextBox Qty = (TextBox)e.Item.FindControl("txtQuantity"); if (HttpContext.Current.Session["ShoppingCart"] == null) { var c = (string)HttpContext.Current.Session["Type"]; MemeberPrivilege m = (c == null) ? MemeberPrivilege.Standard : (MemeberPrivilege)HttpContext.Current.Session["Type"]; ShoppingCart d = ShoppingCart.getShoppingCart(m); HttpContext.Current.Session["ShoppingCart"] = d; d.AddItem(new OrderItem { Name = ItemsInfo[0], ProductNum = int.Parse(ItemsInfo[2]), ProductQty = int.Parse(Qty.Text), Price = decimal.Parse(ItemsInfo[1]) }); } else { ShoppingCart d = (ShoppingCart)HttpContext.Current.Session["ShoppingCart"]; d.AddItem(new OrderItem { Name = ItemsInfo[0], ProductNum = int.Parse(ItemsInfo[2]), ProductQty = int.Parse(Qty.Text), Price = decimal.Parse(ItemsInfo[1]) }); } } }
public static ShoppingCart getShoppingCart(MemeberPrivilege memberType) { int s = (int)memberType; switch (s) { case 1: return(new StdShoppingCart()); case 2: return(new SCShoppingCart()); case 3: return(new GCShoppingCart()); default: return(new StdShoppingCart()); } }