Create a new web form called frmuseractivity

Assignment Help DOT NET Programming
Reference no: EM13765158

User Activity Monitoring Assignment description

STEP 1: Data Connection, Dataset and Data Access Class

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 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.

Create a new dataset by selecting Website Add New Item. Under Templates, select the Dataset item. Enter dsUserActivity.xsd for the name.

Click Add.

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.

(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".

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;

}

STEP 2: frmUserActivity, frmPersonnel, frmMain (10 points)

Create a new Web form called frmUserActivity. Switch to Design Mode and add a Label and GridView (found under the Toolbox, Data tab) having the following properties:

Property

Value

Label - Text

User Activity

GridView - (ID)

grdUserActivity

Go to the Page_Load method and add the following code:

if (!Page.IsPostBack) {

// Declares the DataSet

dsUserActivity myDataSet = new dsUserActivity();

// Fill the dataset with what is returned from the function

myDataSet = clsDataLayer.GetUserActivity(Server.MapPath("PayrollSystem_DB.mdb"));

// Sets the DataGrid to the DataSource based on the table

grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"];

// Binds the DataGrid

grdUserActivity.DataBind();

}

Open the frmMain form, add a new link button and image button to point to the new frmUserActivity. Find an image to use for the image button and add the new option as View User Activity.

Go to the frmMain Page_Load and add the following code:

// Add your comments here

clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.mdb"), "frmPersonnel");

On the frmUserActivity form, add the CoolBiz logo hyperlinked logo at the top of the page so that when clicked the user is returned to frmMain.

In the Solution Explorer, right click on the frmMain.aspx form and select Set As Start Page. Run your project. When you open the project, 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.

You will now add server side validation code to the frmPersonnel page. Currently, when the Submit button is pressed, the frmPersonnelVerified page is displayed. This is because the frmPersonnelVerified page is set as the Submit button's PostBackUrl property. Instead of having the page go directly to the frmPersonnelVerified page when the Submit button is pressed, we want to do some server side validation. If any of the validation rules fail, we will redisplay the frmPersonnel page with the fields in question highlighted in yellow with an error message displayed.

First, it is important to understand what is currently happening when the submit button is pressed. This is causing a postback of the form to the frmPersonnelVerified form. When this postback happens, all of the data in the fields on the frmPersonnel form are sent to the frmPersonnelVerified form as name value pairs. In the Page_Load code of frmPersonnelVerified these values are picked up from the Request object and displayed. Each name value pair will be in the Request object as the ID of the control containing the value and the value itself. We can pass data between pages by using Session state instead. In order to do validation on the values but still have the values visible on the frmPersonnelVerified page, we will need to change not only the PostBack URL of the frmPersonnel page but also how the frmPersonnelVerified form is getting the data - it will need to get it from Session state rather than from the Request object.

Make the following changes:

Clear the Submit button PostBackURLProperty on the frmPersonnel form.

In the btnSubmit_Click event handler get each value from the data entry fields and set Session state items for each.

Change the frmPersonnelVerified code behind to get the values from the Session state items you created in the previous step.

When you are done with these steps, you should be able to enter data on the frmPersonnel data entry form and then click the Submit button. The frmPersonnelVerified page should then be displayed with the values that were in the data entry fields on frmPersonnel.

Make sure this is all working before proceeding to the next steps.

Add a label to the frmPersonnel form with an ID of lblError. Do not place the label to the right or left of any of the controls on the form. Add it below the controls or above the controls. The text property of this label should be set to an empty string.

Add code to perform server side validation in response to the submit button being clicked. Here are the business rules we want to enforce (remember this will be server C# code in the frmPersonnel code behind): 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.

Lab Hints: To set a value in session state do the following:

Session["txtFirstName"] = txtFirstName.Text;

"txtFirstName" is the key and txtFirstName.Text is the value.

To get this same value back from the session we use the key and the Session object as follows:

Session["txtLastName"].ToString()

There is a Trim method on the string object that will automatically remove spaces from the beginning and end of a string. Remember, you can turn an object like a Session item object into a string using the Convert class or just using it's ToString() method.

You may want to create variables to work with for validation rather than using the Request item objects directly.

To turn a string into a DateTime object you can use the DateTime method Parse. If you had a date value stored in a string called strDate, you could turn it into a DateTime object like this:

DateTime myDateTimeObject = DateTime.Parse(strDate);

You can compare two DateTime objects by using the DateTime.Compare method. If you had two DateTime objects called dt1 and dt2 you can check to see if dt1 is greater than dt2 by doing this:

if (DateTime.Compare(dt1,dt2) > 0)

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 than dt2.

If you put in an invalid date for either of the date fields, you will get an exception/server error when trying to parse the values. We will address this in a later lab - for now make sure you enter valid dates (valid meaning a date in the form of mm/dd/yyyy).

If I had a TextBox control that was called txtAge and you wanted to set it's background color you could do this:
txtAge.BackColor = System.Drawing.Color.Yellow;

Remember to clear the PostBackURL property of the submit button!

Reference no: EM13765158

Questions Cloud

Summarize the role of management : Summarize the role of management as it relates to finance in a corporation. In your post, address the following: Indicate the various aspects of finance that management must understand.
The impact of cultural diversity : Why is knowing your audience an important part of capturing and maintaining their attention? What is the impact of cultural diversity in your audience?
Prepare the journal entry to record the acquisition of land : Fielder Company obtained land by issuing 2,970 shares of its $10 par value common stock. The land was recently appraised at $123,140. The common stock is actively traded at $40 per share. Prepare the journal entry to record the acquisition of the lan..
Essay on the reconstruction : Write a 500 or more word, APA style, essay on the Reconstruction. In your paper be sure to discuss: The approach to Reconstruction advocated by Presidents Lincoln and Johnson and explain what they expected to accomplish
Create a new web form called frmuseractivity : Create a new Web form called frmUserActivity. Switch to Design Mode and add a Label and GridView (found under the Toolbox, Data tab) having the following properties:
Reorganizations and consolidated tax returns : Suppose you are a CPA, and you have a corporate client that has been operating for several years. The company is considering expansion through reorganizations.
Do you agree with this criticism : "Philosophy may be an interesting academic pursuit, but it has no relevance to my own life and so is of no value to me." Do you agree with this criticism
What has been the most impart skill you have improved : Write a one-page reflection paper answering the following:As you reflect on your work and your learning in this class, what has been the most impart skill you have improved, insight you have secured, or knowledge you have gained
Employer structures and utilize constructors : Variables and member functions are the building blocks of a class and are passed on to the objects created by that class. explains these building blocks of classes but first introduces you to structures; objects that are similar to class objects e..

Reviews

Write a Review

DOT NET Programming Questions & Answers

  Write a program that computes the amount of money

Write a program that computes the amount of money the computer club will receive from proceeds of their granola bar sales project. Allow the user to enter the number of cases sold and the sale price per bar. Each case contains 12 bars; each case is p..

  Different data types and their typical usage

In programming, you'll find that variables are fundamental building blocks in creating programs. Review the various data types used in C# and discuss and elaborate in detail as to the typical usage of those data types. Discuss a minimum of six dif..

  Prepare a web application that will be used to keep track

prepare a web application that will be used to keep track of patients registering in a hospital.this application will

  A parking garage charges a 200 minimum fee to park for up

a parking garage charges a 2.00 minimum fee to park for up to three hours. the garage charges an additional 0.50 per

  A company wants to see a printout

A company wants to see a printout of the gross payroll for each of its 7 departments. The output should be a list of the seven departments and the total gross payroll (rate times hours) for each department

  Create an illustration of a nested if structure and build

write a 200- to 300-word short-answer response to the followinga create an example of a nested if structure and build

  The data for 10 professional baseball teams for the year

the data for 10 professional baseball teams for the year 2001 is given below. write a c console application that does

  Describe the characteristics of visual studio 2005

Describe the characteristics of Visual Studio 2005 Visual Studio.Net is a suite of products that includes 4 main languages. Name these languages and outline their use in industries

  Convert meters to feet and inches.

1. Write a program that can be used to convert meters to feet and inches. Allow the user to enter a metric meter value in a method .

  Add insert and edit menu options - insert will allow the

add insert and edit menu options - insert will allow the user to insert a new account in a position of his choice -

  The users will use a browser to access the on-line store

the users will use a browser to access the on-line store. the web server software for the production web server is

  Question 1a using the help of a diagram describe the layer

question 1a using the help of a diagram describe the layer of the .net framework that sits between visual basic.net

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd