Example #1
0
        /* Update the shopping cart total when the delete item button is press
        or the quantity of the item changes */
        public List<CartItem> UpdateCartItems()
        {
            using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions())
            {
                String cartId = usersShoppingCart.GetCartId();

                ShoppingCartFunctions.ShoppingCartUpdates[] cartUpdates = new ShoppingCartFunctions.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("Delete");
                    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();
                var cartTotal = usersShoppingCart.GetTotal();
                var tax = (decimal)0.07 * (cartTotal + (decimal)5.00);
                var total = cartTotal + tax;
                lbltaxTotal.Text = String.Format("{0:c}", tax);
                lblTotal.Text = String.Format("{0:c}", total);
                return usersShoppingCart.GetCartItems();
            }
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string rawId = Request.QueryString["ProductID"];
            int productId;
            if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out productId))
            {
                int currentID = Convert.ToInt16(rawId);

                //create new product and brick model if it is a custom model
                if((currentID < 0))
                {
                    string text1 = Request.QueryString["tb1"];
                    string text2 = Request.QueryString["tb2"];
                    string text3 = Request.QueryString["tb3"];
                    string incription = string.Concat(text1, " ", text2, " ", text3);
                    var _db = new ZVerseBrickProject.Models.ProductContext();
                    Brick theproduct;
                    AddProducts products = new AddProducts();
                    AddBricks bricks = new AddBricks();
                    bool isStandard = false;
                    bool isVisible = false;

                    theproduct = _db.Bricks.Find(-currentID);
                    //Debug.WriteLine("add to cart: js path is " + theproduct.JSPath);
                    currentID = products.AddProduct(theproduct.BrickName, theproduct.Description,theproduct.UnitPrice.ToString(), "1", theproduct.ImagePath, incription);
                    bricks.AddBrick(currentID, theproduct.BrickName, theproduct.Description, incription, theproduct.UnitPrice.ToString(), theproduct.ImagePath, theproduct.JSPath, isVisible, "show", isStandard, text1, text2, text3);

                }

                using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions())
                {
                    usersShoppingCart.AddToCart(currentID);
                }

            }
            else
            {
                Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ProductId.");
                throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ProductId.");
            }
            Response.Redirect("ShoppingCart.aspx", false);
            Context.ApplicationInstance.CompleteRequest();
        }
 /* Obtain the current cart from its context */
 public ShoppingCartFunctions GetCart(HttpContext context)
 {
     using (var cart = new ShoppingCartFunctions())
     {
         cart.ShoppingCartId = cart.GetCartId();
         return cart;
     }
 }
Example #4
0
 /* Display the number of items on shopping cart on navbar */
 protected void Page_PreRender(object sender, EventArgs e)
 {
     using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions())
     {
         string cartStr = string.Format("Cart ({0})", usersShoppingCart.GetCount());
         cartCount.InnerHtml = "<span class='glyphicon glyphicon-shopping-cart'></span>" + cartStr;
     }
 }
Example #5
0
        /* Responsible for the footer row and order summary */
        protected void gridViewOrders_RowCreated(object sender, GridViewRowEventArgs e)
        {
            using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions())
            {

                decimal cartTotal = 0;
                cartTotal = usersShoppingCart.GetTotal();
                if (cartTotal > 0)
                {
                    if (e.Row.RowType == DataControlRowType.Footer)
                    {
                        int intNoOfMergeCol = e.Row.Cells.Count - 1;
                        for (int intCellCol = 1; intCellCol < intNoOfMergeCol; intCellCol++)
                        {
                            e.Row.Cells.RemoveAt(1);
                        }
                        e.Row.Cells[0].ColumnSpan = intNoOfMergeCol;
                        e.Row.Cells[0].Text = "SubTotal: ";
                        e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Right;
                        e.Row.Cells[1].Font.Bold = true;
                        e.Row.Cells[1].Text = String.Format("{0:c}", cartTotal);
                    }
                }

            }
        }
Example #6
0
 /* Empty the cart and redirect to checkout page when checkout button is pressed */
 protected void CheckoutBtn_Click(object sender, EventArgs e)
 {
     using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions())
     {
         usersShoppingCart.EmptyCart();
     }
     Response.Redirect("Checkout.aspx", false);
     Context.ApplicationInstance.CompleteRequest();
 }
Example #7
0
 /* Obtain all cart items */
 public List<CartItem> GetShoppingCartItems()
 {
     ShoppingCartFunctions actions = new ShoppingCartFunctions();
     return actions.GetCartItems();
 }
Example #8
0
 /* On page load, if empty, display the "please add an item message
 Otherwise, display the cart totatl with tax and shipping summary */
 protected void Page_Load(object sender, EventArgs e)
 {
     using (ShoppingCartFunctions usersShoppingCart = new ShoppingCartFunctions())
     {
         decimal cartTotal = 0;
         cartTotal = usersShoppingCart.GetTotal();
         if (cartTotal > 0)
         {
             // Display Total.
             // tax = 7% of the subtotal + shipping
             var tax = (decimal)0.07 * (cartTotal + (decimal)5.00);
             var total = cartTotal + tax;
             lbltaxTotal.Text = String.Format("{0:c}", tax );
             lblTotal.Text = String.Format("{0:c}", total);
         }
         else
         {
             LabelShipping.Text = "";
             LabelTax.Text = "";
             lbltaxTotal.Text = "";
             LabelTotalText.Text = "";
             lblTotal.Text = "";
             ShoppingCartTitle.InnerHtml = "<h2>Please add an item onto the shopping cart.</h2>";
             UpdateBtn.Visible = false;
             CheckoutBtn.Visible = false;
         }
     }
 }