protected void btnUpdate_Click(object sender, EventArgs e)
        {
            bool isValid = true;

            foreach (GridViewRow row in grvOrderDetails.Rows)
            {
                TextBox txtQty = (TextBox)row.FindControl("txtQty");

                if (!objBAL.CheckIsValidNumber(txtQty.Text))
                {
                    isValid = false;
                }
            }

            if (isValid)
            {
                Dictionary <string, int> shoppingCartList = new Dictionary <string, int>();

                foreach (GridViewRow row in grvOrderDetails.Rows)
                {
                    shoppingCartList.Add(((HiddenField)row.FindControl("hdnProductID")).Value, Convert.ToInt32(((TextBox)row.FindControl("txtQty")).Text));
                }

                string shoppingCartString = objBAL.UpdateShoppingCart(shoppingCartList);

                Session["ShoppingCart"] = shoppingCartString;
                FillCart();
            }
        }
Esempio n. 2
0
        protected void dltAllItems_ItemCommand(object source, DataListCommandEventArgs e)
        {
            string productID = Convert.ToString(e.CommandArgument);
            int    cartItems = 0;

            Label lblCart = (Label)this.Master.FindControl("lblCart");

            foreach (DataListItem item in dltAllItems.Items)
            {
                HiddenField hdnProductID = (HiddenField)item.FindControl("hdnProductID");

                if (hdnProductID.Value == productID)
                {
                    TextBox txtQty = (TextBox)item.FindControl("txtQty");

                    bool isValidNumber = objBAL.CheckIsValidNumber(txtQty.Text);

                    if (!isValidNumber)
                    {
                        Panel pnlQtyErr = (Panel)item.FindControl("pnlQtyErr");
                        pnlQtyErr.Visible = true;
                    }
                    else
                    {
                        if (Convert.ToInt32(txtQty.Text) > 0)
                        {
                            Panel pnlQtyErr = (Panel)item.FindControl("pnlQtyErr");
                            pnlQtyErr.Visible = false;

                            if (Session["ShoppingCart"] == null || Session["ShoppingCart"].ToString().Trim().Length <= 0)
                            {
                                string shoppingCart = productID + "|@|" + txtQty.Text;
                                Session["ShoppingCart"] = shoppingCart;

                                lblCart.Text = Convert.ToString(UserScript1.FillCart()) + " items";
                            }
                            else
                            {
                                string shoppingCart = Session["ShoppingCart"].ToString();
                                shoppingCart           += "|@|" + productID + "|@|" + txtQty.Text;
                                Session["ShoppingCart"] = shoppingCart;

                                lblCart.Text = Convert.ToString(UserScript1.FillCart()) + " items";
                            }
                        }
                    }

                    break;
                }
            }
        }