Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            NorwinDBTableAdapters.ProductsTableAdapter products = new NorwinDBTableAdapters.ProductsTableAdapter();

            //get the product Id from the query string
            prodID = int.Parse(Request.QueryString[0]);

            //get the other needed info from various queries
            //TODO get this from the logged in account
            custID   = "GROSR";
            prodName = products.GetNameByProdID(prodID).ToString();


            //use the product id to call my scalar SQL statement to get the number of units in stock
            unitsInStock = Convert.ToInt32(products.GetInStockByProdID(prodID));

            if (unitsInStock > 0)
            {
                //set the max value of the validator to be the amount thats in stock
                vldQuantity.MaximumValue = unitsInStock.ToString();
            }
            else
            {
                vldQuantity.MinimumValue = "0";
                vldQuantity.MaximumValue = "0";
            }

            lsvProdDetails.DataSource = products.GetDataByProdID(Convert.ToInt32(Request.QueryString[0]));
            lsvProdDetails.DataBind();
        }
Пример #2
0
        protected void btnRemove_Click(object sender, EventArgs e)
        {
            custID = cbxCustomer.SelectedValue;
            //casting sender to a Button to make use of the CommandArgument property. Not sure if this is good practice, feels a little hacky.
            Button btnRm = (Button)sender;

            //Must pass it all as one string from the page, so it takes a few extra steps to split it up into the required types.
            string[] theArgs = btnRm.CommandArgument.Split(',');

            int productId        = int.Parse(theArgs[0]);
            int cartItemQuantity = int.Parse(theArgs[1]);
            int cartItemId       = int.Parse(theArgs[2]);
            int currentlyInStock = Convert.ToInt32(products.GetInStockByProdID(productId));

            //delete the row from the db in the cart
            cart.removeCartItem(cartItemId);

            //refresh the view
            lsvCart.DataSource = cart.GetDataByCustID(custID);
            lsvCart.DataBind();

            products.UpdateInStock((short)(cartItemQuantity + currentlyInStock), productId);
        }