Beispiel #1
0
        //------------------------------------------------------------------------------------------------------------------------------------------+
        protected void CheckoutBtn_Click(object sender, ImageClickEventArgs e)
        {
            MyShoppingCart usersShoppingCart = new MyShoppingCart();

            if (usersShoppingCart.SubmitOrder(User.Identity.Name) == true)
            {
                CheckOutHeader.InnerText = "Thank You - Your Order is Complete.";
                Message.Visible          = false;
                CheckoutBtn.Visible      = false;
            }
            else
            {
                CheckOutHeader.InnerText = "Order Submission Failed - Please try again. ";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int    productId;

            if (!String.IsNullOrEmpty(rawId) && Int32.TryParse(rawId, out productId))
            {
                MyShoppingCart usersShoppingCart = new MyShoppingCart();
                String         cartId            = usersShoppingCart.GetShoppingCartId();
                usersShoppingCart.AddItem(cartId, productId, 1);
            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId.");
                throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId.");
            }
            Response.Redirect("MyShoppingCart.aspx");
        }
        //------------------------------------------------------------------------------------------------------------------------------------------+
        protected void Page_Load(object sender, EventArgs e)
        {
            MyShoppingCart usersShoppingCart = new MyShoppingCart();
            String         cartId            = usersShoppingCart.GetShoppingCartId();
            decimal        cartTotal         = 0;

            cartTotal = usersShoppingCart.GetTotal(cartId);
            if (cartTotal > 0)
            {
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal(cartId));
            }
            else
            {
                LabelTotalText.Text         = "";
                lblTotal.Text               = "";
                ShoppingCartTitle.InnerText = "Shopping Cart is Empty";
                UpdateBtn.Visible           = false;
                CheckoutBtn.Visible         = false;
            }
        }
        //------------------------------------------------------------------------------------------------------------------------------------------+
        protected void UpdateBtn_Click(object sender, ImageClickEventArgs e)
        {
            MyShoppingCart usersShoppingCart = new MyShoppingCart();
            String         cartId            = usersShoppingCart.GetShoppingCartId();

            ShoppingCartUpdates[] cartUpdates = new ShoppingCartUpdates[MyList.Rows.Count];
            for (int i = 0; i < MyList.Rows.Count; i++)
            {
                IOrderedDictionary rowValues = new OrderedDictionary();
                rowValues = GetValues(MyList.Rows[i]);
                cartUpdates[i].ProductId        = Convert.ToInt32(rowValues["ProductID"]);
                cartUpdates[i].PurchaseQuantity = Convert.ToInt32(rowValues["Quantity"]);

                CheckBox cbRemove = new CheckBox();
                cbRemove = (CheckBox)MyList.Rows[i].FindControl("Remove");
                cartUpdates[i].RemoveItem = cbRemove.Checked;
            }

            usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
            MyList.DataBind();
            lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal(cartId));
        }