SlideShare una empresa de Scribd logo
1 de 10
CIS407A iLab 3 Web Application
Development Devry University
Click this link to get the tutorial:
http://homeworkfox.com/tutorials/general-
questions/6225/cis407a-ilab-3-web-application-development-
devry-university/
iLab 3 of 7: User activity monitoring

Submit your assignment to the Dropbox located on the silver tab at the top of this page.

(See Syllabus/"Due Dates for Assignments & Exams" for due dates.)

iLABOVERVIEW

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.

iLABSTEPS

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

1.Open Microsoft Visual Studio.NET 2008.

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

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

4.Now we need to create a new connection to the PayrollSystem_DB.MDB. To begin, click
View Server Explorer.

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

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

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

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

10.

Click here for text discription of this image.

11.

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

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

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

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

Click on image to enlarge.

Dataset Saved

16.

Click here for text discription of this image.
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. 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

19.

Click here for text discription of this image.

20.If the following message appears, select Yes. You want to make this class available to
everything in your solution.

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

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

OleDbConnection(";" +

"Data select * from tblUserActivity", sqlConn);

// Add your comments here

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 OleDbConnection(";" +

"Data Insert into tblUserActivity (UserIP, FormAccessed) values ('" +

GetIP4Address() + "', '" + FormAccessed + "')";

;

;

command.ExecuteNonQuery();

conn.Close();

}

// This function gets the IP Address
public static string GetIP4Address()

{

string ;

foreach (IPAddress IPA in

Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress)) {

if (IPA.AddressFamily.ToString() == "InterNetwork") {

();

break;

}

}

if (IP4Address != string.Empty) {

return IP4Address;

}

foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName())) {

if (IPA.AddressFamily.ToString() == "InterNetwork") {

();

break;

}

}

return IP4Address;

}

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

18.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:
PropertyValue

Label - TextUser Activity

GridView - (ID)grdUserActivity

19.Go to the Page_Load method and add the following code:

if (!Page.IsPostBack) {

// Declares the DataSet

dsUserActivity dsUserActivity();

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

(Server.MapPath("PayrollSystem_DB.mdb"));

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

["tblUserActivity"];

// Binds the DataGrid

grdUserActivity.DataBind();

}

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

21.Go to the frmMain Page_Load and add the following code:

// Add your comments here

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

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

23.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.
24.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:

1.Clear the Submit button PostBackURLProperty on the frmPersonnel form.

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

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

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

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

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

Session["txtFirstName"] = txtFirstName.Text;

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

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

Session["txtLastName"].ToString()

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

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

32.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 (strDate);

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

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

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

36.If I had a TextBox control that was called txtAge and you wanted to set it's background color
you could do this:

;

37.Remember to clear the PostBackURL property of the submit button!
STEP 3: Verify and submit (10 points)

28.View the video above on what functions your lab should have so far.

29.Run your project. When you open the project, and go to the main menu form 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. The validation and error display should work for entering data. All
navigation and hyperlinks should work.

Once you have verified that it works, 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. You basically put two forward slashes, which start
the comment; anything after the // on that line is disregarded by the compiler. Then type a brief
statement describing what is happening in following code. Comments show professionalism and
are a must in systems. As a professional developer, comments will set you apart from others and
make your life much easier if maintenance and debugging are needed

Más contenido relacionado

La actualidad más candente

Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7helpido9
 
Cis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry universityCis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry universitylhkslkdh89009
 
Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Slideshare
 
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
 
Tutorial on how to load images in crystal reports dynamically using visual ba...
Tutorial on how to load images in crystal reports dynamically using visual ba...Tutorial on how to load images in crystal reports dynamically using visual ba...
Tutorial on how to load images in crystal reports dynamically using visual ba...Aeric Poon
 
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
 
Binding to multiple datasources on a single xPage
Binding to multiple datasources on a single xPageBinding to multiple datasources on a single xPage
Binding to multiple datasources on a single xPagedominion
 
Part 4 working with databases
Part 4 working with databasesPart 4 working with databases
Part 4 working with databasestechbed
 
Oracle apex hands on lab#2
Oracle apex hands on lab#2Oracle apex hands on lab#2
Oracle apex hands on lab#2Amit Sharma
 
Crystal report
Crystal reportCrystal report
Crystal reportEverywhere
 
Responsive Design and Bootstrap
Responsive Design  and BootstrapResponsive Design  and Bootstrap
Responsive Design and BootstrapMahmoudOHassouna
 
Moss2007 Enterprise Features Administration
Moss2007 Enterprise Features AdministrationMoss2007 Enterprise Features Administration
Moss2007 Enterprise Features AdministrationLiquidHub
 
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
 
Sales force managing-data
Sales force managing-dataSales force managing-data
Sales force managing-dataAmit Sharma
 
Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7helpido9
 
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB MahmoudOHassouna
 
Getting started with workflow
Getting started with workflowGetting started with workflow
Getting started with workflowseenu126
 
Office Share Point Server2007 Functionaland Architectural Overview
Office Share Point Server2007 Functionaland Architectural OverviewOffice Share Point Server2007 Functionaland Architectural Overview
Office Share Point Server2007 Functionaland Architectural OverviewLiquidHub
 

La actualidad más candente (20)

Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7Cis 407 i lab 1 of 7
Cis 407 i lab 1 of 7
 
Cis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry universityCis407 a ilab 7 web application development devry university
Cis407 a ilab 7 web application development devry university
 
Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010Crystal report generation in visual studio 2010
Crystal report generation in visual studio 2010
 
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
 
Tutorial on how to load images in crystal reports dynamically using visual ba...
Tutorial on how to load images in crystal reports dynamically using visual ba...Tutorial on how to load images in crystal reports dynamically using visual ba...
Tutorial on how to load images in crystal reports dynamically using visual ba...
 
informatica
informaticainformatica
informatica
 
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...
 
Binding to multiple datasources on a single xPage
Binding to multiple datasources on a single xPageBinding to multiple datasources on a single xPage
Binding to multiple datasources on a single xPage
 
Oracle EMC 12C Grand Tour
Oracle EMC 12C Grand TourOracle EMC 12C Grand Tour
Oracle EMC 12C Grand Tour
 
Part 4 working with databases
Part 4 working with databasesPart 4 working with databases
Part 4 working with databases
 
Oracle apex hands on lab#2
Oracle apex hands on lab#2Oracle apex hands on lab#2
Oracle apex hands on lab#2
 
Crystal report
Crystal reportCrystal report
Crystal report
 
Responsive Design and Bootstrap
Responsive Design  and BootstrapResponsive Design  and Bootstrap
Responsive Design and Bootstrap
 
Moss2007 Enterprise Features Administration
Moss2007 Enterprise Features AdministrationMoss2007 Enterprise Features Administration
Moss2007 Enterprise Features Administration
 
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
 
Sales force managing-data
Sales force managing-dataSales force managing-data
Sales force managing-data
 
Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7Cis 407 i lab 5 of 7
Cis 407 i lab 5 of 7
 
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
Murach': HOW TO DEVELOP A DATA DRIVEN MVC WEB
 
Getting started with workflow
Getting started with workflowGetting started with workflow
Getting started with workflow
 
Office Share Point Server2007 Functionaland Architectural Overview
Office Share Point Server2007 Functionaland Architectural OverviewOffice Share Point Server2007 Functionaland Architectural Overview
Office Share Point Server2007 Functionaland Architectural Overview
 

Destacado

Rooney rea dmp3
Rooney rea dmp3Rooney rea dmp3
Rooney rea dmp3rearooney
 
Apple book
Apple bookApple book
Apple bookmbush002
 
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
 
The Importance of Place in Online Learning
The Importance of Place in Online Learning The Importance of Place in Online Learning
The Importance of Place in Online Learning Dr. Kristin Palmer
 
MOOCs at UVa as of March 1, 2013
MOOCs at UVa as of March 1, 2013MOOCs at UVa as of March 1, 2013
MOOCs at UVa as of March 1, 2013Dr. Kristin Palmer
 
SWUN Business Courses Online and Mobile May 2015
SWUN Business Courses Online and Mobile May 2015SWUN Business Courses Online and Mobile May 2015
SWUN Business Courses Online and Mobile May 2015Dr. Kristin Palmer
 
Apple book
Apple bookApple book
Apple bookmbush002
 
MOOCs at UVa for Teaching with Technology Fair October 2015
MOOCs at UVa for Teaching with Technology Fair October 2015MOOCs at UVa for Teaching with Technology Fair October 2015
MOOCs at UVa for Teaching with Technology Fair October 2015Dr. Kristin Palmer
 
MOOCovery for #SXSWEDU #UVaMOOC Planning, Process, Ideas
MOOCovery for #SXSWEDU #UVaMOOC Planning, Process, IdeasMOOCovery for #SXSWEDU #UVaMOOC Planning, Process, Ideas
MOOCovery for #SXSWEDU #UVaMOOC Planning, Process, IdeasDr. Kristin Palmer
 
MOOCs at UVa for eLearn October 2015
MOOCs at UVa for eLearn October 2015MOOCs at UVa for eLearn October 2015
MOOCs at UVa for eLearn October 2015Dr. Kristin Palmer
 
Chile's market analisys
Chile's market analisysChile's market analisys
Chile's market analisysNicolas Charif
 
Six young men presentation
Six young men presentationSix young men presentation
Six young men presentationRebeccaHuckett
 
Wolf pack project ii
Wolf pack project iiWolf pack project ii
Wolf pack project iikatherinej93
 

Destacado (16)

Diego
DiegoDiego
Diego
 
Rooney rea dmp3
Rooney rea dmp3Rooney rea dmp3
Rooney rea dmp3
 
Apple book
Apple bookApple book
Apple book
 
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
 
The Importance of Place in Online Learning
The Importance of Place in Online Learning The Importance of Place in Online Learning
The Importance of Place in Online Learning
 
MOOCs at UVa as of March 1, 2013
MOOCs at UVa as of March 1, 2013MOOCs at UVa as of March 1, 2013
MOOCs at UVa as of March 1, 2013
 
SWUN Business Courses Online and Mobile May 2015
SWUN Business Courses Online and Mobile May 2015SWUN Business Courses Online and Mobile May 2015
SWUN Business Courses Online and Mobile May 2015
 
Apple book
Apple bookApple book
Apple book
 
MOOCs at UVa for Teaching with Technology Fair October 2015
MOOCs at UVa for Teaching with Technology Fair October 2015MOOCs at UVa for Teaching with Technology Fair October 2015
MOOCs at UVa for Teaching with Technology Fair October 2015
 
MOOCovery for #SXSWEDU #UVaMOOC Planning, Process, Ideas
MOOCovery for #SXSWEDU #UVaMOOC Planning, Process, IdeasMOOCovery for #SXSWEDU #UVaMOOC Planning, Process, Ideas
MOOCovery for #SXSWEDU #UVaMOOC Planning, Process, Ideas
 
MOOCs at UVa for eLearn October 2015
MOOCs at UVa for eLearn October 2015MOOCs at UVa for eLearn October 2015
MOOCs at UVa for eLearn October 2015
 
Rouen presentation
Rouen presentationRouen presentation
Rouen presentation
 
BMW
BMWBMW
BMW
 
Chile's market analisys
Chile's market analisysChile's market analisys
Chile's market analisys
 
Six young men presentation
Six young men presentationSix young men presentation
Six young men presentation
 
Wolf pack project ii
Wolf pack project iiWolf pack project ii
Wolf pack project ii
 

Similar a Cis407 a ilab 3 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.docxkeilenettie
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletMitchinson
 
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx        Greetings and Salutations.docxCIS407AWk2iLabDefault.aspx        Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docxclarebernice
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxniraj57
 
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
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universitylhkslkdh89009
 
XPages - The Ties That Bind
XPages - The Ties That BindXPages - The Ties That Bind
XPages - The Ties That BindMichael McGarel
 
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
 
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
 
Database development connection steps
Database development connection stepsDatabase development connection steps
Database development connection stepsAravindharamanan S
 
Once the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docxOnce the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docxarnit1
 
systems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docxsystems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docxperryk1
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnukeNguyễn Anh
 
Events Registration System Part 1
Events Registration System Part 1Events Registration System Part 1
Events Registration System Part 1Adolfo Nasol
 

Similar a Cis407 a ilab 3 web application development devry university (20)

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
 
Open microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutletOpen microsoft visual studio/tutorialoutlet
Open microsoft visual studio/tutorialoutlet
 
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx        Greetings and Salutations.docxCIS407AWk2iLabDefault.aspx        Greetings and Salutations.docx
CIS407AWk2iLabDefault.aspx Greetings and Salutations.docx
 
Database Connection
Database ConnectionDatabase Connection
Database Connection
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
 
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
 
Cis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry universityCis407 a ilab 5 web application development devry university
Cis407 a ilab 5 web application development devry university
 
Mca 504 dotnet_unit5
Mca 504 dotnet_unit5Mca 504 dotnet_unit5
Mca 504 dotnet_unit5
 
XPages - The Ties That Bind
XPages - The Ties That BindXPages - The Ties That Bind
XPages - The Ties That Bind
 
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
 
Grid view control
Grid view controlGrid view control
Grid view control
 
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
 
Database development connection steps
Database development connection stepsDatabase development connection steps
Database development connection steps
 
Once the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docxOnce the Application has started up and you are at the Start Page, s.docx
Once the Application has started up and you are at the Start Page, s.docx
 
systems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docxsystems labOnce the Application has started up and you are at the .docx
systems labOnce the Application has started up and you are at the .docx
 
Android sql examples
Android sql examplesAndroid sql examples
Android sql examples
 
data binding.docx
data binding.docxdata binding.docx
data binding.docx
 
Oracle ADF 11g Tutorial
Oracle ADF 11g TutorialOracle ADF 11g Tutorial
Oracle ADF 11g Tutorial
 
Creating a dot netnuke
Creating a dot netnukeCreating a dot netnuke
Creating a dot netnuke
 
Events Registration System Part 1
Events Registration System Part 1Events Registration System Part 1
Events Registration System Part 1
 

Cis407 a ilab 3 web application development devry university

  • 1. CIS407A iLab 3 Web Application Development Devry University Click this link to get the tutorial: http://homeworkfox.com/tutorials/general- questions/6225/cis407a-ilab-3-web-application-development- devry-university/ iLab 3 of 7: User activity monitoring Submit your assignment to the Dropbox located on the silver tab at the top of this page. (See Syllabus/"Due Dates for Assignments & Exams" for due dates.) iLABOVERVIEW 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:
  • 2. •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. iLABSTEPS STEP 1: Data Connection, Dataset and Data Access Class (10 points) 1.Open Microsoft Visual Studio.NET 2008. 2.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. 3.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. 4.Now we need to create a new connection to the PayrollSystem_DB.MDB. To begin, click View Server Explorer. 5.When the Server Explorer toolbox appears, click the Connect to Database button. 6.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. 7.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.
  • 3. 8.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. 9.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 10. Click here for text discription of this image. 11. 12.If the following message appears, select Yes. You want to make this dataset available to your entire website. 13.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.) 14.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. 15.Click the Save icon on the toolbar to save the dsUserActivity.xsd dataset. Click on image to enlarge. Dataset Saved 16. Click here for text discription of this image.
  • 4. 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. 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 19. Click here for text discription of this image. 20.If the following message appears, select Yes. You want to make this class available to everything in your solution. 21.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; 22.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;
  • 5. // Add your comments here OleDbConnection(";" + "Data select * from tblUserActivity", sqlConn); // Add your comments here 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 OleDbConnection(";" + "Data Insert into tblUserActivity (UserIP, FormAccessed) values ('" + GetIP4Address() + "', '" + FormAccessed + "')"; ; ; command.ExecuteNonQuery(); conn.Close(); } // This function gets the IP Address
  • 6. public static string GetIP4Address() { string ; foreach (IPAddress IPA in Dns.GetHostAddresses(HttpContext.Current.Request.UserHostAddress)) { if (IPA.AddressFamily.ToString() == "InterNetwork") { (); break; } } if (IP4Address != string.Empty) { return IP4Address; } foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName())) { if (IPA.AddressFamily.ToString() == "InterNetwork") { (); break; } } return IP4Address; } STEP 2: frmUserActivity, frmPersonnel, frmMain (10 points) 18.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:
  • 7. PropertyValue Label - TextUser Activity GridView - (ID)grdUserActivity 19.Go to the Page_Load method and add the following code: if (!Page.IsPostBack) { // Declares the DataSet dsUserActivity dsUserActivity(); // Fill the dataset with what is returned from the function (Server.MapPath("PayrollSystem_DB.mdb")); // Sets the DataGrid to the DataSource based on the table ["tblUserActivity"]; // Binds the DataGrid grdUserActivity.DataBind(); } 20.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. 21.Go to the frmMain Page_Load and add the following code: // Add your comments here clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.mdb"), "frmPersonnel"); 22.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. 23.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.
  • 8. 24.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: 1.Clear the Submit button PostBackURLProperty on the frmPersonnel form. 2.In the btnSubmit_Click event handler get each value from the data entry fields and set Session state items for each. 3.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. 25.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. 26.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
  • 9. 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. 27.Lab Hints: To set a value in session state do the following: Session["txtFirstName"] = txtFirstName.Text; 28."txtFirstName" is the key and txtFirstName.Text is the value. 29.To get this same value back from the session we use the key and the Session object as follows: Session["txtLastName"].ToString() 30.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. 31.You may want to create variables to work with for validation rather than using the Request item objects directly. 32.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 (strDate); 33.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) 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 than dt2. 35.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). 36.If I had a TextBox control that was called txtAge and you wanted to set it's background color you could do this: ; 37.Remember to clear the PostBackURL property of the submit button!
  • 10. STEP 3: Verify and submit (10 points) 28.View the video above on what functions your lab should have so far. 29.Run your project. When you open the project, and go to the main menu form 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. The validation and error display should work for entering data. All navigation and hyperlinks should work. Once you have verified that it works, 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. You basically put two forward slashes, which start the comment; anything after the // on that line is disregarded by the compiler. Then type a brief statement describing what is happening in following code. Comments show professionalism and are a must in systems. As a professional developer, comments will set you apart from others and make your life much easier if maintenance and debugging are needed