S511 Tech Foundations of Net-enabled Organizations

Assignment 4 - Working with ADO .NET

Due: Sunday Dec 5 2004 by 11:59PM- firm Deadline

Objectives of this assignment

The primary objective of this assignment is to connect ASP.NET web forms to databases using ADO.NET. In this assignment, you are going to start with the files you submitted for Assignment 3, and build up from that to make a complete application.

Part 0. Authentication screen

Remember our old authentication forms that we created in a couple of in-class exercises? You will need to now make a real one of those. This form will simply have two textboxes, one for username, and one for password, and one login button, which will verify the password of the user with passwords in the database, and if the password matches the one in the database for that user, it will redirect the page to the stocks.aspx web form, otherwise display an error message. Name this form login.aspx

If you like, you can do this with a custom validator, which makes connection to the database, searches for the username and password, and returns valid if a row exists with the username and password, say its valid, otherwise not. You can then check Page.IsValid to determine if validations passed, and proceed to stocks.aspx. To redirect to a different page, use the following code:

	Response.redirect("stocks.aspx")

Remember that you will need to save the username in a session variable for it to be available to other programs. A session variable is simply an extension to cookies that allow you to save information in the client for integration between different pages. You can see some more info on session variables in http://hotwired.lycos.com/webmonkey/03/30/index3a.html, but basically, all you are doing is:

	Session("username") = whatever the username value is

If the user does not have an account in the database, you should provide a link to go to the userprofile.aspx page, to create a new profile.


Part 1. User profile Web form

You have already created the user profile page in Assignment 2 - now you have to do some real things:

  1. Obviously, now the information gets stored in a database. When you submit the information, if the fields are all valid, then you need to save the information in the database in a table (say, called, userprofiles). You will need to create this table in your SQL server database, with all the fields that you have in your user profile form.
  2. A user may edit his/her information - so you should be able to load the information from the database. Note that if the user loads the information from the database, he/she cannot change his/her username - so you should disable the username textbox. How do you know if a user is actually editing existing information and not creating a new profile? All you have to do is to check the session variable. If the session variable is not empty, then you are in edit mode, otherwise in insert mode. In edit mode, when you save, your query would be an update table query rather than an insert query.
  3. The username uniqueness can now be tested. The requirement that the username be between 5 and 10 characters, and not start with a numeric value still stay. You don't need the last requirement - that it ends with a numeric value. Instead you actually check for uniqueness, to make sure that the username does not actually exist in the database already.
  4. You should have a "log out" button - and when this button is pushed, set the session variable to empty, and redirect to the login.aspx page.
  5. You should also include a link for the user to go to the stocks page from here.

Part 2 - Stock Calculator

In this part of the assignment, you will modify your stock calculator so that it now actually reads information from the database.

  1. You will need a stocks table, in which you store the symbols, names, and current prices of, say, 10-15 different stocks. Just go to www.nasdaq.com and pick up some stocks from there to load this table. You will need to save the ddl statements for creating this table, and loading values in this table, so avoid using MS access ADP for this. See What to submit for details.
  2. You will now need to modify your form to let the user pick stocks for his/her portfolio. You can do this in many ways - here are a couple of options, but feel free to come up with your own idea as well:
  3. To save the information for users, you will need to create a joining table between userprofile and stocks - say in a table called "userstocks". Create this table in your database, with userid and stocksymbol as foreign keys from the two other tables, and purchase price and quantity as the other fields.
  4. Like before, you will need to display the gain/loss and percentages for individual and cumulative display.
  5. You should have a "log out" button - and when this button is pushed, set the session variable to empty, and redirect to the login.aspx page.
  6. You should also have a link to go to the userprofile.aspx page to edit your profile.

Name this form stocks.aspx.


What to Submit

You will need to submit the following (follow the naming conventions exactly, otherwise you will not get the credit). Both the forms must show your name and username, as well as in the footer it should indicate the declaration stating "I have neither given nor received unauthorized aid on this deliverable." Make sure the files are submitted in proper case (in this case, everything is in lowercase):

How to Submit

To submit your assignment, follow the steps below:


Individual assignment policy

This assignment is an individual assignment. You are to work on this assignment solely by yourself with no direct help from any other student in the class or outside. You are welcome to post your questions or doubts on the course discussion forums as long as that does not involve posting part or whole of your solution. You can email me your questions if you need someone to look at your code. You can ask a fellow student for small help such as help with fixing a parse error, or a doubt about a statement in the assignment. However, the following will be considered violation of the individual policy and you will be penalized if you violate this policy: