CIS407 Week 5 Lab Touch-Up
PayrollSystem (1)/App_Code/clsDataLayer.cs
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.OleDb; using System.Net; using System.Data; public class clsDataLayer { // This function gets the user activity from the tblUserActivity public static dsUserActivity GetUserActivity(string Database) { // Declare DataSet, connection, and data adapter object dsUserActivity DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // Inintialize connection using the connection string to the database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // Initialize the data adapter using SQL sqlDA = new OleDbDataAdapter("select * from tblUserActivity", sqlConn); // Create and empty data set DS = new dsUserActivity(); // It fills the data set from the data adapter sqlDA.Fill(DS.tblUserActivity); // returns the retrieved data to the caller return DS; } // This function saves the user activity public static void SaveUserActivity(string Database, string FormAccessed) { // It saves the user information by connecting to the database and saving it to the dataset 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; // Declares the transaction variable. OleDbTransaction myTransaction = null; try { // Opens the 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; // Begin transaction as new transaction myTransaction = conn.BeginTransaction(); command.Transaction = myTransaction; // It perform an insert interaction with the database to insert the data below; FirstName and LastName //from the form filled by the user. strSQL = "Insert into tblPersonnel " + "(FirstName, LastName) values ('" + FirstName + "', '" + LastName + "')"; // Indicate the type of command being executed, in this case is .Text; Second command is to identify // the command to execute which is strSQL that insert data into the datasources in the data set. command.CommandType = CommandType.Text; command.CommandText = strSQL; // perform a query without returning any value since we are performing an Insert operation for the database. command.ExecuteNonQuery(); // perform and UPDATE to save the PayRate, StartDate, and EndDate into the new record. strSQL = "Update tblPersonnel " + "Set PayRate=" + PayRate + ", " + "StartDate='" + StartDate + "', " + "EndDate='" + EndDate + "' " + "Where ID=(Select Max(ID) From tblPersonnel)"; // Indicate the type of command being executed, in this case is .Text; Second command is to identify // the command to execute which is strSQL that insert data into the datasources in the data set. command.CommandType = CommandType.Text; command.CommandText = strSQL; // perform a query without returning any value since we are performing an Insert operation for the database. command.ExecuteNonQuery(); // Commits the transaction saving changes and competing the current transaction. myTransaction.Commit(); // Close the connection to the database. conn.Close(); recordSaved = true; } catch (Exception ex) { // Rollsback the transaction canceling any changes during the current transaction and ends the transaction. myTransaction.Rollback(); recordSaved = false; } return recordSaved; } public static dsPersonnel GetPersonnel(string Database, string strSearch) { // Declare DataSet, connection, and data adapter object dsPersonnel DS; OleDbConnection sqlConn; OleDbDataAdapter sqlDA; // Inintialize connection using the connection string to the database sqlConn = new OleDbConnection("PROVIDER=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + Database); // Will check if the text box for search is empty or the user hit the search button with nothing on the text box // then it will return all the personnel. If a last name is filled up it will return the table with the last names on the table. if (strSearch == null || strSearch.Trim() == "") { sqlDA = new OleDbDataAdapter("select * from tblPersonnel", sqlConn); } else { sqlDA = new OleDbDataAdapter("select * from tblPersonnel where LastName = '" + strSearch + "'", sqlConn); } // Create and empty data set DS = new dsPersonnel(); // It fills the data set from the data adapter sqlDA.Fill(DS.tblPersonnel); // returns the retrieved data to the caller return DS; } }
PayrollSystem (1)/App_Code/dsPersonnel.xsd
PayrollSystem (1)/App_Code/dsPersonnel.xss
PayrollSystem (1)/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` = ?))
PayrollSystem (1)/App_Code/dsUserActivity.xss
PayrollSystem (1)/frmSearchPersonnel.aspx
PayrollSystem (1)/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) { } }
PayrollSystem (1)/frmUserActivity.aspx
PayrollSystem (1)/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(); } } }
PayrollSystem (1)/frmViewPersonnel.aspx
PayrollSystem (1)/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(); } } } } }
PayrollSystem (1)/PayrollSystem/App_Code/clsDataLayer.cs
// Add your comments here using System.Data.OleDb; using System.Net; using System.Data; using System; using System.Collections.Generic; using System.Linq; using System.Web; /// <summary> /// Summary description for clsDataLayer /// </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; } public clsDataLayer() { // // TODO: Add constructor logic here // } }
PayrollSystem (1)/PayrollSystem/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` = ?))
PayrollSystem (1)/PayrollSystem/App_Code/dsUserActivity.xss
PayrollSystem (1)/PayrollSystem/CIS407A_iLab_ACITLogo.jpg
PayrollSystem (1)/PayrollSystem/Default.aspx
Greetings and Salutations. I will master ASP.NET in this course.
PayrollSystem (1)/PayrollSystem/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) { } }
PayrollSystem (1)/PayrollSystem/frmMain.aspx
Annual Salary Calulator Add New Employee View User Activity View Personnel Search PersonnelPayrollSystem (1)/PayrollSystem/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) { // Add your comments here clsDataLayer.SaveUserActivity(Server.MapPath("PayrollSystem_DB.accdb"), "frmPersonnel"); } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { } }
PayrollSystem (1)/PayrollSystem/frmPersonnel.aspx
PayrollSystem (1)/PayrollSystem/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) { // Variables for the Date for the user entries. DateTime dt1; DateTime dt2; // This will make the error textbox blank again and the entry textbox back to white color. lblError.Text = ""; Boolean validatedState = false; // The next 5 validation controls check if there are left blank or filled with blank spaces and gives the error message. if (Request["txtFirstName"].ToString().Trim() == "") { txtFirstName.BackColor = System.Drawing.Color.Yellow; lblError.Text = "Must enter a First Name. "; validatedState = true; } else { txtFirstName.BackColor = System.Drawing.Color.White; } if (Request["txtLastName"].ToString().Trim() == "") { txtLastName.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Must enter a Last Name. "; validatedState = true; } else { txtLastName.BackColor = System.Drawing.Color.White; } if (Request["txtPayRate"].ToString().Trim() == "") { txtPayRate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Must enter a Pay Rate. "; validatedState = true; } else { txtPayRate.BackColor = System.Drawing.Color.White; } if (Request["txtStartDate"].ToString().Trim() == "") { txtStartDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Must enter a Start Date. "; validatedState = true; } if (Request["txtEndDate"].ToString().Trim() == "") { txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "Must enter an End Date. "; validatedState = true; } // First this method saves the dates into the dt1 and dt2 variables and then perform the second part described on next line. // Second part it is a compare method to ensure the end date is later than the start date and will make the text boxes background yellow color. if (txtStartDate.Text.Trim() != "" & txtEndDate.Text.Trim() != "") { dt1 = DateTime.Parse(txtStartDate.Text); dt2 = DateTime.Parse(txtEndDate.Text); if (DateTime.Compare(dt1, dt2) > 0) { txtStartDate.BackColor = System.Drawing.Color.Yellow; txtEndDate.BackColor = System.Drawing.Color.Yellow; lblError.Text += "The end date must be a later date than the start date."; validatedState = true; } else { // This will ensure that the background color goes back to white if the textbox is filled and no errors are found. txtStartDate.BackColor = System.Drawing.Color.White; txtEndDate.BackColor = System.Drawing.Color.White; } } // This method saves the data from the session and pass it to the frmPersonnelVerified. if (validatedState == false) { Session["txtFirstName"] = txtFirstName.Text; Session["txtLastName"] = txtLastName.Text; Session["txtPayRate"] = txtPayRate.Text; Session["txtStartDate"] = txtStartDate.Text; Session["txtEndDate"] = txtEndDate.Text; Response.Redirect("frmPersonnelVerified.aspx"); } } } } }
PayrollSystem (1)/PayrollSystem/frmPersonnelVerified.aspx
HyperLinkPayrollSystem (1)/PayrollSystem/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) { //Get the data from the Session of the previous form, the frmPersonnel.aspx txtVerifiedInfo.Text = Session["txtFirstName"].ToString() + "\n" + Session["txtLastName"].ToString() + "\n" + Session["txtPayRate"].ToString() + "\n" + Session["txtStartDate"].ToString() + "\n" + Session["txtEndDate"].ToString(); // call the SavePersonnel method from clsDataLayer.cs and pass the session data. After it will validate if the // data was saved if not then will pop an error message saying that the data was not saved. 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."; } } }
PayrollSystem (1)/PayrollSystem/frmSalaryCalculator.aspx
PayrollSystem (1)/PayrollSystem/frmSalaryCalculator.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 frmSalaryCalculator : System.Web.UI.Page { protected void btnReset_Click(object sender, EventArgs e) { txtAnnualHours.Text = ""; txtAnnualSalary.Text = ""; txtPayRate.Text = ""; } protected void btnCalculateSalary_Click(object sender, EventArgs e) { Double annualhours, payrate, annualsalary; try { annualhours = Double.Parse(txtAnnualHours.Text); payrate = Double.Parse(txtPayRate.Text); if (annualhours > 0) { if (payrate > 0) { annualsalary = annualhours * payrate; txtAnnualSalary.Text = annualsalary.ToString("C"); } else txtAnnualSalary.Text = "Pay Rate should be greater than zero"; } else txtAnnualSalary.Text = "Annual Hours should be greater than zero"; } catch (Exception ex) { txtAnnualSalary.Text = "Error : " + ex.Message; } } }
PayrollSystem (1)/PayrollSystem/frmUserActivity.aspx
PayrollSystem (1)/PayrollSystem/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(); } } }
PayrollSystem (1)/PayrollSystem/Images/Activity.png
PayrollSystem (1)/PayrollSystem/Images/calculator.jpeg
PayrollSystem (1)/PayrollSystem/Images/employee.jpg
PayrollSystem (1)/PayrollSystem/Images/personnelmanager.png
PayrollSystem (1)/PayrollSystem/Images/Search.png
PayrollSystem (1)/PayrollSystem/PayrollSystem_DB.accdb
| ID | FirstName | LastName | PayRate | StartDate | EndDate |
|---|
| ActivityID | UserIP | DateOfActivity | FormAccessed |
|---|---|---|---|
| 1 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| 2 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| 3 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| 4 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| UserID | UserName | UserPassword | SecurityLevel |
|---|---|---|---|
| 1 | Mickey | Mouse | A |
| 2 | Minnie | Mouse | U |
PayrollSystem (1)/PayrollSystem/Web.config
PayrollSystem (1)/PayrollSystem/Web.Debug.config
PayrollSystem (1)/PayrollSystem_DB.accdb
| ID | FirstName | LastName | PayRate | StartDate | EndDate |
|---|
| ActivityID | UserIP | DateOfActivity | FormAccessed |
|---|---|---|---|
| 1 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| 2 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| 3 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| 4 | 10.154.77.78 | 2017-11-26 | frmPersonnel |
| UserID | UserName | UserPassword | SecurityLevel |
|---|---|---|---|
| 1 | Mickey | Mouse | A |
| 2 | Minnie | Mouse | U |
PayrollSystem (1)/Web.config