protected void Page_Load(object sender, EventArgs e) { //Check if logged in if (Session["UserID"] == null) { //Set a session variable to indicate return to checkout after login Session.Add("ReturnToCheckout", true); Response.Redirect("~/Login.aspx"); } if (!IsPostBack) { List <Tuple <string, int> > list = new List <Tuple <string, int> >(); if (Session["cartList"] != null) { list = (List <Tuple <string, int> >)(Session["cartList"]); } else { Response.Redirect("~/Index.aspx"); } //Collection that will be bound to the checkout datalist List <CheckoutItem> coItems = new List <CheckoutItem>(); foreach (Tuple <string, int> item in list) { CheckoutItem coItem = new CheckoutItem(); coItem.Prodcd = item.Item1; coItem.Quantity = item.Item2; //Get product info Product prod = new Product(); prod.GetProductByCode(item.Item1); coItem.Name = prod.Name.ToString(); coItem.Msrp = prod.Msrp; //Get all product delivery types ProductDeliveryType pdt = new ProductDeliveryType(); List <ProductDeliveryType> pdtypes = pdt.GetAllProductDeliveryTypesByProdCode(prod.ProductCode.ToString()); foreach (ProductDeliveryType pdtype in pdtypes) { DeliveryType dt = new DeliveryType(); dt.GetDeliveryTypeByID(pdtype.DeliveryTypeID); coItem.DeliveryTypes.Add(dt); } //Add checkout item to datasource list coItems.Add(coItem); } //Bind to the datalist DataListCheckout.DataSource = coItems; DataListCheckout.DataBind(); } }
protected void ButtonGoToPayInfo_Click(object sender, EventArgs e) { List <Hashtable> products_hshList = new List <Hashtable>(); foreach (DataListItem item in DataListCheckout.Items) { //This hashtable represents one row of the checkout datalist Hashtable hsh = new Hashtable(); CheckoutItem coItem = (CheckoutItem)item.DataItem; hsh.Add("prodcd", coItem.Prodcd); hsh.Add("quantity", coItem.Prodcd); hsh.Add("deliverytypeid", Convert.ToInt32(((DropDownList)(item.FindControl("DropDownListDeliveryType"))).SelectedValue)); //Add it to the list (which will be passed into session) products_hshList.Add(hsh); } //Go to next page Response.Redirect("~/PaymentInfo.aspx"); }
protected void Page_Load(object sender, EventArgs e) { //Check if logged in if (Session["UserID"] == null) { //Set a session variable to indicate return to checkout after login Session.Add("ReturnToCheckout", true); Response.Redirect("~/Login.aspx"); } if (!IsPostBack) { List<Tuple<string, int>> list = new List<Tuple<string, int>>(); if (Session["cartList"] != null) { list = (List<Tuple<string, int>>)(Session["cartList"]); } else { Response.Redirect("~/Index.aspx"); } //Collection that will be bound to the checkout datalist List<CheckoutItem> coItems = new List<CheckoutItem>(); foreach (Tuple<string, int> item in list) { CheckoutItem coItem = new CheckoutItem(); coItem.Prodcd = item.Item1; coItem.Quantity = item.Item2; //Get product info Product prod = new Product(); prod.GetProductByCode(item.Item1); coItem.Name = prod.Name.ToString(); coItem.Msrp = prod.Msrp; //Get all product delivery types ProductDeliveryType pdt = new ProductDeliveryType(); List<ProductDeliveryType> pdtypes = pdt.GetAllProductDeliveryTypesByProdCode(prod.ProductCode.ToString()); foreach(ProductDeliveryType pdtype in pdtypes) { DeliveryType dt = new DeliveryType(); dt.GetDeliveryTypeByID(pdtype.DeliveryTypeID); coItem.DeliveryTypes.Add(dt); } //Add checkout item to datasource list coItems.Add(coItem); } //Bind to the datalist DataListCheckout.DataSource = coItems; DataListCheckout.DataBind(); } }