コード例 #1
0
ファイル: ShoppingCart.aspx.cs プロジェクト: Bris-bb/web-form
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

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

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

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
コード例 #2
0
        //UpdatecartItems Method
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    //The amount of products in the cart.
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);


                    //This the checkbox to tick to remove a product.
                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remove");
                    cartUpdates[i].RemoveItem = cbRemove.Checked;

                    //This is the textbox to change the quantity.
                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }

                //This updates the total for all prdoucts in the cart using the GetTotal method.
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
コード例 #3
0
        //update cart item with db
        private List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions shopaction = new ShoppingCartActions())
            {
                string cartId = shopaction.GetCartId().ToString();
                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];

                //collect item in cart to update list
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId = Convert.ToInt32(rowValues["ProductID"]);

                    CheckBox cbRm = CartList.Rows[i].FindControl("Remove") as CheckBox;
                    cartUpdates[i].RemoveItem = cbRm.Checked;

                    TextBox qnt = CartList.Rows[i].FindControl("PurchaseQuantity") as TextBox;
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(qnt.Text);
                }

                shopaction.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = string.Format("{0:c}", shopaction.GetTotal());
                return(shopaction.GetCartItems());
            }
        }
コード例 #4
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                List <ShoppingCartActions.ShoppingCartUpdates> cartUpdates = new List <ShoppingCartActions.ShoppingCartUpdates>();
                foreach (GridViewRow row in CartList.Rows)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(row);
                    var ControlCheckbox = (CheckBox)row.FindControl("Remove");
                    var TextBox         = (TextBox)row.FindControl("PurchaseQuantity");
                    ShoppingCartActions.ShoppingCartUpdates cartUpdate = new ShoppingCartActions.ShoppingCartUpdates
                    {
                        ProductId        = Convert.ToInt32(rowValues["ProductID"]),
                        RemoveItem       = ControlCheckbox.Checked,
                        PurchaseQuantity = Convert.ToInt16(TextBox.Text.ToString())
                    };
                    cartUpdates.Add(cartUpdate);
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
コード例 #5
0
        public List <CartItem> UpdateRepeats()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

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

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

                    // DropDownList selectedRepeat = new DropDownList();
                    // selectedRepeat =
                    //(DropDownList)CartList.Rows[i].FindControl("Repeat");
                    // cartUpdates[i].RepeatOrder = selectedRepeat.SelectedValue; /* HERE */

                    //DropDownList selectedRepeat = new DropDownList();
                    DropDownList selectedRepeat = (DropDownList)CartList.Rows[i].FindControl("RepeatOrder");
                    cartUpdates[i].RepeatOrder = selectedRepeat.SelectedValue; /* HERE */
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                //lblTotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
コード例 #6
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].LivroId = Convert.ToInt32(rowValues["livro_id"]);

                    CheckBox cbRemove = new CheckBox();
                    cbRemove = (CheckBox)CartList.Rows[i].FindControl("Remover");
                    cartUpdates[i].RemoverItem = cbRemove.Checked;

                    int quantidadeAnterior = GetShoppingCartItems().Cast <CartItem>().ElementAt(i).quantidade;

                    Estoque estoque = commands["CONSULTAR"].execute(new Estoque()
                    {
                        Livro = new Dominio.Livro.Livro()
                        {
                            ID = cartUpdates[i].LivroId
                        }
                    }).Entidades.Cast <Estoque>().ElementAt(0);

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");

                    if (estoque.Qtde < Convert.ToInt32(quantityTextBox.Text))
                    {
                        cartUpdates[i].PurchaseQuantity = quantidadeAnterior;
                        lblResultadoCarrinho.Text       = "Quantidade em estoque do livro " + estoque.Livro.Titulo + " é de " + estoque.Qtde + " unidade(s)";
                        lblResultadoCarrinho.Visible    = true;
                    }
                    else
                    {
                        cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                        lblResultadoCarrinho.Text       = "";
                        lblResultadoCarrinho.Visible    = false;
                    }
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                lblSubtotal.Text = String.Format("{0:c}", usersShoppingCart.GetTotal());
                return(usersShoppingCart.GetCartItems());
            }
        }
コード例 #7
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartActions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartActions.ShoppingCartUpdates[CartList.Rows.Count];
                for (int i = 0; i < CartList.Rows.Count; i++)
                {
                    IOrderedDictionary rowValues = new OrderedDictionary();
                    rowValues = GetValues(CartList.Rows[i]);
                    cartUpdates[i].ProductId
                }
            }
        }
コード例 #8
0
        public List <CartItem> UpdateCartItems()
        {
            using (ShoppingCartActions usersShoppingCart = new ShoppingCartActions())
            {
                String cartId = usersShoppingCart.GetCartId();

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

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

                    TextBox priceTextBox = new TextBox();
                    priceTextBox           = (TextBox)CartList.Rows[i].FindControl("PriceBx");
                    cartUpdates[i].PriceBx = Convert.ToDecimal(priceTextBox.Text.ToString());

                    //cartUpdates[i].ItemPrice = Convert.ToInt32(rowValues["OriginalPrice"]);

                    TextBox quantityTextBox = new TextBox();
                    quantityTextBox = (TextBox)CartList.Rows[i].FindControl("PurchaseQuantity");
                    cartUpdates[i].PurchaseQuantity = Convert.ToInt16(quantityTextBox.Text.ToString());
                }
                usersShoppingCart.UpdateShoppingCartDatabase(cartId, cartUpdates);
                CartList.DataBind();
                //GetTotal() suppose to execute after UpdateShoppingCartDatabase
                string x = String.Format("{0:c}", usersShoppingCart.GetTotal());
                if (x != "$0.00")
                {
                    lblTotal.Text = x;
                }
                else
                {
                    lblTotal.Text = "";
                }
                return(usersShoppingCart.GetCartItems());
            }
        }