Friday, October 29, 2010

Requirements to allow a new student to learn ASP.Net Step By Step

The Requirements that were sent by Radha garu were as follows -

1. First Requirement:
- there is an employees database table with the following columns - EmpID, FirstName, LastName, DOB, DOJ, Skillset, Address
- We have to create a Search page where the user can search by specifying the fields - To start with, the first assignment was to just search by Skillset

2. Second Requirement:
- make sure that the date fields (DOB, DOJ) not have the time component
- change the query to a stored proc (i.e. call a stored proc in the code instead of directly specifying the select statement as a string;

3. Third Requirement:
- allow user to specify other fields also as parameters for Searching

4. Fourth Requirement:
- Allow paging and sorting for the previous page
- Create a Login page (and associated table in database etc)
- Encrypt the password / Hash the password - DBA also should not be able to view user's password (by doing a 'select * from ....')

5. Fifth Requirement: (that I added and it is progress currently)
- Display another link at the top in Login.aspx to go to MoreUserDetails.aspx; The fields in this page should be - Nickname (textbox), Sex(RadioButton), Favorite Color(Dropdown); Validation controls should be set for these also;Only a logged in user can go enter details in that page; If a non-logged-in user reaches that page, then a message is displayed "Please login first...." and a link to Login.aspx is displayed....(Perhaps it would be good to disable the Panel consisting of the controls when a non-logged-in user reaches the page); A logged-in user should be able to see their details in this page if they have had entered at some previous time....If they have not entered this data before, then they should be able to enter the details

---------------------------------------------------------------------------

1. First Requirement -
Work done proceeded as follows -
- table in database was created ; to do this, it was necessary to understand if all the fields were Required or not - i.e. if fields were going to allow Null or not.. ; creating a Identity column (for empId) was also done - constraints specification was understood
- the select statement will use the 'like' operator, so 'like' operator and '%' were explained; string concatenation also was needed to be explained since we construct the 'select statement' as a string in C# code and assign it to CommandText property; Breakpoint & Use-of-F10-key were also explained (since debugging needed to done to ensure that the 'select statement string' was being built properly
- GridView and the statements to assign the 'select statement's results' to GridView have to be covered; hence SqlCommand, SqlConnection, ExecuteReader (dr.Read() method), ExecuteNonQuery (optional) had to be covered


Second Requirement -
Work done proceeded as follows -
Date fields, DOB & DOJ, are changed from DateTime types to varchar(10) types

Query was converted to stored proc; Assigning a default value to a SP parameter was explained; Then practice was done in SQL Server Management Studio on calling the SP in different ways (with all parameters , or with only the parameters with no default value assigned etc); C# code to call a stored proc and add SqlParameters was also explained;

Third Requirement -
Work done proceeded as follows -
First adding just one extra field was done to Search page, that of Salary.. The SP was modified accordingly.. SP was written first without using Dynamic SQL, i..e each incoming parameter was checked and then the appropriate select statement would be executed.. (This is there in Nikhila's screenshots).... Then, it was made to understand that this way writing the SP would not Scale for more number of parameters... So Dynamic SQL concept was introduced and then used for the 2 parameters first, Skillset and Salary.. After this was successful, other fields were also added to the UI and the SP also modified accordingly

Fourth Requirement -
Work done proceeded as follows -
To allow Paging and Sorting, EnablePaging and EnableSorting were set to True; but the date columns, since they are now varchar and appear in mm-dd-yyyy format, their columns do not get sorted properly.... So while returning their values in select statement, their values were changed to the format yyyy-mm-dd, so that sorting works peoperly...

A Login.aspx page was built.. But for this to work, first a Register.aspx page was built. The Register.aspx page had similar fields as that of ASP.Net Login controls - UserName, Password, Confirm Password, Email, Secret Question, Secret Answer...Except Secret Question and Answer, others are required fields..... On successfully Registering, all the fields would disappear and a message would appear at the top saying 'user registered successfully' and link displayed to go to Login page.... To store data into database, Insert command was used..but to use it, ExecuteNonQuery was introduced... Also, there was a check done to see if there was already a user with the same user name (since 2 users should not have the same username).... Also, validation controls were used to perform various checks...Regular Expressions were introduced and then an intensive exercise of about 20 examples was done... Regular Expressions were used to validate UserName, Password, Email fields. Ultimately, the default regex for email, that is provided by vs.net, was used since it was becoming too complicated... (This served to demonstrate that vs.net already provides some regex for most commonly used strings)....RequiredFieldValidator and CompareValidator were the other validation controls that were used in addition to RegularExpressionValidator.....
Then, on successful login, all the controls were then made invisible and a message assigned to a label (lblMessage) which was placed below all these controls.. But that resulted in the message 'user registered successfully' being displayed in the middle of the page....It does not look good.... Then DIV and Panel controls were explained and it was explained that when DIV and PANEL controls become invisible, other block controls shift up.... This was demonstrated with both DIV and PANEL....
BTW, in addition to displaying the message "User Registered Successfully", a link to go to the Login page is also displayed..
(One interesting point is that, for Confirm Password field, if a Compare Validator was placed to the Left of the RequiredFieldValidator, then the RequiredFieldValidator's error message would be displayed slightly to the right...Hence it was decided to remove RequiredFieldValidator altogether since CompareValidator would be enough for the job)

Login Page also had RequiredFieldValidators....and when user would successfully log in, a message was displayed at the bottom that "user logged in successfully"...

Fifth Requirement -
Word is proceeding as follows -
A new database table was created called AdditionalUserDetails whose primary key is UserName and has foreign key relation to Account table created in Register.aspx page... Session variable is introduced to allow storing User Name on a successful login.
At the beginning of the MoreUserDetails.aspx page, this Session variable is checked and user is asked to go to Login.aspx page if he/she is not logged in yet; If a logged-in user reaches the page, the Session variable will have been set, so it can be used to - (a). if the user has not previously filled this form, then a blank form should be displayed and then Session variable should be used to fill into AdditionalUserDetails table... (b) if user has previously filled this form, then the Session variable should be used to retrieve the user's info and the fields in this page should be populated...

.Net Course thoughts

1. Introduction to the Web as a Platform

Perhaps a few examples of HTML and Javascript should be taught..
Javascript should be limited to getElementById()

Video - http://msdn.microsoft.com/en-us/beginner/bb308772.aspx

In the Video listed above, the speaker talks about - IP Addresses (ipconfig), DNS Servers, http protocol, web server & client, etc.

The article related to the video -
Article - http://msdn.microsoft.com/hi-in/library/bb330932%28en-us,VS.80%29.aspx



NEXT IS THE MATERIAL COVERED BY SRIKANTH SIR's MATERIAL

Perhaps the order should be as follows, but too much of "basics theory" should not be covered. We should start off and explain the "basics" as and when required.
However intensive practice needs to be done whenever the "basics" are dealt with. (i.e Explaining the "basics" should not be a "passing mention" affair. The idea is only to postpone teaching the basics to just before using them, rather than all at once in the beginning of the course, since it is very likely the student will not be able visualize the importance/use of those basics until they see a need for them or see them in practice)

It might also be a good idea to make students write code on their books.. Writing at least once will make them think about the code... Just watching code in action will not be enough for beginners..

A very quick short session of theory should be followed by a list of exercises (like Shanti madam used to do)...It is very likely that most students will not study anything at home... At least writing the program once on their notebooks will give them a 1-time practice..

It is very important to start the class on time....finish theory part very very quickly - in the first 15-20 minutes and use rest of the 40 minutes for exercises, correcting, perhaps another theory part, followed by exerices again...

2. Basic SQL - select, insert, delete, update; create tables; contraints, primary keys, foreign keys...
Stored Procedures - creating them, passing parameters to them

3. Regular Expressions - while explaining RegularExpressionValidator - Intensive exercise by doing at least 20-30 examples

4. String manipulation using C# syntax - Intensive exercise by doing 20 examples

5. Cookies

6. Page Life Cycle