protected void Page_Load(object sender, EventArgs e)
        {
            //Get value of mode and product from when button is clicked to determine which button is clicked
            mode     = Request.QueryString["mode"];
            product  = Request.QueryString["product"];
            products = QueryClass.GetProductData();
            int productID = 0;

            try
            {
                productID = Convert.ToInt32(product);
            }
            catch { }
            if (mode != null && product != null)
            {
                if (mode.Equals("toggleDelete"))
                {
                    //Delete an item depending on product which acts as index pointer

                    //query for deleting
                    GlobalData.productList.RemoveAt(Convert.ToInt32(product));
                }

                //if (mode.Equals("UpdateItem"))
                //{
                //    //Open up update page sending the product value so the correct product can be determined
                //    Response.Redirect("Update.aspx?PassingValue=" + Server.UrlEncode(product));

                //}
            }
        }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            mode    = Request.QueryString["mode"];
            product = Request.QueryString["product"];
            String category = Request.QueryString["category"];
            String search   = Request.QueryString["search"];

            products = QueryClass.GetProductData();

            //directs to the page that displays a single product
            if (mode != null)
            {
                if (mode.Equals("PurchaseProductPage"))
                {
                    Response.Redirect("PurchaseProduct.aspx?PassingValue=" + Server.UrlEncode(product));
                }
            }

            //adds an item into the cart based on th addItem value
            if (Request.QueryString["addItem"] != null)
            {
                int            productIndex = Convert.ToInt32(Request.QueryString["addItem"]);
                List <Product> cart         = new List <Product>();
                bool           isCartNew    = false;

                //gets the cart or sets a new one
                if (Session["cart"] == null)
                {
                    isCartNew = true;
                }
                else
                {
                    cart = (List <Product>)Session["cart"];
                }

                Product p = products[productIndex];

                if (isCartNew)
                {
                    cart.Add(p);
                    Session.Add("cart", cart);
                }
                else
                {
                    int positionIndex = -1;
                    //find said product in the cart
                    for (int i = 0; i < cart.Count; i++)
                    {
                        if (cart[i].Name.Equals(p.Name))
                        {
                            positionIndex = i;
                        }
                    }
                    if (positionIndex == -1)
                    {
                        cart.Add(p);
                    }
                    //if found, only adds item if there is enought stock
                    else if (p.Stock > cart[positionIndex].Quantity)
                    {
                        cart[positionIndex].Quantity += 1;
                    }
                    Session["cart"] = cart;
                }
            }

            //finds products by category
            if (category != null)
            {
                products = QueryClass.GetProductsByCategory(category);
            }

            //finds products by search
            if (search != null)
            {
                products = QueryClass.GetProductsBySearch(search);
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            product = Request.QueryString["product"];
            String category = Request.QueryString["category"];
            String search   = Request.QueryString["search"];

            products   = QueryClass.GetProductData();
            categories = QueryClass.GetCategories();

            //adds an item into the cart based on th addItem value
            if (Request.QueryString["addItem"] != null)
            {
                //
                int            productID = Convert.ToInt32(Request.QueryString["addItem"]);
                List <Product> cart      = new List <Product>();
                bool           isCartNew = false;

                //gets the cart or sets a new one
                if (Session["cart"] == null)
                {
                    isCartNew = true;
                }
                else
                {
                    cart = (List <Product>)Session["cart"];
                }

                int productIndex = -1;
                foreach (Product pTemp in products)
                {
                    productIndex++;
                    if (pTemp.ID == productID)
                    {
                        break;
                    }
                }
                Product p = products[productIndex];

                if (isCartNew)
                {
                    cart.Add(p);
                    Session.Add("cart", cart);
                }
                else
                {
                    int positionIndex = -1;
                    //find said product in the cart
                    for (int i = 0; i < cart.Count; i++)
                    {
                        if (cart[i].Name.Equals(p.Name))
                        {
                            positionIndex = i;
                        }
                    }
                    if (positionIndex == -1)
                    {
                        cart.Add(p);
                    }
                    //if found, only adds item if there is enought stock
                    else if (p.Stock > cart[positionIndex].Quantity)
                    {
                        cart[positionIndex].Quantity += 1;
                    }
                    Session["cart"] = cart;
                }
            }

            //finds products by category
            if (category != null)
            {
                products = QueryClass.GetProductsByCategory(category);
            }

            //finds products by search
            if (search != null)
            {
                products = QueryClass.GetProductsBySearch(search);
            }
        }