23.05.2017 Views

CIS 407 DeVry iLab 4 of 7 latest

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>CIS</strong> <strong>407</strong> <strong>DeVry</strong> <strong>iLab</strong> 4 <strong>of</strong> 7 <strong>latest</strong><br />

Downloading is very simple, you can download this Course here:<br />

http://wiseamerican.us/product/cis-<strong>407</strong>-devry-ilab-4-7-<strong>latest</strong>/<br />

Or<br />

Contact us at:<br />

SUPPORT@WISEAMERICAN.US<br />

<strong>CIS</strong> <strong>407</strong> <strong>DeVry</strong> <strong>iLab</strong> 4 <strong>of</strong> 7 Latest<br />

<strong>CIS</strong><strong>407</strong><br />

<strong>CIS</strong> <strong>407</strong> <strong>DeVry</strong> <strong>iLab</strong> 4 <strong>of</strong> 7 Latest<br />

<strong>iLab</strong> 4 <strong>of</strong> 7: Web Forms with Database Interaction (30 Points)<br />

Submit your assignment to the Dropbox located on the silver tab at the top <strong>of</strong> this page.<br />

(See Syllabus “Due Dates for Assignments & Exams” for due dates.)<br />

i L A B O V E R V I E W<br />

Scenario/Summary<br />

In this lab, we will start with the form we created in Week 2 (frmPersonnel) and add functionality to INSERT records<br />

into a database table and SELECT records for display to the user. We will create a typed dataset, a Data Layer class,<br />

several functions to access the data, and a connection to a database. We also will add a search form to allow the user<br />

to search records in the database and display the results <strong>of</strong> that search.<br />

Instructions for Week 4 <strong>iLab</strong>: Web Forms with Database Interaction<br />

Click on the link above to view the tutorial.<br />

Please watch this tutorial before beginning the <strong>iLab</strong>.<br />

The tutorial has audio.<br />

Deliverables<br />

All files are located in the subdirectory <strong>of</strong> the project. The project should function as specified: When you press the<br />

Submit button in frmPersonnel, a record should be saved in the tblPersonnel table having the FirstName, LastName,<br />

PayRate, StartDate, and EndDate you entered on the form. Add a search feature to the project. Update your main<br />

navigation page with the new options. Once you have verified that it works, save your website, zip up all files, and<br />

submit it in the Dropbox.<br />

i L A B S T E P S<br />

STEP 1: Data Layer (10 points)<br />

1. Open Micros<strong>of</strong>t Visual Studio.NET 2008.<br />

2. Click the ASP.NET project called PayrollSystem to open it.<br />

3. Open the clsDataLayer class and add the following function:<br />

// This function saves the personnel data<br />

public static bool SavePersonnel(string Database, string FirstName, string LastName,<br />

string PayRate, string StartDate, string EndDate)


{ bool recordSaved;<br />

try { // Add your comments here<br />

OleDbConnection conn = new OleDbConnection(“PROVIDER=Micros<strong>of</strong>t.Jet.OLEDB.4.0;” +<br />

“Data Source=” + Database);<br />

conn.Open();<br />

OleDbCommand command = conn.CreateCommand();<br />

string strSQL;<br />

// Add your comments here<br />

strSQL = “Insert into tblPersonnel ” +<br />

“(FirstName, LastName, PayRate, StartDate, EndDate) values (‘” +<br />

FirstName + “‘, ‘” + LastName + “‘, ” + PayRate + “, ‘” + StartDate +<br />

“‘, ‘” + EndDate + “‘)”;<br />

// Add your comments here<br />

command.CommandType = CommandType.Text;<br />

command.CommandText = strSQL;<br />

// Add your comments here<br />

command.ExecuteNonQuery();<br />

// Add your comments here<br />

conn.Close();<br />

recordSaved = true;<br />

} catch (Exception ex) {<br />

recordSaved = false; }<br />

return recordSaved; }<br />

4. In the frmPersonnelVerified form, go to the Page_Load() event and add the following code after the existing code<br />

(but in the Page_Load event handler):<br />

// Add your comments here<br />

if (clsDataLayer.SavePersonnel(Server.MapPath(“PayrollSystem_DB.mdb”),<br />

Session["txtFirstName"].ToString(),<br />

Session ["txtLastName"].ToString(),<br />

Session ["txtPayRate"].ToString(),<br />

Session ["txtStartDate"].ToString(),<br />

Session ["txtEndDate"].ToString()))<br />

{ txtVerifiedInfo.Text = txtVerifiedInfo.Text +<br />

“ The information was successfully saved!”; }<br />

else<br />

{ txtVerifiedInfo.Text = txtVerifiedInfo.Text +<br />

“ The information was NOT saved.”;


5. Add comments for all code containing // Add your comments here.<br />

6. Test your work to make sure no errors occur! (Make sure to put in valid date values for the date data entry fields).<br />

STEP 2: Data Display and Search (10 points)<br />

7. Using the skills you learned in Week 3, create a new DataSet for the tblPersonnel table (called the DataSet<br />

dsPersonnel).<br />

8. Using the skills you learned in Week 3, create a new function called GetPersonnel in the clsDataLayer class. This<br />

function should retrieve all data from the tblPersonnel table and return it in the form <strong>of</strong> a dsPersonnel DataSet. Use the<br />

GetUserActivity function as an example.<br />

9. Create a new Web form called frmViewPersonnel.<br />

10. Using the skills you learned in Week 3, add a GridView control (called grdViewPersonnel) to the form. This<br />

GridView control will be used to display data from the tblPersonnel table. Add the CoolBiz logo at the top <strong>of</strong> the page<br />

and make sure it links back to frmMain.<br />

11. Add the following code to the Page_Load() function in frmViewPersonnel:<br />

if (!Page.IsPostBack) {<br />

// Declare the DataSet<br />

dsPersonnel myDataSet = new dsPersonnel();<br />

// Fill the dataset with what is returned from the function<br />

myDataSet = clsDataLayer.GetPersonnel(Server.MapPath(“PayrollSystem_DB.mdb”));<br />

// Set the DataGrid to the DataSource based on the table<br />

grdViewPersonnel.DataSource = myDataSet.Tables["tblPersonnel"];<br />

// Bind the DataGrid<br />

grdViewPersonnel.DataBind(); }<br />

12. Return to the frmPersonnel Web form and add a button ((ID) = btnViewPersonnel, Text = View Personnel) which,<br />

when clicked, will display form frmViewPersonnel.<br />

13. Using the skills you learned in Week 3, open the frmPersonnelVerified form and add a button ((ID) =<br />

btnViewPersonnel, Text = View Personnel) which, when clicked, will display form frmViewPersonnel. NOTE: This is the<br />

same button with the same functionality that you added to form frmPersonnel in the previous step. Also add a new link<br />

and linked image to frmMain called View Personnel that will go to the new frmViewPersonnel page you created.<br />

14. You will now add a search feature to allow the user to find and display data. The user will enter a last name and<br />

the web application will display the grid <strong>of</strong> employees with all employees that match that last name.<br />

15. Create a new web form called frmSearchPersonnel. Add the hyperlinked Cool Biz logo to this page. Also add a<br />

new item on frmMain (with a link button and image button) called Search Personnel.<br />

16. On the frmSearchPersonnel form, add a label that displays “Search for employee by last name:”. Next to the label,<br />

add a text box with an ID <strong>of</strong> txtSearchName. Add a button with an ID <strong>of</strong> btnSearch and set the text <strong>of</strong> the button to<br />

“Search”.<br />

17. When the frmSearchPersonnel Search button is pressed, the frmViewPersonnel is displayed. At this point, no<br />

searching is actually happening, but you have the forms you need and the navigation working. Now you can focus on<br />

the coding you will need to do to have the grid only display matching employees.<br />

18. Before calling the GetPersonnel method you added previously in the lab, get the value that is in the<br />

Request["txtSearch"] item. When the form posts the search page results to the frmViewPersonnel, the name value pair<br />

for the search value is passed as part <strong>of</strong> the Request object. Assign this value to a string variable.<br />

19. Modify the GetPersonnel method you added to include a new parameter called strSearch <strong>of</strong> type string. This<br />

parameter needs to be after the Database string parameter that is already in the method.<br />

20. When calling the GetPersonnel method, pass the value you received to the strSearch parameter.


21. In the GetPersonnel method, you now need to use the passed in strSearch parameter value as part <strong>of</strong> the SQL<br />

string being used to retrieve data. You also need to add logic so that, if strSearch is empty or has no value, all employees<br />

are returned in the query.<br />

22. Test the search so that when you enter a last name, employees with that last name are returned. Make sure that<br />

when you access frmViewPersonnel and you are not searching, all employees are returned.<br />

23. Lab Hints:<br />

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

Before you pass the search value into the GetPersonnel method, make sure you check to see if the Request item is<br />

null. If it is, you need to pass an empty string into the method or check for null inside the method. If you don’t do this,<br />

you will get a server error. To check to see if an object is null, you compare the object to the keyword null.<br />

To create an SQL statement that will search for a given last name in the tblPersonnel table, you can do the following<br />

(assume that the search variable was called strSearch).<br />

“select * from tblPersonnel where LastName = ‘” + strSearch + “‘”<br />

24. Add the new Search option and the View Employees option to your main navigation page.<br />

STEP 3: Test and submit (10 points)<br />

Run your project and test it as follows:<br />

The frmMain form should be displayed first (set this form as your start page).<br />

Click on imag e to enlarge.<br />

Click here for text discription <strong>of</strong> this image.<br />

Click on the Add New Employee hyperlink to go to the frmPersonnel data entry form. Click the View Personnel button<br />

on this form. The frmViewPersonnel form should be displayed in the browser, but at this point, there should not be any<br />

personnel listed (because you haven’t entered any yet).<br />

Use the Back button in your web browser to return to the frmPersonnel form and enter some personnel data, similar to<br />

the following:<br />

Click here for text discription <strong>of</strong> this image.<br />

Now click the Submit button. The frmPersonnelVerified form should be displayed, showing the data you entered, and<br />

you should get a message saying that the data was successfully saved, like this:<br />

Click here for text discription <strong>of</strong> this image.<br />

Finally, click the View Personnel data button on this form. The frmViewPersonnel form should be displayed and should<br />

show the personnel record you just entered, retrieved from the database, like this:<br />

Click here for text discription <strong>of</strong> this image.<br />

You also should be able to view the employee records by clicking the link on the home page.<br />

Test the search feature and make sure that entering no search string returns all the data and that typing in a last name<br />

will return all employees with the same last name.<br />

NOTE: Make sure you include comments in the code provided where specified (where the ” // Your comments here”<br />

line appears) and for any code you write, or else a five point deduction per item (form, class, function) will be made

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!