コード例 #1
0
        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();
            }
        }
コード例 #2
0
ファイル: Checkout.aspx.cs プロジェクト: gmeehan/QuickStart
        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");
                }

                //Datatable that will be bound to the checkout datalist
                DataTable dt = new DataTable();
                dt.Columns.Add("Prodcd");
                dt.Columns.Add("Quantity");
                dt.Columns.Add("Name");
                dt.Columns.Add("Msrp");

                foreach (Tuple <string, int> item in list)
                {
                    DataRow dr = dt.NewRow();
                    dr["Prodcd"]   = item.Item1;
                    dr["Quantity"] = item.Item2;

                    //Get product info
                    Product prod = new Product();
                    prod.GetProductByCode(item.Item1);
                    dr["Name"] = prod.Name.ToString();
                    dr["Msrp"] = prod.Msrp;

                    //Add checkout item to datasource list
                    dt.Rows.Add(dr);
                }

                //Bind to the datalist
                DataListCheckout.DataSource = dt;
                DataListCheckout.DataBind();
            }
        }