Example #1
0
    /// <summary>
    /// items to be added to database
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void AddToCartLinkButton_Click(object sender, EventArgs e)
    {
        //RetreiveWishList();
        ShoppingCartItem cart = new ShoppingCartItem();
        GridViewRow      row  = ((Control)sender).NamingContainer as GridViewRow;
        GridView         grid = row.NamingContainer as GridView;

        //LOADCATEGORIES
        cart.ProductId   = grid.DataKeys[row.RowIndex].Value.ToString();
        cart.ProductName = (row.FindControl("ProductLabel") as Label).Text;
        cart.UnitPrice   = decimal.Parse((row.FindControl("UnitPriceLabel") as Label).Text);
        cart.Quantity    = 1;
        cart.Total       = cart.UnitPrice * cart.Quantity;

        ShoppingCartItem temp = new ShoppingCartItem {
            ProductId = cart.ProductId, Quantity = cart.Quantity
        };

        if (!myCart.FindProduct(temp))
        {
            myCart.AddCart(cart);
        }

        Server.Transfer("~/Modules/aspx/MyCart.aspx");
    }
Example #2
0
    private void AddToCart(DataListCommandEventArgs e, ShoppingCartItem cart)
    {
        LoadProducts(categoryId);

        cart.ProductId   = ProductDataList.DataKeys[e.Item.ItemIndex].ToString();
        cart.ProductName = (e.Item.FindControl("ProductDetailLink") as HyperLink).Text;
        cart.UnitPrice   = decimal.Parse((e.Item.FindControl("UnitPriceLabel") as Label).Text);
        TextBox quantityTextBox = (e.Item.FindControl("QuantityTextBox") as TextBox);

        if (quantityTextBox.Text.Equals(string.Empty))
        {
            cart.Quantity = 1;
        }
        else
        {
            cart.Quantity = int.Parse(quantityTextBox.Text);
        }
        cart.Total = cart.UnitPrice * cart.Quantity;

        ShoppingCartItem temp = new ShoppingCartItem {
            ProductId = cart.ProductId, Quantity = cart.Quantity
        };

        if (!myCart.FindProduct(temp))
        {
            myCart.AddCart(cart);
        }

        //added additionally
        Session["MyCart"] = myCart;

        Server.Transfer("~/Modules/aspx/MyCart.aspx");
    }
Example #3
0
    private void AddToCart(ShoppingCartItem cart)
    {
        cart.ProductId   = ProductFormView.DataKey[0].ToString();
        cart.ProductName = (ProductFormView.Row.FindControl("ProductLabel") as Label).Text;
        cart.UnitPrice   = decimal.Parse((ProductFormView.Row.FindControl("UnitPriceLabel") as Label).Text);
        TextBox quantityTextBox = ProductFormView.Row.FindControl("QuantityTextBox") as TextBox;

        if (quantityTextBox.Text.Equals(string.Empty))
        {
            cart.Quantity = 1;
        }
        else
        {
            cart.Quantity = int.Parse(quantityTextBox.Text);
        }
        cart.Total = cart.UnitPrice * cart.Quantity;

        ShoppingCartItem temp = new ShoppingCartItem {
            ProductId = cart.ProductId, Quantity = cart.Quantity
        };

        if (!myCart.FindProduct(temp))
        {
            myCart.AddCart(cart);
        }

        Session["MyCart"] = myCart;

        Server.Transfer("~/Modules/aspx/MyCart.aspx");
    }