Esempio n. 1
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();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }
Esempio n. 5
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();
        }