Exemplo n.º 1
0
    protected void ItemsGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (Helper.StringExists(e.CommandName))
        {
            GridViewRow row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
            DataTable dt = BuildDataSource(CurrentCart.Items);
            DataRow dr = dt.Rows[row.RowIndex];

            int cart_contents_id = (int)dr["CartItemId"];

            CartDB db = new CartDB();
            if (e.CommandName == "AddToWishlist")
            {
                //Response.Write("Adding to Wishlist: " + dr["CartItemId"].ToString());
                throw new NotImplementedException("Add To Wishlist Not Implemented");
            }
            else if (e.CommandName == "UpdateQuantity")
            {
                Control c = row.FindControl("QtyTextbox");
                if (c != null && c.GetType().Equals(typeof(TextBox)))
                {
                    TextBox t = (TextBox)c;
                    int quantity;
                    if (Int32.TryParse(t.Text, out quantity))
                    {
                        // Update Quantity
                        // If 0, Remove
                        if (quantity > 0)
                        {
                            decimal subtotal = (decimal)dr["UnitPrice"] * quantity;

                            db.CartUpdateItemQuantity(cart_contents_id, quantity, subtotal);
                        }
                        else
                        {
                            db.CartDeleteItem(cart_contents_id);
                        }
                    }
                }
            }
            else if (e.CommandName == "RemoveItem")
            {
                db.CartDeleteItem(cart_contents_id);
            }
            Response.Redirect(Constants.Pages.CART);
        }
    }