Cis407 a ilab 3 web application development devry university

790 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
790
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cis407 a ilab 3 web application development devry university

  1. 1. CIS407A iLab 3 Web ApplicationDevelopment Devry UniversityClick 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 monitoringSubmit 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.)iLABOVERVIEWScenario/SummaryIn this lab, we will demonstrate how to save user activity data in a database. We will be creatinga new form to display the user activity data, a new dataset to contain the data, a data access classto structure the code, and a function within the data access class to save users activity data whenusers visit the Personnel form page (frmPersonnel.aspx). We will also be adding server sidevalidation to the frmPersonnel for you added in the previous lab and update or main menu for thenew 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.DeliverablesAll 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 thetblUserActivity table with the IP address, form name accessed (frmPersonnel), and the dateaccessed. When you click the "View Activity" button, you should see at least one record withthis information. When the user goes to the frmPersonnel web form and enters data the followingbusiness rules are to be enforced:
  2. 2. •Fields may not be empty or filled with spaces. If any field is empty, turn that field backgroundcolor 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 turnboth 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 usershould see the frmPersonnelVerified form with all the values displayed. You will also add a newitem to frmMain that will take the user to the new frmUserActivity form you added. Add theproper link and a hyperlinked image to allow the user to select this new option. Once you haveverified that everything works, save your website, zip up all files, and submit in the Dropbox.iLABSTEPSSTEP 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 pullingdown the File menu, selecting Open Website, navigating to the folder where you previouslysaved the PayrollSystem, and clicking Open.3.Download the PayrollSystem_DB.MDB file from Doc Sharing and save it on your localcomputer. (Note: your operating system may lock or block the file. Once you have copied itlocally, right click on the file and select Properties and then Unblock if available). Then add it tothe 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 clickthe Add button.4.Now we need to create a new connection to the PayrollSystem_DB.MDB. To begin, clickView 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 DataSource" dialog, select MS Access Database File; Uncheck Always use this Selection; then clickOK.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 yourPayrollSystem website folder, not the one you originally downloaded from Doc Sharing!) ClickTest Connection. You should receive a message that the test connection succeeded. Click OK toacknowledge the message, then click "OK" again to close the Add Connection dialog.
  3. 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 ServerExplorer 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 Datasetitem. Enter dsUserActivity.xsd for the name. Click Add.Click on image to enlarge.Add Data Set10.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 yourentire website.13.If the TableAdapter Configuration Wizard dialog appears, click Cancel. (We will beconfiguring a Data Adapter for this dataset later in C# code, so we do not need to run thiswizard.)14.Drag-and-drop the tblUserActivity table from the Server Explorer window into thedsUserActivity dataset in the editor window.NOTE: If you see a message that says your connection uses a local data file that is not in thecurrent project, that indicates you did not select the correct PayrollSystem_DB.mdb file whenyou created your data connection. To fix this problem, click No, then right-click onPayrollSystem_DB.mdb in the Server Explorer window and choose Modify Connection. Clickthe Browse button, navigate to the PayrollSystem_DB.mdb file that is in your PayrollSystemwebsite 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 Saved16.Click here for text discription of this image.
  4. 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, clickWebsite, Add New Item. In the Add New Item dialog, select the Class template, and enterclsDataLayer for the name. Make sure the Language is set to Visual C#. Click "Add".Click on image to enlarge.Add DataLayer Class19.Click here for text discription of this image.20.If the following message appears, select Yes. You want to make this class available toeverything in your solution.21.Add the following to the top of your class, below any other using statements created for youby Visual Studio:// Add your comments hereusing System.Data.OleDb;using System.Net;using System.Data;22.Add the following three functions inside the squiggly braces for the "public classclsDataLayer" class, above the beginning of the "public clsDataLayer()" constructor:// This function gets the user activity from the tblUserActivitypublic static dsUserActivity GetUserActivity(string Database){// Add your comments heredsUserActivity DS;OleDbConnection sqlConn;OleDbDataAdapter sqlDA;
  5. 5. // Add your comments hereOleDbConnection(";" +"Data select * from tblUserActivity", sqlConn);// Add your comments heredsUserActivity();// Add your comments heresqlDA.Fill(DS.tblUserActivity);// Add your comments herereturn DS;}// This function saves the user activitypublic static void SaveUserActivity(string Database, string FormAccessed){// Add your comments hereOleDbConnection OleDbConnection(";" +"Data Insert into tblUserActivity (UserIP, FormAccessed) values (" +GetIP4Address() + ", " + FormAccessed + ")";;;command.ExecuteNonQuery();conn.Close();}// This function gets the IP Address
  6. 6. public static string GetIP4Address(){string ;foreach (IPAddress IPA inDns.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 andGridView (found under the Toolbox, Data tab) having the following properties:
  7. 7. PropertyValueLabel - TextUser ActivityGridView - (ID)grdUserActivity19.Go to the Page_Load method and add the following code:if (!Page.IsPostBack) {// Declares the DataSetdsUserActivity 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 DataGridgrdUserActivity.DataBind();}20.Open the frmMain form, add a new link button and image button to point to the newfrmUserActivity. Find an image to use for the image button and add the new option as ViewUser Activity.21.Go to the frmMain Page_Load and add the following code:// Add your comments hereclsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.mdb"), "frmPersonnel");22.On the frmUserActivity form, add the CoolBiz logo hyperlinked logo at the top of the page sothat 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 tblUserActivitytable with the IP address, form name accessed (frmPersonnel), and the date accessed. When youclick the View Activity button, you should see at least one record with this information.
  8. 8. 24.You will now add server side validation code to the frmPersonnel page. Currently, when theSubmit button is pressed, the frmPersonnelVerified page is displayed. This is because thefrmPersonnelVerified page is set as the Submit buttons PostBackUrl property. Instead of havingthe page go directly to the frmPersonnelVerified page when the Submit button is pressed, wewant to do some server side validation. If any of the validation rules fail, we will redisplay thefrmPersonnel page with the fields in question highlighted in yellow with an error messagedisplayed.First, it is important to understand what is currently happening when the submit button ispressed. This is causing a postback of the form to the frmPersonnelVerified form. When thispostback happens, all of the data in the fields on the frmPersonnel form are sent to thefrmPersonnelVerified form as name value pairs. In the Page_Load code of frmPersonnelVerifiedthese values are picked up from the Request object and displayed. Each name value pair will bein the Request object as the ID of the control containing the value and the value itself. We canpass data between pages by using Session state instead. In order to do validation on the valuesbut still have the values visible on the frmPersonnelVerified page, we will need to change notonly the PostBack URL of the frmPersonnel page but also how the frmPersonnelVerified form isgetting 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 Sessionstate items for each.3.Change the frmPersonnelVerified code behind to get the values from the Session state itemsyou created in the previous step.When you are done with these steps, you should be able to enter data on the frmPersonnel dataentry form and then click the Submit button. The frmPersonnelVerified page should then bedisplayed 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 theright 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 thefrmPersonnel 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 theerror label. The end date must be greater than the start date. If the end date is less than the startdate, turn both date fields yellow and add to/create an error message to be shown in the error
  9. 9. label. If all fields validate properly then the session state items should be set properly and theuser 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 asfollows:Session["txtLastName"].ToString()30.There is a Trim method on the string object that will automatically remove spaces from thebeginning and end of a string. Remember, you can turn an object like a Session item object into astring using the Convert class or just using its ToString() method.31.You may want to create variables to work with for validation rather than using the Requestitem objects directly.32.To turn a string into a DateTime object you can use the DateTime method Parse. If you had adate 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 hadtwo DateTime objects called dt1 and dt2 you can check to see if dt1 is greater than dt2 by doingthis: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, anda -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 errorwhen trying to parse the values. We will address this in a later lab – for now make sure you entervalid 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 its background coloryou could do this:;37.Remember to clear the PostBackURL property of the submit button!
  10. 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 shouldbe 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 onerecord with this information. The validation and error display should work for entering data. Allnavigation and hyperlinks should work.Once you have verified that it works, save your project, zip up all files, and submit in theDropbox.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 deductionper item (form, class, function) will be made. You basically put two forward slashes, which startthe comment; anything after the // on that line is disregarded by the compiler. Then type a briefstatement describing what is happening in following code. Comments show professionalism andare a must in systems. As a professional developer, comments will set you apart from others andmake your life much easier if maintenance and debugging are needed

×