an endless loop of Csharp.Frustration[s]

    Date: 11/22/07 (Web Development)    Keywords: database, asp, security, web, shopping

    Hi all,

    I'll write my C# frustrations here...Note that this is for an assignment, so there is no need to worry about security issues and all those other wonderful things. I would ask my professor, but he's a programmer...and he's horrible at getting his thoughts across.

    I created a web form that allows users to choose a certain amount of a product they want, and afterwards, it all gets confirmed and a message shows up saying the conversion was completed (even though it wasn't...not yet anyway)

    Please note that I am NOT looking for code answers just to copy and paste. I would like the theory of how I should go about solving this - since most websites just give you a basic understanding of how try/catch works.

    Problem 1: How do I implement the "try", "catch", "finally" exception if a user picks the same product and quantity twice? I already have an if-statement that keeps track of what has been chosen in the user's session. Would the try/catch go into that if-statement?

    Problem 2: What if the user decides to first order 3 items of a product, then decides to order more? How would I input this into the "try", "catch", "finally"? I have an if-statement that keeps track of whether the quantity has been "trimmed" or not.

    Problem 3: Do I need a database connection command in that particular web page to determine how much of a product has been chosen and how much is available to other users?

    Problem 4: Confirmation e-mail. I understand the whole idea of "using System.Net;" for email, but how would I go about implementing code to get an e-mail application started? (This problem/question is seperate from the code below)


    Here's my code for the different problems 1 - 3:





    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

    Source: http://community.livejournal.com/webdev/449890.html

« CSS + Links || trouble with lists »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home