CIS407a Web Application Development with Lab

profileHellokate
archive.zip

CIS407_Lab3_2016.zip

CIS407_Lab3_2016/Screenshots/frmPersonnel.png

CIS407_Lab3_2016/Screenshots/frmPersonnel2.png

CIS407_Lab3_2016/Screenshots/frmPersonnel3.png

CIS407_Lab3_2016/Screenshots/frmPersonnelVerified.png

CIS407_Lab3_2016/Screenshots/frmUserActivity.png

CIS407_Lab3_2016/Week3Lab/App_Code/clsDataLayer.cs

// Namespaces to be used in the class using System.Data.OleDb; using System.Net; using System.Data; using System.Web; /// <summary> /// This class handles all the database operations for the website /// </summary> public class clsDataLayer { // 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.ACE.OLEDB.12.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.ACE.OLEDB.12.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; } }

CIS407_Lab3_2016/Week3Lab/App_Code/dsUserActivity.xsd

DELETE FROM `tblUserActivity` WHERE ((`ActivityID` = ?)) INSERT INTO `tblUserActivity` (`UserIP`, `DateOfActivity`, `FormAccessed`) VALUES (?, ?, ?) SELECT ActivityID, UserIP, DateOfActivity, FormAccessed FROM tblUserActivity UPDATE `tblUserActivity` SET `UserIP` = ?, `DateOfActivity` = ?, `FormAccessed` = ? WHERE ((`ActivityID` = ?))

CIS407_Lab3_2016/Week3Lab/App_Code/dsUserActivity.xss

CIS407_Lab3_2016/Week3Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

CIS407_Lab3_2016/Week3Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab3_2016/Week3Lab/frmMain.aspx

  Annual Salary Calculator   Add New Employee  User Activity

CIS407_Lab3_2016/Week3Lab/frmMain.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmMain : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // whenever user opens main form a record is added to the table useractivity clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.accdb"), "frmPersonnel"); } }

CIS407_Lab3_2016/Week3Lab/frmPersonnel.aspx

                    

CIS407_Lab3_2016/Week3Lab/frmPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { bool isValid = true; //Variable to hold whether validation is successful or not //reset back color of all controls txtFirstName.BackColor = System.Drawing.Color.White; txtLastName.BackColor = System.Drawing.Color.White; txtPayRate.BackColor = System.Drawing.Color.White; txtStartDate.BackColor = System.Drawing.Color.White; txtEndDate.BackColor = System.Drawing.Color.White; lblError.Text = ""; //Check all controls whether they have blank inputs or not if (Request["txtFirstName"].ToString().Trim() == "") { txtFirstName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter First Name.<br/>"; isValid = false; } if (Request["txtLastName"].ToString().Trim() == "") { txtLastName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Last Name.<br/>"; isValid = false; } if (Request["txtPayRate"].ToString().Trim() == "") { txtPayRate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Pay Rate.<br/>"; isValid = false; } //get startdate and enddate in variables string startDate = Request["txtStartDate"].ToString(); string endDate = Request["txtEndDate"].ToString(); DateTime myDateTimeStartDateObj = new DateTime(); DateTime myDateTimeEndDateObj = new DateTime(); ; //check if start date or end date is blank if (startDate.Trim() =="") { txtStartDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter start date.<br/>"; isValid = false; } if (endDate.Trim() == "") { txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter end date.<br/>"; isValid = false; } //if start date and end date are not blank then check for date comparison validation if(startDate.Trim() !="" && endDate.Trim() !="") { myDateTimeStartDateObj = DateTime.Parse(startDate); myDateTimeEndDateObj = DateTime.Parse(endDate); //check if end date is smaller than start date if (DateTime.Compare(myDateTimeStartDateObj, myDateTimeEndDateObj) > 0) { txtStartDate.BackColor = System.Drawing.Color.Yellow; txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "The End Date must be greater than the start Date.\n"; isValid = false; } } //if everything is valid then set session variable. if (isValid) { Session["txtFirstName"] = txtFirstName.Text; Session["txtLastName"] = txtLastName.Text; Session["txtPayRate"] = txtPayRate.Text; Session["txtStartDate"] = myDateTimeStartDateObj; Session["txtEndDate"] = myDateTimeEndDateObj; Response.Redirect("frmPersonnelVerified.aspx"); } } }

CIS407_Lab3_2016/Week3Lab/frmPersonnelVerified.aspx

CIS407_Lab3_2016/Week3Lab/frmPersonnelVerified.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnelVerified : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { /** * This statement will get all the session parameters sent from frmPersonnel page * and set them to the text box in frmPersonnelVerified form */ txtVerifiedInfo.Text = Session["txtFirstName"] + "\n" + Session["txtLastName"] + "\n" + Session["txtPayRate"] + "\n" + Session["txtStartDate"] + "\n" + Session["txtEndDate"]; } }

CIS407_Lab3_2016/Week3Lab/frmSalaryCalculator.aspx

                                            

CIS407_Lab3_2016/Week3Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

CIS407_Lab3_2016/Week3Lab/frmUserActivity.aspx

CIS407_Lab3_2016/Week3Lab/frmUserActivity.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmUserActivity : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { 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.accdb")); // Sets the DataGrid to the DataSource based on the table grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"]; // Binds the DataGrid grdUserActivity.DataBind(); } } }

CIS407_Lab3_2016/Week3Lab/Images/CIS407A_iLab_ACITLogo.jpg

CIS407_Lab3_2016/Week3Lab/Images/personnel.jpg

CIS407_Lab3_2016/Week3Lab/Images/salaryCalculator.jpg

CIS407_Lab3_2016/Week3Lab/Images/userActivity.jpg

CIS407_Lab3_2016/Week3Lab/PayrollSystem_DB.accdb

ID FirstName LastName PayRate StartDate EndDate
ActivityID UserIP DateOfActivity FormAccessed
1 192.168.153.1 3/19/16 frmPersonnel
2 192.168.153.1 3/19/16 frmPersonnel
3 192.168.153.1 3/19/16 frmPersonnel
4 192.168.153.1 3/19/16 frmPersonnel
5 192.168.153.1 3/19/16 frmPersonnel
6 192.168.153.1 3/19/16 frmPersonnel
7 192.168.153.1 3/19/16 frmPersonnel
8 192.168.153.1 3/19/16 frmPersonnel
9 192.168.153.1 3/19/16 frmPersonnel
10 192.168.153.1 3/19/16 frmPersonnel
11 192.168.153.1 3/19/16 frmPersonnel
12 192.168.153.1 3/19/16 frmPersonnel
13 192.168.153.1 3/19/16 frmPersonnel
14 192.168.153.1 3/19/16 frmPersonnel
15 192.168.153.1 3/19/16 frmPersonnel
16 192.168.153.1 3/19/16 frmPersonnel
17 192.168.153.1 3/19/16 frmPersonnel
18 192.168.153.1 3/19/16 frmPersonnel
19 192.168.153.1 3/19/16 frmPersonnel
20 192.168.153.1 3/19/16 frmPersonnel
UserID UserName UserPassword SecurityLevel
1 Mickey Mouse A
2 Minnie Mouse U

CIS407_Lab3_2016/Week3Lab/Web.config

CIS407_Lab3_2016/Week3Lab/Web.Debug.config

CIS407_Lab7_2016.zip

CIS407_Lab7_2016/Screenshots/2016-04-15_23-01-21.png

CIS407_Lab7_2016/Screenshots/2016-04-15_23-02-35.png

CIS407_Lab7_2016/Screenshots/2016-04-15_23-03-36.png

CIS407_Lab7_2016/Week7Lab/App_Code/clsBusinessLayer.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; // Import mail namespace using System.Net.Mail; /// <summary> /// Summary description for clsBusinessLayer /// </summary> public class clsBusinessLayer { public clsBusinessLayer() { } public static bool SendEmail(string Sender, string Recipient, string bcc, string cc, string Subject, string Body) { try { // Create a new mail message MailMessage MyMailMessage = new MailMessage(); // Set the from address MyMailMessage.From = new MailAddress(Sender); // Add the recipient address MyMailMessage.To.Add(new MailAddress(Recipient)); // Check if Bcc is provided or not if (bcc != null && bcc != string.Empty) { // Add Bcc address MyMailMessage.Bcc.Add(new MailAddress(bcc)); } // Check if CC is provided if (cc != null && cc != string.Empty) { // Add the CC address MyMailMessage.CC.Add(new MailAddress(cc)); } // Set the subject MyMailMessage.Subject = Subject; // Set the contents of the mail MyMailMessage.Body = Body; // Set html content to true MyMailMessage.IsBodyHtml = true; // Set normal priority MyMailMessage.Priority = MailPriority.Normal; // Set the smtpclient SmtpClient MySmtpClient = new SmtpClient("localhost"); //SMTP Port = 25; //Generic IP host = "127.0.0.1"; // Send the mail MySmtpClient.Send(MyMailMessage); // Return true because by this time mail is successsfully sent return true; } catch (Exception ex) { // Incase of exception return false return false; } } }

CIS407_Lab7_2016/Week7Lab/App_Code/clsDataLayer.cs

// Namespaces to be used in the class using System.Data.OleDb; using System.Net; using System.Data; using System.Web; using System; /// <summary> /// This class handles all the database operations for the website /// </summary> public class clsDataLayer { // This function gets the user activity from the tblUserActivity public static dsUserActivity GetUserActivity(string Database) { // Declare data set, connection and data adapter objects dsUserActivity DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // create a connection to the access database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // set the dataadapter with the query sqlDA = new OleDbDataAdapter("select * from tblUserActivity", sqlConn); // initialize the dataset DS = new dsUserActivity(); // Fill the dataset sqlDA.Fill(DS.tblUserActivity); // return the dataset return DS; } // This function saves the user activity public static void SaveUserActivity(string Database, string FormAccessed) { // create a connection to the database and inserts user activity record to the table OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.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; } // This function saves the personnel data public static bool SavePersonnel(string Database, string FirstName, string LastName, string PayRate, string StartDate, string EndDate) { bool recordSaved; // Declare a transaction variable OleDbTransaction myTransaction = null; try { // create a connection to the database OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); conn.Open(); OleDbCommand command = conn.CreateCommand(); string strSQL; // Start the transaction and set the transaction to the command object myTransaction = conn.BeginTransaction(); command.Transaction = myTransaction; // query to insert record in the tblPersonnel table strSQL = "Insert into tblPersonnel " + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Set command object with the query command.CommandType = CommandType.Text; command.CommandText = strSQL; // execute the insert query command.ExecuteNonQuery(); // update query strSQL = "Update tblPersonnel " + "Set PayRate=" + PayRate + ", " + "StartDate='" + StartDate + "', " + "EndDate='" + EndDate + "' " + "Where ID=(Select Max(ID) From tblPersonnel)"; // Set the command object with the update query command.CommandType = CommandType.Text; command.CommandText = strSQL; // Execute the query command.ExecuteNonQuery(); // Commit the transaction myTransaction.Commit(); // Close connection to the database conn.Close(); recordSaved = true; } catch (Exception ex) { //Incase of exception rollback the transaction myTransaction.Rollback(); recordSaved = false; } return recordSaved; } // This function gets the user activity from the tblPersonnel public static dsPersonnel GetPersonnel(string Database, string strSearch) { // Create the dataset, connection and data adapter objects dsPersonnel DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // Create connection the database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // if strsearch is empty or null select all records from tblPersonnel //otherwise select only those records matching with strsearch in lastname if (strSearch == null || strSearch.Trim() == "") { sqlDA = new OleDbDataAdapter("select * from tblPersonnel", sqlConn); } else { sqlDA = new OleDbDataAdapter("select * from tblPersonnel where LastName = '" + strSearch + "'", sqlConn); } // initialize the dataset DS = new dsPersonnel(); // populate the dataset with the data returned from the query sqlDA.Fill(DS.tblPersonnel); // return the dataset return DS; } // This function verifies a user in the tblUser table public static dsUser VerifyUser(string Database, string UserName, string UserPassword) { // Declare the Dataset, sqlConnection and SQLDataadapter objects dsUser DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // set the connection to the sql connection object sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // set the sql adapter with the query to get the record for the user sqlDA = new OleDbDataAdapter("Select SecurityLevel from tblUserLogin " + "where UserName like '" + UserName + "' " + "and UserPassword like '" + UserPassword + "'", sqlConn); // set the dataset object DS = new dsUser(); // fill the dataset with the results returned from the query sqlDA.Fill(DS.tblUserLogin); // return the dataset return DS; } public static bool SaveUser(string Database, string UserName, string Password,string SecurityLevel) { bool recordSaved; // Declare a transaction variable OleDbTransaction myTransaction = null; try { // create a connection to the database OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); conn.Open(); OleDbCommand command = conn.CreateCommand(); string strSQL; // query to insert record in the tblUserLogin table strSQL = "Insert into tblUserLogin " + "(UserName, UserPassword,SecurityLevel) values ('" + UserName + "', '" + Password + "', '" + SecurityLevel + "')"; // Set command object with the query command.CommandType = CommandType.Text; command.CommandText = strSQL; // execute the insert query command.ExecuteNonQuery(); // Close connection to the database conn.Close(); recordSaved = true; } catch (Exception ex) { recordSaved = false; } return recordSaved; } }

CIS407_Lab7_2016/Week7Lab/App_Code/dsPersonnel.xsd

DELETE FROM `tblPersonnel` WHERE ((`ID` = ?)) INSERT INTO `tblPersonnel` (`FirstName`, `LastName`, `PayRate`, `StartDate`, `EndDate`) VALUES (?, ?, ?, ?, ?) SELECT ID, FirstName, LastName, PayRate, StartDate, EndDate FROM tblPersonnel UPDATE `tblPersonnel` SET `FirstName` = ?, `LastName` = ?, `PayRate` = ?, `StartDate` = ?, `EndDate` = ? WHERE ((`ID` = ?))

CIS407_Lab7_2016/Week7Lab/App_Code/dsPersonnel.xss

CIS407_Lab7_2016/Week7Lab/App_Code/dsUser.xsd

INSERT INTO `tblUserLogin` (`UserName`, `UserPassword`, `SecurityLevel`) VALUES (?, ?, ?) SELECT UserID, UserName, UserPassword, SecurityLevel FROM tblUserLogin

CIS407_Lab7_2016/Week7Lab/App_Code/dsUser.xss

CIS407_Lab7_2016/Week7Lab/App_Code/dsUserActivity.xsd

DELETE FROM `tblUserActivity` WHERE ((`ActivityID` = ?)) INSERT INTO `tblUserActivity` (`UserIP`, `DateOfActivity`, `FormAccessed`) VALUES (?, ?, ?) SELECT ActivityID, UserIP, DateOfActivity, FormAccessed FROM tblUserActivity UPDATE `tblUserActivity` SET `UserIP` = ?, `DateOfActivity` = ?, `FormAccessed` = ? WHERE ((`ActivityID` = ?))

CIS407_Lab7_2016/Week7Lab/App_Code/dsUserActivity.xss

CIS407_Lab7_2016/Week7Lab/App_Data/PayrollSystem_DB.accdb

ID FirstName LastName PayRate StartDate EndDate
1 test1 Test2 100 12/12/01 12/12/2003 12:00:00 AM
2 test2 test2 101 12/12/01 12/12/2003 12:00:00 AM
3 John Smith 191 12/12/03 12/2/2015 12:00:00 AM
4 James Doe 90 1/1/01 1/1/2010 12:00:00 AM
6 CFirstname CLastName 400 1/1/11 1/1/2012 12:00:00 AM
8 john smith 109 1/1/12 1/1/2012 12:00:00 AM
9 John Smith 400 1/1/12 1/1/2012 12:00:00 AM
ActivityID UserIP DateOfActivity FormAccessed
1 192.168.153.1 3/19/16 frmPersonnel
2 192.168.153.1 3/19/16 frmPersonnel
3 192.168.153.1 3/19/16 frmPersonnel
4 192.168.153.1 3/19/16 frmPersonnel
5 192.168.153.1 3/19/16 frmPersonnel
6 192.168.153.1 3/19/16 frmPersonnel
7 192.168.153.1 3/19/16 frmPersonnel
8 192.168.153.1 3/19/16 frmPersonnel
9 192.168.153.1 3/19/16 frmPersonnel
10 192.168.153.1 3/19/16 frmPersonnel
11 192.168.153.1 3/19/16 frmPersonnel
12 192.168.153.1 3/19/16 frmPersonnel
13 192.168.153.1 3/19/16 frmPersonnel
14 192.168.153.1 3/19/16 frmPersonnel
15 192.168.153.1 3/19/16 frmPersonnel
16 192.168.153.1 3/19/16 frmPersonnel
17 192.168.153.1 3/19/16 frmPersonnel
18 192.168.153.1 3/19/16 frmPersonnel
19 192.168.153.1 3/19/16 frmPersonnel
20 192.168.153.1 3/19/16 frmPersonnel
21 192.168.153.1 3/26/16 frmPersonnel
22 192.168.153.1 3/26/16 frmPersonnel
23 192.168.153.1 3/26/16 frmPersonnel
24 192.168.153.1 3/26/16 frmPersonnel
25 192.168.153.1 3/26/16 frmPersonnel
26 192.168.153.1 3/26/16 frmPersonnel
27 192.168.153.1 3/26/16 frmPersonnel
28 192.168.153.1 3/26/16 frmPersonnel
29 192.168.153.1 3/26/16 frmPersonnel
30 192.168.153.1 3/26/16 frmPersonnel
31 192.168.153.1 4/2/16 frmPersonnel
32 192.168.153.1 4/2/16 frmPersonnel
33 192.168.153.1 4/2/16 frmPersonnel
34 192.168.153.1 4/2/16 frmPersonnel
35 192.168.153.1 4/2/16 frmPersonnel
36 192.168.153.1 4/2/16 frmPersonnel
37 192.168.153.1 4/2/16 frmPersonnel
38 192.168.153.1 4/2/16 frmPersonnel
39 192.168.153.1 4/2/16 frmPersonnel
40 192.168.153.1 4/2/16 frmPersonnel
41 192.168.153.1 4/2/16 frmPersonnel
42 192.168.153.1 4/2/16 frmPersonnel
43 192.168.153.1 4/2/16 frmPersonnel
44 192.168.153.1 4/2/16 frmPersonnel
45 192.168.153.1 4/2/16 frmPersonnel
UserID UserName UserPassword SecurityLevel
1 Mickey Mouse A
2 Minnie Mouse U

CIS407_Lab7_2016/Week7Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

CIS407_Lab7_2016/Week7Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab7_2016/Week7Lab/frmEditPersonnel.aspx

CIS407_Lab7_2016/Week7Lab/frmEditPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmEditPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["SecurityLevel"] != "A") { Response.Redirect("frmLogin.aspx"); } } }

CIS407_Lab7_2016/Week7Lab/frmLogin.aspx

CIS407_Lab7_2016/Week7Lab/frmLogin.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmLogin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { // declare the dataset dsUser dsUserLogin; // security level variable declaration string SecurityLevel; // call the verify user method to verify the login dsUserLogin = clsDataLayer.VerifyUser(Server.MapPath("PayrollSystem_DB.accdb"), Login1.UserName, Login1.Password); // if results are returned from the method then user is authenticated otherwise no if (dsUserLogin.tblUserLogin.Count < 1) { e.Authenticated = false; // Add your comments here // Add your comments here if (clsBusinessLayer.SendEmail("[email protected]", "[email protected]", "", "", "Login Incorrect", "The login failed for UserName: " + Login1.UserName + " Password: " + Login1.Password)) { Login1.FailureText = Login1.FailureText + " Your incorrect login information was sent to [email protected]"; } return; } // if login is authenticated then set teh security level for the user SecurityLevel = dsUserLogin.tblUserLogin[0].SecurityLevel.ToString(); // check for security level switch (SecurityLevel) { case "A": // if it is A then set the session value to A e.Authenticated = true; FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false); Session["SecurityLevel"] = "A"; break; case "U": // if it is U then set the session value to U e.Authenticated = true; FormsAuthentication.RedirectFromLoginPage(Login1.UserName, false); Session["SecurityLevel"] = "U"; break; default: e.Authenticated = false; break; } } }

CIS407_Lab7_2016/Week7Lab/frmMain.aspx

  Annual Salary Calculator   Add New Employee  User Activity  View Personnel  Search Personnel Edit Employees Manage Users

CIS407_Lab7_2016/Week7Lab/frmMain.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmMain : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // if Security Level is A if (Session["SecurityLevel"] == "A") { imgbtnNewEmployee.Visible = true; imgbtnViewUserActivity.Visible = true; imgbtnEditEmployees.Visible = true; imgbtnManageUsers.Visible = true; linkbtnNewEmployee.Visible = true; linkbtnViewUserActivity.Visible = true; linkbtnEditEmployees.Visible = true; linkbtnManageUsers.Visible = true; //then show the buttons and images for add Employee, view user activity and } else { imgbtnNewEmployee.Visible = false; imgbtnViewUserActivity.Visible = false; imgbtnEditEmployees.Visible = false; imgbtnManageUsers.Visible = false; linkbtnNewEmployee.Visible = false; linkbtnViewUserActivity.Visible = false; linkbtnEditEmployees.Visible = false; linkbtnManageUsers.Visible = false; } // whenever user opens main form a record is added to the table useractivity clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.accdb"), "frmPersonnel"); } }

CIS407_Lab7_2016/Week7Lab/frmManageUsers.aspx

                A U

CIS407_Lab7_2016/Week7Lab/frmManageUsers.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmManageUsers : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["SecurityLevel"] != "A") { Response.Redirect("frmLogin.aspx"); } } protected void Button1_Click(object sender, EventArgs e) { if (clsDataLayer.SaveUser(Server.MapPath("PayrollSystem_DB.accdb"), txtUserName.Text, txtPassword.Text, ddlSecurityLevel.SelectedValue)) { lblError.Text = "The user was successfully added!"; grdUsers.DataBind(); } else { lblError.Text = "The user could not be added!"; } } }

CIS407_Lab7_2016/Week7Lab/frmPersonnel.aspx

                    

CIS407_Lab7_2016/Week7Lab/frmPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["SecurityLevel"] != "A") { Response.Redirect("frmLogin.aspx"); } } protected void btnSubmit_Click(object sender, EventArgs e) { bool isValid = true; //Variable to hold whether validation is successful or not //reset back color of all controls txtFirstName.BackColor = System.Drawing.Color.White; txtLastName.BackColor = System.Drawing.Color.White; txtPayRate.BackColor = System.Drawing.Color.White; txtStartDate.BackColor = System.Drawing.Color.White; txtEndDate.BackColor = System.Drawing.Color.White; lblError.Text = ""; //Check all controls whether they have blank inputs or not if (Request["txtFirstName"].ToString().Trim() == "") { txtFirstName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter First Name.<br/>"; isValid = false; } if (Request["txtLastName"].ToString().Trim() == "") { txtLastName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Last Name.<br/>"; isValid = false; } if (Request["txtPayRate"].ToString().Trim() == "") { txtPayRate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Pay Rate.<br/>"; isValid = false; } //get startdate and enddate in variables string startDate = Request["txtStartDate"].ToString(); string endDate = Request["txtEndDate"].ToString(); DateTime myDateTimeStartDateObj = new DateTime(); DateTime myDateTimeEndDateObj = new DateTime(); ; //check if start date or end date is blank if (startDate.Trim() =="") { txtStartDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter start date.<br/>"; isValid = false; } if (endDate.Trim() == "") { txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter end date.<br/>"; isValid = false; } //if start date and end date are not blank then check for date comparison validation if(startDate.Trim() !="" && endDate.Trim() !="") { myDateTimeStartDateObj = DateTime.Parse(startDate); myDateTimeEndDateObj = DateTime.Parse(endDate); //check if end date is smaller than start date if (DateTime.Compare(myDateTimeStartDateObj, myDateTimeEndDateObj) > 0) { txtStartDate.BackColor = System.Drawing.Color.Yellow; txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "The End Date must be greater than the start Date.\n"; isValid = false; } } //if everything is valid then set session variable. if (isValid) { Session["txtFirstName"] = txtFirstName.Text; Session["txtLastName"] = txtLastName.Text; Session["txtPayRate"] = txtPayRate.Text; Session["txtStartDate"] = myDateTimeStartDateObj; Session["txtEndDate"] = myDateTimeEndDateObj; Response.Redirect("frmPersonnelVerified.aspx"); } } }

CIS407_Lab7_2016/Week7Lab/frmPersonnelVerified.aspx

CIS407_Lab7_2016/Week7Lab/frmPersonnelVerified.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnelVerified : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { /** * This statement will get all the session parameters sent from frmPersonnel page * and set them to the text box in frmPersonnelVerified form */ txtVerifiedInfo.Text = Session["txtFirstName"] + "\n" + Session["txtLastName"] + "\n" + Session["txtPayRate"] + "\n" + Session["txtStartDate"] + "\n" + Session["txtEndDate"]; // if record is successfully saved to the database then add the success line to the text if (clsDataLayer.SavePersonnel(Server.MapPath("PayrollSystem_DB.accdb"), Session["txtFirstName"].ToString(), Session["txtLastName"].ToString(), Session["txtPayRate"].ToString(), Session["txtStartDate"].ToString(), Session["txtEndDate"].ToString())) { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was successfully saved!"; } else { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was NOT saved."; } } }

CIS407_Lab7_2016/Week7Lab/frmSalaryCalculator.aspx

                                            

CIS407_Lab7_2016/Week7Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

CIS407_Lab7_2016/Week7Lab/frmSearchPersonnel.aspx

   

CIS407_Lab7_2016/Week7Lab/frmSearchPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSearchPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab7_2016/Week7Lab/frmUserActivity.aspx

CIS407_Lab7_2016/Week7Lab/frmUserActivity.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmUserActivity : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["SecurityLevel"] != "A") { Response.Redirect("frmLogin.aspx"); } 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.accdb")); // Sets the DataGrid to the DataSource based on the table grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"]; // Binds the DataGrid grdUserActivity.DataBind(); } } }

CIS407_Lab7_2016/Week7Lab/frmViewPersonnel.aspx

View Personnel

CIS407_Lab7_2016/Week7Lab/frmViewPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmViewPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //Declare the Dataset dsPersonnel myDataSet = new dsPersonnel(); string strSearch = Request["txtSearch"]; //Fill the dataset with shat is returned from the method. myDataSet = clsDataLayer.GetPersonnel(Server.MapPath("PayrollSystem_DB.accdb"), strSearch); //Set the DataGrid to the DataSource based on the table grdViewPersonnel.DataSource = myDataSet.Tables["tblPersonnel"]; //Bind the DataGrid grdViewPersonnel.DataBind(); } } }

CIS407_Lab7_2016/Week7Lab/Images/CIS407A_iLab_ACITLogo.jpg

CIS407_Lab7_2016/Week7Lab/Images/editpersonnel.jpg

CIS407_Lab7_2016/Week7Lab/Images/manageUsers.jpg

CIS407_Lab7_2016/Week7Lab/Images/personnel.jpg

CIS407_Lab7_2016/Week7Lab/Images/salaryCalculator.jpg

CIS407_Lab7_2016/Week7Lab/Images/searchpersonnel.jpg

CIS407_Lab7_2016/Week7Lab/Images/userActivity.jpg

CIS407_Lab7_2016/Week7Lab/Images/viewpersonnel.jpg

CIS407_Lab7_2016/Week7Lab/PayrollSystem_DB.accdb

ID FirstName LastName PayRate StartDate EndDate
1 test1 Test2 100 12/12/01 12/12/2003 12:00:00 AM
2 test2 test2 101 12/12/01 12/12/2003 12:00:00 AM
3 John Smith 191 12/12/03 12/2/2015 12:00:00 AM
4 James Doe 90 1/1/01 1/1/2010 12:00:00 AM
6 CFirstname CLastName 400 1/1/11 1/1/2012 12:00:00 AM
8 john smith 109 1/1/12 1/1/2012 12:00:00 AM
9 John Smith 400 1/1/12 1/1/2012 12:00:00 AM
10 user2 jkj 100 1/1/15 1/1/2016 12:00:00 AM
ActivityID UserIP DateOfActivity FormAccessed
1 192.168.153.1 3/19/16 frmPersonnel
2 192.168.153.1 3/19/16 frmPersonnel
3 192.168.153.1 3/19/16 frmPersonnel
4 192.168.153.1 3/19/16 frmPersonnel
5 192.168.153.1 3/19/16 frmPersonnel
6 192.168.153.1 3/19/16 frmPersonnel
7 192.168.153.1 3/19/16 frmPersonnel
8 192.168.153.1 3/19/16 frmPersonnel
9 192.168.153.1 3/19/16 frmPersonnel
10 192.168.153.1 3/19/16 frmPersonnel
11 192.168.153.1 3/19/16 frmPersonnel
12 192.168.153.1 3/19/16 frmPersonnel
13 192.168.153.1 3/19/16 frmPersonnel
14 192.168.153.1 3/19/16 frmPersonnel
15 192.168.153.1 3/19/16 frmPersonnel
16 192.168.153.1 3/19/16 frmPersonnel
17 192.168.153.1 3/19/16 frmPersonnel
18 192.168.153.1 3/19/16 frmPersonnel
19 192.168.153.1 3/19/16 frmPersonnel
20 192.168.153.1 3/19/16 frmPersonnel
21 192.168.153.1 3/26/16 frmPersonnel
22 192.168.153.1 3/26/16 frmPersonnel
23 192.168.153.1 3/26/16 frmPersonnel
24 192.168.153.1 3/26/16 frmPersonnel
25 192.168.153.1 3/26/16 frmPersonnel
26 192.168.153.1 3/26/16 frmPersonnel
27 192.168.153.1 3/26/16 frmPersonnel
28 192.168.153.1 3/26/16 frmPersonnel
29 192.168.153.1 3/26/16 frmPersonnel
30 192.168.153.1 3/26/16 frmPersonnel
31 192.168.153.1 4/2/16 frmPersonnel
32 192.168.153.1 4/2/16 frmPersonnel
33 192.168.153.1 4/2/16 frmPersonnel
34 192.168.153.1 4/2/16 frmPersonnel
35 192.168.153.1 4/2/16 frmPersonnel
36 192.168.153.1 4/2/16 frmPersonnel
37 192.168.153.1 4/2/16 frmPersonnel
38 192.168.153.1 4/2/16 frmPersonnel
39 192.168.153.1 4/2/16 frmPersonnel
40 192.168.153.1 4/2/16 frmPersonnel
41 192.168.153.1 4/2/16 frmPersonnel
42 192.168.153.1 4/2/16 frmPersonnel
43 192.168.153.1 4/2/16 frmPersonnel
44 192.168.153.1 4/2/16 frmPersonnel
45 192.168.153.1 4/2/16 frmPersonnel
46 192.168.153.1 4/9/16 frmPersonnel
47 192.168.153.1 4/9/16 frmPersonnel
48 192.168.153.1 4/9/16 frmPersonnel
49 192.168.153.1 4/9/16 frmPersonnel
50 192.168.153.1 4/9/16 frmPersonnel
51 192.168.153.1 4/9/16 frmPersonnel
52 192.168.153.1 4/9/16 frmPersonnel
53 192.168.153.1 4/9/16 frmPersonnel
54 192.168.153.1 4/9/16 frmPersonnel
55 192.168.153.1 4/9/16 frmPersonnel
56 192.168.153.1 4/9/16 frmPersonnel
57 192.168.153.1 4/9/16 frmPersonnel
58 192.168.153.1 4/9/16 frmPersonnel
59 192.168.153.1 4/9/16 frmPersonnel
60 192.168.153.1 4/9/16 frmPersonnel
61 192.168.153.1 4/9/16 frmPersonnel
62 192.168.153.1 4/9/16 frmPersonnel
63 192.168.153.1 4/9/16 frmPersonnel
64 192.168.153.1 4/9/16 frmPersonnel
65 192.168.153.1 4/9/16 frmPersonnel
66 192.168.153.1 4/9/16 frmPersonnel
67 192.168.153.1 4/9/16 frmPersonnel
68 192.168.153.1 4/9/16 frmPersonnel
69 192.168.153.1 4/9/16 frmPersonnel
70 192.168.153.1 4/9/16 frmPersonnel
71 192.168.153.1 4/9/16 frmPersonnel
72 192.168.153.1 4/9/16 frmPersonnel
73 192.168.153.1 4/15/16 frmPersonnel
74 192.168.153.1 4/15/16 frmPersonnel
75 192.168.153.1 4/15/16 frmPersonnel
76 192.168.153.1 4/15/16 frmPersonnel
77 192.168.153.1 4/15/16 frmPersonnel
78 192.168.153.1 4/15/16 frmPersonnel
79 192.168.153.1 4/15/16 frmPersonnel
80 192.168.153.1 4/15/16 frmPersonnel
81 192.168.153.1 4/15/16 frmPersonnel
82 192.168.153.1 4/15/16 frmPersonnel
83 192.168.153.1 4/15/16 frmPersonnel
84 192.168.153.1 4/15/16 frmPersonnel
85 192.168.153.1 4/15/16 frmPersonnel
86 192.168.153.1 4/15/16 frmPersonnel
UserID UserName UserPassword SecurityLevel
1 Mickey Mouse A
2 Minnie Mouse U
3 test test U
5 test11 test11 A
6 newuser newuser A
7 test test A
8 jhj jhj A

CIS407_Lab7_2016/Week7Lab/Web.config

CIS407_Lab7_2016/Week7Lab/Web.Debug.config

CIS407_Lab4_2016.zip

CIS407_Lab4_2016/Screenshots/frmMain.png

CIS407_Lab4_2016/Screenshots/frmPersonnel.png

CIS407_Lab4_2016/Screenshots/frmPersonnelVerified.png

CIS407_Lab4_2016/Screenshots/frmSearchPersonnel.png

CIS407_Lab4_2016/Screenshots/frmViewPersonnel.png

CIS407_Lab4_2016/Screenshots/frmViewPersonnelWithSearch.png

CIS407_Lab4_2016/Week4Lab/App_Code/clsDataLayer.cs

// Namespaces to be used in the class using System.Data.OleDb; using System.Net; using System.Data; using System.Web; using System; /// <summary> /// This class handles all the database operations for the website /// </summary> public class clsDataLayer { // This function gets the user activity from the tblUserActivity public static dsUserActivity GetUserActivity(string Database) { // Declare data set, connection and data adapter objects dsUserActivity DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // create a connection to the access database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // set the dataadapter with the query sqlDA = new OleDbDataAdapter("select * from tblUserActivity", sqlConn); // initialize the dataset DS = new dsUserActivity(); // Fill the dataset sqlDA.Fill(DS.tblUserActivity); // return the dataset return DS; } // This function saves the user activity public static void SaveUserActivity(string Database, string FormAccessed) { // create a connection to the database and inserts user activity record to the table OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.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; } // This function saves the personnel data public static bool SavePersonnel(string Database, string FirstName, string LastName, string PayRate, string StartDate, string EndDate) { bool recordSaved; try { // create a connection to the database OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); conn.Open(); OleDbCommand command = conn.CreateCommand(); string strSQL; // query to insert record in the tblPersonnel table strSQL = "Insert into tblPersonnel " + "(FirstName, LastName, PayRate, StartDate, EndDate) values ('" + FirstName + "', '" + LastName + "', " + PayRate + ", '" + StartDate + "', '" + EndDate + "')"; // Set the command object with the query command.CommandType = CommandType.Text; command.CommandText = strSQL; // Execute the query command.ExecuteNonQuery(); // Close connection to the database conn.Close(); recordSaved = true; } catch (Exception ex) { recordSaved = false; } return recordSaved; } // This function gets the user activity from the tblPersonnel public static dsPersonnel GetPersonnel(string Database, string strSearch) { // Create the dataset, connection and data adapter objects dsPersonnel DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // Create connection the database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // if strsearch is empty or null select all records from tblPersonnel //otherwise select only those records matching with strsearch in lastname if (strSearch == null || strSearch.Trim() == "") { sqlDA = new OleDbDataAdapter("select * from tblPersonnel", sqlConn); } else { sqlDA = new OleDbDataAdapter("select * from tblPersonnel where LastName = '" + strSearch + "'", sqlConn); } // initialize the dataset DS = new dsPersonnel(); // populate the dataset with the data returned from the query sqlDA.Fill(DS.tblPersonnel); // return the dataset return DS; } }

CIS407_Lab4_2016/Week4Lab/App_Code/dsPersonnel.xsd

DELETE FROM `tblPersonnel` WHERE ((`ID` = ?)) INSERT INTO `tblPersonnel` (`FirstName`, `LastName`, `PayRate`, `StartDate`, `EndDate`) VALUES (?, ?, ?, ?, ?) SELECT ID, FirstName, LastName, PayRate, StartDate, EndDate FROM tblPersonnel UPDATE `tblPersonnel` SET `FirstName` = ?, `LastName` = ?, `PayRate` = ?, `StartDate` = ?, `EndDate` = ? WHERE ((`ID` = ?))

CIS407_Lab4_2016/Week4Lab/App_Code/dsPersonnel.xss

CIS407_Lab4_2016/Week4Lab/App_Code/dsUserActivity.xsd

DELETE FROM `tblUserActivity` WHERE ((`ActivityID` = ?)) INSERT INTO `tblUserActivity` (`UserIP`, `DateOfActivity`, `FormAccessed`) VALUES (?, ?, ?) SELECT ActivityID, UserIP, DateOfActivity, FormAccessed FROM tblUserActivity UPDATE `tblUserActivity` SET `UserIP` = ?, `DateOfActivity` = ?, `FormAccessed` = ? WHERE ((`ActivityID` = ?))

CIS407_Lab4_2016/Week4Lab/App_Code/dsUserActivity.xss

CIS407_Lab4_2016/Week4Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

CIS407_Lab4_2016/Week4Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab4_2016/Week4Lab/frmMain.aspx

  Annual Salary Calculator   Add New Employee  User Activity  View Personnel  Search Personnel

CIS407_Lab4_2016/Week4Lab/frmMain.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmMain : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // whenever user opens main form a record is added to the table useractivity clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.accdb"), "frmPersonnel"); } }

CIS407_Lab4_2016/Week4Lab/frmPersonnel.aspx

                    

CIS407_Lab4_2016/Week4Lab/frmPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { bool isValid = true; //Variable to hold whether validation is successful or not //reset back color of all controls txtFirstName.BackColor = System.Drawing.Color.White; txtLastName.BackColor = System.Drawing.Color.White; txtPayRate.BackColor = System.Drawing.Color.White; txtStartDate.BackColor = System.Drawing.Color.White; txtEndDate.BackColor = System.Drawing.Color.White; lblError.Text = ""; //Check all controls whether they have blank inputs or not if (Request["txtFirstName"].ToString().Trim() == "") { txtFirstName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter First Name.<br/>"; isValid = false; } if (Request["txtLastName"].ToString().Trim() == "") { txtLastName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Last Name.<br/>"; isValid = false; } if (Request["txtPayRate"].ToString().Trim() == "") { txtPayRate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Pay Rate.<br/>"; isValid = false; } //get startdate and enddate in variables string startDate = Request["txtStartDate"].ToString(); string endDate = Request["txtEndDate"].ToString(); DateTime myDateTimeStartDateObj = new DateTime(); DateTime myDateTimeEndDateObj = new DateTime(); ; //check if start date or end date is blank if (startDate.Trim() =="") { txtStartDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter start date.<br/>"; isValid = false; } if (endDate.Trim() == "") { txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter end date.<br/>"; isValid = false; } //if start date and end date are not blank then check for date comparison validation if(startDate.Trim() !="" && endDate.Trim() !="") { myDateTimeStartDateObj = DateTime.Parse(startDate); myDateTimeEndDateObj = DateTime.Parse(endDate); //check if end date is smaller than start date if (DateTime.Compare(myDateTimeStartDateObj, myDateTimeEndDateObj) > 0) { txtStartDate.BackColor = System.Drawing.Color.Yellow; txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "The End Date must be greater than the start Date.\n"; isValid = false; } } //if everything is valid then set session variable. if (isValid) { Session["txtFirstName"] = txtFirstName.Text; Session["txtLastName"] = txtLastName.Text; Session["txtPayRate"] = txtPayRate.Text; Session["txtStartDate"] = myDateTimeStartDateObj; Session["txtEndDate"] = myDateTimeEndDateObj; Response.Redirect("frmPersonnelVerified.aspx"); } } }

CIS407_Lab4_2016/Week4Lab/frmPersonnelVerified.aspx

CIS407_Lab4_2016/Week4Lab/frmPersonnelVerified.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnelVerified : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { /** * This statement will get all the session parameters sent from frmPersonnel page * and set them to the text box in frmPersonnelVerified form */ txtVerifiedInfo.Text = Session["txtFirstName"] + "\n" + Session["txtLastName"] + "\n" + Session["txtPayRate"] + "\n" + Session["txtStartDate"] + "\n" + Session["txtEndDate"]; // if record is successfully saved to the database then add the success line to the text if (clsDataLayer.SavePersonnel(Server.MapPath("PayrollSystem_DB.accdb"), Session["txtFirstName"].ToString(), Session["txtLastName"].ToString(), Session["txtPayRate"].ToString(), Session["txtStartDate"].ToString(), Session["txtEndDate"].ToString())) { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was successfully saved!"; } else { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was NOT saved."; } } }

CIS407_Lab4_2016/Week4Lab/frmSalaryCalculator.aspx

                                            

CIS407_Lab4_2016/Week4Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

CIS407_Lab4_2016/Week4Lab/frmSearchPersonnel.aspx

   

CIS407_Lab4_2016/Week4Lab/frmSearchPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSearchPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab4_2016/Week4Lab/frmUserActivity.aspx

CIS407_Lab4_2016/Week4Lab/frmUserActivity.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmUserActivity : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { 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.accdb")); // Sets the DataGrid to the DataSource based on the table grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"]; // Binds the DataGrid grdUserActivity.DataBind(); } } }

CIS407_Lab4_2016/Week4Lab/frmViewPersonnel.aspx

View Personnel

CIS407_Lab4_2016/Week4Lab/frmViewPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmViewPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //Declare the Dataset dsPersonnel myDataSet = new dsPersonnel(); string strSearch = Request["txtSearch"]; //Fill the dataset with shat is returned from the method. myDataSet = clsDataLayer.GetPersonnel(Server.MapPath("PayrollSystem_DB.accdb"), strSearch); //Set the DataGrid to the DataSource based on the table grdViewPersonnel.DataSource = myDataSet.Tables["tblPersonnel"]; //Bind the DataGrid grdViewPersonnel.DataBind(); } } }

CIS407_Lab4_2016/Week4Lab/Images/CIS407A_iLab_ACITLogo.jpg

CIS407_Lab4_2016/Week4Lab/Images/personnel.jpg

CIS407_Lab4_2016/Week4Lab/Images/salaryCalculator.jpg

CIS407_Lab4_2016/Week4Lab/Images/searchpersonnel.jpg

CIS407_Lab4_2016/Week4Lab/Images/userActivity.jpg

CIS407_Lab4_2016/Week4Lab/Images/viewpersonnel.jpg

CIS407_Lab4_2016/Week4Lab/PayrollSystem_DB.accdb

ID FirstName LastName PayRate StartDate EndDate
1 test1 Test2 100 12/12/01 12/12/2003 12:00:00 AM
2 test2 test2 101 12/12/01 12/12/2003 12:00:00 AM
3 John Smith 191 12/12/03 12/2/2015 12:00:00 AM
4 James Doe 90 1/1/01 1/1/2010 12:00:00 AM
ActivityID UserIP DateOfActivity FormAccessed
1 192.168.153.1 3/19/16 frmPersonnel
2 192.168.153.1 3/19/16 frmPersonnel
3 192.168.153.1 3/19/16 frmPersonnel
4 192.168.153.1 3/19/16 frmPersonnel
5 192.168.153.1 3/19/16 frmPersonnel
6 192.168.153.1 3/19/16 frmPersonnel
7 192.168.153.1 3/19/16 frmPersonnel
8 192.168.153.1 3/19/16 frmPersonnel
9 192.168.153.1 3/19/16 frmPersonnel
10 192.168.153.1 3/19/16 frmPersonnel
11 192.168.153.1 3/19/16 frmPersonnel
12 192.168.153.1 3/19/16 frmPersonnel
13 192.168.153.1 3/19/16 frmPersonnel
14 192.168.153.1 3/19/16 frmPersonnel
15 192.168.153.1 3/19/16 frmPersonnel
16 192.168.153.1 3/19/16 frmPersonnel
17 192.168.153.1 3/19/16 frmPersonnel
18 192.168.153.1 3/19/16 frmPersonnel
19 192.168.153.1 3/19/16 frmPersonnel
20 192.168.153.1 3/19/16 frmPersonnel
21 192.168.153.1 3/26/16 frmPersonnel
22 192.168.153.1 3/26/16 frmPersonnel
23 192.168.153.1 3/26/16 frmPersonnel
24 192.168.153.1 3/26/16 frmPersonnel
25 192.168.153.1 3/26/16 frmPersonnel
26 192.168.153.1 3/26/16 frmPersonnel
27 192.168.153.1 3/26/16 frmPersonnel
28 192.168.153.1 3/26/16 frmPersonnel
29 192.168.153.1 3/26/16 frmPersonnel
30 192.168.153.1 3/26/16 frmPersonnel
UserID UserName UserPassword SecurityLevel
1 Mickey Mouse A
2 Minnie Mouse U

CIS407_Lab4_2016/Week4Lab/Web.config

CIS407_Lab4_2016/Week4Lab/Web.Debug.config

CIS407_Lab1_2016.zip

CIS407_Lab1_2016/Week1_Screenshot.png

CIS407_Lab1_2016/Week1Lab.zip

Week1Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

Week1Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

Week1Lab/frmSalaryCalculator.aspx

                                            

Week1Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

Week1Lab/Web.config

Week1Lab/Web.Debug.config

CIS407_Lab1_2016/Week1Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

CIS407_Lab1_2016/Week1Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab1_2016/Week1Lab/frmSalaryCalculator.aspx

                                            

CIS407_Lab1_2016/Week1Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

CIS407_Lab1_2016/Week1Lab/Web.config

CIS407_Lab1_2016/Week1Lab/Web.Debug.config

CIS407_Lab5_2016.zip

CIS407_Lab5_2016/Screenshots/frmEditEmployees.png

CIS407_Lab5_2016/Screenshots/frmMain.png

CIS407_Lab5_2016/Screenshots/frmPersonnelValidation1.png

CIS407_Lab5_2016/Screenshots/frmPersonnelValidation2.png

CIS407_Lab5_2016/Screenshots/frmPersonnelVerified.png

CIS407_Lab5_2016/Week5Lab/App_Code/clsDataLayer.cs

// Namespaces to be used in the class using System.Data.OleDb; using System.Net; using System.Data; using System.Web; using System; /// <summary> /// This class handles all the database operations for the website /// </summary> public class clsDataLayer { // This function gets the user activity from the tblUserActivity public static dsUserActivity GetUserActivity(string Database) { // Declare data set, connection and data adapter objects dsUserActivity DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // create a connection to the access database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // set the dataadapter with the query sqlDA = new OleDbDataAdapter("select * from tblUserActivity", sqlConn); // initialize the dataset DS = new dsUserActivity(); // Fill the dataset sqlDA.Fill(DS.tblUserActivity); // return the dataset return DS; } // This function saves the user activity public static void SaveUserActivity(string Database, string FormAccessed) { // create a connection to the database and inserts user activity record to the table OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.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; } // This function saves the personnel data public static bool SavePersonnel(string Database, string FirstName, string LastName, string PayRate, string StartDate, string EndDate) { bool recordSaved; // Declare a transaction variable OleDbTransaction myTransaction = null; try { // create a connection to the database OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); conn.Open(); OleDbCommand command = conn.CreateCommand(); string strSQL; // Start the transaction and set the transaction to the command object myTransaction = conn.BeginTransaction(); command.Transaction = myTransaction; // query to insert record in the tblPersonnel table strSQL = "Insert into tblPersonnel " + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Set command object with the query command.CommandType = CommandType.Text; command.CommandText = strSQL; // execute the insert query command.ExecuteNonQuery(); // update query strSQL = "Update tblPersonnel " + "Set PayRate=" + PayRate + ", " + "StartDate='" + StartDate + "', " + "EndDate='" + EndDate + "' " + "Where ID=(Select Max(ID) From tblPersonnel)"; // Set the command object with the update query command.CommandType = CommandType.Text; command.CommandText = strSQL; // Execute the query command.ExecuteNonQuery(); // Commit the transaction myTransaction.Commit(); // Close connection to the database conn.Close(); recordSaved = true; } catch (Exception ex) { //Incase of exception rollback the transaction myTransaction.Rollback(); recordSaved = false; } return recordSaved; } // This function gets the user activity from the tblPersonnel public static dsPersonnel GetPersonnel(string Database, string strSearch) { // Create the dataset, connection and data adapter objects dsPersonnel DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // Create connection the database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // if strsearch is empty or null select all records from tblPersonnel //otherwise select only those records matching with strsearch in lastname if (strSearch == null || strSearch.Trim() == "") { sqlDA = new OleDbDataAdapter("select * from tblPersonnel", sqlConn); } else { sqlDA = new OleDbDataAdapter("select * from tblPersonnel where LastName = '" + strSearch + "'", sqlConn); } // initialize the dataset DS = new dsPersonnel(); // populate the dataset with the data returned from the query sqlDA.Fill(DS.tblPersonnel); // return the dataset return DS; } }

CIS407_Lab5_2016/Week5Lab/App_Code/dsPersonnel.xsd

DELETE FROM `tblPersonnel` WHERE ((`ID` = ?)) INSERT INTO `tblPersonnel` (`FirstName`, `LastName`, `PayRate`, `StartDate`, `EndDate`) VALUES (?, ?, ?, ?, ?) SELECT ID, FirstName, LastName, PayRate, StartDate, EndDate FROM tblPersonnel UPDATE `tblPersonnel` SET `FirstName` = ?, `LastName` = ?, `PayRate` = ?, `StartDate` = ?, `EndDate` = ? WHERE ((`ID` = ?))

CIS407_Lab5_2016/Week5Lab/App_Code/dsPersonnel.xss

CIS407_Lab5_2016/Week5Lab/App_Code/dsUserActivity.xsd

DELETE FROM `tblUserActivity` WHERE ((`ActivityID` = ?)) INSERT INTO `tblUserActivity` (`UserIP`, `DateOfActivity`, `FormAccessed`) VALUES (?, ?, ?) SELECT ActivityID, UserIP, DateOfActivity, FormAccessed FROM tblUserActivity UPDATE `tblUserActivity` SET `UserIP` = ?, `DateOfActivity` = ?, `FormAccessed` = ? WHERE ((`ActivityID` = ?))

CIS407_Lab5_2016/Week5Lab/App_Code/dsUserActivity.xss

CIS407_Lab5_2016/Week5Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

CIS407_Lab5_2016/Week5Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab5_2016/Week5Lab/frmEditPersonnel.aspx

CIS407_Lab5_2016/Week5Lab/frmEditPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmEditPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab5_2016/Week5Lab/frmMain.aspx

  Annual Salary Calculator   Add New Employee  User Activity  View Personnel  Search Personnel Edit Employees

CIS407_Lab5_2016/Week5Lab/frmMain.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmMain : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // whenever user opens main form a record is added to the table useractivity clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.accdb"), "frmPersonnel"); } }

CIS407_Lab5_2016/Week5Lab/frmPersonnel.aspx

                    

CIS407_Lab5_2016/Week5Lab/frmPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { bool isValid = true; //Variable to hold whether validation is successful or not //reset back color of all controls txtFirstName.BackColor = System.Drawing.Color.White; txtLastName.BackColor = System.Drawing.Color.White; txtPayRate.BackColor = System.Drawing.Color.White; txtStartDate.BackColor = System.Drawing.Color.White; txtEndDate.BackColor = System.Drawing.Color.White; lblError.Text = ""; //Check all controls whether they have blank inputs or not if (Request["txtFirstName"].ToString().Trim() == "") { txtFirstName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter First Name.<br/>"; isValid = false; } if (Request["txtLastName"].ToString().Trim() == "") { txtLastName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Last Name.<br/>"; isValid = false; } if (Request["txtPayRate"].ToString().Trim() == "") { txtPayRate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Pay Rate.<br/>"; isValid = false; } //get startdate and enddate in variables string startDate = Request["txtStartDate"].ToString(); string endDate = Request["txtEndDate"].ToString(); DateTime myDateTimeStartDateObj = new DateTime(); DateTime myDateTimeEndDateObj = new DateTime(); ; //check if start date or end date is blank if (startDate.Trim() =="") { txtStartDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter start date.<br/>"; isValid = false; } if (endDate.Trim() == "") { txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter end date.<br/>"; isValid = false; } //if start date and end date are not blank then check for date comparison validation if(startDate.Trim() !="" && endDate.Trim() !="") { myDateTimeStartDateObj = DateTime.Parse(startDate); myDateTimeEndDateObj = DateTime.Parse(endDate); //check if end date is smaller than start date if (DateTime.Compare(myDateTimeStartDateObj, myDateTimeEndDateObj) > 0) { txtStartDate.BackColor = System.Drawing.Color.Yellow; txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "The End Date must be greater than the start Date.\n"; isValid = false; } } //if everything is valid then set session variable. if (isValid) { Session["txtFirstName"] = txtFirstName.Text; Session["txtLastName"] = txtLastName.Text; Session["txtPayRate"] = txtPayRate.Text; Session["txtStartDate"] = myDateTimeStartDateObj; Session["txtEndDate"] = myDateTimeEndDateObj; Response.Redirect("frmPersonnelVerified.aspx"); } } }

CIS407_Lab5_2016/Week5Lab/frmPersonnelVerified.aspx

CIS407_Lab5_2016/Week5Lab/frmPersonnelVerified.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnelVerified : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { /** * This statement will get all the session parameters sent from frmPersonnel page * and set them to the text box in frmPersonnelVerified form */ txtVerifiedInfo.Text = Session["txtFirstName"] + "\n" + Session["txtLastName"] + "\n" + Session["txtPayRate"] + "\n" + Session["txtStartDate"] + "\n" + Session["txtEndDate"]; // if record is successfully saved to the database then add the success line to the text if (clsDataLayer.SavePersonnel(Server.MapPath("PayrollSystem_DB.accdb"), Session["txtFirstName"].ToString(), Session["txtLastName"].ToString(), Session["txtPayRate"].ToString(), Session["txtStartDate"].ToString(), Session["txtEndDate"].ToString())) { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was successfully saved!"; } else { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was NOT saved."; } } }

CIS407_Lab5_2016/Week5Lab/frmSalaryCalculator.aspx

                                            

CIS407_Lab5_2016/Week5Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

CIS407_Lab5_2016/Week5Lab/frmSearchPersonnel.aspx

   

CIS407_Lab5_2016/Week5Lab/frmSearchPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSearchPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab5_2016/Week5Lab/frmUserActivity.aspx

CIS407_Lab5_2016/Week5Lab/frmUserActivity.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmUserActivity : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { 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.accdb")); // Sets the DataGrid to the DataSource based on the table grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"]; // Binds the DataGrid grdUserActivity.DataBind(); } } }

CIS407_Lab5_2016/Week5Lab/frmViewPersonnel.aspx

View Personnel

CIS407_Lab5_2016/Week5Lab/frmViewPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmViewPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //Declare the Dataset dsPersonnel myDataSet = new dsPersonnel(); string strSearch = Request["txtSearch"]; //Fill the dataset with shat is returned from the method. myDataSet = clsDataLayer.GetPersonnel(Server.MapPath("PayrollSystem_DB.accdb"), strSearch); //Set the DataGrid to the DataSource based on the table grdViewPersonnel.DataSource = myDataSet.Tables["tblPersonnel"]; //Bind the DataGrid grdViewPersonnel.DataBind(); } } }

CIS407_Lab5_2016/Week5Lab/Images/CIS407A_iLab_ACITLogo.jpg

CIS407_Lab5_2016/Week5Lab/Images/editpersonnel.jpg

CIS407_Lab5_2016/Week5Lab/Images/personnel.jpg

CIS407_Lab5_2016/Week5Lab/Images/salaryCalculator.jpg

CIS407_Lab5_2016/Week5Lab/Images/searchpersonnel.jpg

CIS407_Lab5_2016/Week5Lab/Images/userActivity.jpg

CIS407_Lab5_2016/Week5Lab/Images/viewpersonnel.jpg

CIS407_Lab5_2016/Week5Lab/PayrollSystem_DB.accdb

ID FirstName LastName PayRate StartDate EndDate
1 test1 Test2 100 12/12/01 12/12/2003 12:00:00 AM
2 test2 test2 101 12/12/01 12/12/2003 12:00:00 AM
3 John Smith 191 12/12/03 12/2/2015 12:00:00 AM
4 James Doe 90 1/1/01 1/1/2010 12:00:00 AM
6 CFirstname CLastName 400 1/1/11 1/1/2012 12:00:00 AM
8 john smith 109 1/1/12 1/1/2012 12:00:00 AM
9 John Smith 400 1/1/12 1/1/2012 12:00:00 AM
ActivityID UserIP DateOfActivity FormAccessed
1 192.168.153.1 3/19/16 frmPersonnel
2 192.168.153.1 3/19/16 frmPersonnel
3 192.168.153.1 3/19/16 frmPersonnel
4 192.168.153.1 3/19/16 frmPersonnel
5 192.168.153.1 3/19/16 frmPersonnel
6 192.168.153.1 3/19/16 frmPersonnel
7 192.168.153.1 3/19/16 frmPersonnel
8 192.168.153.1 3/19/16 frmPersonnel
9 192.168.153.1 3/19/16 frmPersonnel
10 192.168.153.1 3/19/16 frmPersonnel
11 192.168.153.1 3/19/16 frmPersonnel
12 192.168.153.1 3/19/16 frmPersonnel
13 192.168.153.1 3/19/16 frmPersonnel
14 192.168.153.1 3/19/16 frmPersonnel
15 192.168.153.1 3/19/16 frmPersonnel
16 192.168.153.1 3/19/16 frmPersonnel
17 192.168.153.1 3/19/16 frmPersonnel
18 192.168.153.1 3/19/16 frmPersonnel
19 192.168.153.1 3/19/16 frmPersonnel
20 192.168.153.1 3/19/16 frmPersonnel
21 192.168.153.1 3/26/16 frmPersonnel
22 192.168.153.1 3/26/16 frmPersonnel
23 192.168.153.1 3/26/16 frmPersonnel
24 192.168.153.1 3/26/16 frmPersonnel
25 192.168.153.1 3/26/16 frmPersonnel
26 192.168.153.1 3/26/16 frmPersonnel
27 192.168.153.1 3/26/16 frmPersonnel
28 192.168.153.1 3/26/16 frmPersonnel
29 192.168.153.1 3/26/16 frmPersonnel
30 192.168.153.1 3/26/16 frmPersonnel
31 192.168.153.1 4/2/16 frmPersonnel
32 192.168.153.1 4/2/16 frmPersonnel
33 192.168.153.1 4/2/16 frmPersonnel
34 192.168.153.1 4/2/16 frmPersonnel
35 192.168.153.1 4/2/16 frmPersonnel
36 192.168.153.1 4/2/16 frmPersonnel
37 192.168.153.1 4/2/16 frmPersonnel
38 192.168.153.1 4/2/16 frmPersonnel
39 192.168.153.1 4/2/16 frmPersonnel
40 192.168.153.1 4/2/16 frmPersonnel
41 192.168.153.1 4/2/16 frmPersonnel
42 192.168.153.1 4/2/16 frmPersonnel
43 192.168.153.1 4/2/16 frmPersonnel
44 192.168.153.1 4/2/16 frmPersonnel
45 192.168.153.1 4/2/16 frmPersonnel
UserID UserName UserPassword SecurityLevel
1 Mickey Mouse A
2 Minnie Mouse U

CIS407_Lab5_2016/Week5Lab/Web.config

CIS407_Lab5_2016/Week5Lab/Web.Debug.config

CIS407_Lab6_2016.zip

CIS407_Lab6_2016/Screenshots/frmLogin.png

CIS407_Lab6_2016/Screenshots/frmMain_AdminLogin.png

CIS407_Lab6_2016/Screenshots/frmMain_NonAdminLogin.png

CIS407_Lab6_2016/Screenshots/frmManageUser.png

CIS407_Lab6_2016/Week6Lab/App_Code/clsDataLayer.cs

// Namespaces to be used in the class using System.Data.OleDb; using System.Net; using System.Data; using System.Web; using System; /// <summary> /// This class handles all the database operations for the website /// </summary> public class clsDataLayer { // This function gets the user activity from the tblUserActivity public static dsUserActivity GetUserActivity(string Database) { // Declare data set, connection and data adapter objects dsUserActivity DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // create a connection to the access database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // set the dataadapter with the query sqlDA = new OleDbDataAdapter("select * from tblUserActivity", sqlConn); // initialize the dataset DS = new dsUserActivity(); // Fill the dataset sqlDA.Fill(DS.tblUserActivity); // return the dataset return DS; } // This function saves the user activity public static void SaveUserActivity(string Database, string FormAccessed) { // create a connection to the database and inserts user activity record to the table OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.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; } // This function saves the personnel data public static bool SavePersonnel(string Database, string FirstName, string LastName, string PayRate, string StartDate, string EndDate) { bool recordSaved; // Declare a transaction variable OleDbTransaction myTransaction = null; try { // create a connection to the database OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); conn.Open(); OleDbCommand command = conn.CreateCommand(); string strSQL; // Start the transaction and set the transaction to the command object myTransaction = conn.BeginTransaction(); command.Transaction = myTransaction; // query to insert record in the tblPersonnel table strSQL = "Insert into tblPersonnel " + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Set command object with the query command.CommandType = CommandType.Text; command.CommandText = strSQL; // execute the insert query command.ExecuteNonQuery(); // update query strSQL = "Update tblPersonnel " + "Set PayRate=" + PayRate + ", " + "StartDate='" + StartDate + "', " + "EndDate='" + EndDate + "' " + "Where ID=(Select Max(ID) From tblPersonnel)"; // Set the command object with the update query command.CommandType = CommandType.Text; command.CommandText = strSQL; // Execute the query command.ExecuteNonQuery(); // Commit the transaction myTransaction.Commit(); // Close connection to the database conn.Close(); recordSaved = true; } catch (Exception ex) { //Incase of exception rollback the transaction myTransaction.Rollback(); recordSaved = false; } return recordSaved; } // This function gets the user activity from the tblPersonnel public static dsPersonnel GetPersonnel(string Database, string strSearch) { // Create the dataset, connection and data adapter objects dsPersonnel DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // Create connection the database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // if strsearch is empty or null select all records from tblPersonnel //otherwise select only those records matching with strsearch in lastname if (strSearch == null || strSearch.Trim() == "") { sqlDA = new OleDbDataAdapter("select * from tblPersonnel", sqlConn); } else { sqlDA = new OleDbDataAdapter("select * from tblPersonnel where LastName = '" + strSearch + "'", sqlConn); } // initialize the dataset DS = new dsPersonnel(); // populate the dataset with the data returned from the query sqlDA.Fill(DS.tblPersonnel); // return the dataset return DS; } // This function verifies a user in the tblUser table public static dsUser VerifyUser(string Database, string UserName, string UserPassword) { // Declare the Dataset, sqlConnection and SQLDataadapter objects dsUser DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // set the connection to the sql connection object sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // set the sql adapter with the query to get the record for the user sqlDA = new OleDbDataAdapter("Select SecurityLevel from tblUserLogin " + "where UserName like '" + UserName + "' " + "and UserPassword like '" + UserPassword + "'", sqlConn); // set the dataset object DS = new dsUser(); // fill the dataset with the results returned from the query sqlDA.Fill(DS.tblUserLogin); // return the dataset return DS; } public static bool SaveUser(string Database, string UserName, string Password,string SecurityLevel) { bool recordSaved; // Declare a transaction variable OleDbTransaction myTransaction = null; try { // create a connection to the database OleDbConnection conn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); conn.Open(); OleDbCommand command = conn.CreateCommand(); string strSQL; // query to insert record in the tblUserLogin table strSQL = "Insert into tblUserLogin " + "(UserName, UserPassword,SecurityLevel) values ('" + UserName + "', '" + Password + "', '" + SecurityLevel + "')"; // Set command object with the query command.CommandType = CommandType.Text; command.CommandText = strSQL; // execute the insert query command.ExecuteNonQuery(); // Close connection to the database conn.Close(); recordSaved = true; } catch (Exception ex) { recordSaved = false; } return recordSaved; } }

CIS407_Lab6_2016/Week6Lab/App_Code/dsPersonnel.xsd

DELETE FROM `tblPersonnel` WHERE ((`ID` = ?)) INSERT INTO `tblPersonnel` (`FirstName`, `LastName`, `PayRate`, `StartDate`, `EndDate`) VALUES (?, ?, ?, ?, ?) SELECT ID, FirstName, LastName, PayRate, StartDate, EndDate FROM tblPersonnel UPDATE `tblPersonnel` SET `FirstName` = ?, `LastName` = ?, `PayRate` = ?, `StartDate` = ?, `EndDate` = ? WHERE ((`ID` = ?))

CIS407_Lab6_2016/Week6Lab/App_Code/dsPersonnel.xss

CIS407_Lab6_2016/Week6Lab/App_Code/dsUser.xsd

INSERT INTO `tblUserLogin` (`UserName`, `UserPassword`, `SecurityLevel`) VALUES (?, ?, ?) SELECT UserID, UserName, UserPassword, SecurityLevel FROM tblUserLogin

CIS407_Lab6_2016/Week6Lab/App_Code/dsUser.xss

CIS407_Lab6_2016/Week6Lab/App_Code/dsUserActivity.xsd

DELETE FROM `tblUserActivity` WHERE ((`ActivityID` = ?)) INSERT INTO `tblUserActivity` (`UserIP`, `DateOfActivity`, `FormAccessed`) VALUES (?, ?, ?) SELECT ActivityID, UserIP, DateOfActivity, FormAccessed FROM tblUserActivity UPDATE `tblUserActivity` SET `UserIP` = ?, `DateOfActivity` = ?, `FormAccessed` = ? WHERE ((`ActivityID` = ?))

CIS407_Lab6_2016/Week6Lab/App_Code/dsUserActivity.xss

CIS407_Lab6_2016/Week6Lab/App_Data/PayrollSystem_DB.accdb

ID FirstName LastName PayRate StartDate EndDate
1 test1 Test2 100 12/12/01 12/12/2003 12:00:00 AM
2 test2 test2 101 12/12/01 12/12/2003 12:00:00 AM
3 John Smith 191 12/12/03 12/2/2015 12:00:00 AM
4 James Doe 90 1/1/01 1/1/2010 12:00:00 AM
6 CFirstname CLastName 400 1/1/11 1/1/2012 12:00:00 AM
8 john smith 109 1/1/12 1/1/2012 12:00:00 AM
9 John Smith 400 1/1/12 1/1/2012 12:00:00 AM
ActivityID UserIP DateOfActivity FormAccessed
1 192.168.153.1 3/19/16 frmPersonnel
2 192.168.153.1 3/19/16 frmPersonnel
3 192.168.153.1 3/19/16 frmPersonnel
4 192.168.153.1 3/19/16 frmPersonnel
5 192.168.153.1 3/19/16 frmPersonnel
6 192.168.153.1 3/19/16 frmPersonnel
7 192.168.153.1 3/19/16 frmPersonnel
8 192.168.153.1 3/19/16 frmPersonnel
9 192.168.153.1 3/19/16 frmPersonnel
10 192.168.153.1 3/19/16 frmPersonnel
11 192.168.153.1 3/19/16 frmPersonnel
12 192.168.153.1 3/19/16 frmPersonnel
13 192.168.153.1 3/19/16 frmPersonnel
14 192.168.153.1 3/19/16 frmPersonnel
15 192.168.153.1 3/19/16 frmPersonnel
16 192.168.153.1 3/19/16 frmPersonnel
17 192.168.153.1 3/19/16 frmPersonnel
18 192.168.153.1 3/19/16 frmPersonnel
19 192.168.153.1 3/19/16 frmPersonnel
20 192.168.153.1 3/19/16 frmPersonnel
21 192.168.153.1 3/26/16 frmPersonnel
22 192.168.153.1 3/26/16 frmPersonnel
23 192.168.153.1 3/26/16 frmPersonnel
24 192.168.153.1 3/26/16 frmPersonnel
25 192.168.153.1 3/26/16 frmPersonnel
26 192.168.153.1 3/26/16 frmPersonnel
27 192.168.153.1 3/26/16 frmPersonnel
28 192.168.153.1 3/26/16 frmPersonnel
29 192.168.153.1 3/26/16 frmPersonnel
30 192.168.153.1 3/26/16 frmPersonnel
31 192.168.153.1 4/2/16 frmPersonnel
32 192.168.153.1 4/2/16 frmPersonnel
33 192.168.153.1 4/2/16 frmPersonnel
34 192.168.153.1 4/2/16 frmPersonnel
35 192.168.153.1 4/2/16 frmPersonnel
36 192.168.153.1 4/2/16 frmPersonnel
37 192.168.153.1 4/2/16 frmPersonnel
38 192.168.153.1 4/2/16 frmPersonnel
39 192.168.153.1 4/2/16 frmPersonnel
40 192.168.153.1 4/2/16 frmPersonnel
41 192.168.153.1 4/2/16 frmPersonnel
42 192.168.153.1 4/2/16 frmPersonnel
43 192.168.153.1 4/2/16 frmPersonnel
44 192.168.153.1 4/2/16 frmPersonnel
45 192.168.153.1 4/2/16 frmPersonnel
UserID UserName UserPassword SecurityLevel
1 Mickey Mouse A
2 Minnie Mouse U

CIS407_Lab6_2016/Week6Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

CIS407_Lab6_2016/Week6Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab6_2016/Week6Lab/frmEditPersonnel.aspx

CIS407_Lab6_2016/Week6Lab/frmEditPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmEditPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab6_2016/Week6Lab/frmLogin.aspx

CIS407_Lab6_2016/Week6Lab/frmLogin.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmLogin : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { // declare the dataset dsUser dsUserLogin; // security level variable declaration string SecurityLevel; // call the verify user method to verify the login dsUserLogin = clsDataLayer.VerifyUser(Server.MapPath("PayrollSystem_DB.accdb"), Login1.UserName, Login1.Password); // if results are returned from the method then user is authenticated otherwise no if (dsUserLogin.tblUserLogin.Count < 1) { e.Authenticated = false; return; } // if login is authenticated then set teh security level for the user SecurityLevel = dsUserLogin.tblUserLogin[0].SecurityLevel.ToString(); // check for security level switch (SecurityLevel) { case "A": // if it is A then set the session value to A e.Authenticated = true; Session["SecurityLevel"] = "A"; break; case "U": // if it is U then set the session value to U e.Authenticated = true; Session["SecurityLevel"] = "U"; break; default: e.Authenticated = false; break; } } }

CIS407_Lab6_2016/Week6Lab/frmMain.aspx

  Annual Salary Calculator   Add New Employee  User Activity  View Personnel  Search Personnel Edit Employees Manage Users

CIS407_Lab6_2016/Week6Lab/frmMain.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmMain : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // if Security Level is A if (Session["SecurityLevel"] == "A") { imgbtnNewEmployee.Visible = true; imgbtnViewUserActivity.Visible = true; imgbtnEditEmployees.Visible = true; imgbtnManageUsers.Visible = true; linkbtnNewEmployee.Visible = true; linkbtnViewUserActivity.Visible = true; linkbtnEditEmployees.Visible = true; linkbtnManageUsers.Visible = true; //then show the buttons and images for add Employee, view user activity and } else { imgbtnNewEmployee.Visible = false; imgbtnViewUserActivity.Visible = false; imgbtnEditEmployees.Visible = false; imgbtnManageUsers.Visible = false; linkbtnNewEmployee.Visible = false; linkbtnViewUserActivity.Visible = false; linkbtnEditEmployees.Visible = false; linkbtnManageUsers.Visible = false; } // whenever user opens main form a record is added to the table useractivity clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.accdb"), "frmPersonnel"); } }

CIS407_Lab6_2016/Week6Lab/frmManageUsers.aspx

                A U

CIS407_Lab6_2016/Week6Lab/frmManageUsers.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmManageUsers : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { if (clsDataLayer.SaveUser(Server.MapPath("PayrollSystem_DB.accdb"), txtUserName.Text, txtPassword.Text, ddlSecurityLevel.SelectedValue)) { lblError.Text = "The user was successfully added!"; grdUsers.DataBind(); } else { lblError.Text = "The user could not be added!"; } } }

CIS407_Lab6_2016/Week6Lab/frmPersonnel.aspx

                    

CIS407_Lab6_2016/Week6Lab/frmPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // if Security Level is A if (Session["SecurityLevel"] == "A") { btnSubmit.Visible = true; //then show the submit button } else { btnSubmit.Visible = false; } } protected void btnSubmit_Click(object sender, EventArgs e) { bool isValid = true; //Variable to hold whether validation is successful or not //reset back color of all controls txtFirstName.BackColor = System.Drawing.Color.White; txtLastName.BackColor = System.Drawing.Color.White; txtPayRate.BackColor = System.Drawing.Color.White; txtStartDate.BackColor = System.Drawing.Color.White; txtEndDate.BackColor = System.Drawing.Color.White; lblError.Text = ""; //Check all controls whether they have blank inputs or not if (Request["txtFirstName"].ToString().Trim() == "") { txtFirstName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter First Name.<br/>"; isValid = false; } if (Request["txtLastName"].ToString().Trim() == "") { txtLastName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Last Name.<br/>"; isValid = false; } if (Request["txtPayRate"].ToString().Trim() == "") { txtPayRate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter Pay Rate.<br/>"; isValid = false; } //get startdate and enddate in variables string startDate = Request["txtStartDate"].ToString(); string endDate = Request["txtEndDate"].ToString(); DateTime myDateTimeStartDateObj = new DateTime(); DateTime myDateTimeEndDateObj = new DateTime(); ; //check if start date or end date is blank if (startDate.Trim() =="") { txtStartDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter start date.<br/>"; isValid = false; } if (endDate.Trim() == "") { txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Please enter end date.<br/>"; isValid = false; } //if start date and end date are not blank then check for date comparison validation if(startDate.Trim() !="" && endDate.Trim() !="") { myDateTimeStartDateObj = DateTime.Parse(startDate); myDateTimeEndDateObj = DateTime.Parse(endDate); //check if end date is smaller than start date if (DateTime.Compare(myDateTimeStartDateObj, myDateTimeEndDateObj) > 0) { txtStartDate.BackColor = System.Drawing.Color.Yellow; txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "The End Date must be greater than the start Date.\n"; isValid = false; } } //if everything is valid then set session variable. if (isValid) { Session["txtFirstName"] = txtFirstName.Text; Session["txtLastName"] = txtLastName.Text; Session["txtPayRate"] = txtPayRate.Text; Session["txtStartDate"] = myDateTimeStartDateObj; Session["txtEndDate"] = myDateTimeEndDateObj; Response.Redirect("frmPersonnelVerified.aspx"); } } }

CIS407_Lab6_2016/Week6Lab/frmPersonnelVerified.aspx

CIS407_Lab6_2016/Week6Lab/frmPersonnelVerified.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnelVerified : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { /** * This statement will get all the session parameters sent from frmPersonnel page * and set them to the text box in frmPersonnelVerified form */ txtVerifiedInfo.Text = Session["txtFirstName"] + "\n" + Session["txtLastName"] + "\n" + Session["txtPayRate"] + "\n" + Session["txtStartDate"] + "\n" + Session["txtEndDate"]; // if record is successfully saved to the database then add the success line to the text if (clsDataLayer.SavePersonnel(Server.MapPath("PayrollSystem_DB.accdb"), Session["txtFirstName"].ToString(), Session["txtLastName"].ToString(), Session["txtPayRate"].ToString(), Session["txtStartDate"].ToString(), Session["txtEndDate"].ToString())) { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was successfully saved!"; } else { txtVerifiedInfo.Text = txtVerifiedInfo.Text + "\nThe information was NOT saved."; } } }

CIS407_Lab6_2016/Week6Lab/frmSalaryCalculator.aspx

                                            

CIS407_Lab6_2016/Week6Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

CIS407_Lab6_2016/Week6Lab/frmSearchPersonnel.aspx

   

CIS407_Lab6_2016/Week6Lab/frmSearchPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSearchPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab6_2016/Week6Lab/frmUserActivity.aspx

CIS407_Lab6_2016/Week6Lab/frmUserActivity.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmUserActivity : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { 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.accdb")); // Sets the DataGrid to the DataSource based on the table grdUserActivity.DataSource = myDataSet.Tables["tblUserActivity"]; // Binds the DataGrid grdUserActivity.DataBind(); } } }

CIS407_Lab6_2016/Week6Lab/frmViewPersonnel.aspx

View Personnel

CIS407_Lab6_2016/Week6Lab/frmViewPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmViewPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //Declare the Dataset dsPersonnel myDataSet = new dsPersonnel(); string strSearch = Request["txtSearch"]; //Fill the dataset with shat is returned from the method. myDataSet = clsDataLayer.GetPersonnel(Server.MapPath("PayrollSystem_DB.accdb"), strSearch); //Set the DataGrid to the DataSource based on the table grdViewPersonnel.DataSource = myDataSet.Tables["tblPersonnel"]; //Bind the DataGrid grdViewPersonnel.DataBind(); } } }

CIS407_Lab6_2016/Week6Lab/Images/CIS407A_iLab_ACITLogo.jpg

CIS407_Lab6_2016/Week6Lab/Images/editpersonnel.jpg

CIS407_Lab6_2016/Week6Lab/Images/manageUsers.jpg

CIS407_Lab6_2016/Week6Lab/Images/personnel.jpg

CIS407_Lab6_2016/Week6Lab/Images/salaryCalculator.jpg

CIS407_Lab6_2016/Week6Lab/Images/searchpersonnel.jpg

CIS407_Lab6_2016/Week6Lab/Images/userActivity.jpg

CIS407_Lab6_2016/Week6Lab/Images/viewpersonnel.jpg

CIS407_Lab6_2016/Week6Lab/PayrollSystem_DB.accdb

ID FirstName LastName PayRate StartDate EndDate
1 test1 Test2 100 12/12/01 12/12/2003 12:00:00 AM
2 test2 test2 101 12/12/01 12/12/2003 12:00:00 AM
3 John Smith 191 12/12/03 12/2/2015 12:00:00 AM
4 James Doe 90 1/1/01 1/1/2010 12:00:00 AM
6 CFirstname CLastName 400 1/1/11 1/1/2012 12:00:00 AM
8 john smith 109 1/1/12 1/1/2012 12:00:00 AM
9 John Smith 400 1/1/12 1/1/2012 12:00:00 AM
ActivityID UserIP DateOfActivity FormAccessed
1 192.168.153.1 3/19/16 frmPersonnel
2 192.168.153.1 3/19/16 frmPersonnel
3 192.168.153.1 3/19/16 frmPersonnel
4 192.168.153.1 3/19/16 frmPersonnel
5 192.168.153.1 3/19/16 frmPersonnel
6 192.168.153.1 3/19/16 frmPersonnel
7 192.168.153.1 3/19/16 frmPersonnel
8 192.168.153.1 3/19/16 frmPersonnel
9 192.168.153.1 3/19/16 frmPersonnel
10 192.168.153.1 3/19/16 frmPersonnel
11 192.168.153.1 3/19/16 frmPersonnel
12 192.168.153.1 3/19/16 frmPersonnel
13 192.168.153.1 3/19/16 frmPersonnel
14 192.168.153.1 3/19/16 frmPersonnel
15 192.168.153.1 3/19/16 frmPersonnel
16 192.168.153.1 3/19/16 frmPersonnel
17 192.168.153.1 3/19/16 frmPersonnel
18 192.168.153.1 3/19/16 frmPersonnel
19 192.168.153.1 3/19/16 frmPersonnel
20 192.168.153.1 3/19/16 frmPersonnel
21 192.168.153.1 3/26/16 frmPersonnel
22 192.168.153.1 3/26/16 frmPersonnel
23 192.168.153.1 3/26/16 frmPersonnel
24 192.168.153.1 3/26/16 frmPersonnel
25 192.168.153.1 3/26/16 frmPersonnel
26 192.168.153.1 3/26/16 frmPersonnel
27 192.168.153.1 3/26/16 frmPersonnel
28 192.168.153.1 3/26/16 frmPersonnel
29 192.168.153.1 3/26/16 frmPersonnel
30 192.168.153.1 3/26/16 frmPersonnel
31 192.168.153.1 4/2/16 frmPersonnel
32 192.168.153.1 4/2/16 frmPersonnel
33 192.168.153.1 4/2/16 frmPersonnel
34 192.168.153.1 4/2/16 frmPersonnel
35 192.168.153.1 4/2/16 frmPersonnel
36 192.168.153.1 4/2/16 frmPersonnel
37 192.168.153.1 4/2/16 frmPersonnel
38 192.168.153.1 4/2/16 frmPersonnel
39 192.168.153.1 4/2/16 frmPersonnel
40 192.168.153.1 4/2/16 frmPersonnel
41 192.168.153.1 4/2/16 frmPersonnel
42 192.168.153.1 4/2/16 frmPersonnel
43 192.168.153.1 4/2/16 frmPersonnel
44 192.168.153.1 4/2/16 frmPersonnel
45 192.168.153.1 4/2/16 frmPersonnel
46 192.168.153.1 4/9/16 frmPersonnel
47 192.168.153.1 4/9/16 frmPersonnel
48 192.168.153.1 4/9/16 frmPersonnel
49 192.168.153.1 4/9/16 frmPersonnel
50 192.168.153.1 4/9/16 frmPersonnel
51 192.168.153.1 4/9/16 frmPersonnel
52 192.168.153.1 4/9/16 frmPersonnel
53 192.168.153.1 4/9/16 frmPersonnel
54 192.168.153.1 4/9/16 frmPersonnel
55 192.168.153.1 4/9/16 frmPersonnel
56 192.168.153.1 4/9/16 frmPersonnel
57 192.168.153.1 4/9/16 frmPersonnel
58 192.168.153.1 4/9/16 frmPersonnel
59 192.168.153.1 4/9/16 frmPersonnel
60 192.168.153.1 4/9/16 frmPersonnel
61 192.168.153.1 4/9/16 frmPersonnel
62 192.168.153.1 4/9/16 frmPersonnel
63 192.168.153.1 4/9/16 frmPersonnel
64 192.168.153.1 4/9/16 frmPersonnel
65 192.168.153.1 4/9/16 frmPersonnel
66 192.168.153.1 4/9/16 frmPersonnel
67 192.168.153.1 4/9/16 frmPersonnel
68 192.168.153.1 4/9/16 frmPersonnel
69 192.168.153.1 4/9/16 frmPersonnel
70 192.168.153.1 4/9/16 frmPersonnel
71 192.168.153.1 4/9/16 frmPersonnel
72 192.168.153.1 4/9/16 frmPersonnel
UserID UserName UserPassword SecurityLevel
1 Mickey Mouse A
2 Minnie Mouse U
3 test test U
5 test11 test11 A

CIS407_Lab6_2016/Week6Lab/Web.config

CIS407_Lab6_2016/Week6Lab/Web.Debug.config

CIS407_Lab2_2016.zip

CIS407_Lab2_2016/Screenshots/frmMain.png

CIS407_Lab2_2016/Screenshots/frmPersonnel.png

CIS407_Lab2_2016/Screenshots/frmPersonnelVerified.png

CIS407_Lab2_2016/Screenshots/frmSalaryCalculator.png

CIS407_Lab2_2016/Week2Lab/Default.aspx

Good morning Students. I bid you welcome to CIS407A.

CIS407_Lab2_2016/Week2Lab/Default.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab2_2016/Week2Lab/frmMain.aspx

  Annual Salary Calculator   Add New Employee

CIS407_Lab2_2016/Week2Lab/frmMain.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmMain : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab2_2016/Week2Lab/frmPersonnel.aspx

                    

CIS407_Lab2_2016/Week2Lab/frmPersonnel.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnel : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } }

CIS407_Lab2_2016/Week2Lab/frmPersonnelVerified.aspx

CIS407_Lab2_2016/Week2Lab/frmPersonnelVerified.aspx.cs

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmPersonnelVerified : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { /** * This statement will get all the request parameters sent from frmPersonnel page * and set them to the text box in frmPersonnelVerified form */ txtVerifiedInfo.Text = Request["txtFirstName"] + "\n" + Request["txtLastName"] + "\n" + Request["txtPayRate"] + "\n" + Request["txtStartDate"] + "\n" + Request["txtEndDate"]; } }

CIS407_Lab2_2016/Week2Lab/frmSalaryCalculator.aspx

                                            

CIS407_Lab2_2016/Week2Lab/frmSalaryCalculator.aspx.cs

/** *CIS407 A - LAB 1 * Sarabjit Singh * */ using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class frmSalaryCalculator : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCalculateSalary_Click(object sender, EventArgs e) { double annualHours = Double.Parse(txtAnnualHours.Text); double payRate = Double.Parse(txtPayRate.Text); double annualSalary = annualHours * payRate; lblAnnualSalary.Text = "Annual Salary is $" + annualSalary.ToString("N"); } }

CIS407_Lab2_2016/Week2Lab/Images/CIS407A_iLab_ACITLogo.jpg

CIS407_Lab2_2016/Week2Lab/Images/personnel.jpg

CIS407_Lab2_2016/Week2Lab/Images/salaryCalculator.jpg

CIS407_Lab2_2016/Week2Lab/Web.config

CIS407_Lab2_2016/Week2Lab/Web.Debug.config