CIS 407 DeVry iLab 3 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> 3 <strong>of</strong> 7 <strong>latest</strong><br />
Downloading is very simple, you can download this Course here:<br />
https://www.mindsblow.com/product/cis-<strong>407</strong>-devry-ilab-3-7-<strong>latest</strong>/<br />
Or<br />
Contact us at:<br />
SUPPORT@MINDSBLOW.COM<br />
<strong>CIS</strong> <strong>407</strong> <strong>DeVry</strong> <strong>iLab</strong> 3 <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> 3 <strong>of</strong> 7 Latest<br />
<strong>iLab</strong> 3 <strong>of</strong> 7: User activity monitoring<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 demonstrate how to save user activity data in a database. We will be creating a new form to display<br />
the user activity data, a new dataset to contain the data, a data access class to structure the code, and a function within<br />
the data access class to save users’ activity data when users visit the Personnel form page (frmPersonnel.aspx). We<br />
will also be adding server side validation to the frmPersonnel for you added in the previous lab and update or main<br />
menu for the new functionality.<br />
Instructions for Week 3 <strong>iLab</strong>: “User Activity Monitoring”<br />
Click on the link above to view the tutorial.<br />
This video will show you how to set up user activity monitoring using Visula Studio and C#.<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 visit the<br />
Personnel form page (frmPersonnel.aspx), a record should be saved in the tblUserActivity table with the IP address,<br />
form name accessed (frmPersonnel), and the date accessed. When you click the “View Activity” button, you should see<br />
at least one record with this information. When the user goes to the frmPersonnel web form and enters data the following<br />
business rules are to be enforced:<br />
• Fields may not be empty or filled with spaces. If any field is empty, turn that field background color to yellow and<br />
add to/create an error message to be shown in the error label.<br />
• The end date must be greater than the start date. If the end date is less than the start date turn both date fields<br />
yellow and add to/create an error message to be shown in the error label.<br />
If all fields validate properly, then the session state items should be set properly and the user should see the<br />
frmPersonnelVerified form with all the values displayed. You will also add a new item to frmMain that will take the user<br />
to the new frmUserActivity form you added. Add the proper link and a hyperlinked image to allow the user to select this<br />
new option. Once you have verified that everything works, save your website, zip up all files, and submit in the Dropbox.<br />
i L A B S T E P S
STEP 1: Data Connection, Dataset and Data Access Class (10 points)<br />
1. Open Micros<strong>of</strong>t Visual Studio.NET 2008.<br />
2. Open the PayrollSystem website by clicking on it in the Recent Projects list, or by pulling down the File menu,<br />
selecting Open Website, navigating to the folder where you previously saved the PayrollSystem, and clicking Open.<br />
3. Download the PayrollSystem_DB.MDB file from Doc Sharing and save it on your local computer. (Note: your<br />
operating system may lock or block the file. Once you have copied it locally, right click on the file and select Properties<br />
and then Unblock if available). Then add it to the PayrollSystem website as follows: In Visual Studio, in the Solution<br />
Explorer click Website, Add Existing Item, then navigate to the PayrollSystem_DB.MDB file you downloaded and click<br />
the Add button.<br />
4. Now we need to create a new connection to the PayrollSystem_DB.MDB. To begin, click View Server Explorer.<br />
5. When the Server Explorer toolbox appears, click the Connect to Database button.<br />
6. When the Add Connection dialog appears, click the Change button. In the “Change Data Source” dialog, select<br />
MS Access Database File; Uncheck Always use this Selection; then click OK.<br />
Click here for text description <strong>of</strong> this image.<br />
7. Click the Browse button to navigate to the PayrollSystem_DB.mdb file in your website folder, then click “Open”.<br />
(NOTE: Be sure you select the PayrollSystem_DB.mdb file in your PayrollSystem website folder, not the one you<br />
originally downloaded from Doc Sharing!) Click Test Connection. You should receive a message that the test<br />
connection succeeded. Click OK to acknowledge the message, then click “OK” again to close the Add Connection<br />
dialog.<br />
8. The PayrollSystem_DB.mdb should be added to the Server Explorer. Expand the database, then expand the<br />
Tables entry under the database until you see tblUserActivity. Leave the Server Explorer window open for now as you<br />
will be returning to it in a moment.<br />
Click here for text description <strong>of</strong> this image.<br />
9. Create a new dataset by selecting Website Add New Item. Under Templates, select the Dataset item. Enter<br />
dsUserActivity.xsd for the name. Click Add.<br />
Click on image to enlarge.<br />
Add Data Set<br />
10. Click here for text discription <strong>of</strong> this image.<br />
11.<br />
12. If the following message appears, select Yes. You want to make this dataset available to your entire website.<br />
13. If the TableAdapter Configuration Wizard dialog appears, click Cancel. (We will be configuring a Data Adapter for<br />
this dataset later in C# code, so we do not need to run this wizard.)<br />
14. Drag-and-drop the tblUserActivity table from the Server Explorer window into the dsUserActivity dataset in the<br />
editor window.<br />
NOTE: If you see a message that says your connection uses a local data file that is not in the current project, that<br />
indicates you did not select the correct PayrollSystem_DB.mdb file when you created your data connection. To fix this<br />
problem, click No, then right-click on PayrollSystem_DB.mdb in the Server Explorer window and choose Modify<br />
Connection. Click the Browse button, navigate to the PayrollSystem_DB.mdb file that is in your PayrollSystem website<br />
folder, and click Open. Test the connection, then click OK.<br />
15. Click the Save icon on the toolbar to save the dsUserActivity.xsd dataset.<br />
Click on image to enlarge.<br />
Dataset Saved<br />
16. Click here for text discription <strong>of</strong> this image.<br />
17. (You can now close the Server Explorer window if you wish.)
18. Create a new class to contain the C# code that will access this dataset. To do so, click Website, Add New Item.<br />
In the Add New Item dialog, select the Class template, and enter clsDataLayer for the name. Make sure the Language<br />
is set to Visual C#. Click “Add”.<br />
Click on image to enlarge.<br />
Add DataLayer Class<br />
19. Click here for text discription <strong>of</strong> this image.<br />
20. If the following message appears, select Yes. You want to make this class available to everything in your solution.<br />
21. Add the following to the top <strong>of</strong> your class, below any other using statements created for you by Visual Studio:<br />
// Add your comments here<br />
using System.Data.OleDb;<br />
using System.Net;<br />
using System.Data;<br />
22. Add the following three functions inside the squiggly braces for the “public class clsDataLayer” class, above the<br />
beginning <strong>of</strong> the “public clsDataLayer()” constructor:<br />
// This function gets the user activity from the tblUserActivity<br />
public static dsUserActivity GetUserActivity(string Database)<br />
{// Add your comments here<br />
dsUserActivity DS;<br />
OleDbConnection sqlConn;<br />
OleDbDataAdapter sqlDA;<br />
// Add your comments here<br />
sqlConn = new OleDbConnection(“PROVIDER=Micros<strong>of</strong>t.Jet.OLEDB.4.0;” +<br />
“Data Source=” + Database);<br />
// Add your comments here<br />
sqlDA = new OleDbDataAdapter(“select * from tblUserActivity”, sqlConn);<br />
// Add your comments here<br />
DS = new dsUserActivity();<br />
// Add your comments here<br />
sqlDA.Fill(DS.tblUserActivity);<br />
// Add your comments here<br />
return DS; }<br />
// This function saves the user activity<br />
public static void SaveUserActivity(string Database, string FormAccessed)<br />
{// 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();
OleDbCommand command = conn.CreateCommand();<br />
string strSQL;<br />
strSQL = “Insert into tblUserActivity (UserIP, FormAccessed) values (‘” +<br />
GetIP4Address() + “‘, ‘” + FormAccessed + “‘)”;<br />
command.CommandType = CommandType.Text;<br />
command.CommandText = strSQL;<br />
command.ExecuteNonQuery();<br />
conn.Close(); }<br />
// This function gets the IP Address<br />
public static string GetIP4Address()<br />
{string IP4Address = string.Empty ;<br />
foreach (IPAddress IPA in<br />
Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress)) {<br />
if (IPA.AddressFamily.ToString() == “InterNetwork”) {<br />
IP4Address = IPA.ToString();<br />
break; } }<br />
if (IP4Address != string.Empty) {<br />
return IP4Address; }<br />
foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName())) {<br />
if (IPA.AddressFamily.ToString() == “InterNetwork”) {<br />
IP4Address = IPA.ToString();<br />
break;} }<br />
return IP4Address; }<br />
STEP 2: frmUserActivity, frmPersonnel, frmMain (10 points)<br />
18. Create a new Web form called frmUserActivity. Switch to Design Mode and add a Label and GridView (found<br />
under the Toolbox, Data tab) having the following properties:<br />
Property<br />
Value<br />
Label – Text<br />
User Activity<br />
GridView – (ID)<br />
grdUserActivity<br />
19. Go to the Page_Load method and add the following code:<br />
if (!Page.IsPostBack) {<br />
// Declares the DataSet<br />
dsUserActivity myDataSet = new dsUserActivity();<br />
// Fill the dataset with what is returned from the function<br />
myDataSet = clsDataLayer.GetUserActivity(Server.MapPath(“PayrollSystem_DB.mdb”));<br />
// Sets the DataGrid to the DataSource based on the table<br />
grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"];
Binds the DataGrid<br />
grdUserActivity.DataBind(); }<br />
20. Open the frmMain form, add a new link button and image button to point to the new frmUserActivity. Find an<br />
image to use for the image button and add the new option as View User Activity.<br />
21. Go to the frmMain Page_Load and add the following code:<br />
// Add your comments here<br />
clsDataLayer.SaveUserActivity(Server.MapPath(“PayrollSystem_DB.mdb”), “frmPersonnel”);<br />
22. On the frmUserActivity form, add the CoolBiz logo hyperlinked logo at the top <strong>of</strong> the page so that when clicked<br />
the user is returned to frmMain.<br />
23. In the Solution Explorer, right click on the frmMain.aspx form and select Set As Start Page. Run your project.<br />
When you open the project, a record should be saved in the tblUserActivity table with the IP address, form name<br />
accessed (frmPersonnel), and the date accessed. When you click the View Activity button, you should see at least one<br />
record with this information.<br />
24. You will now add server side validation code to the frmPersonnel page. Currently, when the Submit button is<br />
pressed, the frmPersonnelVerified page is displayed. This is because the frmPersonnelVerified page is set as the<br />
Submit button’s PostBackUrl property. Instead <strong>of</strong> having the page go directly to the frmPersonnelVerified page when<br />
the Submit button is pressed, we want to do some server side validation. If any <strong>of</strong> the validation rules fail, we will<br />
redisplay the frmPersonnel page with the fields in question highlighted in yellow with an error message displayed.<br />
First, it is important to understand what is currently happening when the submit button is pressed. This is causing a<br />
postback <strong>of</strong> the form to the frmPersonnelVerified form. When this postback happens, all <strong>of</strong> the data in the fields on the<br />
frmPersonnel form are sent to the frmPersonnelVerified form as name value pairs. In the Page_Load code <strong>of</strong><br />
frmPersonnelVerified these values are picked up from the Request object and displayed. Each name value pair will be<br />
in the Request object as the ID <strong>of</strong> the control containing the value and the value itself. We can pass data between<br />
pages by using Session state instead. In order to do validation on the values but still have the values visible on the<br />
frmPersonnelVerified page, we will need to change not only the PostBack URL <strong>of</strong> the frmPersonnel page but also how<br />
the frmPersonnelVerified form is getting the data – it will need to get it from Session state rather than from the Request<br />
object.<br />
Make the following changes:<br />
1. Clear the Submit button PostBackURLProperty on the frmPersonnel form.<br />
2. In the btnSubmit_Click event handler get each value from the data entry fields and set Session state items for<br />
each.<br />
3. Change the frmPersonnelVerified code behind to get the values from the Session state items you created in the<br />
previous step.<br />
When you are done with these steps, you should be able to enter data on the frmPersonnel data entry form and then<br />
click the Submit button. The frmPersonnelVerified page should then be displayed with the values that were in the data<br />
entry fields on frmPersonnel.<br />
Make sure this is all working before proceeding to the next steps.<br />
25. Add a label to the frmPersonnel form with an ID <strong>of</strong> lblError. Do not place the label to the right or left <strong>of</strong> any <strong>of</strong> the<br />
controls on the form. Add it below the controls or above the controls. The text property <strong>of</strong> this label should be set to an<br />
empty string.<br />
26. Add code to perform server side validation in response to the submit button being clicked. Here are the business<br />
rules we want to enforce (remember this will be server C# code in the frmPersonnel code behind): Fields may not be<br />
empty or filled with spaces. If any field is empty, turn that field background color to yellow and add to/create an error<br />
message to be shown in the error label. The end date must be greater than the start date. If the end date is less than<br />
the start date, turn both date fields yellow and add to/create an error message to be shown in the error label. If all fields<br />
validate properly then the session state items should be set properly and the user should see the frmPersonnelVerified<br />
form with all the values displayed.<br />
27. Lab Hints: To set a value in session state do the following:
Session["txtFirstName"] = txtFirstName.Text;<br />
28. “txtFirstName” is the key and txtFirstName.Text is the value.<br />
29. To get this same value back from the session we use the key and the Session object as follows:<br />
Session["txtLastName"].ToString()<br />
30. There is a Trim method on the string object that will automatically remove spaces from the beginning and end <strong>of</strong><br />
a string. Remember, you can turn an object like a Session item object into a string using the Convert class or just using<br />
it’s ToString() method.<br />
31. You may want to create variables to work with for validation rather than using the Request item objects directly.<br />
32. To turn a string into a DateTime object you can use the DateTime method Parse. If you had a date value stored<br />
in a string called strDate, you could turn it into a DateTime object like this:<br />
DateTime myDateTimeObject = DateTime.Parse(strDate);<br />
33. You can compare two DateTime objects by using the DateTime.Compare method. If you had two DateTime<br />
objects called dt1 and dt2 you can check to see if dt1 is greater than dt2 by doing this:<br />
if (DateTime.Compare(dt1,dt2) > 0)<br />
34. DateTime.Compare will return a 0 if the two dates are equal, a 1 if dt1 is greater than dt2, and a -1 if dt1 is less<br />
than dt2.<br />
35. If you put in an invalid date for either <strong>of</strong> the date fields, you will get an exception/server error when trying to parse<br />
the values. We will address this in a later lab – for now make sure you enter valid dates (valid meaning a date in the<br />
form <strong>of</strong> mm/dd/yyyy).<br />
36. If I had a TextBox control that was called txtAge and you wanted to set it’s background color you could do this:<br />
txtAge.BackColor = System.Drawing.Color.Yellow;<br />
37. Remember to clear the PostBackURL property <strong>of</strong> the submit button!<br />
STEP 3: Verify and submit (10 points)<br />
28. View the video above on what functions your lab should have so far.<br />
29. Run your project. When you open the project, and go to the main menu form a record should be saved in the<br />
tblUserActivity table with the IP address, form name accessed (frmPersonnel), and the date accessed. When you click<br />
the View Activity button you should see at least one record with this information. The validation and error display should<br />
work for entering data. All navigation and hyperlinks should work.<br />
Once you have verified that it works, save your project, zip up all files, and submit in the Dropbox.<br />
NOTE: Make sure you include comments in the code provided where specified (where the ” //Your comments here”<br />
is mentioned) and for any code you write, or else a five point deduction per item (form, class, function) will be made.<br />
You basically put two forward slashes, which start the comment; anything after the // on that line is disregarded by the<br />
compiler. Then type a brief statement describing what is happening in following code. Comments show pr<strong>of</strong>essionalism<br />
and are a must in systems. As a pr<strong>of</strong>essional developer, comments will set you apart from others and make your life<br />
much easier if maintenance and debugging are needed