Hi all,I'll create verbally my C# frustrations here... Note that this is for an assignment so there is no need to mind 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 create that allows users to decide a certain amount of a product they be 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 desire 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 undergo an if-statement that keeps bring in 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 undergo an if-statement that keeps bring in of whether the quantity has been "trimmed" or not. Problem 3: Do I need a database connection command in that particular web summon to cause 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 telecommunicate but how would I go about implementing code to get an telecommunicate application started? (This problem/question is seperate from the label below) Here's my code for the different problems 1 - 3:
protected cancel btnOrder_move(disapprove sender. EventArgs e) { //analyse for Shoppingcart object // Create first if not there if (Session["cart"] == null) { Session["cart"] = new ShoppingCart(); int quantity = 0; } // alter sure there is text if (txtQuantity. Text. cut(). Length != 0) { // try to alter text to int ??? int quantity = int. analyse(txtQuantity. Text); // check for this item in the draw // Note this only makes sense if the "cart" exists // since it checks for an individual item in the cart if (((ShoppingCart)Session["draw"]) keyExists(int. Parse(TextBox1. Text))) { //throw new Exception("Item already in cart - fix this"); Response. Write("Item already exists in cart. What do you be 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("gratify choose the quantity"); OrderItem item = new OrderItem( int. Parse(TextBox1. Text). TextBox2. Text double. Parse(TextBox6. Text) int. analyse(txtQuantity. Text)); ((ShoppingCart)Session["draw"]) addToCar
t(item); Response. create verbally("Item added successfully!"); Server. Transfer("CatalogDisplay aspx"); } else { // Make the item OrderItem item = new OrderItem( int. Parse(TextBox1. Text). TextBox2. Text double. analyse(TextBox6. Text) int. Parse(txtQuantity. Text)); // add to cart ((ShoppingCart)Session["draw"]) addToCar
t(item);///////////////////////////////not sure what the next move 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 alter you can't move on to the Order page. Response. create verbally("Nothing OrderedYou must request some of the product or return to the Catalog"); }
Hi there,I've always though that a Try Catch statement is for errors only say a conversion error null or an run out for example. If that error happened you could write a Try surprise statement to command the error instead of the schedule "blowing up". I'm not sure it can be used for other things though. When the user goes to add the same product into their shopping draw ask something desire "Item already exist in your shopping cart. Would you desire to add another?" From there you could try using an if statement. When you try to alter a text to int try placing the label inside a Val(code here) statement. And the sender is the object that sent "fired" the subroutine. I drop about the System. EventArgHope I helped a little bit. Goodluck!
As the other person who replied mentioned the try-catch-finally statements are for errors that arise due to outside events that aren't related to your label. What you're catching is an exception raised by the server when something goes do by with its normal processing. Mostly I've seen them used for database statements or any other time when you're trying to access an external resource that may be drink. THings like:try { connect to database;} surprise ( Exception exp) { if (exp write == "connection error) { errorLabel text = "Database connectivty problem try again later"; } else { errorLabel text = "Unknown error try again later"; }} finally { close database objects}Its really not for implementing your business rules. If the rule is that a user can't add the same item to the basket then you need to handle that possibility using if statements not by using exception handling. Exceptions are OMG the database is drink! or ZOMG that's an integer not a string! or WTF who's dividing by adjust. Yeah you can throw any error you be but things desire "you can't add another toothbrush to your shopping cart if you already undergo one in there" is not an error its the user being stupid and your label should handle for it. I'd stop fooling around with the code and write out a good old fashioned move chart until you have a good idea of how things are supposed to work. I do it at work all the measure. When in disbelieve draw it out.
I think you need to regenerate my C# teacher :) Thanks for the advice but when time is limited for an assignment then it's frustrating to undergo to create verbally everything out before starting the programming - with the assignment being due in about a week and on top of that there's other priorities desire lectures and other assignments (sorry for taking it all out on you lol but that's the truth about college) I was wondering is it possible to consider into an if-statement? ex if (quantity != 0 && item. KeyExists) //the coding is a little off but this is only to get my point across{ Response. create verbally("")}-What I want to do is once the user receives an error that product exists to have several buttons to show up for a user to click on - to regenerate the product's quantity.
I think you need to replace my C# teacher :) Thanks for the advice but when time is limited for an assignment then it's frustrating to have to write everything out before starting the programming - with the assignment being due in about a week and on top of that there's other priorities desire lectures and other assignments (sorry for taking it all out on you lol but that's the truth about college) I was wondering is it possible to consider into an if-statement? ex if (quantity != 0 && item. KeyExists) //the coding is a little off but this is only to get my point across{ Response. create verbally("")}-What I be to do is once the user receives an error that product exists to have several buttons to show up for a user to move on - to replace the product's quantity.
I know about college. I have a degree myself. I'd really declare you take measure to write your program out in at least an depict create before diving into the label. You don't undergo to do all the diamonds and boxes and arrows unless you're really stuck but if you can at least get a basic format for what you need done it will save you measure. Like for adding an item to the cart:function addItem( itemID shopperID) getShopperCart( shopperID) -- get the contents of their cart into an array checkForItem( cartArray itemID) -- be for an existing item if hasItem then displayAlert and displayIncreaseQtyBtn and displayCancelBtn else addItemToCartend functionOtherwise your if statement is fine. If the quantity isn't zero and the item exists in your object then do the response create verbally. That's book. For the buttons showing up.. try using the visible property on the buttons. So part if your if statement would be:btnIncreaseQty. Visible = true;btnCancelAdd. Visible = true;Then on your aspx page you'd add the buttons with the visibility initially to false so they're hiding until you be them.
Forex Groups - Tips on Trading
Related article:
http://community.livejournal.com/webdev/449890.html
comments | Add comment | Report as Spam
|