Free Essay

Cis407,Cis/407,Cis 407,Cis/407 Ilab 1 of 7,Cis407 Ilab 1 of 7,Cis 407 Ilab 1 of 7

In:

Submitted By ashhad
Words 1307
Pages 6
HELPIDO.COM

FOLLOW THIS LINK TO GET THE TUTORIAL

---------------------------------------------------- http://helpido.com/category/cis-407/ ----------------------------------------------------

Cis 407a – ilab 3 of 7

Scenario/Summary

In this lab, we will demonstrate how to save user activity data in a database. We will be creating a new form to display the user activity data, a new dataset to contain the data, a data access class to structure the code, and a function within the data access class to save users’ activity data when users visit the Personnel form page (frmPersonnel.aspx). We will also be adding server side validation to the frmPersonnel for you added in the previous lab and update or main menu for the new functionality.
Instructions for Week 3 iLab: “User Activity Monitoring”
Click on the link above to view the tutorial.
This video will show you how to set up user activity monitoring using Visula Studio and C#.
The tutorial has audio.

Deliverables

All files are located in the subdirectory of the project. The project should function as specified: When you visit the Personnel form page (frmPersonnel.aspx), a record should be saved in the tblUserActivity table with the IP address, form name accessed (frmPersonnel), and the date accessed. When you click the “View Activity” button, you should see at least one record with this information. When the user goes to the frmPersonnel web form and enters data the following business rules are to be enforced:
Fields may not be empty or filled with spaces. If any field is empty, turn that field background color to yellow and add to/create an error 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 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 validate properly, then the session state items should be set properly and the user should see the frmPersonnelVerified form with all the values displayed. You will also add a new item to frmMain that will take the user to the new frmUserActivity form you added. Add the proper link and a hyperlinked image to allow the user to select this new option. Once you have verified that everything works, save your website, zip up all files, and submit in the Dropbox.

i L A B S T E P S

STEP 1: Data Connection, Dataset and Data Access Class (10 points)

Open Microsoft Visual Studio.NET 2008.

Open the PayrollSystem website by clicking on it in the Recent Projects list, or by pulling down the File menu, selecting Open Website, navigating to the folder where you previously saved the PayrollSystem, and clicking Open.

Download the PayrollSystem_DB.MDB file from Doc Sharing and save it on your local computer. (Note: your operating system may lock or block the file. Once you have copied it locally, right click on the file and select Properties and then Unblock if available). Then add it to the PayrollSystem website as follows: In Visual Studio, in the Solution Explorer click Website, Add Existing Item, then navigate to the PayrollSystem_DB.MDB file you downloaded and click the Add button.
Now we need to create a new connection to the PayrollSystem_DB.MDB. To begin, click View Server Explorer.

When the Server Explorer toolbox appears, click the Connect to Database button.

When the Add Connection dialog appears, click the Change button. In the “Change Data Source” dialog, select MS Access Database File; Uncheck Always use this Selection; then click OK.

Click here for text description of this image.

Click the Browse button to navigate to the PayrollSystem_DB.mdb file in your website folder, then click “Open”. (NOTE: Be sure you select the PayrollSystem_DB.mdb file in your PayrollSystem website folder, not the one you originally downloaded from Doc Sharing!) Click Test Connection. You should receive a message that the test connection succeeded. Click OK to acknowledge the message, then click “OK” again to close the Add Connection dialog.

The PayrollSystem_DB.mdb should be added to the Server Explorer. Expand the database, then expand the Tables entry under the database until you see tblUserActivity. Leave the Server Explorer window open for now as you will be returning to it in a moment.

Click here for text description of this image.

Create a new dataset by selecting Website Add New Item. Under Templates, select the Dataset item.

Enter dsUserActivity.xsd for the name. Click Add.

Click on image to enlarge.

Add Data Set

Click here for text discription of this image.

If the following message appears, select Yes. You want to make this dataset available to your entire website.

If the TableAdapter Configuration Wizard dialog appears, click Cancel. (We will be configuring a Data Adapter for this dataset later in C# code, so we do not need to run this wizard.)
Drag-and-drop the tblUserActivity table from the Server Explorer window into the dsUserActivity dataset in the editor window.

NOTE: If you see a message that says your connection uses a local data file that is not in the current project, that indicates you did not select the correct PayrollSystem_DB.mdb file when you created your data connection. To fix this problem, click No, then right-click on PayrollSystem_DB.mdb in the Server Explorer window and choose Modify Connection. Click the Browse button, navigate to the PayrollSystem_DB.mdb file that is in your PayrollSystem website folder, and click Open. Test the connection, then click OK.

Click the Save icon on the toolbar to save the dsUserActivity.xsd dataset.

Click on image to enlarge.

Dataset Saved

Click here for text discription of this image.

(You can now close the Server Explorer window if you wish.)
Create a new class to contain the C# code that will access this dataset. To do so, click Website, Add New Item. In the Add New Item dialog, select the Class template, and enter clsDataLayer for the name. Make sure the Language is set to Visual C#. Click “Add”.
Click on image to enlarge.

Add DataLayer Class

Click here for text discription of this image.
If the following message appears, select Yes. You want to make this class available to everything in your solution.

Add the following to the top of your class, below any other using statements created for you by Visual Studio:

// Add your comments here using System.Data.OleDb; using System.Net; using System.Data;
Add the following three functions inside the squiggly braces for the “public class clsDataLayer” class, above the beginning of the “public clsDataLayer()” constructor:
// This function gets the user activity from the tblUserActivity public static dsUserActivity GetUserActivity(string Database)
{
// Add your comments here dsUserActivity DS;
OleDbConnection sqlConn;
OleDbDataAdapter sqlDA;
// Add your comments here sqlConn = new OleDbConnection(“PROVIDER=Microsoft.Jet.OLEDB.4.0;” +
“Data Source=” + Database);
// Add your comments here sqlDA = new OleDbDataAdapter(“select * from tblUserActivity”, sqlConn);
// Add your comments here
DS = new dsUserActivity();
// Add your comments here sqlDA.Fill(DS.tblUserActivity); // Add your comments here return DS;
}
// This function saves the user activity public static void SaveUserActivity(string Database, string FormAccessed)
{
// 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; strSQL = “Insert into tblUserActivity (UserIP, FormAccessed) values (‘” +
GetIP4Address() + “‘, ‘” + FormAccessed + “‘)”; command.CommandType = CommandType.Text; command.CommandText = strSQL; command.ExecuteNonQuery(); conn.Close();
}
// This function gets the IP Address public static string GetIP4Address()
{
string IP4Address = string.Empty ; foreach (IPAddress IPA in
Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress)) { if (IPA.AddressFamily.ToString() == “InterNetwork”) {
IP4Address = IPA.ToString(); break; }
}
if (IP4Address != string.Empty) { return IP4Address;
}
foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName())) { if (IPA.AddressFamily.ToString() == “InterNetwork”) {
IP4Address = IPA.ToString(); break; }
}
return IP4Address;
}

SKIPPED MORE DATA

HELPIDO.COM

FOLLOW THIS LINK TO GET THE TUTORIAL

---------------------------------------------------- http://helpido.com/category/cis-407/ ----------------------------------------------------

Similar Documents