Exemple #1
0
        /// <summary>
        /// Updates a specified user's cart with data from another cart
        /// </summary>
        /// <param name="cartID">The ID of the cart that's being used</param>
        /// <param name="user">The E-mail address of the user who's cart to sync with</param>
        public void SyncCart(int cartID, string user)
        {
            string[] oldCartData     = DBOps.GetUserCart(DBOps.GetLatestEntry(DBOps.GetUserID(user)));
            string[] currentCartData = null;

            string[] r_currCartDataItems  = null;
            string[] r_currCartDataPrices = null;
            string[] r_currCartDataQuants = null;
            int      r_currQuant          = -1;
            decimal  r_currPrice          = -1;

            lastInsertedItem  = oldCartData[0];
            lastInsertedPrice = oldCartData[1];
            lastInsertedQuant = oldCartData[2];
            totalItemQuantity = Convert.ToInt32(oldCartData[3]);
            totalCartPrice    = Convert.ToDecimal(oldCartData[4]);

            try
            {
                currentCartData      = DBOps.GetUserCart(cartID);
                r_currCartDataItems  = currentCartData[0].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                r_currCartDataPrices = currentCartData[1].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                r_currCartDataQuants = currentCartData[2].Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                r_currQuant          = Convert.ToInt32(currentCartData[3]);
                r_currPrice          = Convert.ToDecimal(currentCartData[4]);

                for (int i = 0; i < r_currCartDataItems.Length; i++)
                {
                    AddItem(r_currCartDataItems[i], Convert.ToDecimal(r_currCartDataPrices[i]), Convert.ToInt32(r_currCartDataQuants[i]));
                }
            }
            catch { }
        }
        protected void btn_checkout_Click(object sender, EventArgs e)
        {
            if (Session["currUser"] != null)
            {
                // Make the application give the user a new cart
                DBOps.ReassignUserCart(user, 0);
            }

            if (Request.Cookies["cartID"] != null)
            {
                HttpCookie myCookie = new HttpCookie("cartID");
                myCookie.Expires = DateTime.Now.AddYears(-1);
                Response.Cookies.Add(myCookie);
            }


            // reset the session variables
            // Session.Abandon will erase everything.
            // Not everything has to be erased.
            // Too lazy to do conditionals.
            Session.Remove("prevID");
            Session.Remove("refNum");

            // empty the cart
            UserCart cart = UserCart.Instance;

            cart.Reset();


            Response.Redirect("~/Confirm.aspx");
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SiteMaster master = Page.Master as SiteMaster;

            string[] totals = DBOps.GetUserCartTotals(_cart.cartID);
            master.UpdateTotalCounters();
        }
Exemple #4
0
        /// <summary>
        /// Validates if the specified item can be added to the cart
        /// </summary>
        /// <param name="itemSKU">The SKU of the item to be added to the cart</param>
        /// <param name="quant">The desired quantity of the item to be added to the cart</param>
        /// <param name="cartID">The ID of the current cart</param>
        /// <returns>True if the item can be added to the cart</returns>
        public bool ItemCanBeAdded(string itemSKU, int quant, int cartID)
        {
            string[] s_lastInsertedItem     = lastInsertedItem.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            string[] s_lastInsertedQuantity = lastInsertedQuant.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            string[] t_originalCartDetails  = DBOps.GetUserCart(cartID);

            for (int i = 0; i < s_lastInsertedItem.Length; i++)
            {
                if (s_lastInsertedItem[i].Trim() == itemSKU.Trim())
                {
                    int t_quant = Convert.ToInt32(s_lastInsertedQuantity[i]);

                    /// The variables in the cart object get updated before
                    /// this method is called. That is why we check if the
                    /// current quantity will equate to an amount that is
                    /// greater than 99 or any defined limit.
                    if (t_quant > 99 || DBOps.GetProductQuantity(itemSKU) <= 0)
                    {
                        lastInsertedPrice = t_originalCartDetails[1];
                        lastInsertedQuant = t_originalCartDetails[2];
                        totalItemQuantity = Convert.ToInt32(t_originalCartDetails[3]);
                        totalCartPrice    = Convert.ToDecimal(t_originalCartDetails[4]);
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // if the user is logged in, obtain his current cart if it's not zero.
            // otherwise, use the ID stored in the session variable.
            if (Session["currUser"] != null)
            {
                _user = (string)Session["currUser"];

                _userCartId = DBOps.GetLatestEntry(DBOps.GetUserID(_user)) != 0 ? DBOps.GetLatestEntry(DBOps.GetUserID(_user)) :
                              Convert.ToInt32(Session["prevID"]);
                _cart.cartID = _userCartId;

                if (Session["sync"] != null)
                {
                    _cart.SyncCart(Convert.ToInt32(Session["prevID"]), _user);
                    cartDatasource.Update();
                    Session["prevID"] = _userCartId;
                    Session.Remove("sync");
                }
            }
            else
            {
                _user       = "******";
                _userCartId = Convert.ToInt32(Session["prevID"]);
            }

            if (Session["prevID"] != null)
            {
                _userCartId = Convert.ToInt32(Session["prevID"]);
            }
            else
            {
                Session["prevID"] = _userCartId;
            }

            _cart.cartID = _userCartId;
            //Session["prevID"] = _userCartId;

            lvw_items.DataSource = DBOps.BuildUserCart(_userCartId);
            lvw_items.DataBind();
            lvw_totals.DataSource = DBOps.BuildUserCartTotals(_userCartId);
            lvw_totals.DataBind();

            Button button = (Button)UpdatePanel1.FindControl("btn_checkout");

            if (DBOps.BuildUserCart(_userCartId).Rows.Count == 0)
            {
                button.Enabled  = false;
                button.CssClass = "btn btn-outline-secondary btn-block";
            }
            else
            {
                button.Enabled = true;
            }

            SiteMaster master = Page.Master as SiteMaster;

            master.UpdateTotalCounters();
        }
Exemple #6
0
        protected void lvw_items_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            DataPager dp = (DataPager)lvw_items.FindControl("DataPager1");

            dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            lvw_items.DataSource = DBOps.BuildUserCart(_refKey);
            lvw_items.DataBind();
        }
Exemple #7
0
        protected void Lvw_transactions_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            DataPager dp = (DataPager)Lvw_transactions.FindControl("DataPager1");

            dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            Lvw_transactions.DataSource = DBOps.UserTransactionsTable(((string)(Session["currUser"])));
            Lvw_transactions.DataBind();
        }
Exemple #8
0
        protected void lvw_items_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            // Prevent the pager from showing an empty page
            // in case the user deletes all the items in a
            // single page
            DataPager dp = (DataPager)lvw_items.FindControl("DataPager1");

            dp.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            lvw_items.DataSource = DBOps.BuildUserCart(_userCartId);
            lvw_items.DataBind();
        }
Exemple #9
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Session["currUser"] == null)
     {
         Response.Redirect("~/Home.aspx");
     }
     else
     {
         Lvw_transactions.DataSource = DBOps.UserTransactionsTable(((string)(Session["currUser"])));
         Lvw_transactions.DataBind();
     }
 }
Exemple #10
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()));
     }
 }
Exemple #11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["refNum"] != null)
            {
                _refKey = (string)Session["refNum"];
            }

            lvw_items.DataSource  = DBOps.BuildUserCart(_refKey);
            lvw_totals.DataSource = DBOps.BuildUserCartTotals(_refKey);
            lvw_items.DataBind();
            lvw_totals.DataBind();

            SiteMaster master = Page.Master as SiteMaster;

            master.UpdateTotalCounters();
        }
Exemple #12
0
        /// <summary>
        /// Updates the details of the specified item in the cart
        /// </summary>
        /// <param name="itemSKU">The SKU of the item to be updated</param>
        /// <param name="price">The price of the item to be updated</param>
        /// <param name="quant">The quantity of the item to be updated</param>
        public void UpdateItem(string itemSKU, decimal price, int quant)
        {
            int index = -1;

            string[] holdData = DBOps.GetCartItems(cartID);
            lastInsertedItem  = holdData[0];
            lastInsertedPrice = holdData[1];
            lastInsertedQuant = holdData[2];
            totalCartPrice    = Convert.ToDecimal(holdData[3]);
            totalItemQuantity = Convert.ToInt32(holdData[4]);

            if (lastInsertedItem != string.Empty && lastInsertedItem != null)
            {
                string[]      items     = lastInsertedItem.Split(',');
                List <string> newItems  = new List <string>();
                List <string> newQuants = new List <string>();
                List <string> newPrices = new List <string>();

                if (Regex.IsMatch(lastInsertedItem, string.Format(@"\b{0}\b", itemSKU)))
                {
                    for (int i = 0; i < items.Length; i++)
                    {
                        if (items[i] == itemSKU)
                        {
                            index = i;
                            break;
                        }
                    }

                    if (index != -1)
                    {
                        string[] prices        = lastInsertedPrice.Split(',');
                        string[] quantities    = lastInsertedQuant.Split(',');
                        int      originalQuant = Convert.ToInt32(quantities[index].Trim());
                        int      qT            = Convert.ToInt32(quant);
                        quantities[index] = qT.ToString();
                        prices[index]     = (price * qT).ToString();

                        lastInsertedPrice = string.Join(",", prices);
                        lastInsertedQuant = string.Join(",", quantities);
                        totalCartPrice    = ComputeTotalPrice();
                        totalItemQuantity = ComputeTotalItems();
                    }
                }
            }
        }
Exemple #13
0
        protected void lvw_items_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            string[] productDetails = ((String)e.CommandArgument).Split(',');

            try
            {
                _cart.RemoveItem(productDetails[0].Trim(), Convert.ToDecimal(productDetails[1].Trim()), Convert.ToInt32(productDetails[2].Trim()));
                cartDatasource.Update();
                _itemSKU   = productDetails[0].Trim();
                _itemQuant = DBOps.GetProductQuantity(_itemSKU) + Convert.ToInt32(productDetails[2].Trim());
                ProductsDataSource.Update();
            }
            catch (Exception)
            {
                // ignored
            }

            Button button = (Button)UpdatePanel1.FindControl("btn_checkout");

            if (DBOps.BuildUserCart(_userCartId).Rows.Count < 1)
            {
                if (_user != "-")
                {
                    //cartDatasource.Delete();
                    //DataOps.reassignUserCart(user);
                }
                button.Enabled  = false;
                button.CssClass = "btn btn-outline-secondary btn-block";
            }

            DataPager dp = (DataPager)lvw_items.FindControl("DataPager1");

            if (lvw_items.Items.Count <= 1)
            {
                dp.SetPageProperties(0, dp.MaximumRows, false);
            }

            lvw_items.DataSource  = DBOps.BuildUserCart(_userCartId);
            lvw_totals.DataSource = DBOps.BuildUserCartTotals(_userCartId);
            lvw_items.DataBind();
            lvw_totals.DataBind();

            SiteMaster master = Page.Master as SiteMaster;

            master.UpdateTotalCounters();
        }
Exemple #14
0
        protected void btn_checkout_Click(object sender, EventArgs e)
        {
            if (Session["currUser"] != null)
            {
                // Make the application give the user a new cart
                DBOps.ReassignUserCart(user, 0);
            }

            if (Request.Cookies["cartID"] != null)
            {
                HttpCookie myCookie = new HttpCookie("cartID");
                myCookie.Expires = DateTime.Now.AddYears(-1);
                Response.Cookies.Set(myCookie);
            }


            CartDataSource.Update();
        }
Exemple #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["refNum"] != null)
            {
                cartNum = Convert.ToInt32(Session["refNum"]);
            }
            else
            {
                Response.Redirect("~/Home.aspx");
            }

            if (Session["currUser"] != null)
            {
                user = (string)Session["currUser"];

                FormView1.DataSource = DBOps.BuildCreditCardDetails(user);
                FormView1.DataBind();
                BindControls(1);
                lvw_totals.DataSource = DBOps.BuildUserCartTotals(cartNum);
                lvw_totals.DataBind();
            }
            else
            {
                FormView1.DataSource = DBOps.BuildCreditCardDetails("-");
                FormView1.DataBind();
                BindControls(0);
                lvw_totals.DataSource = DBOps.BuildUserCartTotals(cartNum);
                lvw_totals.DataBind();
            }

            CompareValidator validator = ((CompareValidator)(FormView1.FindControl("CompareEndTodayValidator")));

            validator.ValueToCompare = DateTime.Now.ToShortDateString();

            SiteMaster master = Page.Master as SiteMaster;

            master.UpdateTotalCounters();
        }
Exemple #16
0
        protected void btn_login_Click(object sender, EventArgs e)
        {
            string username, password;
            bool   grantLogin = false;

            if (Page.IsValid)
            {
                DBOps.GetLoginDetails(tbx_mail.Text, out username, out password);

                if (username == string.Empty)
                {
                    grantLogin = false;
                }
                else
                {
                    if (tbx_password.Text == password)
                    {
                        grantLogin = true;
                    }
                }
            }

            if (grantLogin)
            {
                // used to be "loginRedirect" which indicates that the user was
                // redirected from the cart page. This is because previously,
                // only authenticated users are permitted to purchase anything
                // from the web store.
                if (Session["prevID"] != null)
                {
                    HttpCookie httpCookie = Request.Cookies["cartID"];

                    // user has no cart previously assigned to him? Assign this one
                    if (DBOps.GetLatestEntry(DBOps.GetUserID(tbx_mail.Text)) == 0)
                    {
                        //DBOps.reassignUserCart(tbx_mail.Text, ((Convert.ToInt32(httpCookie.Value.ToString()))));
                        DBOps.ReassignUserCart(tbx_mail.Text, Convert.ToInt32(Session["prevID"]));
                        DBOps.RegisterCart(tbx_mail.Text);
                    }

                    // else, we sync carts.

                    // Delete the cookie used to store the cart ID generated before
                    // We delete it because the user has this cart ID assigned to him in the database
                    // and can be easily retrieved from the said DB.
                    if (Request.Cookies["cartID"] != null)
                    {
                        HttpCookie myCookie = new HttpCookie("cartID");
                        myCookie.Expires = DateTime.Now.AddDays(-5);
                        Response.Cookies.Add(myCookie);
                    }

                    Session["currUser"] = tbx_mail.Text;


                    Session["sync"] = 1;
                    Session.Remove("loginRedirect");

                    // force any page that relies on this to take the user's cart ID
                    //Session.Remove("prevID");

                    Response.Redirect(@"~/Cart.aspx");
                }
                else
                {
                    Session["currUser"] = tbx_mail.Text;
                    Response.Redirect(@"~/Home");
                }
            }
        }
Exemple #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Count == 0)
            {
                Response.Redirect("Default.aspx");
            }

            _results = Products.Select(DataSourceSelectArguments.Empty) as DataView;
            _result  = _results?[0].Row;

            CreateDetails();
            CreateCarousel();

            #region Cart ID Logic
            if (Session["currUser"] != null)
            {
                _currUser = (string)Session["currUser"];
                _tempId   = DBOps.GetLatestEntry(DBOps.GetUserID(_currUser));

                if (_tempId == 0)
                {
                    if (DBOps.GetLatestEntry() < 1)
                    {
                        _userCartId = DBOps.GetLatestEntry() + 2;
                    }
                    else if (DBOps.GetLatestEntry() > 0)
                    {
                        _userCartId = DBOps.GetLatestEntry() + 1;
                    }
                }
                else
                {
                    _userCartId = _tempId;
                }
            }
            else
            {
                if (DBOps.GetLatestEntry() > 0)
                {
                    _userCartId = DBOps.GetLatestEntry() + 1;
                }
                else
                {
                    _userCartId = DBOps.GetLatestEntry() + 2;
                }
            }


            if (Session["prevID"] == null)
            {
                Session["prevID"] = _userCartId;
            }
            else
            {
                _userCartId = Convert.ToInt32(Session["prevID"]);
            }


            Random rand = new Random();
            _referenceKey = rand.Next(99999999).ToString() + _userCartId;

            if (Session["refkey"] == null)
            {
                Session["refkey"] = _referenceKey;
            }
            else
            {
                _referenceKey = (string)Session["refkey"];
            }
            #endregion
        }
 protected void userInfoDataSource_Updating(object sender, SqlDataSourceCommandEventArgs e)
 {
     e.Command.Parameters["@Id"].Value             = DBOps.GetUserID(_currUser);
     e.Command.Parameters["@latest_cart_id"].Value = _userCartId;
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["currUser"] != null)
            {
                _currUser = (string)Session["currUser"];
                _tempId   = DBOps.GetLatestEntry(DBOps.GetUserID(_currUser));

                if (_tempId == 0)
                {
                    if (DBOps.GetLatestEntry() < 1)
                    {
                        _userCartId = DBOps.GetLatestEntry() + 2;
                    }
                    else if (DBOps.GetLatestEntry() > 0)
                    {
                        _userCartId = DBOps.GetLatestEntry() + 1;
                    }
                }
                else
                {
                    _userCartId = _tempId;
                }
            }
            else
            {
                if (DBOps.GetLatestEntry() > 0)
                {
                    _userCartId = DBOps.GetLatestEntry() + 1;
                }
                else
                {
                    _userCartId = DBOps.GetLatestEntry() + 2;
                }
            }


            if (Session["prevID"] == null)
            {
                Session["prevID"] = _userCartId;
            }
            else
            {
                _userCartId = Convert.ToInt32(Session["prevID"]);
            }

            _cart.cartID = _userCartId;


            Random rand = new Random();

            _referenceKey = rand.Next(99999999).ToString() + _userCartId;

            if (Session["refkey"] == null)
            {
                Session["refkey"] = _referenceKey;
            }
            else
            {
                _referenceKey = (string)Session["refkey"];
            }
        }
 protected void CartDataSource_Deleting(object sender, SqlDataSourceCommandEventArgs e)
 {
     e.Command.Parameters["@original_Id"].Value = DBOps.GetLatestEntry();
 }
Exemple #21
0
        protected void tbx_qty_TextChanged(object sender, EventArgs e)
        {
            TextBox          textBox1 = (TextBox)sender;
            ListViewDataItem item     = (ListViewDataItem)textBox1.NamingContainer;
            TextBox          tb       = (TextBox)item.FindControl("tbx_qty"); //get the textbox in the proper listview item

            if (Convert.ToInt32(tb.Text) <= 0 || tb.Text == string.Empty || string.IsNullOrEmpty(tb.Text) || string.IsNullOrWhiteSpace(tb.Text) || (tb.Text == DBNull.Value.ToString(CultureInfo.InvariantCulture)))
            {
                tb.Text = "1";
            }
            else if (Convert.ToInt32(tb.Text) > 99)
            {
                tb.Text = "99";
            }

            Label lblSku   = (Label)item.FindControl("lbl_sku");
            Label lblPrice = (Label)item.FindControl("lbl_price");

            //int t_itemStock = DBOps.GetProductQuantity(lblSku.Text);
            int t_itemStock        = Convert.ToInt32(Session[lblSku.Text]);
            int t_cartQuantity     = Convert.ToInt32(tb.Text);
            int t_currCartQuantity = DBOps.GetItemQuantity(_userCartId, lblSku.Text);

            #region Old validation code
            //int t_sessionQuant = 0;

            //if (Session[lblSku.Text] != null)
            //{
            //    t_sessionQuant = Convert.ToInt32(Session[lblSku.Text]);
            //}
            ////else
            ////{
            ////    Session[lblSku.Text] = t_currCartQuantity;
            ////}
            #endregion


            try
            {
                _itemSKU = lblSku.Text;

                /// user adds a specified amount of the item to the cart
                if (t_currCartQuantity - t_cartQuantity < 0)
                {
                    if (t_itemStock >= t_cartQuantity /* || t_sessionQuant >= t_cartQuantity*/)
                    {
                        _cart.UpdateItem(lblSku.Text, Decimal.Parse(lblPrice.Text, NumberStyles.Currency), Convert.ToInt32(tb.Text));
                        cartDatasource.Update();

                        _itemQuant = DBOps.GetProductQuantity(_itemSKU) - Math.Abs(t_currCartQuantity - t_cartQuantity);
                        ProductsDataSource.Update();
                    }
                    else
                    {
                        ScriptManager.RegisterStartupScript(this, GetType(), "notif",
                                                            string.Format("alert('ITEM NOT ADDED. The specified quantity of {0} is more than the available stock of the item.')",
                                                                          t_cartQuantity), true);
                    }
                }
                else
                {
                    _cart.UpdateItem(lblSku.Text, Decimal.Parse(lblPrice.Text, NumberStyles.Currency), Convert.ToInt32(tb.Text));
                    cartDatasource.Update();
                    _itemQuant = DBOps.GetProductQuantity(_itemSKU) + Math.Abs(t_currCartQuantity - t_cartQuantity);
                    ProductsDataSource.Update();
                }
            }
            catch (Exception)
            {
                // ignored
            }

            lvw_items.DataSource  = DBOps.BuildUserCart(_userCartId);
            lvw_totals.DataSource = DBOps.BuildUserCartTotals(_userCartId);
            lvw_items.DataBind();
            lvw_totals.DataBind();

            SiteMaster master = Page.Master as SiteMaster;
            master.UpdateTotalCounters();
        }
        protected void ProductList_ItemCommand(object sender, ListViewCommandEventArgs 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;
            }

            string[] productDetails = ((String)e.CommandArgument).Split(',');
            _cart.AddItem(productDetails[0].Trim(), Convert.ToDecimal(productDetails[1].Trim()), 1);

            _itemSku = productDetails[0].Trim();


            bool CanBeAdded   = _cart.ItemCanBeAdded(_itemSku, 1, _userCartId);
            int  productQuant = DBOps.GetProductQuantity(_itemSku);

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

            if (!DBOps.RecordExists(_userCartId))
            {
                if (CanBeAdded)
                {
                    CartDataSource.Insert();
                    _itemQuant = productQuant - 1;
                    ProductsDataSource.Update();
                }
            }
            else
            {
                if (CanBeAdded && productQuant > 0)
                {
                    _itemQuant = productQuant - 1;
                    CartDataSource.Update();
                    ProductsDataSource.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 if (!CanBeAdded)
                {
                    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 {1} will exceed the limit of 99.')", true);
                }
            }

            SiteMaster master = Page.Master as SiteMaster;

            master.UpdateTotalCounters();
        }
Exemple #23
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();
        }