/// <summary> /// Method Name: AddSeasonalEmployee /// This function is called to add the SeasonalEmployee object that is newly created from the data /// the user has put in. /// </summary> /// <returns>A boolean indicating whether the adding operation was successful</returns> public bool AddSeasonalEmployee(SeasonalEmployee sn) { bool result = AddEmployee(sn); // To do return(result); }
private void FillSeasonalEmployee(SeasonalEmployee e) { type.InnerText = "Seasonal Time"; season.InnerText = Enum.GetName(typeof(Season), e.Season); seasonYear.InnerText = e.SeasonYear; piecePay.InnerText = e.PiecePay.ToString(); }
protected void Page_Load(object sender, EventArgs e) { if (Employee != null) { // fill base employee information FillBaseEmployee(); // display if (Employee is FulltimeEmployee) { FulltimeEmployee ft = Employee as FulltimeEmployee; FillFullTimeEmployee(ft); } else if (Employee is ParttimeEmployee) { ParttimeEmployee pt = Employee as ParttimeEmployee; FillPartTimeEmployee(pt); } else if (Employee is SeasonalEmployee) { SeasonalEmployee sn = Employee as SeasonalEmployee; FillSeasonalEmployee(sn); } else if (Employee is ContractEmployee) { ContractEmployee ct = Employee as ContractEmployee; FillContractEmployee(ct); } } }
/// <summary> /// This method adds a new Seasonal Employee to the database. /// </summary> /// <param name="fName">The first name of the Seasonal Employee.</param> /// <param name="lName">The last name of the Seasonal Employee.</param> /// <param name="SIN">The Social Insurance Number of the Seasonal Employee.</param> /// <param name="dateOfBirth">The Date of Birth of the Seasonal Employee.</param> /// <param name="season">The season that the Seasonal Employee will be working in.</param> /// <param name="piecePay">The amount paid to the Seasonal Employee per unit-of-work done.</param> /// <returns>A bool. true if employee was added, false otherwise.</returns> public static bool AddSeasonalEmployee(string fName, string lName, string SIN, DateTime dateOfBirth, string season, double piecePay) { bool empAdded = false; try { //Check if an employee with that sin number already exists bool employeeExists = SE.Any(x => x.socialInsuranceNumber == SIN); if (employeeExists) { throw new Exception(); //The employee exists, it can't be added } else { SeasonalEmployee emp = new SeasonalEmployee(fName, lName, SIN, dateOfBirth, piecePay, season); bool valid = emp.Validate(); if (valid) { SE.Add(emp); Logging logger = new Logging(); logger.Log(lName + ", " + fName + " SIN: " + SIN + " - ADDED", "Employees", "AddSeasonalEmployee"); empAdded = true; } } } catch (Exception) { empAdded = false; } return(empAdded); }
public void SeasonalEmployeeTest_Success() { SeasonalEmployee seasonalEmp = new SeasonalEmployee("Ronnie", "Skowron", "123456789", DateTime.Parse("2004-08-17"), 20.00, "Winter"); bool success = seasonalEmp.Validate(); Assert.IsTrue(success); }
/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public string displayEmployeeInfo(string input, bool shouldLog) { string ret = ""; if (tryFindEmployee(input)) { Employee emp = findEmployee(input); switch (emp.GetType().Name) { case "FulltimeEmployee": return(FulltimeEmployee.display((FulltimeEmployee)emp, shouldLog)); //break; case "ParttimeEmployee": return(ParttimeEmployee.display((ParttimeEmployee)emp, shouldLog)); //break; case "ContractEmployee": return(ContractEmployee.display((ContractEmployee)emp, shouldLog)); //break; case "SeasonalEmployee": return(SeasonalEmployee.display((SeasonalEmployee)emp, shouldLog)); //break; default: break; } } return(ret); }
public void ValidateSeasonNormalTestCase() { bool expected = true; bool?actual = null; actual = SeasonalEmployee.validateSeason(Seasons.SUMMER); Assert.AreEqual(expected, actual); }
/// <summary> /// \brief <b>Description</b> /// \details this Method contatinates all records in the employeelist and add's them to the Container /// </summary> /// <returns></returns> public List <string> concatAllRecords() { List <string> container = new List <string>(); EmployeeType type = EmployeeType.Default; int i = 0; foreach (Employee currentEmployee in EmployeeList.Values) { type = getType(currentEmployee); switch (type) { case EmployeeType.FT: container.Add(FulltimeEmployee.join((FulltimeEmployee)currentEmployee)); break; case EmployeeType.PT: container.Add(ParttimeEmployee.join((ParttimeEmployee)currentEmployee)); break; case EmployeeType.CT: container.Add(ContractEmployee.join((ContractEmployee)currentEmployee)); break; case EmployeeType.SN: container.Add(SeasonalEmployee.join((SeasonalEmployee)currentEmployee)); break; default: break; } i++; } container.Insert(0, ""); for (i = 0; i < commentList.Count; i++) { KeyValuePair <int, string> item = commentList.ElementAt(i); if (item.Key > container.Count) { commentList.Remove(item.Key); commentList.Add(container.Count, item.Value); i--; } else { container.Insert(item.Key, item.Value); } } return(container); }
public void ValidateOverloadNormalTestCase() { bool expected = true; bool?actual = null; string firstName = "Jody"; string lastName = "Markic"; DateTime dob = DateTime.Parse("1993-08-24"); string sin = "123456782"; Seasons season = Seasons.SUMMER; double piecePay = 2.50; actual = SeasonalEmployee.validate(firstName, lastName, dob, sin, season, piecePay); Assert.AreEqual(expected, actual); }
public void ValidateNormalTestCase() { bool expected = true; bool?actual = null; SeasonalEmployee seEmployee = new SeasonalEmployee(); seEmployee.FirstName = "Jody"; seEmployee.LastName = "Markic"; seEmployee.DOB = DateTime.Parse("1993-08-24"); seEmployee.SIN = "123456782"; seEmployee.Season = Seasons.SUMMER; seEmployee.PiecePay = 2.50; actual = SeasonalEmployee.validate(seEmployee); Assert.AreEqual(expected, actual); }
/// <summary> /// \brief <b>Description</b> /// \details This function adds an employee to the collection /// </summary> /// <param name="emp">This is the employee that will be added</param> /// <returns>True if the employee was added successfully</returns> public bool addEmployee(Employee emp) { bool retCode = false; switch (getType(emp)) { case EmployeeType.FT: retCode = FulltimeEmployee.validate((FulltimeEmployee)emp); break; case EmployeeType.PT: retCode = ParttimeEmployee.validate((ParttimeEmployee)emp); break; case EmployeeType.CT: retCode = ContractEmployee.validate((ContractEmployee)emp); break; case EmployeeType.SN: retCode = SeasonalEmployee.validate((SeasonalEmployee)emp); break; default: break; } if (retCode) { if (EmployeeList.ContainsKey(emp.SIN)) { retCode = false; } else { EmployeeList.Add(emp.SIN, emp); Logging.Log("[Container.AddEmployee] Employee Added - " + emp.LastName + ", " + emp.FirstName + " (" + emp.SIN + ") - VALID"); } } return(retCode); }
/// <summary> /// Fill seasonal employee /// </summary> /// <param name="reader"></param> /// <returns></returns> private SeasonalEmployee FillSeasonalEmployee(SqlDataReader reader) { float piecePay = 0; SeasonalEmployee sn = EmployeeFactory.CreateSeasonalEmployee(); FillBaseEmployee(sn, reader); sn.Season = reader["season"].ToString(); sn.SeasonYear = reader["season_year"].ToString(); if (float.TryParse(reader["piece_pay"].ToString(), out piecePay)) { sn.PiecePay = piecePay; } else { sn.PiecePay = null; } return(sn); }
/// <summary> /// \brief <b>Description</b> /// \details This function adds an employee to the collection given all the values for a Seasonal employee /// </summary> /// <param name="firstName">first name of the employee</param> /// <param name="lastName">last name of the employee</param> /// <param name="dob">Date of birth of the employee</param> /// <param name="sin">Social Insurance Number of the employee</param> /// <param name="season">season the employee works in</param> /// <param name="piecePay">piecePay of the employee</param> /// <returns>True if the employee was added successfully</returns> public bool addEmployee(string fName, string lName, DateTime dob, string sin, Seasons season, double payAmount) { bool retCode = false; Employee emp = null; if (retCode = SeasonalEmployee.validate(fName, lName, dob, sin, season, payAmount)) { emp = new SeasonalEmployee(fName, lName, dob, sin, season, payAmount); if (EmployeeList.ContainsKey(emp.SIN)) { retCode = false; } else { EmployeeList.Add(emp.SIN, emp); Logging.Log("[Container.AddEmployee] Employee Added - " + emp.LastName + ", " + emp.FirstName + " (" + emp.SIN + ") - VALID"); } } return(retCode); }
private bool GenerateSeasonalEmp(List <string> parameters) { bool status = false; if (parameters.Count == 6) { try { DateTime dateOfBirth = Convert.ToDateTime(parameters[3]); Double piecePay = Convert.ToDouble(parameters[5]); SeasonalEmployee tempEmployee = new SeasonalEmployee(parameters[0], parameters[1], parameters[2], dateOfBirth, parameters[4], piecePay); status = Add(tempEmployee); } catch (Exception e) { status = false; } } return(status); }
static void Main(string[] args) { FullTimeEmployee ft = new FullTimeEmployee(); ft.FullTimeId = 1001; ft.FirstName = "Mary"; ft.LastName = "Mitchell"; ft.PrintFullName(); Console.WriteLine(""); PartTimeEmployee pt = new PartTimeEmployee(); pt.PartTimeID = 3025; pt.FirstName = "Peter"; pt.LastName = "Parker"; pt.PrintFullName(); Console.ReadLine(); SeasonalEmployee Se = new SeasonalEmployee(); CutBackList Cuts = new CutBackList(); }
public void addSlEmp() { SeasonalEmployee sl = new SeasonalEmployee(); bool isAllValid = true; slfNameError.Text = ""; sllNameError.Text = ""; slSinError.Text = ""; slDOBError.Text = ""; slSeasonError.Text = ""; slYearError.Text = ""; slPcPayError.Text = ""; if (!sl.SetFirstName(slfName.Text) && slfName.Text != "") { slfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } if (!sl.SetLastName(sllName.Text) && sllName.Text != "") { sllNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } if (!sl.SetSIN(slSin.Text.Replace(" ", "")) && slSin.Text != "") { slSinError.Text += "<b>SIN</b> should be 9-digit number"; isAllValid = false; } if (!sl.SetDOB(slDOB.Text.Replace(" ", "")) && slDOB.Text != "") { slDOBError.Text += "<b>Date Of Birth</b> should have valid date format"; isAllValid = false; } if (!sl.SetSeason(slSeason.Text.Replace(" ", "")) && slSeason.SelectedIndex.ToString() != "0") { slSeasonError.Text += "<b>Season</b> must be valid. It should not be possible to get this error. Look at you, you little hacker"; isAllValid = false; } //if (!sl.SetYear(slSeason.Text.Replace(" ", ""))) //{ // slSeasonError.Text += "<b>Date Of Birth</b> should have valid date format"; // isAllValid = false; //} if (!sl.SetPiecePay(slPcPay.Text.Replace(" ", "")) && slPcPay.Text != "") { slPcPayError.Text += "<b>Salary</b> should be a number higher than 0"; isAllValid = false; } if (isAllValid) { string activity = "0"; if (slSeason.Text != "" && slPcPay.Text != "" && slDOB.Text != "" && slSin.Text != "" && slYear.Text != "") { activity = "1"; if (slReason.Text != "") { activity = "2"; } } if (addEmpDB("SL", slCompany.Text, slfName.Text, sllName.Text, slSin.Text, slDOB.Text, activity)) { addSlEmpDB(returnID, slSeason.Text, slYear.Text, sldateStart.Text, slPcPay.Text); sucessLbl.Text = slfName.Text + " Has been succesfully added"; } } }
/// <summary> /// Method Name: LoadContainer /// The function is called to populate the container object with the data from the database file /// </summary> /// <param name="fileName">the Name of the database file</param> /// <returns>A boolean indicating whether the operation was successful</returns> public bool LoadContainer() { bool result = true; string[] fileContents; // create string to hold file contents string[] input; Int32 validCount = 0; Int32 lineCount = 0; Int32 entryCount = 0; Employee e = new Employee(); bool duplicate = false; fileContents = dbFile.dBaseOpen_R(); // fill the string with file contents container.Clear(); Console.Clear(); foreach (string s in fileContents) { lineCount++; if (s != "") { input = s.Split('|'); if (s[0] == 'F') { entryCount++; FulltimeEmployee f = new FulltimeEmployee(); if (!f.SetLastName(input[1]) || !f.SetFirstName(input[2]) || !f.SetSIN(input[3]) || !f.SetDOB(input[4]) || !f.SetDateOfHire(input[5]) || !f.SetDateOfTermination(input[6]) || !f.SetSalary(input[7])) { log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); result = false; } else { foreach (Object o in container) { e = (Employee)o; if (e.GetSIN() == f.GetSIN()) { duplicate = true; } } if (duplicate == false) { container.Add(f); validCount++; } else { log.writeLog(f.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); duplicate = false; result = false; } } } else if (s[0] == 'P') { entryCount++; ParttimeEmployee p = new ParttimeEmployee(); if (!p.SetLastName(input[1]) || !p.SetFirstName(input[2]) || !p.SetSIN(input[3]) || !p.SetDOB(input[4]) || !p.SetDateOfHire(input[5]) || !p.SetDateOfTermination(input[6]) || !p.SetHourlyRate(input[7])) { log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); result = false; } else { foreach (Object o in container) { e = (Employee)o; if (e.GetSIN() == p.GetSIN()) { duplicate = true; } } if (duplicate == false) { container.Add(p); validCount++; } else { log.writeLog(p.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); duplicate = false; result = false; } } } else if (s[0] == 'C') { entryCount++; ContractEmployee c = new ContractEmployee(); if (!c.SetLastName(input[1]) || !c.SetFirstName(input[2]) || !c.SetSIN(input[3]) || !c.SetDOB(input[4]) || !c.SetContractStartDate(input[5]) || !c.SetContractEndDate(input[6]) || !c.SetFixedContractAmt(input[7])) { log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); result = false; } else { foreach (Object o in container) { e = (Employee)o; if (e.GetSIN() == c.GetSIN()) { duplicate = true; } } if (duplicate == false) { container.Add(c); validCount++; } else { log.writeLog(c.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); duplicate = false; result = false; } } } else if (s[0] == 'S') { entryCount++; SeasonalEmployee n = new SeasonalEmployee(); if (!n.SetLastName(input[1]) || !n.SetFirstName(input[2]) || !n.SetSIN(input[3]) || !n.SetDOB(input[4]) || !n.SetSeason(input[5]) || !n.SetPiecePay(input[6])) { log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); result = false; } else { foreach (Object o in container) { e = (Employee)o; if (e.GetSIN() == n.GetSIN()) { duplicate = true; } } if (duplicate == false) { container.Add(n); validCount++; } else { log.writeLog(n.produceLogString("LOAD", "1 entry corrupt", s, "FAILED")); duplicate = false; result = false; } } } } } Console.WriteLine("\n\n>>>>>>>>>>>>>>>> TOTAL LINES READ : " + lineCount); Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL ENTRIES FOUND : " + entryCount); Console.WriteLine(">>>>>>>>>>>>>>>> TOTAL VALID ENTRIES LOADED : " + validCount); return(result); }
public void SeasonalEmployeeTest_Exception() { SeasonalEmployee sEmp = new SeasonalEmployee("David", "Pitters", "123456789", DateTime.Parse("1996-02-18"), -1.00, "Summer"); }
protected void btnModify_Click(object sender, EventArgs e) { bool isAllValid = true; ParttimeEmployee pt = new ParttimeEmployee(); FulltimeEmployee ft = new FulltimeEmployee(); SeasonalEmployee sl = new SeasonalEmployee(); ContractEmployee ct = new ContractEmployee(); List <string> normalUpdates = new List <string>(); List <string> specificUpdates = new List <string>(); string updateString = "UPDATE tb_Emp SET"; string updateSpecific = "UPDATE tb_"; int empID = 0; string empType = Session["type"].ToString(); if (empType == "FT") { updateSpecific += "Ft"; } else if (empType == "PT") { updateSpecific += "Pt"; } else if (empType == "SL") { updateSpecific += "Sl"; } else if (empType == "CT") { updateSpecific += "Ct"; } updateSpecific += "Emp SET "; string endUpdate = " OUTPUT INSERTED.empID WHERE socialInsNumber=" + Session["sin"] + " and firstName='" + Session["fname"] + "' and lastName='" + Session["lname"] + "' and companyName='" + Session["company"] + "';"; //string updateSpecificString = "UPDATE " + //for fulltime if (ftfName.Text != "") { if (!ft.SetFirstName(ftfName.Text)) { ftfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } normalUpdates.Add("firstName='" + ftfName.Text + "'"); } if (ftlName.Text != "") { if (!ft.SetLastName(ftlName.Text)) { ftlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } normalUpdates.Add("lastName='" + ftlName.Text + "'"); } if (ftSin.Text != "") { if (!ft.SetSIN(ftSin.Text.Replace(" ", ""))) { ftSinError.Text += "<b>SIN</b> should be 9-digit number"; isAllValid = false; } normalUpdates.Add("socialInsNumber=" + ftSin.Text); } if (ftDOB.Text != "") { if (!ft.SetDOB(ftDOB.Text.Replace(" ", ""))) { ftDOBError.Text += "<b>Date Of Hire</b> should have valid date format"; isAllValid = false; } normalUpdates.Add("dateOfBirth'" + ftDOB.Text + "'"); } if (ftDateHire.Text != "") { if (!ft.SetDateOfHire(ftDateHire.Text.Replace(" ", ""))) { ftDateHireError.Text += "<b>Date Of Birth</b> should have valid date format"; isAllValid = false; } specificUpdates.Add("dateOfHire='" + ftDateHire.Text + "'"); } if (ftDateTerm.Text != "") { if (!ft.SetDateOfTermination(ftDateTerm.Text.Replace(" ", "")) && ftDateTerm.Text != "") { ftDateTermError.Text += "<b>Date Of Termination</b> should have valid date format"; isAllValid = false; } specificUpdates.Add("dateOfTermination='" + ftDateTerm.Text + "'"); } if (ftSalary.Text != "") { if (!ft.SetSalary(ftSalary.Text.Replace(" ", "")) && ftSalary.Text != "") { ftSalaryError.Text += "<b>Salary</b> should be a number higher than 0"; isAllValid = false; } specificUpdates.Add("salary=" + ftSalary.Text + ""); } //for part time if (ptfName.Text != "") { if (!pt.SetFirstName(ptfName.Text)) { ptfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } normalUpdates.Add("firstName='" + ptfName.Text + "'"); } if (ptlName.Text != "") { if (!pt.SetLastName(ptlName.Text) || ptlName.Text == "") { ptlNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } normalUpdates.Add("lastName='" + ptlName.Text + "'"); } if (ptSin.Text != "") { if (!pt.SetSIN(ptSin.Text.Replace(" ", ""))) { ptSinError.Text += "<b>SIN</b> should be 9-digit number"; isAllValid = false; } normalUpdates.Add("socialInsNumber=" + ptSin.Text); } if (ptDOB.Text != "") { if (!pt.SetDOB(ptDOB.Text.Replace(" ", ""))) { ptDOBError.Text += "<b>Date Of Birth</b> should have valid date format"; isAllValid = false; } normalUpdates.Add("dateOfBirth='" + ptDOB.Text + "'"); } if (ptDateHire.Text != "") { if (!pt.SetDateOfHire(ptDateHire.Text.Replace(" ", ""))) { ptDateHireError.Text += "<b>Date Of Hire</b> should have valid date format"; isAllValid = false; } specificUpdates.Add("dateOfHire='" + ptDateHire.Text + "'"); } if (ptDateTerm.Text != "") { if (!pt.SetDateOfTermination(ptDateTerm.Text.Replace(" ", "")) && ptDateTerm.Text != "") { ptDateTermError.Text += "<b>Date Of Termination</b> should have valid date format"; isAllValid = false; } specificUpdates.Add("dateOfTermination='" + ptDateTerm.Text + "'"); } if (ptWage.Text != "") { if (!pt.SetHourlyRate(ptWage.Text.Replace(" ", "")) && ptWage.Text != "") { ptWageError.Text += "<b>Salary</b> should be a number higher than 0"; isAllValid = false; } specificUpdates.Add("hourlyRate=" + ptWage.Text); } //for seasonal if (slfName.Text != "") { if (!sl.SetFirstName(slfName.Text) || slfName.Text == "") { slfNameError.Text += "<b>First Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } normalUpdates.Add("firstName='" + slfName.Text + "'"); } if (sllName.Text != "") { if (!sl.SetLastName(sllName.Text) || sllName.Text == "") { sllNameError.Text += "<b>Last Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } normalUpdates.Add("lastName='" + sllName.Text + "'"); } if (slSin.Text != "") { if (!sl.SetSIN(slSin.Text.Replace(" ", ""))) { slSinError.Text += "<b>SIN</b> should be 9-digit number"; isAllValid = false; } normalUpdates.Add("socialInsNumber=" + ftfName.Text); } if (slDOB.Text != "") { if (!sl.SetDOB(slDOB.Text.Replace(" ", ""))) { slDOBError.Text += "<b>Date Of Birth</b> should have valid date format"; isAllValid = false; } normalUpdates.Add("dateOfBirth='" + slDOB.Text + "'"); } if (slSeason.Text != "" && Session["type"].ToString() == "SL") { if (!sl.SetSeason(slSeason.Text.Replace(" ", "")) && slSeason.Text != "") { slSeasonError.Text += "<b>Season</b> must be valid. It should not be possible to get this error. Look at you, you little hacker"; isAllValid = false; } specificUpdates.Add("season='" + slSeason.Text + "'"); } if (slPcPay.Text != "") { if (!sl.SetPiecePay(slPcPay.Text.Replace(" ", "")) && slPcPay.Text != "") { slPcPayError.Text += "<b>Salary</b> should be a number higher than 0"; isAllValid = false; } specificUpdates.Add("piecePay='" + slPcPay.Text + "'"); } //for contract if (ctName.Text != "") { if (!ct.SetLastName(ctName.Text)) { ctNameError.Text += "<b>Company Name</b> can only contain the following characters: [A-Za-z. -]\n"; isAllValid = false; } normalUpdates.Add("lastName='" + ctName.Text + "'"); } if (ctBin.Text != "") { if (!ct.SetSIN(ctBin.Text.Replace(" ", ""))) { ctBinError.Text += "<b>BIN</b> should be 9-digit number"; isAllValid = false; } normalUpdates.Add("socialInsNumber='" + ctBin.Text + "'"); } if (ctDOI.Text != "") { if (!ct.SetDOB(ctDOI.Text.Replace(" ", ""))) { ctDOIError.Text += "<b>Date Of Incorporation</b> should have valid date format"; isAllValid = false; } normalUpdates.Add("dateOfBirth='" + ctDOI.Text + "'"); } if (ctStart.Text != "") { if (!ct.SetContractStartDate(ctStart.Text.Replace(" ", ""))) { ctStartError.Text += "<b>Contract Start Date</b> must be valid. It should not be possible to get this error. Look at you, you little hacker"; isAllValid = false; } specificUpdates.Add("dateStart='" + ctStart.Text + "'"); } if (ctEnd.Text != "") { if (!ct.SetContractEndDate(ctEnd.Text.Replace(" ", ""))) { ctEndError.Text += "<b>Contract End Date</b> should have valid date format"; isAllValid = false; } specificUpdates.Add("dateStop='" + ctEnd.Text + "'"); } if (ctAmt.Text != "") { if (!ct.SetFixedContractAmt(ctAmt.Text.Replace(" ", ""))) { ctAmtError.Text += "<b>Contract Amount</b> should be a number higher than 0"; isAllValid = false; } specificUpdates.Add("fixedCtAmt='" + ctAmt.Text + "'"); } if (isAllValid) { int emp = 0; int.TryParse(Session["empID"].ToString(), out emp); bool first = true; if (normalUpdates.Count < 1) { normalUpdates.Add("lastName='" + Session["lname"] + "'"); } foreach (string s in normalUpdates) { if (first) { updateString += " " + s; first = false; } else { updateString += ", " + s; } string fieldValue = s.Substring(0, s.IndexOf('=')); string oldVal = sup.GetPreviousValue(conString, emp, @s, ""); string newVal = s; newVal = newVal.Replace(fieldValue + @"='", ""); sup.CreateAudit(conString, userName, emp.ToString(), fieldValue, oldVal, newVal); } updateString += endUpdate; first = true; foreach (string s in specificUpdates) { if (first) { updateSpecific += " " + s; first = false; } else { updateSpecific += ", " + s; } string oldVal = sup.GetPreviousValue(conString, emp, @s, empID.ToString()); } try { using (SqlConnection connect = new SqlConnection(conString)) { connect.Open(); using (SqlCommand changeCmd = new SqlCommand()) { changeCmd.Connection = connect; changeCmd.CommandType = CommandType.Text; changeCmd.CommandText = updateString; empID = (Int32)changeCmd.ExecuteScalar(); changeCmd.Dispose(); } updateSpecific += " WHERE empID=" + empID; using (SqlCommand changeCmd = new SqlCommand()) { changeCmd.Connection = connect; changeCmd.CommandType = CommandType.Text; changeCmd.CommandText = updateSpecific; changeCmd.ExecuteNonQuery(); changeCmd.Dispose(); } } } catch (Exception exce) { } } }