/// <summary> /// Method Name: AddFullTimeEmployee /// This function is called to add the FullTimeEmployee 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 AddFullTimeEmployee(FulltimeEmployee ft) { bool result = AddEmployee(ft); // To do return(result); }
static void Main(string[] args) { // 1. Employee { EmployeeList list = new EmployeeList(); Employee.Employee fte1, fte2, fte3, pte1, pte2; fte1 = new FulltimeEmployee("张无忌", 3200.00, 45); fte2 = new FulltimeEmployee("杨过", 2000.00, 40); fte3 = new FulltimeEmployee("段誉", 2400.00, 38); pte1 = new ParttimeEmployee("洪七公", 80.00, 20); pte2 = new ParttimeEmployee("郭靖", 60.00, 18); list.AddEmployee(fte1); list.AddEmployee(fte2); list.AddEmployee(fte3); list.AddEmployee(pte1); list.AddEmployee(pte2); string visitorStr = ConfigurationManager.AppSettings["visitor"]; Department department = (Department)Assembly.Load("ch24_Visitor").CreateInstance(visitorStr); list.Accept(department); } // 2. Cart // goods // Cashier, Customer // Apple (Weighing, Price), Book(Price) // 3. Award Check // Teacher (){ Paper>10=>ResearchAward; Rating>90=>ExcellenceAward} // Student (){ Paper>2=>ResearchAward; AvgScore>90=>ExcellenceAward} Console.ReadLine(); }
static void Main(string[] args) { EmployeeList list = new EmployeeList(); Employee fte1, fte2, fte3, pte1, pte2; fte1 = new FulltimeEmployee("张无忌", 3200, 45); fte2 = new FulltimeEmployee("杨过", 2000, 40); fte3 = new FulltimeEmployee("段誉", 2400, 38); pte1 = new ParttimeEmployee("洪七公", 80, 20); pte2 = new ParttimeEmployee("郭靖", 60, 18); list.addEmployee(fte1); list.addEmployee(fte2); list.addEmployee(fte3); list.addEmployee(pte1); list.addEmployee(pte2); Console.WriteLine("财务部 访问数据!"); Department fadep = new FADepartment(); list.accept(fadep); Console.WriteLine(); Console.WriteLine("人力资源部 访问数据!"); Department hrdep = new HRDepartment(); list.accept(hrdep); Console.ReadLine(); }
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); } } }
private void FillFullTimeEmployee(FulltimeEmployee e) { type.InnerText = "Full Time"; doh.InnerText = e.DateOfHire.ToShortDateString(); dot.InnerText = e.DateOfTermination.ToShortDateString(); salary.InnerText = e.Salary.ToString(); }
/// <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); }
/// <summary> /// This method adds a new Full Time Employee to the database. /// </summary> /// <param name="fName">The first name of the Full Time Employee.</param> /// <param name="lName">The last name of the Full Time Employee.</param> /// <param name="SIN">The Social Insurance Number of the Full Time Employee.</param> /// <param name="dateOfBirth">The Date of Birth of the Full Time Employee.</param> /// <param name="dateOfHire">The Date that the Full Time Employee was hired.</param> /// <param name="dateOfTermination">The Date that the Full Time Employee was terminated.</param> /// <param name="salary">The total amount paid to the Full Time Employee over the course of a year.</param> /// <returns>A bool. true if employee was added, false otherwise.</returns> public static bool AddFulltimeEmployee(string fName, string lName, string SIN, DateTime dateOfBirth, DateTime dateOfHire, DateTime dateOfTermination, double salary) { bool empAdded = false; try { //Check if an employee with that sin number already exists bool employeeExists = FE.Any(x => x.socialInsuranceNumber == SIN); if (employeeExists) { throw new Exception(); //The employee exists, it can't be added } else { FulltimeEmployee emp = new FulltimeEmployee(fName, lName, SIN, dateOfBirth, dateOfHire, dateOfTermination, salary); bool valid = emp.Validate(); if (valid) { FE.Add(emp); Logging logger = new Logging(); logger.Log(lName + ", " + fName + " SIN: " + SIN + " - ADDED", "Employees", "AddFulltimeEmployee"); empAdded = true; } } } catch (Exception) { empAdded = false; } return(empAdded); }
public void FulltimeEmployeeTest_Success() { FulltimeEmployee fullTimeEmp = new FulltimeEmployee("Ronnie", "Skowron", "123456789", DateTime.Parse("2004-08-17"), DateTime.Parse("2006-08-14"), DateTime.Parse("2010-11-12"), 16); bool success = fullTimeEmp.Validate(); Assert.IsTrue(success); }
public void ValidateDateOfHireBoundaryTestCase() { //Arrange bool expected = true; bool?actual = null; //Act actual = FulltimeEmployee.validateStartDate(DateTime.Now, DateTime.Now); //Assert Assert.AreEqual(expected, actual); }
public void ValidateDateOfHireExceptionTestCase() { //Arrange bool expected = false; bool? actual = null; DateTime dateOfHire = DateTime.Parse("2025-12-14"); //Act actual = FulltimeEmployee.validateStartDate(dateOfHire, DateTime.Now); //Assert Assert.AreEqual(expected, actual); }
public void ValidateSalaryBoundaryTestCase() { //Arrange bool expected = true; bool? actual = null; double salary = 0.000001; //Act actual = FulltimeEmployee.validatePay(salary); //Assert Assert.AreEqual(expected, actual); }
public void ValidateSalaryExceptionTestCase() { //Arrange bool expected = false; bool? actual = null; double salary = -40567.58; //Act actual = FulltimeEmployee.validatePay(salary); //Assert Assert.AreEqual(expected, actual); }
public void validateTypeNormalTest() { // Arrange dBase = new Container(); Employee temp = new FulltimeEmployee("bobby", "tables", DateTime.Now, "123456782", DateTime.Now, null, 54000.00); // Act EmployeeType expected = EmployeeType.FT; EmployeeType actual = dBase.getType(temp); // Assert Assert.AreEqual(expected, actual); }
public void ValidateDateOfTerminationNullBoundaryTestCase() { //Arrange bool expected = true; bool? actual = null; DateTime dateOfHire = DateTime.Parse("1999-08-24"); DateTime?dateOfTermination = null; //Act actual = FulltimeEmployee.validateStopDate(dateOfHire, dateOfTermination); //Assert Assert.AreEqual(expected, actual); }
public void ValidateDateOfHireNormalTestCase() { //Arrange DateTime DateOfBirth = DateTime.Parse("1970-01-01"); DateTime dateOfHire = DateTime.Parse("1999-08-24"); bool expected = true; bool? actual = null; //Act actual = FulltimeEmployee.validateStartDate(DateOfBirth, dateOfHire); //Assert 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); }
/// <summary> /// \brief <b>Description</b> /// \details This function adds an employee to the collection given all the values /// of a valid Fulltime, Parttime, or Contract Employee /// </summary> /// <param name="type">the type of employee (Fulltime, Parttime, or Contract)</param> /// <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="startDate"> - Date of Hire of the employee</param> /// <param name="stopDate"> - Date of termination of the employee</param> /// <param name="payAmount"> - Annual salary of the employee</param> /// <returns>True if the employee was added successfully</returns> public bool addEmployee(EmployeeType type, string fName, string lName, DateTime dob, string sin, DateTime startDate, DateTime?stopDate, double payAmount) { bool retCode = false; Employee emp = null; switch (type) { case EmployeeType.FT: if (retCode = FulltimeEmployee.validate(fName, lName, dob, sin, startDate, stopDate, payAmount)) { emp = new FulltimeEmployee(fName, lName, dob, sin, startDate, stopDate, payAmount); } break; case EmployeeType.PT: if (retCode = ParttimeEmployee.validate(fName, lName, dob, sin, startDate, stopDate, payAmount)) { emp = new ParttimeEmployee(fName, lName, dob, sin, startDate, stopDate, payAmount); } break; case EmployeeType.CT: if (stopDate != null) { if (retCode = ContractEmployee.validate(lName, dob, sin, startDate, (DateTime)stopDate, payAmount)) { emp = new ContractEmployee(lName, dob, sin, startDate, (DateTime)stopDate, payAmount); } } 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); }
public void validateAddNormalTest() { // Arrange dBase = new Container(); FulltimeEmployee temp = new FulltimeEmployee("bobby", "tables", DateTime.Now, "123456782", DateTime.Now, null, 54000.00); // Act dBase.addEmployee(temp); int expected = 1; int actual = dBase.Length; // Assert Assert.AreEqual(expected, actual); }
public void validateDeleteExceptionTest() { // Arrange dBase = new Container(); FulltimeEmployee temp = new FulltimeEmployee("bobby", "tables", DateTime.Now, "123456782", DateTime.Now, null, 54000.00); // Act dBase.addEmployee(temp); dBase.removeEmployee("123456782"); bool expected = true; bool actual = dBase.removeEmployee("123456782"); // Assert Assert.AreNotEqual(expected, actual); }
static void Main(string[] args) { //abstract prevents you from create an instance //abstract acts like interface by using abstract method stubs //abstract is a mix of interface and class FulltimeEmployee fte = new FulltimeEmployee() { Id = 1, AnnualSalary = 90000, FirstName = "Truc", LastName = "Nguyen" }; ContractEmployee ce = new ContractEmployee() { Id = 2, HourlyPay = 40, TotalHoursPerMonth = 60, LastName = "Ng", FirstName = "Frankie" }; }
public void ValidateOverloadExceptionTestCase() { //Arrange bool expected = false; bool? actual = null; string firstName = "Nathan"; string lastName = "Bray"; DateTime dob = DateTime.Parse("1993-09-15"); string sin = "333333334"; DateTime dateOfHire = DateTime.Parse("2015-04-12"); DateTime dateOfTermination = DateTime.Parse("2012-08-13"); double salary = 54749.00; //Act actual = FulltimeEmployee.validate(firstName, lastName, dob, sin, dateOfHire, dateOfTermination, salary); //Assert Assert.AreEqual(expected, actual); }
public void ValidateNormalTestCase() { //Arrange bool expected = true; bool? actual = null; FulltimeEmployee ftEmployee = new FulltimeEmployee(); ftEmployee.FirstName = "Jody"; ftEmployee.LastName = "Markic"; ftEmployee.DOB = DateTime.Parse("1993-08-24"); ftEmployee.SIN = "123456782"; ftEmployee.DateOfHire = DateTime.Parse("2012-04-12"); ftEmployee.DateOfTermination = DateTime.Parse("2015-06-04"); ftEmployee.Salary = 54750.00; //Act actual = FulltimeEmployee.validate(ftEmployee); //Assert Assert.AreEqual(expected, actual); }
public void validateUpdateNormalTest() { // Arrange dBase = new Container(); FulltimeEmployee tempOld = new FulltimeEmployee("bobby", "tables", DateTime.Now, "123456782", DateTime.Now, null, 54000.00); FulltimeEmployee tempNew = new FulltimeEmployee("Robert", "Surface", DateTime.Now, "123456782", DateTime.Now, null, 55000.00); // Act dBase.addEmployee(tempOld); bool expected = true; bool actual = dBase.updateEmployee(tempNew); // Assert Assert.AreEqual(expected, actual); }
public void validateTryFindExceptionTest() { // Arrange dBase = new Container(); FulltimeEmployee temp = new FulltimeEmployee("bobby", "tables", DateTime.Now, "123456782", DateTime.Now, null, 54000.00); FulltimeEmployee temp2 = new FulltimeEmployee("Robert", "Surface", DateTime.Now, "935345678", DateTime.Now, null, 55000.00); // Act dBase.addEmployee(temp); dBase.addEmployee(temp2); bool expected = true; bool actual = dBase.tryFindEmployee("123456784"); // Assert Assert.AreNotEqual(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> /// 实现人力资源部对全职员工的访问 /// </summary> /// <param name="employee"></param> public override void Visit(FulltimeEmployee employee) { int workTime = employee.WorkTime; Console.WriteLine("正式员工{0}实际工作时间为:{1}小时。", employee.Name, employee.WorkTime); if (workTime > 40) { Console.WriteLine("正式员工{0}加班时间为{1}小时。", employee.Name, workTime - 40); } else if (workTime < 40) { Console.WriteLine("正式员工{0}请假时间为:{1}小时。", employee.Name, 40 - workTime); } }
/// <summary> /// 实现财务部对全职员工的访问 /// </summary> /// <param name="employee"></param> public override void Visit(FulltimeEmployee employee) { int workTime = employee.WorkTime; Decimal weekWage = employee.WeeklyWage; if (workTime > 40) { weekWage = weekWage + (workTime - 40) * 100; } else if (workTime < 40) { weekWage = weekWage - (40 - workTime) * 80; if (weekWage < 0) { weekWage = 0; } } Console.WriteLine("正式员工{0}实际工资为:{1}元。", employee.Name, weekWage); }
/// <summary> /// Fills in full time employee /// </summary> /// <param name="reader"></param> /// <returns></returns> private FulltimeEmployee FillFullTimeEmployee(SqlDataReader reader) { FulltimeEmployee ft = EmployeeFactory.CreateFullTimeEmployee(); float salary = 0; DateTime doh; DateTime dot; FillBaseEmployee(ft, reader); if (DateTime.TryParse(reader["dateOfHire"].ToString(), out doh)) { ft.DateOfHire = doh; } else { ft.DateOfHire = DateTime.MinValue; } if (DateTime.TryParse(reader["dateOfTermination"].ToString(), out dot)) { ft.DateOfTermination = dot; } else { ft.DateOfTermination = DateTime.MinValue; } if (float.TryParse(reader["salary_pay"].ToString(), out salary)) { ft.Salary = salary; } else { ft.Salary = null; } return(ft); }
public void validateJoinNormalTest() { // Arrange List <string> actual = new List <string>(); dBase = new Container(); List <string> expected = new List <string>() { "FT|tables|bobby|123456782|" + DateTime.Now.ToString("yyyy-MM-dd") + "|" + DateTime.Now.ToString("yyyy-MM-dd") + "|N/A|54000" }; FulltimeEmployee temp = new FulltimeEmployee("bobby", "tables", DateTime.Now, "123456782", DateTime.Now, null, 54000.00); // Act dBase.addEmployee(temp); actual = dBase.concatAllRecords(); // Assert Assert.AreEqual(expected[0], actual[1]); }
public void validateFindExceptionTest() { // Arrange dBase = new Container(); FulltimeEmployee expected = new FulltimeEmployee("bobby", "tables", DateTime.Now, "123456782", DateTime.Now, null, 54000.00); FulltimeEmployee temp = new FulltimeEmployee("bobby", "tables", DateTime.Now, "333333334", DateTime.Now, null, 54000.00); FulltimeEmployee temp2 = new FulltimeEmployee("bobby", "tables", DateTime.Now, "935345678", DateTime.Now, null, 54000.00); // Act dBase.addEmployee(temp); dBase.addEmployee(expected); dBase.addEmployee(temp2); FulltimeEmployee actual = (FulltimeEmployee)dBase.findEmployee("123456784"); // Assert Assert.AreNotEqual(expected, actual); }