SlideShare uma empresa Scribd logo
1 de 8
HELPIDO.COM
CLICK HERE TO GET THE SOLUTION !!!!!!
CIS 407 A – ILAB 5 OF 7
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
strSQL = "Insert into tblPersonnel " +
"(FirstName, LastName, PayRate, StartDate, EndDate) values ('" +
FirstName + "', '" + LastName + "', " + PayRate + ", '" + StartDate +
"', '" + EndDate + "')";
// Add your comments here
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
// Add your comments here
command.ExecuteNonQuery();
5.
Modify it so that it reads as follows:
// Add your comments here
strSQL = "Insert into tblPersonnel " +
"(FirstName, LastName) values ('" +
FirstName + "', '" + LastName + "')";
// Add your comments here
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
// Add your comments here
command.ExecuteNonQuery();
// Add your comments here
strSQL = "Update tblPersonnel " +
"Set PayRate=" + PayRate + ", " +
"StartDate='" + StartDate + "', " +
"EndDate='" + EndDate + "' " +
"Where ID=(Select Max(ID) From tblPersonnel)";
// Add your comments here
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
// 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.
frmPersonnel With
Bad Data
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.
frmPersonnel Verified
With Error Message
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.
Incomplete Personnel
Record
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 boolSavePersonnel(string Database, string FirstName, string LastName,
string PayRate, string StartDate, string EndDate)
{
boolrecordSaved;
// ** NEW ** Add your comments here
OleDbTransactionmyTransaction = null;
try
{
// Add your comments here
OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Database);
conn.Open();
OleDbCommand command = conn.CreateCommand();
string strSQL;
// ** NEW ** Add your comments here
myTransaction = conn.BeginTransaction();
command.Transaction = myTransaction;
// Add your comments here
strSQL = "Insert into tblPersonnel " +
"(FirstName, LastName) values ('" +
FirstName + "', '" + LastName + "')";
// Add your comments here
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
// Add your comments here
command.ExecuteNonQuery();
// Add your comments here
strSQL = "Update tblPersonnel " +
"Set PayRate=" + PayRate + ", " +
"StartDate='" + StartDate + "', " +
"EndDate='" + EndDate + "' " +
"Where ID=(Select Max(ID) From tblPersonnel)";
// Add your comments here
command.CommandType = CommandType.Text;
command.CommandText = strSQL;
// Add your comments here
command.ExecuteNonQuery();
// ** NEW ** Add your comments here
myTransaction.Commit();
// Add your comments here
conn.Close();
recordSaved = true;
}
catch (Exception ex)
{
// ** NEW ** Add your comments here
myTransaction.Rollback();
recordSaved = false;
}
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.
frmPersonnelVerified
After Commit
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.
frmViewPersonnel
After Commit
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.
frmPersonnel Verified
After Rollback
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.
frmViewPersonnel
After Rollback
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.
frmPersonnel
Validation Controls
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.
Click on image to
enlarge.
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.
Edit Employees
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.
NOTE: Make sure you include comments in the code provided where specified (where the " //
Your comments here" is mentioned) and for any code you write, or else a five point deduction per
item (form, class, function) will be made.
CLICK HERE TO GET THE SOLUTION !!!!!!

Mais conteúdo relacionado

Mais procurados

Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...
Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...
Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...Amit Sharma
 
Plsql task
Plsql taskPlsql task
Plsql taskNawaz Sk
 
How to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationHow to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationnitin2517
 
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
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answersNawaz Sk
 

Mais procurados (6)

Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...
Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...
Salesforce interview-preparation-toolkit-formula-and-validation-rules-in-sale...
 
Plsql task
Plsql taskPlsql task
Plsql task
 
How to develop a gateway service using code based implementation
How to develop a gateway service using code based implementationHow to develop a gateway service using code based implementation
How to develop a gateway service using code based implementation
 
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
 
Clean Test Code
Clean Test CodeClean Test Code
Clean Test Code
 
Plsql task answers
Plsql task answersPlsql task answers
Plsql task answers
 

Destaque (6)

Presentación1
Presentación1Presentación1
Presentación1
 
Selaras 1 y5 p1
Selaras 1 y5 p1Selaras 1 y5 p1
Selaras 1 y5 p1
 
ibuyer_Manual
ibuyer_Manualibuyer_Manual
ibuyer_Manual
 
Movimientos sociales y Tecnopolítica: Tecnoactivismo
Movimientos sociales y Tecnopolítica: TecnoactivismoMovimientos sociales y Tecnopolítica: Tecnoactivismo
Movimientos sociales y Tecnopolítica: Tecnoactivismo
 
DEEPAK[1]_(5)(1)
DEEPAK[1]_(5)(1)DEEPAK[1]_(5)(1)
DEEPAK[1]_(5)(1)
 
Proceso penal. personas con discapacidad.
Proceso penal. personas con discapacidad.Proceso penal. personas con discapacidad.
Proceso penal. personas con discapacidad.
 

Semelhante a CIS 407 A - Two-step data process and transactions

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.docxabhi353063
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletMitchinson
 
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 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
 
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.docxkeilenettie
 
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.docxsmile790243
 
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx        Greetings and Salutations.docxCIS407AWk2iLabDefault.aspx        Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docxclarebernice
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universitylhkslkdh89009
 
Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7helpido9
 
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxBe sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxaman341480
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologiesjamessakila
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxgilpinleeanna
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedureftz 420
 
Murach : How to work with session state and cookies
Murach : How to work with session state and cookiesMurach : How to work with session state and cookies
Murach : How to work with session state and cookiesMahmoudOHassouna
 

Semelhante a CIS 407 A - Two-step data process and transactions (20)

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
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
 
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 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
 
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
 
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
 
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 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
 
Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7Cis 407 i lab 6 of 7
Cis 407 i lab 6 of 7
 
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docxBe sure to read all of Chapters 8 and 9 before starting this assignm.docx
Be sure to read all of Chapters 8 and 9 before starting this assignm.docx
 
Detail view in distributed technologies
Detail view in distributed technologiesDetail view in distributed technologies
Detail view in distributed technologies
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Wheels
WheelsWheels
Wheels
 
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docxMSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
MSCD650 Final Exam feedback FormMSCD650 Final Exam Grading For.docx
 
Bam
BamBam
Bam
 
Bam
BamBam
Bam
 
Salary advanceworkflow
Salary advanceworkflowSalary advanceworkflow
Salary advanceworkflow
 
Qtp day 3
Qtp day 3Qtp day 3
Qtp day 3
 
Sql storeprocedure
Sql storeprocedureSql storeprocedure
Sql storeprocedure
 
Murach : How to work with session state and cookies
Murach : How to work with session state and cookiesMurach : How to work with session state and cookies
Murach : How to work with session state and cookies
 

Último

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Último (20)

Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

CIS 407 A - Two-step data process and transactions

  • 1. HELPIDO.COM CLICK HERE TO GET THE SOLUTION !!!!!! CIS 407 A – ILAB 5 OF 7 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 strSQL = "Insert into tblPersonnel " + "(FirstName, LastName, PayRate, StartDate, EndDate) values ('" + FirstName + "', '" + LastName + "', " + PayRate + ", '" + StartDate + "', '" + EndDate + "')"; // Add your comments here command.CommandType = CommandType.Text; command.CommandText = strSQL; // Add your comments here command.ExecuteNonQuery(); 5. Modify it so that it reads as follows: // Add your comments here strSQL = "Insert into tblPersonnel " + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Add your comments here command.CommandType = CommandType.Text;
  • 2. command.CommandText = strSQL; // Add your comments here command.ExecuteNonQuery(); // Add your comments here strSQL = "Update tblPersonnel " + "Set PayRate=" + PayRate + ", " + "StartDate='" + StartDate + "', " + "EndDate='" + EndDate + "' " + "Where ID=(Select Max(ID) From tblPersonnel)"; // Add your comments here command.CommandType = CommandType.Text; command.CommandText = strSQL; // 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. frmPersonnel With Bad Data 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. frmPersonnel Verified With Error Message
  • 3. 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. Incomplete Personnel Record 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 boolSavePersonnel(string Database, string FirstName, string LastName, string PayRate, string StartDate, string EndDate) { boolrecordSaved; // ** NEW ** Add your comments here OleDbTransactionmyTransaction = null; try { // Add your comments here OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Database); conn.Open(); OleDbCommand command = conn.CreateCommand(); string strSQL; // ** NEW ** Add your comments here myTransaction = conn.BeginTransaction();
  • 4. command.Transaction = myTransaction; // Add your comments here strSQL = "Insert into tblPersonnel " + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Add your comments here command.CommandType = CommandType.Text; command.CommandText = strSQL; // Add your comments here command.ExecuteNonQuery(); // Add your comments here strSQL = "Update tblPersonnel " + "Set PayRate=" + PayRate + ", " + "StartDate='" + StartDate + "', " + "EndDate='" + EndDate + "' " + "Where ID=(Select Max(ID) From tblPersonnel)"; // Add your comments here command.CommandType = CommandType.Text; command.CommandText = strSQL; // Add your comments here command.ExecuteNonQuery(); // ** NEW ** Add your comments here myTransaction.Commit(); // Add your comments here conn.Close(); recordSaved = true; } catch (Exception ex) { // ** NEW ** Add your comments here myTransaction.Rollback(); recordSaved = false; } return recordSaved; }
  • 5. 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. frmPersonnelVerified After Commit 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. frmViewPersonnel After Commit 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. frmPersonnel Verified After Rollback 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.
  • 6. frmViewPersonnel After Rollback 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. frmPersonnel Validation Controls 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. Click on image to enlarge.
  • 7. 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. Edit Employees 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.
  • 8. 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. NOTE: Make sure you include comments in the code provided where specified (where the " // Your comments here" is mentioned) and for any code you write, or else a five point deduction per item (form, class, function) will be made. CLICK HERE TO GET THE SOLUTION !!!!!!