SlideShare a Scribd company logo
CIS407A iLab 5 Web Application
Development Devry University
Click this link to get the tutorial:
http://homeworkfox.com/tutorials/general-
questions/6227/cis407a-ilab-5-web-application-development-
devry-university/
iLab 5 of 7: Transaction Processing (30 Points)

Submit your assignment to the Dropbox located on the silver tab at the top of this page.

(See "Due Dates for Assignments & Exams" in the Syllabus for due dates.)

iLABOVERVIEW

Scenario/Summary

This week, we will use the .NET OleDbTransaction functions to either commit a set of changes
to the database, if all of them were done correctly, or to roll back all of the changes if there was
an error in any one of them. We will first modify the code we created last week so that it saves
personnel data in the database in two steps; first by inserting a personnel record for a new
employee, and then by updating that record to fill in the start and end dates. This two-step
approach is not really needed in this simple case, but we will use it to simulate a more complex
database transaction that would have to be done in multiple steps, such as one involving more
than one table or even more than one database. We will then see what happens when there is an
error in the second operation (the update), allowing a record to be created containing incomplete
information--not a good result! We will fix the problem by wrapping both operations (the insert
and the update) into a single transaction that will be committed (made permanent) only if both
operations succeed or that will be rolled back (undone) if either operation fails. We will also add
client-side validation using the ASP.Net validation controls, and we will allow the user an easy
way to edit all employees.

Instructions for Week 5 iLab: "Transaction Processing"

Click on the link above to view the tutorial.

Please watch this tutorial before beginning the iLab.

The tutorial has audio.

Deliverables
All files are located in the subdirectory of the project. The project should function as specified:
When you press the Submit button in frmPersonnel, a record should be saved in the tblPersonnel
table containing the FirstName, LastName, PayRate, StartDate, and EndDate you entered. Test
that the transaction will rollback by entering invalid information in one or more items, such as
Hello for a StartDate. Check tht client-side validation works: The ability to edit employees in a
grid is working. Once you have verified that it works, save your website, zip up all files, and
submit them to the Dropbox.

iLABSTEPS

STEP 1: Modify the clsDataLayer to use a two-step process (10 points)

1. Open Microsoft Visual Studio.NET 2008.

2. Click the ASP.NET project called PayrollSystem to open it.

3. Open the clsDataLayer class.

4. Modify the SavePersonnel() function so that instead of just doing a single SQL INSERT
operation with all the personnel data, it does an INSERT with only the FirstName and LastName,
followed by an UPDATE to save the PayRate, StartDate, and EndDate into the new record. (This
two-step approach is not really necessary here because we are dealing with only one table,
tblPersonnel, but we are doing it to simulate a case with more complex processing requirements,
where we would need to insert or update data in more than one table or maybe even more than
one database.) Find the following existing code in the SavePersonnel() function:

// Add your comments here

+

"(FirstName, LastName, PayRate, StartDate, EndDate) values ('" +

FirstName + "', '" + LastName + "', " + PayRate + ", '" + StartDate +

"', '" + EndDate + "')";

// Add your comments here

;

;

// Add your comments here

command.ExecuteNonQuery();
5.

Modify it so that it reads as follows:

// Add your comments here

+

"(FirstName, LastName) values ('" +

FirstName + "', '" + LastName + "')";

// Add your comments here

;

;

// Add your comments here

command.ExecuteNonQuery();

// Add your comments here

+

"Set , " +

", " +

""+

"Where ID=(Select Max(ID) From tblPersonnel)";

// Add your comments here

;

;

// Add your comments here

command.ExecuteNonQuery();

6. Set frmMain as the startup form and run the PayrollSystem Web application to test the
changes. When valid data values are entered for a new employee, things should work exactly as
they did before. To test this, enter valid data for a new employee in frmPersonnel and click
Submit. The frmPersonnelVerified form should be displayed with the entered data values and a
message that the record was saved successfully. Click the View Personnel button and check that
the new personnel record was indeed saved to the database and that all the entered data values,
including the PayRate, StartDate, and EndDate, were stored correctly. Close the browser
window.

7. Now run the PayrollSystem Web application again, but this time enter some invalid data (a
nonnumeric value) in the PayRate field to cause an error, like this:

Click on image to enlarge.

8.

Click here for text description of this image.

9. Now when you click Submit, the frmPersonnelVerified form should display a message
indicating the record was not saved:

Click on image to enlarge.

10.

Click here for text description of this image.

11. However, when you click on the View Personnel button to display the personnel records,
you should see that an incomplete personnel record was in fact created, with missing values for
the PayRate, StartDate and EndDate fields:

Click on image to enlarge.

12.

Click here for text description of this image.

13. This occurred because the Insert statement succeeded but the following Update statement
did not. We do not want to allow this to happen because we end up with incomplete or incorrect
data in the database. If the Update statement fails, we want the Insert statement to be rolled back,
or undone, so that we end up with no record at all. We will fix this by adding transaction code in
the next step.

STEP 2: Add transaction code (10 points)

7. In the clsDataLayer.cls class file, add code to the SavePersonnel() function to create a
transaction object. Begin the transaction, commit the transaction if all database operations are
successful, and roll back the transaction if any database operation fails. The following listing
shows the complete SavePersonnel() function; the lines you will need to add are marked with **
NEW ** in the preceding comment and are shown in bold.

// This function saves the personnel data

public static bool SavePersonnel(string Database, string FirstName, string LastName,

string PayRate, string StartDate, string EndDate)

{

bool recordSaved;

// ** NEW ** Add your comments here

OleDbTransaction ;

try

{

// Add your comments here

OleDbConnection OleDbConnection(";" +

"Data Insert into tblPersonnel " +

"(FirstName, LastName) values ('" +

FirstName + "', '" + LastName + "')";

// Add your comments here

;

;

// Add your comments here

command.ExecuteNonQuery();

// Add your comments here

+

"Set , " +
", " +

""+

"Where ID=(Select Max(ID) From tblPersonnel)";

// Add your comments here

;

;

// Add your comments here

command.ExecuteNonQuery();

// ** NEW ** Add your comments here

myTransaction.Commit();

// Add your comments here

conn.Close();

;

}

catch (Exception ex)

{

// ** NEW ** Add your comments here

myTransaction.Rollback();

;

}

return recordSaved;

}

8. Run your Web application. First, enter valid data in all the fields of frmPersonnel. When you
press the Submit button in frmPersonnel, a record should be saved in the tblPersonnel table
containing the FirstName, LastName, PayRate, StartDate, and EndDate. With valid data entered
in all the items, the "successfully saved" message should appear indicating that the transaction
was committed.

Click on image to enlarge.

9.

Click here for text description of this image.

10. Click the View Personnel button and verify that the new record was in fact added to the
database table correctly.

Click on image to enlarge.

11.

Click here for text description of this image.

12. Now close the browser, run the Web application again, and this time test that the transaction
will roll back after entering incorrect information. On the frmPersonnel form, enter invalid data
for PayRate and click Submit. The "not saved" message should appear, which indicates that the
transaction was rolled back.

Click on image to enlarge.

13.

Click here for text description of this image.

14. Click the View Personnel button and verify that this time, as desired, an incomplete record
was not added to the database table.

Click on image to enlarge.

15.

Click here for text description of this image.

16. You have seen how we used the try/catch block to catch an unexpected error. You may have
noticed that if you enter bad data for the dates, an exception is thrown. Go back to the validation
code you added in the frmPersonnel code and add a try/catch with logic to prevent an invalid
date from causing a server error.

17. In the Week 3 and Week 5 labs, you learned how to validate code once the page was posted
back to the server. There is some validation that must be done on the server because it requires
server resources such as the database. Some validation can also be done on the client. If you can
do validation on the client it saves a round trip to the server, which will improve performance. In
this approach, we will check values before the page is submitted to the server for processing.
Normally, there is a combination of server and client validation used in a web application.
ASP.Net includes validation controls which will use JavaScript on the client to perform
validation. You will find these controls in the Validation group in the toolbox.

18. Add validation controls to the frmPersonnel form as follows: For the first and last name,
make sure each field has data in it. Use the RequiredFieldValidator for this. Add the control to
the right of the text box you are validating. The location of the validator control is where the
error message (if there is one) will appear for the control you link the validator to. You will be
adding one validator control for each text box you want to validate. Remember to set the
ControlToValidate and ErrorMessage properties on the validator control. Making this change
eliminates the need for the server-side check you were doing previously. Use a regular
expression validator to check that the start and end date are in the correct format.

Click on image to enlarge.

19.

Click here for text description of this image.

20. Remove the View Personnel and Cancel buttons from the frmPersonnel form as they will
cause a Postback and invoke the client-side editing you just added. The user is able to get to the
View Personnel from the main form and from the personnel verification screen, so there is no
need for these buttons now.

21. Because you have entered data in this lab that is invalid and those partial records are in the
database, you will need to add the ability to remove or update data. Add a new main form option
called Edit Employees. Add the link and image for this. This option will take the user to a new
form called frmEditPersonnel.

frmMain with links added

22.

Click here for text description of this image.

23. Add the new form frmEditPersonnel. On frmEditPersonnel, add the CoolBiz log at the top of
the form. Add a label that says "Edit Employees." Add a GridView control with an ID of
grdEditPersonnel.

24. You will now add a SQLDataSource to the page. You will be using a databound grid for this
form unlike the previous grids, in which you added as unbound (in the designer).
25. Add a new SQLDataSource control to the frmEditPersonnel in the design view. This is not a
visible control; that is, it will only appear in design view but the user will never see it. Note: If
you change the folder name or location of your database, you will need to reconfigure the data
source (right-click on the data source control and select the "Configure Data Source" option.

26. There is a small > indicator in the design view of the SQL Data Source control you added if
the configuration menu is collapsed (press it to open the menu), or there is a < with the menu
displayed. From the data source menu, select "Configure Data Source."

27. Press the New Connection button and select the database.

28. Press the Next button.

29. When asked if you want to save the connection in the application configuration file, check
the Yes check box and press Next.

30. Select the tblPersonnel table.

31. Select all columns (you can use the * for this).

32. Press the Advanced button and check the Generate Insert, Update, and Delete option and
press the OK button.

33. Press the Next button.

34. Press the Test Query button and make sure everything works as it is supposed to. If it does
not repeat the above steps to make sure you did everything properly. Press the Finish button.

7. Click on the grid you added in the design view and expand the properties menu (the little > in
the upper right of the control). Choose the data source you just added. On the GridView tasks
menu, select Edit columns. Add an Edit, Update, and Cancel Command field. Add a Delete
Command field. Press OK. You can now test the grid, which is a fully functioning Update and
Delete grid. Try it out!

Click on image to enlarge.

8.

Click here for text description of this image.

9. Hints:

Make sure you reestablish your database connection if you copied the files from a previous lab.

In order to keep the validation controls from causing wrapping, you may want to increase the
Panel width.
A regular expression for mm/dd/yyyy is this:

^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)dd$

Experiment with the editable grid and command buttons for different display styles.

STEP 3: Test and submit (10 points)

29. Once you have verified that everything works as it is supposed to, save your project, zip up
all files, and submit in the Dropbox.

More Related Content

What's hot

Automation Anywhere Examples
Automation Anywhere ExamplesAutomation Anywhere Examples
Automation Anywhere Examples
Shekar S
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
MariAnne Woehrle
 
Wheels
WheelsWheels
Wheels
guest9fd0a95
 
Merrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
Merrill's Journey to CI-CD and Continuous Testing by Ashish MukherjeeMerrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
Merrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
Sauce Labs
 
Best Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and TricksBest Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and Tricks
Techtic Solutions
 
Introduction to the .NET Access Control Service
Introduction to the .NET Access Control ServiceIntroduction to the .NET Access Control Service
Introduction to the .NET Access Control Servicebutest
 
Nativescript angular
Nativescript angularNativescript angular
Nativescript angular
Christoffer Noring
 
Salesforce connector Example
Salesforce connector ExampleSalesforce connector Example
Salesforce connector Example
prudhvivreddy
 
Vue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and VuexVue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and Vuex
Christoffer Noring
 
Soa8
Soa8Soa8
Getting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiGetting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiAmit Sharma
 
Test Coverage for Your WP REST API Project
Test Coverage for Your WP REST API ProjectTest Coverage for Your WP REST API Project
Test Coverage for Your WP REST API Project
Pantheon
 
CrossUI Tutorial - Advanced - CRUD
CrossUI Tutorial  -  Advanced - CRUDCrossUI Tutorial  -  Advanced - CRUD
CrossUI Tutorial - Advanced - CRUD
Jack Lee
 
Getting started-with-oracle-so a- lab 11
Getting started-with-oracle-so a- lab 11Getting started-with-oracle-so a- lab 11
Getting started-with-oracle-so a- lab 11Amit Sharma
 
3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components
Surendra kumar
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJSTroy Miles
 
Demo how to create visualforce and apex controller to update, delete custom o...
Demo how to create visualforce and apex controller to update, delete custom o...Demo how to create visualforce and apex controller to update, delete custom o...
Demo how to create visualforce and apex controller to update, delete custom o...
tuan vo
 
Automation anywhere user manual tethys solutions
Automation anywhere user manual   tethys solutionsAutomation anywhere user manual   tethys solutions
Automation anywhere user manual tethys solutions
Vijay Reddy
 
Validating forms (and more) with the HTML5 pattern attribute
Validating forms (and more) with the HTML5 pattern attributeValidating forms (and more) with the HTML5 pattern attribute
Validating forms (and more) with the HTML5 pattern attribute
cliener
 

What's hot (20)

Automation Anywhere Examples
Automation Anywhere ExamplesAutomation Anywhere Examples
Automation Anywhere Examples
 
Aug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics IntegrationAug Xml Net Forum Dynamics Integration
Aug Xml Net Forum Dynamics Integration
 
Wheels
WheelsWheels
Wheels
 
Merrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
Merrill's Journey to CI-CD and Continuous Testing by Ashish MukherjeeMerrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
Merrill's Journey to CI-CD and Continuous Testing by Ashish Mukherjee
 
Best Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and TricksBest Laravel Eloquent Tips and Tricks
Best Laravel Eloquent Tips and Tricks
 
Introduction to the .NET Access Control Service
Introduction to the .NET Access Control ServiceIntroduction to the .NET Access Control Service
Introduction to the .NET Access Control Service
 
Nativescript angular
Nativescript angularNativescript angular
Nativescript angular
 
Salesforce connector Example
Salesforce connector ExampleSalesforce connector Example
Salesforce connector Example
 
70562-Dumps
70562-Dumps70562-Dumps
70562-Dumps
 
Vue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and VuexVue fundamentasl with Testing and Vuex
Vue fundamentasl with Testing and Vuex
 
Soa8
Soa8Soa8
Soa8
 
Getting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viiiGetting started-with-oracle-so a-viii
Getting started-with-oracle-so a-viii
 
Test Coverage for Your WP REST API Project
Test Coverage for Your WP REST API ProjectTest Coverage for Your WP REST API Project
Test Coverage for Your WP REST API Project
 
CrossUI Tutorial - Advanced - CRUD
CrossUI Tutorial  -  Advanced - CRUDCrossUI Tutorial  -  Advanced - CRUD
CrossUI Tutorial - Advanced - CRUD
 
Getting started-with-oracle-so a- lab 11
Getting started-with-oracle-so a- lab 11Getting started-with-oracle-so a- lab 11
Getting started-with-oracle-so a- lab 11
 
3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components
 
Beginning AngularJS
Beginning AngularJSBeginning AngularJS
Beginning AngularJS
 
Demo how to create visualforce and apex controller to update, delete custom o...
Demo how to create visualforce and apex controller to update, delete custom o...Demo how to create visualforce and apex controller to update, delete custom o...
Demo how to create visualforce and apex controller to update, delete custom o...
 
Automation anywhere user manual tethys solutions
Automation anywhere user manual   tethys solutionsAutomation anywhere user manual   tethys solutions
Automation anywhere user manual tethys solutions
 
Validating forms (and more) with the HTML5 pattern attribute
Validating forms (and more) with the HTML5 pattern attributeValidating forms (and more) with the HTML5 pattern attribute
Validating forms (and more) with the HTML5 pattern attribute
 

Viewers also liked

AbleGamers And The Inevitability of Inclusive Gaming
AbleGamers And The Inevitability of Inclusive GamingAbleGamers And The Inevitability of Inclusive Gaming
AbleGamers And The Inevitability of Inclusive GamingJohnny Richardson
 
Water
WaterWater
Cis407 a ilab 2 web application development devry university
Cis407 a ilab 2 web application development devry universityCis407 a ilab 2 web application development devry university
Cis407 a ilab 2 web application development devry universitylhkslkdh89009
 
phantomoftheopera
phantomoftheoperaphantomoftheopera
phantomoftheoperaanneha
 
Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2
Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2
Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2
Rizki Ramadhan
 
Listado de personas espiadas por el gobierno argentino 20-10-15
Listado de personas espiadas por el gobierno argentino 20-10-15Listado de personas espiadas por el gobierno argentino 20-10-15
Listado de personas espiadas por el gobierno argentino 20-10-15
Ciudadanos Autoconvocados Cuarto
 
Vizual Affectz
Vizual AffectzVizual Affectz
Vizual Affectz
jbull08
 
B@by B4 Me
B@by B4 MeB@by B4 Me
B@by B4 Me
jbull08
 

Viewers also liked (8)

AbleGamers And The Inevitability of Inclusive Gaming
AbleGamers And The Inevitability of Inclusive GamingAbleGamers And The Inevitability of Inclusive Gaming
AbleGamers And The Inevitability of Inclusive Gaming
 
Water
WaterWater
Water
 
Cis407 a ilab 2 web application development devry university
Cis407 a ilab 2 web application development devry universityCis407 a ilab 2 web application development devry university
Cis407 a ilab 2 web application development devry university
 
phantomoftheopera
phantomoftheoperaphantomoftheopera
phantomoftheopera
 
Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2
Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2
Izin pelaksanaan transmigrasi (ipt) kemitraan badan usaha file#2
 
Listado de personas espiadas por el gobierno argentino 20-10-15
Listado de personas espiadas por el gobierno argentino 20-10-15Listado de personas espiadas por el gobierno argentino 20-10-15
Listado de personas espiadas por el gobierno argentino 20-10-15
 
Vizual Affectz
Vizual AffectzVizual Affectz
Vizual Affectz
 
B@by B4 Me
B@by B4 MeB@by B4 Me
B@by B4 Me
 

Similar to Cis407 a ilab 5 web application development devry university

Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7helpido9
 
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docxThis is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
abhi353063
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docx
keilenettie
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
Mitchinson
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universitylhkslkdh89009
 
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx        Greetings and Salutations.docxCIS407AWk2iLabDefault.aspx        Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
clarebernice
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universitylhkslkdh89009
 
Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7helpido9
 
Cis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry universityCis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry universitylhkslkdh89009
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
niraj57
 
Adapters db-104-informixstoredprocedure
Adapters db-104-informixstoredprocedureAdapters db-104-informixstoredprocedure
Adapters db-104-informixstoredprocedure
prathap kumar
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
smile790243
 
Lampstack (1)
Lampstack (1)Lampstack (1)
Lampstack (1)
ShivamKumar773
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
vitabile
 
Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7helpido9
 
OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation Steps
Dharmaraj Borse
 
Building AWS Redshift Data Warehouse with Matillion and Tableau
Building AWS Redshift Data Warehouse with Matillion and TableauBuilding AWS Redshift Data Warehouse with Matillion and Tableau
Building AWS Redshift Data Warehouse with Matillion and Tableau
Lynn Langit
 
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
( 16 ) Office 2007   Create An Extranet Site With Forms Authentication( 16 ) Office 2007   Create An Extranet Site With Forms Authentication
( 16 ) Office 2007 Create An Extranet Site With Forms AuthenticationLiquidHub
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
Aravindharamanan S
 

Similar to Cis407 a ilab 5 web application development devry university (20)

Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7
 
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docxThis is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
This is part 1 of 3STEP 1 Modify the clsDataLayer to Use a Two-St.docx
 
Previous weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docxPrevious weeks work has been uploaded as well as any other pieces ne.docx
Previous weeks work has been uploaded as well as any other pieces ne.docx
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
 
Cis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry universityCis407 a ilab 4 web application development devry university
Cis407 a ilab 4 web application development devry university
 
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx        Greetings and Salutations.docxCIS407AWk2iLabDefault.aspx        Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
 
Cis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry universityCis407 a ilab 3 web application development devry university
Cis407 a ilab 3 web application development devry university
 
Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7Cis 407 i lab 4 of 7
Cis 407 i lab 4 of 7
 
Cis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry universityCis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry university
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
 
Adapters db-104-informixstoredprocedure
Adapters db-104-informixstoredprocedureAdapters db-104-informixstoredprocedure
Adapters db-104-informixstoredprocedure
 
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docxLab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
Lab StepsSTEP 1 Login Form1. In order to do this lab, we need.docx
 
Lampstack (1)
Lampstack (1)Lampstack (1)
Lampstack (1)
 
Tony Vitabile .Net Portfolio
Tony Vitabile .Net PortfolioTony Vitabile .Net Portfolio
Tony Vitabile .Net Portfolio
 
Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7
 
OBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation StepsOBIEE 11g : Repository Creation Steps
OBIEE 11g : Repository Creation Steps
 
Building AWS Redshift Data Warehouse with Matillion and Tableau
Building AWS Redshift Data Warehouse with Matillion and TableauBuilding AWS Redshift Data Warehouse with Matillion and Tableau
Building AWS Redshift Data Warehouse with Matillion and Tableau
 
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
( 16 ) Office 2007   Create An Extranet Site With Forms Authentication( 16 ) Office 2007   Create An Extranet Site With Forms Authentication
( 16 ) Office 2007 Create An Extranet Site With Forms Authentication
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 

Cis407 a ilab 5 web application development devry university

  • 1. CIS407A iLab 5 Web Application Development Devry University Click this link to get the tutorial: http://homeworkfox.com/tutorials/general- questions/6227/cis407a-ilab-5-web-application-development- devry-university/ iLab 5 of 7: Transaction Processing (30 Points) Submit your assignment to the Dropbox located on the silver tab at the top of this page. (See "Due Dates for Assignments & Exams" in the Syllabus for due dates.) iLABOVERVIEW Scenario/Summary This week, we will use the .NET OleDbTransaction functions to either commit a set of changes to the database, if all of them were done correctly, or to roll back all of the changes if there was an error in any one of them. We will first modify the code we created last week so that it saves personnel data in the database in two steps; first by inserting a personnel record for a new employee, and then by updating that record to fill in the start and end dates. This two-step approach is not really needed in this simple case, but we will use it to simulate a more complex database transaction that would have to be done in multiple steps, such as one involving more than one table or even more than one database. We will then see what happens when there is an error in the second operation (the update), allowing a record to be created containing incomplete information--not a good result! We will fix the problem by wrapping both operations (the insert and the update) into a single transaction that will be committed (made permanent) only if both operations succeed or that will be rolled back (undone) if either operation fails. We will also add client-side validation using the ASP.Net validation controls, and we will allow the user an easy way to edit all employees. Instructions for Week 5 iLab: "Transaction Processing" Click on the link above to view the tutorial. Please watch this tutorial before beginning the iLab. The tutorial has audio. Deliverables
  • 2. All files are located in the subdirectory of the project. The project should function as specified: When you press the Submit button in frmPersonnel, a record should be saved in the tblPersonnel table containing the FirstName, LastName, PayRate, StartDate, and EndDate you entered. Test that the transaction will rollback by entering invalid information in one or more items, such as Hello for a StartDate. Check tht client-side validation works: The ability to edit employees in a grid is working. Once you have verified that it works, save your website, zip up all files, and submit them to the Dropbox. iLABSTEPS STEP 1: Modify the clsDataLayer to use a two-step process (10 points) 1. Open Microsoft Visual Studio.NET 2008. 2. Click the ASP.NET project called PayrollSystem to open it. 3. Open the clsDataLayer class. 4. Modify the SavePersonnel() function so that instead of just doing a single SQL INSERT operation with all the personnel data, it does an INSERT with only the FirstName and LastName, followed by an UPDATE to save the PayRate, StartDate, and EndDate into the new record. (This two-step approach is not really necessary here because we are dealing with only one table, tblPersonnel, but we are doing it to simulate a case with more complex processing requirements, where we would need to insert or update data in more than one table or maybe even more than one database.) Find the following existing code in the SavePersonnel() function: // Add your comments here + "(FirstName, LastName, PayRate, StartDate, EndDate) values ('" + FirstName + "', '" + LastName + "', " + PayRate + ", '" + StartDate + "', '" + EndDate + "')"; // Add your comments here ; ; // Add your comments here command.ExecuteNonQuery();
  • 3. 5. Modify it so that it reads as follows: // Add your comments here + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Add your comments here ; ; // Add your comments here command.ExecuteNonQuery(); // Add your comments here + "Set , " + ", " + ""+ "Where ID=(Select Max(ID) From tblPersonnel)"; // Add your comments here ; ; // Add your comments here command.ExecuteNonQuery(); 6. Set frmMain as the startup form and run the PayrollSystem Web application to test the changes. When valid data values are entered for a new employee, things should work exactly as
  • 4. they did before. To test this, enter valid data for a new employee in frmPersonnel and click Submit. The frmPersonnelVerified form should be displayed with the entered data values and a message that the record was saved successfully. Click the View Personnel button and check that the new personnel record was indeed saved to the database and that all the entered data values, including the PayRate, StartDate, and EndDate, were stored correctly. Close the browser window. 7. Now run the PayrollSystem Web application again, but this time enter some invalid data (a nonnumeric value) in the PayRate field to cause an error, like this: Click on image to enlarge. 8. Click here for text description of this image. 9. Now when you click Submit, the frmPersonnelVerified form should display a message indicating the record was not saved: Click on image to enlarge. 10. Click here for text description of this image. 11. However, when you click on the View Personnel button to display the personnel records, you should see that an incomplete personnel record was in fact created, with missing values for the PayRate, StartDate and EndDate fields: Click on image to enlarge. 12. Click here for text description of this image. 13. This occurred because the Insert statement succeeded but the following Update statement did not. We do not want to allow this to happen because we end up with incomplete or incorrect data in the database. If the Update statement fails, we want the Insert statement to be rolled back, or undone, so that we end up with no record at all. We will fix this by adding transaction code in the next step. STEP 2: Add transaction code (10 points) 7. In the clsDataLayer.cls class file, add code to the SavePersonnel() function to create a transaction object. Begin the transaction, commit the transaction if all database operations are successful, and roll back the transaction if any database operation fails. The following listing
  • 5. shows the complete SavePersonnel() function; the lines you will need to add are marked with ** NEW ** in the preceding comment and are shown in bold. // This function saves the personnel data public static bool SavePersonnel(string Database, string FirstName, string LastName, string PayRate, string StartDate, string EndDate) { bool recordSaved; // ** NEW ** Add your comments here OleDbTransaction ; try { // Add your comments here OleDbConnection OleDbConnection(";" + "Data Insert into tblPersonnel " + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Add your comments here ; ; // Add your comments here command.ExecuteNonQuery(); // Add your comments here + "Set , " +
  • 6. ", " + ""+ "Where ID=(Select Max(ID) From tblPersonnel)"; // Add your comments here ; ; // Add your comments here command.ExecuteNonQuery(); // ** NEW ** Add your comments here myTransaction.Commit(); // Add your comments here conn.Close(); ; } catch (Exception ex) { // ** NEW ** Add your comments here myTransaction.Rollback(); ; } return recordSaved; } 8. Run your Web application. First, enter valid data in all the fields of frmPersonnel. When you press the Submit button in frmPersonnel, a record should be saved in the tblPersonnel table
  • 7. containing the FirstName, LastName, PayRate, StartDate, and EndDate. With valid data entered in all the items, the "successfully saved" message should appear indicating that the transaction was committed. Click on image to enlarge. 9. Click here for text description of this image. 10. Click the View Personnel button and verify that the new record was in fact added to the database table correctly. Click on image to enlarge. 11. Click here for text description of this image. 12. Now close the browser, run the Web application again, and this time test that the transaction will roll back after entering incorrect information. On the frmPersonnel form, enter invalid data for PayRate and click Submit. The "not saved" message should appear, which indicates that the transaction was rolled back. Click on image to enlarge. 13. Click here for text description of this image. 14. Click the View Personnel button and verify that this time, as desired, an incomplete record was not added to the database table. Click on image to enlarge. 15. Click here for text description of this image. 16. You have seen how we used the try/catch block to catch an unexpected error. You may have noticed that if you enter bad data for the dates, an exception is thrown. Go back to the validation code you added in the frmPersonnel code and add a try/catch with logic to prevent an invalid date from causing a server error. 17. In the Week 3 and Week 5 labs, you learned how to validate code once the page was posted back to the server. There is some validation that must be done on the server because it requires
  • 8. server resources such as the database. Some validation can also be done on the client. If you can do validation on the client it saves a round trip to the server, which will improve performance. In this approach, we will check values before the page is submitted to the server for processing. Normally, there is a combination of server and client validation used in a web application. ASP.Net includes validation controls which will use JavaScript on the client to perform validation. You will find these controls in the Validation group in the toolbox. 18. Add validation controls to the frmPersonnel form as follows: For the first and last name, make sure each field has data in it. Use the RequiredFieldValidator for this. Add the control to the right of the text box you are validating. The location of the validator control is where the error message (if there is one) will appear for the control you link the validator to. You will be adding one validator control for each text box you want to validate. Remember to set the ControlToValidate and ErrorMessage properties on the validator control. Making this change eliminates the need for the server-side check you were doing previously. Use a regular expression validator to check that the start and end date are in the correct format. Click on image to enlarge. 19. Click here for text description of this image. 20. Remove the View Personnel and Cancel buttons from the frmPersonnel form as they will cause a Postback and invoke the client-side editing you just added. The user is able to get to the View Personnel from the main form and from the personnel verification screen, so there is no need for these buttons now. 21. Because you have entered data in this lab that is invalid and those partial records are in the database, you will need to add the ability to remove or update data. Add a new main form option called Edit Employees. Add the link and image for this. This option will take the user to a new form called frmEditPersonnel. frmMain with links added 22. Click here for text description of this image. 23. Add the new form frmEditPersonnel. On frmEditPersonnel, add the CoolBiz log at the top of the form. Add a label that says "Edit Employees." Add a GridView control with an ID of grdEditPersonnel. 24. You will now add a SQLDataSource to the page. You will be using a databound grid for this form unlike the previous grids, in which you added as unbound (in the designer).
  • 9. 25. Add a new SQLDataSource control to the frmEditPersonnel in the design view. This is not a visible control; that is, it will only appear in design view but the user will never see it. Note: If you change the folder name or location of your database, you will need to reconfigure the data source (right-click on the data source control and select the "Configure Data Source" option. 26. There is a small > indicator in the design view of the SQL Data Source control you added if the configuration menu is collapsed (press it to open the menu), or there is a < with the menu displayed. From the data source menu, select "Configure Data Source." 27. Press the New Connection button and select the database. 28. Press the Next button. 29. When asked if you want to save the connection in the application configuration file, check the Yes check box and press Next. 30. Select the tblPersonnel table. 31. Select all columns (you can use the * for this). 32. Press the Advanced button and check the Generate Insert, Update, and Delete option and press the OK button. 33. Press the Next button. 34. Press the Test Query button and make sure everything works as it is supposed to. If it does not repeat the above steps to make sure you did everything properly. Press the Finish button. 7. Click on the grid you added in the design view and expand the properties menu (the little > in the upper right of the control). Choose the data source you just added. On the GridView tasks menu, select Edit columns. Add an Edit, Update, and Cancel Command field. Add a Delete Command field. Press OK. You can now test the grid, which is a fully functioning Update and Delete grid. Try it out! Click on image to enlarge. 8. Click here for text description of this image. 9. Hints: Make sure you reestablish your database connection if you copied the files from a previous lab. In order to keep the validation controls from causing wrapping, you may want to increase the Panel width.
  • 10. A regular expression for mm/dd/yyyy is this: ^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)dd$ Experiment with the editable grid and command buttons for different display styles. STEP 3: Test and submit (10 points) 29. Once you have verified that everything works as it is supposed to, save your project, zip up all files, and submit in the Dropbox.