Date: 11/22/07 (Web Development) Keywords: database, asp, security, web, shopping Hi all, protected void btnOrder_Click(object sender, EventArgs e) { //Check for Shoppingcart object // Create first if not there if (Session["cart"] == null) { Session["cart"] = new ShoppingCart(); int quantity = 0; } // make sure there is text if (txtQuantity.Text.Trim().Length != 0) { // try to convert text to int ??? int quantity = int.Parse(txtQuantity.Text); // check for this item in the cart // Note this only makes sense if the "cart" exists // since it checks for an individual item in the cart if (((ShoppingCart)Session["cart"]). keyExists(int.Parse(TextBox1.Text))) { //throw new Exception("Item already in cart - fix this"); Response.Write("Item already exists in cart. What do you want to do?"); // Message to user that product is already in the order ///AND this is where my problems start: /*try { Response.Write("Item already exists, what do you want to do?"); } catch (ArgumentException de) { ShoppingCart; } finally { Console.WriteLine("Finally Block"); } * */ ///END of one set of problems (sorry for intending issues) } if ((txtQuantity.Text.Trim().Length != 0)) // This is a new item { //Response.Write("Please choose the quantity"); OrderItem item = new OrderItem( int.Parse(TextBox1.Text), TextBox2.Text, double.Parse(TextBox6.Text), int.Parse(txtQuantity.Text)); ((ShoppingCart)Session["cart"]).addToCart(item); Response.Write("Item added successfully!"); Server.Transfer("CatalogDisplay.aspx"); } else { // Make the item OrderItem item = new OrderItem( int.Parse(TextBox1.Text), TextBox2.Text, double.Parse(TextBox6.Text), int.Parse(txtQuantity.Text)); // add to cart ((ShoppingCart)Session["cart"]).addToCart(item); ///////////////////////////////not sure what the next part does // How to make this work ?? // Who is the sender ? // What are the System.EventArgs ? this.btnReturn_Click(sender, e); //////////end of "not sure" } else { //Basically if the quantity field is empty, you can't move on to the Order page. Response.Write("Nothing Ordered You must order some of the product or return to the Catalog"); } Database reference: Northwind.mdb
|