Example #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteMaster master = Page.Master as SiteMaster;

            string[] totals = DBOps.GetUserCartTotals(_cart.cartID);
            master.UpdateTotalCounters();
        }
Example #2
0
 /// <summary>
 /// Updates the values displayed in the my cart link found in the navbar
 /// </summary>
 public void UpdateTotalCounters()
 {
     if (Session["prevID"] != null)
     {
         string[] totals = DBOps.GetUserCartTotals(Convert.ToInt32(Session["prevID"]));
         LBL_Counter.Text = string.Format("Cart ({0} | {1:C})", totals[0], Convert.ToDecimal(totals[1]));
     }
     else
     {
         LBL_Counter.Text = string.Format("Cart ({0} | {1:C})", 0, Convert.ToDecimal(0.ToString()));
     }
 }
Example #3
0
        protected void btnAddToCart_Click(object sender, EventArgs e)
        {
            if (_currUser != "-" && _tempId != 0)
            {
                _cart.cartID    = _userCartId;
                _cart.cartOwner = _currUser;
                string[] items = DBOps.GetCartItems(_userCartId);
                _cart.lastInsertedItem  = items[0];
                _cart.lastInsertedPrice = items[1];
                _cart.lastInsertedQuant = items[2];
                _cart.totalItemQuantity = Convert.ToInt32(items[3]);
                _cart.totalCartPrice    = Convert.ToDecimal(items[4]);
            }
            else if (_currUser != "-" && _tempId == 0)
            {
                _cart.cartID = _userCartId;
                userInfoDataSource.Update();
            }
            else
            {
                _cart.cartID = _userCartId;
            }

            _itemSku = _result?["sku"].ToString();
            int productQuant = DBOps.GetProductQuantity(_itemSku);

            if (Session[_itemSku] == null)
            {
                Session[_itemSku] = productQuant;
            }

            int  t_itemStock    = DBOps.GetProductQuantity(_itemSku);
            int  t_cartQuantity = Convert.ToInt32(tbxQty.Text);
            bool proceed        = t_itemStock >= t_cartQuantity;

            _cart.AddItem(_result?["sku"].ToString(), Convert.ToDecimal($"{_result?["price"]}"), Convert.ToInt32(tbxQty.Text));
            if (!DBOps.RecordExists(_userCartId))
            {
                if (proceed)
                {
                    CartDataSource.Insert();
                    _itemQuant = productQuant - Convert.ToInt32(tbxQty.Text);
                    Products.Update();
                }
                else if (productQuant == 0)
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "notif",
                                                        "alert('ITEM NOT ADDED. This product is currently out of stock. Try again later.')", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "notif",
                                                        $"alert('ITEM NOT ADDED. You either have the maximum number of it in your cart or adding the specified amount of {tbxQty.Text} will exceed the limit of 99.')", true);
                }
            }
            else
            {
                if (proceed)
                {
                    CartDataSource.Update();
                    _itemQuant = productQuant - Convert.ToInt32(tbxQty.Text);
                    Products.Update();
                }
                else if (productQuant == 0)
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "notif",
                                                        "alert('ITEM NOT ADDED. This product is currently out of stock. Try again later.')", true);
                }
                else
                {
                    ScriptManager.RegisterStartupScript(this, GetType(), "notif",
                                                        $"alert('ITEM NOT ADDED. You either have the maximum number of it in your cart or adding the specified amount of {tbxQty.Text} will exceed the limit of 99.')", true);
                }
            }

            string[] totals = DBOps.GetUserCartTotals(_cart.cartID);

            SiteMaster master = Page.Master as SiteMaster;

            master.UpdateTotalCounters();
        }