public List <Employee> GetAllEmployees() { List <Employee> lista = new List <Employee>(); using (Model.TESTEntities DB = new Model.TESTEntities()) { var ListEmp = (from e in DB.Employees select e).ToList(); foreach (Model.Employee emp in ListEmp) { if (emp is Model.PartTimeEmployee) { Model.PartTimeEmployee empDB = (Model.PartTimeEmployee)emp; PartTimeEmployee nuevo = new PartTimeEmployee(); nuevo.Id = empDB.EmployeeId; nuevo.Name = empDB.Name; nuevo.StartDate = empDB.StartDate; nuevo.HourlyRate = (Double)empDB.HourlyRate; lista.Add(nuevo); } else { Model.FullTimeEmployee empDB = (Model.FullTimeEmployee)emp; FullTimeEmployee nuevo = new FullTimeEmployee(); nuevo.Id = empDB.EmployeeId; nuevo.Name = empDB.Name; nuevo.StartDate = empDB.StartDate; nuevo.Salary = (int)empDB.Salary; lista.Add(nuevo); } } } return(lista); }
public void AddEmployee(Employee emp) { using (Model.PracticoEntities en = new Model.PracticoEntities()) { Model.Employee empNuevo; if (emp.GetType() == typeof(FullTimeEmployee)) { FullTimeEmployee empFT = (FullTimeEmployee)emp; empNuevo = new Model.FullTimeEmployee() { EmployeeId = empFT.Id, Name = empFT.Name, Salary = empFT.Salary, StartDate = empFT.StartDate }; en.EmployeeTPH.Add(empNuevo); en.SaveChanges(); } else { PartTimeEmployee empPT = (PartTimeEmployee)emp; empNuevo = new Model.PartTimeEmployee() { EmployeeId = empPT.Id, Name = empPT.Name, StartDate = empPT.StartDate, HourlyRate = empPT.HourlyRate }; en.EmployeeTPH.Add(empNuevo); en.SaveChanges(); } } }
public Employee GetEmployee(int id) { using (Model.TESTEntities DB = new Model.TESTEntities()) { var ListEmp = (from e in DB.Employees where e.EmployeeId == id select e).ToList(); foreach (Model.Employee emp in ListEmp) { if (emp is Model.PartTimeEmployee) { Model.PartTimeEmployee empDB = (Model.PartTimeEmployee)emp; PartTimeEmployee nuevo = new PartTimeEmployee(); nuevo.Id = empDB.EmployeeId; nuevo.Name = empDB.Name; nuevo.StartDate = empDB.StartDate; nuevo.HourlyRate = (Double)empDB.HourlyRate; return(nuevo); } else { Model.FullTimeEmployee empDB = (Model.FullTimeEmployee)emp; FullTimeEmployee nuevo = new FullTimeEmployee(); nuevo.Id = empDB.EmployeeId; nuevo.Name = empDB.Name; nuevo.StartDate = empDB.StartDate; nuevo.Salary = (int)empDB.Salary; return(nuevo); } } return(null); } }
public void UpdateEmployee(Employee emp) { using (Model.TESTEntities DB = new Model.TESTEntities()) { if (emp != null) { if (emp != null) { Model.Employee EmpDB = DB.Employees.Find(emp.Id); if (EmpDB is Model.PartTimeEmployee) { PartTimeEmployee empLP = (PartTimeEmployee)emp; Model.PartTimeEmployee nuevo = (Model.PartTimeEmployee)EmpDB; nuevo.Name = empLP.Name; nuevo.StartDate = empLP.StartDate; nuevo.HourlyRate = empLP.HourlyRate; DB.Employees.Attach(nuevo); } else { FullTimeEmployee empLP = (FullTimeEmployee)emp; Model.FullTimeEmployee nuevo = (Model.FullTimeEmployee)EmpDB; nuevo.Name = empLP.Name; nuevo.StartDate = empLP.StartDate; nuevo.Salary = empLP.Salary; DB.Employees.Attach(nuevo); } DB.SaveChanges(); } } } }
static void Main(string[] args) { FullTimeEmployee fte = new FullTimeEmployee() { ID = 101, FirstName = "Joe", LastName = "Smith", AnnualSalary = 60000 }; Console.WriteLine($"Get full name: {fte.GetFullName()}, Annual Salary: {fte.GetMonthlySalary()}"); Console.WriteLine("------------------------------------------------"); ContractEmployee cte = new ContractEmployee() { ID = 102, FirstName = "Sarah", LastName = "Jones", HourlyPay = 50, TotalHours = 40 * 4 }; Console.WriteLine($"Get full name: {cte.GetFullName()}, Annual Salary: {cte.GetMonthlySalary()}"); Console.WriteLine("------------------------------------------------"); }
public void AddEmployee(Employee emp) { using (Model.TESTEntities DB = new Model.TESTEntities()) { if (emp is PartTimeEmployee) { PartTimeEmployee empLP = new PartTimeEmployee(); Model.PartTimeEmployee nuevo = new Model.PartTimeEmployee(); nuevo.EmployeeId = empLP.Id; nuevo.Name = empLP.Name; nuevo.StartDate = empLP.StartDate; nuevo.HourlyRate = empLP.HourlyRate; DB.Employees.Add(nuevo); } else { FullTimeEmployee empLP = new FullTimeEmployee(); Model.FullTimeEmployee nuevo = new Model.FullTimeEmployee(); nuevo.EmployeeId = empLP.Id; nuevo.Name = empLP.Name; nuevo.StartDate = empLP.StartDate; nuevo.Salary = empLP.Salary; DB.Employees.Add(nuevo); } DB.SaveChanges(); } }
public async void AddEmployee(Employee emp) { try { BsonDocument datos = new BsonDocument(); datos.Add("_id", emp.Id); datos.Add("name", emp.Name); datos.Add("start_date", emp.StartDate); if (emp.GetType() == typeof(FullTimeEmployee)) { FullTimeEmployee fullTime = (FullTimeEmployee)emp; datos.Add("salary", fullTime.Salary); datos.Add("type_emp", 1); } else { PartTimeEmployee partTime = (PartTimeEmployee)emp; datos.Add("rate", partTime.HourlyRate); datos.Add("type_emp", 0); } await this.collection.InsertOneAsync(datos); } catch (MongoWriteException e) { // Clave de entidad duplicada } }
public List <Employee> GetAllEmployees() { Debug.WriteLine("test print in ServiceEmployee::GetAllEmployees"); if (blHandler != null) { List <Employee> listEmp = new List <Employee>(); listEmp = Program.blHandler.GetAllEmployees(); Debug.WriteLine(listEmp.Count); foreach (Employee emp in listEmp) { if (emp.Name != "") { Debug.WriteLine(emp.Name); } } return(null); } else { Debug.WriteLine("es null"); List <Employee> ret = new List <Employee>(); Employee emp = new FullTimeEmployee() { Name = "blHandler Vacio" }; ret.Add(emp); return(ret); } }
public Employee GetEmployee(int id) { Employee ret = new FullTimeEmployee(); BsonDocument filter = new BsonDocument(); filter.Add("_id", id); List <BsonDocument> lista = this.collection.Find(filter).ToList(); lista.ForEach(emp => { if (emp.GetValue("type_emp").ToBoolean()) { ret = new FullTimeEmployee() { Id = emp.GetValue("_id").ToInt32(), Name = emp.GetValue("name").ToString(), Salary = emp.GetValue("salary").ToInt32(), StartDate = new DateTime() }; } else { ret = new PartTimeEmployee() { Id = emp.GetValue("_id").ToInt32(), Name = emp.GetValue("name").ToString(), HourlyRate = emp.GetValue("rate").ToInt32(), StartDate = new DateTime() }; } }); return(ret); }
/// When you want to hide base class method, Use new keyword. /// 1st way, If you want to invoke base class hidden method, Use base.HiddenMethodName(). /// 2nd way, If you want to invoke base class hidden method, Use base.HiddenMethodName(). static void Main(string[] args) { FullTimeEmployee ft = new FullTimeEmployee(); ft.firstName = "Anand"; ft.lastName = "Dev"; ft.PrintFullName(); PartTimeEmployee pt = new PartTimeEmployee(); pt.firstName = "Uttamm"; pt.lastName = "Kumar"; pt.PrintFullName(); // 2nd way, If you want to invoke base class hidden method, Use base.HiddenMethodName(). PartTimeEmployee pt2 = new PartTimeEmployee(); pt2.firstName = "Praveen"; pt2.lastName = "Shamra"; ((Employee)pt2).PrintFullName(); // 3rd way, If you want to invoke base class hidden method, Use base.HiddenMethodName(). Employee e = new PartTimeEmployee(); e.firstName = "Anoop"; e.lastName = "Agarwal"; e.PrintFullName(); Console.ReadKey(); }
public void AddEmployee(Employee emp) { using (Model.PracticoObligatorioEntities en = new Model.PracticoObligatorioEntities()) { if (emp.GetType().Name == "FullTimeEmployee") { FullTimeEmployee employee = (FullTimeEmployee)emp; Model.FullTimeEmployee employeeBase = new Model.FullTimeEmployee() { Name = employee.Name, StartDate = employee.StartDate, Salary = employee.Salary }; en.EmployeesTPH.Add(employeeBase); en.SaveChanges(); } else { PartTimeEmployee employee = (PartTimeEmployee)emp; Model.PartTimeEmployee employeeBase = new Model.PartTimeEmployee() { Name = employee.Name, StartDate = employee.StartDate, HourlyRate = employee.HourlyRate }; en.EmployeesTPH.Add(employeeBase); en.SaveChanges(); } } }
public void UpdateEmployee(Employee emp) { using (Model.PracticoEntities en = new Model.PracticoEntities()) { if (emp.GetType() == typeof(FullTimeEmployee)) { FullTimeEmployee FullTimeEmp = (FullTimeEmployee)emp; Model.Employee e = en.EmployeeTPH.Find(emp.Id); if (e != null) { Model.FullTimeEmployee empFT = (Model.FullTimeEmployee)e; empFT.Name = FullTimeEmp.Name; empFT.Salary = FullTimeEmp.Salary; empFT.StartDate = FullTimeEmp.StartDate; en.SaveChanges(); } } else { PartTimeEmployee PartTimeEmp = (PartTimeEmployee)emp; Model.Employee e = en.EmployeeTPH.Find(emp.Id); if (e != null) { Model.PartTimeEmployee empFT = (Model.PartTimeEmployee)e; empFT.Name = PartTimeEmp.Name; empFT.StartDate = PartTimeEmp.StartDate; empFT.HourlyRate = PartTimeEmp.HourlyRate; en.SaveChanges(); } } } }
protected void btnSave_Click(object sender, EventArgs e) { Employee employee = null; if ((EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue) == EmployeeType.FullTime) { employee = new FullTimeEmployee { AnnualSalary = Convert.ToInt32(txtAnnualSalary.Text), Type = EmployeeType.FullTime }; } else { employee = new PartTimeEmployee { HourlyPay = Convert.ToInt32(txtHourlyPay.Text), HoursWorked = Convert.ToInt32(txtHoursWorked.Text), Type = EmployeeType.PartTime }; } employee.ID = Convert.ToInt32(txtID.Text); employee.Name = txtName.Text; employee.Gender = txtGender.Text; employee.DateOfBirth = Convert.ToDateTime(txtDateOfBirth.Text); EmployeeServiceClient client = new EmployeeServiceClient(); client.SaveEmployee(employee); lblMessage.Text = "Employee saved"; }
public Employee GetEmployee(int id) { Model.ER1Entities context = new Model.ER1Entities(); // DataContext takes a connection string. IQueryable <Model.Employee> query = from employee in context.Employees where employee.Id == id select employee; Model.Employee empR = query.First(); if (empR.GetType() == typeof(Model.FullTimeEmployee)) { FullTimeEmployee result = new FullTimeEmployee(); result.Id = id; result.Name = empR.Name; result.Salary = ((Model.FullTimeEmployee)empR).Salary; result.StartDate = empR.StartDate; return(result); } else { PartTimeEmployee result = new PartTimeEmployee(); result.Id = id; result.Name = empR.Name; result.HourlyRate = ((Model.PartTimeEmployee)empR).HourlyRate; result.StartDate = empR.StartDate; return(result); } }
// PUT api/<controller>/5 public void Put(int id, [FromBody] EmployeeRequest EmployeeRequest) { /// BusinessLogicLayer.BLEmployees bLEmployees = new BLEmployees(); Employee emp = null; if (EmployeeRequest.type == 1) { emp = new PartTimeEmployee() { Id = id, Name = EmployeeRequest.Name, StartDate = EmployeeRequest.StartDate, HourlyRate = EmployeeRequest.HourlyRate }; } else if (EmployeeRequest.type == 2) { emp = new FullTimeEmployee() { Id = id, // cubrir cuando se manda id vacio Name = EmployeeRequest.Name, StartDate = EmployeeRequest.StartDate, Salary = EmployeeRequest.Salary }; } this._bLEmployees.UpdateEmployee(emp); }
public static void Main() { // whenever we creare an instance of a child class, we automatically create an instance of the base class FullTimeEmployee FTE = new FullTimeEmployee(); FTE.firstname = "Geetha"; FTE._lastname = "Yedida"; FTE.PrintFullName(); FTE.YearlySalary = 15000F; PartTimeEmployee PTE = new PartTimeEmployee(); PTE.firstname = "Gee"; PTE._lastname = "Yed"; PTE.HourlyRate = 13; PTE.PrintFullName(); A A1 = new A(); A1.YearlySalary = 1200; A1.PrintFullName(); // it is also possible for the derived class constructor to control which of the constructors in the parent class is called. if the parent // class has more than one constructor. }
private bool GenerateFullTimeEmp(List <string> parameters) { bool status = false; if (parameters.Count == 7) { try { DateTime dateOfBirth = Convert.ToDateTime(parameters[3]); DateTime dateOfHire = Convert.ToDateTime(parameters[4]); DateTime dateOfTermination; if ((parameters[5].Equals("N/A")) || (parameters[5].Equals("n/a"))) { dateOfTermination = new DateTime(); } else { dateOfTermination = Convert.ToDateTime(parameters[5]); } Double salary = Convert.ToDouble(parameters[6]); FullTimeEmployee tempEmployee = new FullTimeEmployee(parameters[0], parameters[1], parameters[2], dateOfBirth, dateOfHire, dateOfTermination, salary); status = Add(tempEmployee); } catch (Exception e) { status = false; } } return(status); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string id = Request.Params["Id"]; if (id != null && !id.Equals("")) { EmployeeController EC = new EmployeeController(); Employee emp = EC.GetEmployee(Convert.ToInt32(id)); if (emp.GetType() == typeof(FullTimeEmployee)) { FullTimeEmployee em = (FullTimeEmployee)emp; Name.Text = em.Name; StartDate.SelectedDate = em.StartDate; RadioButtonType.SelectedValue = "Full Time Employee"; Salary.Text = em.Salary.ToString(); HourlyRate.Enabled = false; } else { PartTimeEmployee em = (PartTimeEmployee)emp; Name.Text = em.Name; StartDate.SelectedDate = em.StartDate; RadioButtonType.SelectedValue = "Part Time Employee"; HourlyRate.Text = em.HourlyRate.ToString(); Salary.Enabled = false; } } } }
private Employee Casteo(Model.Employee emp) { if (emp == null) { return(null); } if (emp.GetType().Name == "FullTimeEmployee") { Model.FullTimeEmployee Memp = (Model.FullTimeEmployee)emp; FullTimeEmployee employeeBase = new FullTimeEmployee() { Id = Memp.EmployeeId, Name = Memp.Name, StartDate = Memp.StartDate, Salary = Memp.Salary }; return(employeeBase); } else { Model.PartTimeEmployee Memp = (Model.PartTimeEmployee)emp; PartTimeEmployee employeeBase = new PartTimeEmployee() { Id = Memp.EmployeeId, Name = Memp.Name, StartDate = Memp.StartDate, HourlyRate = Memp.HourlyRate }; return(employeeBase); } }
private Model.Employee Casteo(Employee emp) { if (emp == null) { return(null); } if (emp.GetType().Name == "FullTimeEmployee") { FullTimeEmployee employee = (FullTimeEmployee)emp; Model.FullTimeEmployee employeeBase = new Model.FullTimeEmployee() { Name = employee.Name, StartDate = employee.StartDate, Salary = employee.Salary }; return(employeeBase); } else { PartTimeEmployee employee = (PartTimeEmployee)emp; Model.PartTimeEmployee employeeBase = new Model.PartTimeEmployee() { Name = employee.Name, StartDate = employee.StartDate, HourlyRate = employee.HourlyRate }; return(employeeBase); } }
public ActionResult Create(FormCollection collection) { try { // TODO: Add insert logic here if (collection["Type"] == "1") { PartTimeEmployee emp = new PartTimeEmployee(); emp.Name = collection["Name"]; emp.StartDate = DateTime.Parse(collection["StartDate"]); emp.HourlyRate = Convert.ToInt32(collection["Salary"]); _bl.AddEmployee(emp); } else { if (collection["Type"] == "2") { FullTimeEmployee emp = new FullTimeEmployee(); emp.Name = collection["Name"]; emp.StartDate = DateTime.Parse(collection["StartDate"]); emp.Salary = Convert.ToInt32(collection["Salary"]); _bl.AddEmployee(emp); } } return(RedirectToAction("Index")); } catch { return(View()); } }
public void AddEmployee(Employee emp) { if (emp != null) { using (Model.Practico_EntregableEntities en = new Model.Practico_EntregableEntities()) { if (emp.GetType().Name == "PartTimeEmployee") { PartTimeEmployee Pte = (PartTimeEmployee)emp; Model.PartTimeEmployee obj = new Model.PartTimeEmployee() { Name = Pte.Name, StartDate = Pte.StartDate, HourlyRate = Pte.HourlyRate }; en.Employee.Add(obj); en.SaveChanges(); } else { FullTimeEmployee Fte = (FullTimeEmployee)emp; Model.FullTimeEmployee obj = new Model.FullTimeEmployee() { Name = Fte.Name, StartDate = Fte.StartDate, Salary = Fte.Salary }; en.Employee.Add(obj); en.SaveChanges(); } } } }
private Employee cast(Model.EmployeesTPH emp) { if (emp == null) { return(null); } if (emp.GetType().Name == "FullTimeEmployee") { Model.FullTimeEmployees employee = (Model.FullTimeEmployees)emp; FullTimeEmployee employeeBase = new FullTimeEmployee() { Id = employee.EmployeeId, Name = employee.name, StartDate = employee.StartDate, Salary = employee.Salary }; return(employeeBase); } else { Model.PartTimeEmployees employee = (Model.PartTimeEmployees)x; PartTimeEmployee employeeBase = new PartTimeEmployee() { Id = employee.EmployeeId, Name = employee.name, StartDate = employee.StartDate, HourlyRate = employee.HourlyRate }; return(employeeBase); } }
public static void Main() { //---------------------------------------------------------------------------------------------------- // Here we are creating object of derived class and accessing the property of base and derived class. //--------------------------------------------------------------------------------------------------- FullTimeEmployee FTE = new FullTimeEmployee(); FTE.FirstName = "John"; FTE.LastName = "Doe"; FTE.Email = "*****@*****.**"; FTE.YearlySalary = 500000; FTE.FullName(); PartTimeEmployee PTE = new PartTimeEmployee(); PTE.FirstName = "Jimmi"; PTE.LastName = "Suyang"; PTE.Email = "*****@*****.**"; PTE.HourlyPay = 10; PTE.FullName(); //---------------------------------------------------------------------------------------------------- // Note : Here in 'FullTimeEmployee' we cannot access property of 'PartTimeEmployee' as 'HourlyPay' // because it is specific to 'FullTimeEmployee' and Vice-Versa // Here we able to re-use the member of base class. //--------------------------------------------------------------------------------------------------- }
private void LoadTextFull(FullTimeEmployee full) { Cedula.Text = full.Id.ToString(); Nombre.Text = full.Name; FechaIng.Value = full.StartDate; Salario.Text = full.Salary.ToString(); }
public static void Main(string[] args) { //Console.WriteLine("Hello World"); //abstract class initialisation is prevented during compile time. //BaseEmployee be =new BaseEmployee(); FullTimeEmployee fte = new FullTimeEmployee() { ID = 101, first_name = "Arun", last_name = "May", anual_salary = 10000 }; ContractEmployee cte = new ContractEmployee() { ID = 102, first_name = "Vel", last_name = "murugan", total_hours = 40, months = 12 }; Console.WriteLine(cte.GetFullName()); Console.WriteLine(cte.GetMonthlySalary()); Console.WriteLine(fte.GetFullName()); Console.WriteLine(fte.GetMonthlySalary()); }
internal static int Main() { // Using an interface makes the code more flexible // but ensures at the same time that the commitments // of an Employee are fulfilled. IEmployable Max = new FullTimeEmployee() { FirstName = "Max", LastName = "Mustermann", AnnualSalary = 60000 }; Console.WriteLine($"{Max.GetFullName()} earns {Max.GetMonthlySalary()} per month."); Max.WorkOn(); Console.WriteLine(); IEmployable Moritz = new Freelancer() { FirstName = "Moritz", LastName = "Mustermann", HourlyWage = 200, HoursWorked = 20 }; Console.WriteLine($"{Moritz.GetFullName()} worked {((Freelancer)Moritz).HoursWorked} hours and earned {Moritz.GetMonthlySalary()} last month."); Moritz.WorkOn(); Console.WriteLine("\nProgram end reached. Press the any-key to exit."); Console.ReadKey(); return(0); }
// GET: Employees/Details/5 public ActionResult Details(int id) { Models.Employee emp = new Models.Employee(); Employee e = _bl.GetEmployee(id); if (e.GetType() == typeof(FullTimeEmployee)) { FullTimeEmployee em = (FullTimeEmployee)e; emp.Id = em.Id; emp.Name = em.Name; emp.StartDate = em.StartDate; emp.Type = 2; emp.Salary = em.Salary; } else { PartTimeEmployee em = (PartTimeEmployee)e; emp.Id = em.Id; emp.Name = em.Name; emp.StartDate = em.StartDate; emp.Type = 2; emp.Salary = Convert.ToInt32(em.HourlyRate); } return(View(emp)); }
private Employee casteo(Model.Employee emp) { if (emp != null) { if (emp.GetType().Name == "FullTimeEmployee") { Model.FullTimeEmployee x = (Model.FullTimeEmployee)emp; FullTimeEmployee employeeBase = new FullTimeEmployee() { Id = x.EmployeeId, Name = x.Name, StartDate = x.StartDate, Salary = x.Salary }; return(employeeBase); } else { Model.PartTimeEmployee x = (Model.PartTimeEmployee)emp; PartTimeEmployee employeeBase = new PartTimeEmployee() { Id = x.EmployeeId, Name = x.Name, StartDate = x.StartDate, HourlyRate = x.HourlyRate }; return(employeeBase); } } return(null); }
public static void Main() { //class Inheritance FullTimeEmployee FTE = new FullTimeEmployee(); FTE.FirstName = "Yuvi"; FTE.LastName = "cad"; FTE.YearlySalary = 30000; FTE.PrintFullName(); PartTimeEmployee PTE = new PartTimeEmployee(); PTE.FirstName = "Jack"; PTE.LastName = "Cloud"; PTE.HourlySalary = 300; PTE.PrintFullName(); //polymorphism CompanyEmployee[] employee = new CompanyEmployee[3]; employee[0] = new CompanyEmployee(); employee[1] = new CompanyFullTimeEmployee(); employee[2] = new CompanyPartTimeEmployee(); foreach (CompanyEmployee e in employee) { e.PrintEmployeeName(); } }
public void Execute(object parameter) { try { if (_source.SelectedType == 1) { Employee employee = new Employee(); employee = new FullTimeEmployee { Id = _source.Employee.Id, Name = _source.Employee.Name, Gender = _source.Employee.Gender, Dateofb = _source.Employee.Dateofb, Type = EmployeeType.FullTimeEmployee, AnnualSalary = ((FullTimeEmployeeObj)_source.Employee).AnnualSalary }; _source.EmployeeService.SaveEmployee(employee); _source.UserNotification = "Full Time Employee saved"; _source.GetAllEmployees(); } else if (_source.SelectedType == 2) { Employee employee = new Employee(); employee = new PartTimeEmployee { Id = _source.Employee.Id, Name = _source.Employee.Name, Gender = _source.Employee.Gender, Dateofb = _source.Employee.Dateofb, Type = EmployeeType.PartTimeEmployee, HourlyPay = ((PartTimeEmployeeObj)_source.Employee).HourlyPay, HoursWorked = ((PartTimeEmployeeObj)_source.Employee).HoursWorked }; _source.EmployeeService.SaveEmployee(employee); _source.UserNotification = "Part Time Employee saved"; _source.GetAllEmployees(); } else { _source.UserNotification = "Please select an employee"; } } catch (Exception ex) { _source.UserNotification = ex.Message; } }
protected void btnSaveEmployee_Click(object sender, EventArgs e) { try { IBiduleService client = new BiduleServiceClient(); //IEmployeeService client = new EmployeeServiceClient(); Employee employee = new Employee(); if ((EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue) == EmployeeType.FullTimeEmployee) { employee = new FullTimeEmployee { Id = Convert.ToInt32(txtID.Text), Name = txtName.Text, Gender = txtGender.Text, Dateofb = Convert.ToDateTime(txtDateofb.Text), Type = EmployeeType.FullTimeEmployee, AnnualSalary = Convert.ToInt32(txtAnnualSalary.Text) }; client.SaveEmployee(employee); LblMessage.Text = "Full time employee saved"; } else if ((EmployeeType)Convert.ToInt32(ddlEmployeeType.SelectedValue) == EmployeeType.PartTimeEmployee) { employee = new PartTimeEmployee { Id = Convert.ToInt32(txtID.Text), Name = txtName.Text, Gender = txtGender.Text, Dateofb = Convert.ToDateTime(txtDateofb.Text), Type = EmployeeType.PartTimeEmployee, HourlyPay = Convert.ToInt32(txtHourlyPay.Text), HoursWorked = Convert.ToInt32(txtHoursworked.Text) }; client.SaveEmployee(employee); LblMessage.Text = "Part time employee saved"; } else { LblMessage.Text = "Please select Employee type"; } } catch (FaultException faultException) { LblMessage.Text = faultException.Message; } }
public List<Employee> GetAllEmployees() { try { List<Employee> listEmployees = new List<Employee>(); LogDeb.LogException("EmployeeService", "GetAllEmployees", "GetAllEmployees Debut Ok"); //Employee employee = new Employee(); Employee employee = null; string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("spGetAllEmployees", con); cmd.CommandType = CommandType.StoredProcedure; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if ((EmployeeType)reader["EmployeeType"] == EmployeeType.FullTimeEmployee) { employee = new FullTimeEmployee { Id = Convert.ToInt32(reader["Id"]), Name = reader["Name"].ToString(), Gender = reader["Gender"].ToString(), Dateofb = Convert.ToDateTime(reader["Dateofb"]), AnnualSalary = Convert.ToInt32(reader["AnnualSalary"]), Type = EmployeeType.FullTimeEmployee }; listEmployees.Add(employee); } else { employee = new PartTimeEmployee { Id = Convert.ToInt32(reader["Id"]), Name = reader["Name"].ToString(), Gender = reader["Gender"].ToString(), Dateofb = Convert.ToDateTime(reader["Dateofb"]), HourlyPay = Convert.ToInt32(reader["HourlyPay"]), HoursWorked = Convert.ToInt32(reader["HoursWorked"]), Type = EmployeeType.PartTimeEmployee }; listEmployees.Add(employee); } } } LogDeb.LogException("EmployeeService", "GetAllEmployees", "GetAllEmployees End Ok"); return listEmployees; } catch (Exception ex) { LogDeb.LogException("EmployeeService", "GetEmployee", "Error :" + ex.Message); throw ex; } }
public Employee GetEmployeeDB(int Id) { try { //if (Id == 0) // throw new FaultException("Id égal a zero",new FaultCode("IdIsEqualToZero")); LogDeb.LogException("EmployeeService", "GetEmployee", "GetEmployee Debut Ok"); //Employee employee = new Employee(); Employee employee = null; string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand("spGetEmployee", con); cmd.CommandType = CommandType.StoredProcedure; SqlParameter parameterId = new SqlParameter(); parameterId.ParameterName = "@Id"; parameterId.Value = Id; cmd.Parameters.Add(parameterId); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { if ((EmployeeType)reader["EmployeeType"] == EmployeeType.FullTimeEmployee) { employee = new FullTimeEmployee { Id = Convert.ToInt32(reader["Id"]), Name = reader["Name"].ToString(), Gender = reader["Gender"].ToString(), Dateofb = Convert.ToDateTime(reader["Dateofb"]), AnnualSalary = Convert.ToInt32(reader["AnnualSalary"]), Type = EmployeeType.FullTimeEmployee }; } else { employee = new PartTimeEmployee { Id = Convert.ToInt32(reader["Id"]), Name = reader["Name"].ToString(), Gender = reader["Gender"].ToString(), Dateofb = Convert.ToDateTime(reader["Dateofb"]), HourlyPay = Convert.ToInt32(reader["HourlyPay"]), HoursWorked = Convert.ToInt32(reader["HoursWorked"]), Type = EmployeeType.PartTimeEmployee }; } } } LogDeb.LogException("EmployeeService", "GetEmployee", "Employee : " + employee.Id + " - " + employee.Name + " - " + employee.Type + " "); LogDeb.LogException("EmployeeService", "GetEmployee", "GetEmployee End Ok"); return employee; } catch (Exception ex) { LogDeb.LogException("EmployeeService", "GetEmployee", "Error :" + ex.Message); throw ex; } //// throw new FaultException<ZeroFault>(zeroException); //// //return null; ////} //catch (FaultException faultException) //{ // LogDeb.LogException("EmployeeService", "GetEmployee", faultException.Message); // return null; //} }
public List<Employee> GetAllEmployeesDummy() { try { List<Employee> listEmployees = new List<Employee>(); LogDeb.LogException("EmployeeService", "GetAllEmployees", "GetAllEmployees Debut Ok"); Employee employee = null; employee = new FullTimeEmployee { Id = 1, Name = "Name Dummy 1", Gender = "M", Dateofb = Convert.ToDateTime("21/10/1990"), AnnualSalary = 35000, Type = EmployeeType.FullTimeEmployee }; listEmployees.Add(employee); employee = new PartTimeEmployee { Id = 2, Name = "Name Dummy 2", Gender = "M", Dateofb = Convert.ToDateTime("21/10/1990"), HourlyPay = 150, HoursWorked = 2500, Type = EmployeeType.PartTimeEmployee }; listEmployees.Add(employee); LogDeb.LogException("EmployeeService", "GetAllEmployees", "GetAllEmployees End Ok"); return listEmployees; } catch (Exception ex) { LogDeb.LogException("EmployeeService", "GetEmployee", "Error :" + ex.Message); throw ex; } }
/// <summary> /// Method Name: UpdateEmployeeData. /// The purpose of this method is to allow a user to enter a SIN corresponding to an employee that they wish to update. /// A menu will then be presented in the console that will allow the user to update specific attributes found in any /// of the four employee types. The user also has the option of changing all attributes. /// </summary> /// <returns></returns> public bool UpdateEmployeeData() { // initialize local variables int foundElement = 0; String SIN = ""; int returnedResult = 0; bool result = false; float salary = 0, hourlyRate = 0, piecePay = 0, contractorsFixedAmount = 0; int i = 0; String input = ""; String firstName = ""; String lastName = ""; String temp = ""; // create objects of each type of employee to be used depending on what type of employee // the user is updating Employee baseEmployee = new Employee(); FullTimeEmployee ftEmployee = new FullTimeEmployee(); PartTimeEmployee ptEmployee = new PartTimeEmployee(); ContractEmployee cEmployee = new ContractEmployee(); SeasonalEmployee sEmployee = new SeasonalEmployee(); // get the user to enter a SIN number of the employee they would like to update Console.WriteLine("Please enter the SIN number of the employee you would like to update:"); // get the user to enter the sin until SIN = Console.ReadLine().Replace(" ", "") ; // reset the returnedResult returnedResult = 0; // find the element based on the employee's SIN number for (i = 0; i < databaseContainer.Count; i++) { // if the sin number is found in the database set the // found element to be that index if (databaseContainer[i].GetSocialNumber() == SIN) { foundElement = i; returnedResult++; } } // if the result was 0 then the Employee with the SIN entered from the user // was not found in the database - return false if (returnedResult == 0) { Console.WriteLine("Could not find employee with the specified SIN"); logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'M', 'F', (databaseContainer[foundElement].GetFirstName() + " " + databaseContainer[foundElement].GetLastName())); return false; } // until the user presses 9 allow them to update the employee with the SIN they // previously entered while (input != "9") { // clear the console and display the menu Console.Clear(); // set the baseEmployee to be the employee found in the database baseEmployee = databaseContainer[foundElement]; Console.WriteLine("Currently Updating : {0} {1}", databaseContainer[foundElement].GetFirstName(), databaseContainer[foundElement].GetLastName()); Console.WriteLine("Updates Available:"); Console.WriteLine("\t1. First Name."); Console.WriteLine("\t2. Last Name/Business."); Console.WriteLine("\t3. SIN."); Console.WriteLine("\t4. Date Of Birth."); Console.WriteLine("\t5. Date Of Hire, Contract Start Date, Season"); Console.WriteLine("\t6. Salary, PiecePay, Fixed Contract Amount, Hourly Wage"); Console.WriteLine("\t7. Date of Termination, Contract End Date"); Console.WriteLine("\t8. Update All Information"); Console.WriteLine("\t9. Exit"); // read the user's menu choice input = Console.ReadLine(); // if the option is 1 to 4 then no casting needs to be done to find out which // type of employee it is because those attributes are found in all employees if (input == "1" || input == "2" || input == "3" || input == "4") { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'M', 'S', (databaseContainer[foundElement].GetFirstName() + " " + databaseContainer[foundElement].GetLastName())); // switch on the input switch (input) { // modify the first name case "1": if (baseEmployee.GetEmployeeType() != "CT") { // display the current employee's firstname Console.WriteLine("Current employee's first name: {0} \n", baseEmployee.GetFirstName()); // get the employee's first name, make the user enter it until // it is valid Console.WriteLine("Please enter a new first name:"); firstName = Console.ReadLine().Replace(" ", ""); if (firstName == "") { result = false; } else { result = baseEmployee.SetFirstName(firstName); } while (result == false) { Console.WriteLine("Please re-enter a valid employee's first name:"); firstName = Console.ReadLine().Replace(" ", ""); if (firstName == "") { result = false; } else { result = baseEmployee.SetFirstName(firstName); } } } break; // modify the last name case "2": if (baseEmployee.GetEmployeeType() != "CT") { // display the current employee's last name Console.WriteLine("Current employee's last name: {0}\n", baseEmployee.GetLastName()); // get the employee's last name, make the user enter a last name // until it is a valid string Console.WriteLine("Please enter a new last name:"); lastName = Console.ReadLine().Replace(" ", ""); if (lastName == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } while (result == false) { Console.WriteLine("Please re-enter a valid employee's last name:"); lastName = Console.ReadLine().Replace(" ", ""); if (lastName == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } } } else { Console.WriteLine("Please enter a bussiness name:"); lastName = Console.ReadLine(); temp = lastName.Replace(" ", ""); if (temp == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } while (result == false) { Console.WriteLine("Please re-enter a valid business name:"); lastName = Console.ReadLine(); temp = lastName.Replace(" ", ""); if (temp == "") { result = false; } else { result = baseEmployee.SetLastName(lastName); } } } break; // modify the employee's social insurance number case "3": // display the current employee's social insurance number Console.WriteLine("Current employee's social insurance number : {0}\n", baseEmployee.GetSocialNumber()); // get the employee's social insurance number, make user re-enter the SIN until // it is valid Console.WriteLine("Please enter the employee's Social Insurance Number:"); while (result == false) { Console.WriteLine("Please re-enter a valid employee's Social Insurance Number:"); result = baseEmployee.SetSocialNumber(Console.ReadLine()); } break; // modify the employee's date of birth case "4": // display the current employee's date of birth Console.WriteLine("Current employee's date of birth : {0}\n", baseEmployee.GetDateOfBirth().ToShortDateString()); // get the employee's date of birth, make the user re-enter the birth date until // it is valid Console.WriteLine("Please enter the employee's date of birth <YYYY-MM-DD>:"); result = baseEmployee.SetDateOfBirth(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid employee's date of birth <YYYY-MM-DD>:"); result = baseEmployee.SetDateOfBirth(Console.ReadLine()); } break; } } // if were modifying attributes under the menu options 5 - 8 // then the attributes change accordingly to which type of employee being modified else { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'M', 'F', (databaseContainer[foundElement].GetFirstName() + " " + databaseContainer[foundElement].GetLastName())); // switch on the employee type switch (databaseContainer[foundElement].GetEmployeeType()) { // if it's a full time employee being modified then: // // date of hire is being modifited when option 5 is pressed // yearly salary is being modified when option 6 is pressed // date of termination is being modified when option 7 is pressed case "FT": // cast the base employee as a full time employee ftEmployee = (FullTimeEmployee)baseEmployee; switch (input) { // update date of hire case "5": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current Date of Hire : {0}", ftEmployee.GetDateOfHire().ToShortDateString()); // get the date the employee was hired Console.WriteLine("Please enter the date the employee was hired"); // get teh new date until it is valid result = ftEmployee.SetDateOfHire(Console.ReadLine()); while (result == false) { Console.WriteLine("Please enter a valid date in which the employee was hired"); result = ftEmployee.SetDateOfHire(Console.ReadLine()); } break; // update yearly salary case "6": // display the current salary and get the user to enter a new salary Console.WriteLine("Current Salary is : {0}", ftEmployee.GetSalary()); // get the employee's yearly salary Console.WriteLine("Please enter the employee's yearly salary (example 45000.54):"); while (true) { try { salary = float.Parse(Console.ReadLine()); ftEmployee.SetSalary(salary); break; } catch { Console.WriteLine("Please re-enter a valid employee's salary (example 45000.54):"); } } break; // update the date of termination case "7": // display the current salary and get the user to enter a new salary Console.WriteLine("Current date of Termination is : {0}", ftEmployee.GetDateOfTermination().ToShortDateString()); // get the date of termination if the employee was fired Console.WriteLine("Please enter a date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ftEmployee.SetDateOfTermination(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ftEmployee.SetDateOfTermination(Console.ReadLine()); } break; // update all employee information case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); ftEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddFullTimeEmployee(); break; } break; // if the employee type is a part time employee then: // // option 5 updates the employee's date of hire // option 6 updates the employee's hourly wage // option 7 updates the employee's date of termination // option 8 updates all fields case "PT": // cast the base employee as a part time employee ptEmployee = (PartTimeEmployee)baseEmployee; // switch on the input number switch (input) { // update the employee's hire date case "5": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current Date of Hire : {0}", ptEmployee.GetDateOfHire().ToShortDateString()); // get the new date from the user Console.WriteLine("Please enter the date the employee was hired <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfHire(Console.ReadLine()); while (result == false) { Console.WriteLine("Please enter a valid date in which the employee was hired <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfHire(Console.ReadLine()); } break; // update the employee's hourly wages case "6": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current employee's hourly wages : {0}", ptEmployee.GetHourlyWage()); // get the employee's hourly wages Console.WriteLine("Please enter the employee's hourly wage(ie. 15.00):"); while (true) { try { // attempt to parse if it does not succeed then it will throw an exception hourlyRate = float.Parse(Console.ReadLine()); ptEmployee.SetHourlyRate(hourlyRate); break; } catch { // display the error message to the user Console.WriteLine("Please re-enter a valid employee's hourly wage(ie. 15.00):"); } } break; // update the employee's date of termination case "7": // display the current date of hire and get the user to enter the // new date of hire Console.WriteLine("Current Employee's date of termination : {0}", ftEmployee.GetDateOfTermination().ToShortDateString()); // get the new date of termination Console.WriteLine("Please enter a date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfTermination(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid date of termination or enter a '0' if the \nemployee is still employed at your company <YYYY-MM-DD>:"); result = ptEmployee.SetDateOfTermination(Console.ReadLine()); } break; case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); ptEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddPartTimeEmployee(); break; } break; // if were modifying a Contract Employee then // // option 5 is modifying the date in which the contract employee started // option 6 is the fixed contract amount // option 7 is modifying the date in which the contract employee ended their work case "CT": // cast the base employee as a contract employee cEmployee = (ContractEmployee)baseEmployee; switch (input) { // modify the date which the contract employee started case "5": // display the current date the empployee began Console.WriteLine("Current contract employee's start date : {0}", cEmployee.GetContractStartDate().ToShortDateString()); // get the start date in which the contractor began work Console.WriteLine("Please enter the start date for the contracted employee <YYYY-MM-DD>:"); result = cEmployee.SetContractStartDate(Console.ReadLine()); while (result == false) { Console.WriteLine("Please enter a valid date in which the employee was hired <YYYY-MM-DD>:"); result = cEmployee.SetContractStopDate(Console.ReadLine()); } break; // modify the fixed amount pay the contractor received case "6": // display the current fixed amount pay the contractor received Console.WriteLine("Current contractor's fixed pay amount : {0}", cEmployee.GetFixedContractAmount()); // get the contractor's fixed amount of pay Console.WriteLine("Please enter the contractor's fixed amount of pay (e.g. 4570.80):"); while (true) { try { contractorsFixedAmount = float.Parse(Console.ReadLine()); cEmployee.SetFixedContractAmount(contractorsFixedAmount); break; } catch { Console.WriteLine("Please re-enter a valid contractor's fixed amount of pay (e.g. 4570.80):"); } } break; // modify the date in which the contractor ended work case "7": // display the current date the empployee began Console.WriteLine("Current contract employee's stop date : {0}", cEmployee.GetContractStopDate().ToShortDateString()); // get the date in which the contractor ended the work Console.WriteLine("Please enter the date the contractor ended \nworking for your company <YYYY-MM-DD>:"); result = cEmployee.SetContractStopDate(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter the date the contractor \nended working for your company <YYYY-MM-DD>:"); result = cEmployee.SetContractStopDate(Console.ReadLine()); } break; // modify all the data in the current contract employee case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); cEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddContractEmployee(); break; } break; // if we are modifying a seasonal employee // // option 5 modifies the season in which the employee was employed // option 6 modifies the piece pay in which the employee received while employed // option 8 modifies all the attributes case "SN": sEmployee = (SeasonalEmployee)baseEmployee; switch (input) { // modify the season case "5": // display the season in which the employee was employed Console.WriteLine("Current employee's season of employment : {0}", sEmployee.GetSeason()); // get the season in which the employee was employed Console.WriteLine("Please enter the season in which the employee was employed:"); result = sEmployee.SetSeason(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid season in which the employee was employed:"); result = sEmployee.SetSeason(Console.ReadLine()); } break; // modify the piece pay case "6": // display the season in which the employee was employed Console.WriteLine("Current employee's piece pay : {0}", sEmployee.GetPiecePay()); // get the pay in which the employee received Console.WriteLine("Please enter the piece pay which the employee received for their work:"); while (true) { try { piecePay = float.Parse(Console.ReadLine()); sEmployee.SetPiecePay(piecePay); break; } catch { Console.WriteLine("Please re-enter a valid piece in which the employee received for their work:"); } } break; // modify all attributes case "8": Console.Clear(); Console.WriteLine("Employee's current information:"); sEmployee.Details(); Console.WriteLine("\n"); // if the user is updating all data for an employee remove the current one // and get them to update all fields by calling the add function databaseContainer.RemoveAt(foundElement); this.AddSeasonalEmployee(); break; } break; }/* End Switch */ }/* End Else Statement*/ }/* End While Loop*/ return true; }
/// <summary> /// Method Name: AddFullTimeEmployee. /// The purpose of thsi function is to get the data associated with a Full Time Employee from the user, and /// add it to the database. The data will be validated before it is added to the database. Any errors /// will be indicated to the user. /// </summary> /// <returns></returns> private bool AddFullTimeEmployee() { // create a Full Time employee object which will house the following information // for this full time employee FullTimeEmployee entry = new FullTimeEmployee(); // declare local variables bool result = false; float salary = 0; this.SetBaseAttributes(entry); // get the date the employee was hired Console.WriteLine("Please enter the date the employee was hired <YYYY-MM-DD>:"); result = entry.SetDateOfHire(Console.ReadLine()); while (result == false) { Console.WriteLine("Please enter a valid date in which the employee was hired <YYYY-MM-DD>:"); result = entry.SetDateOfHire(Console.ReadLine()); } // get the employee's yearly salary Console.WriteLine("Please enter the employee's yearly salary (example 45000.54):"); while (true) { try { salary = float.Parse(Console.ReadLine().Replace("$", "")); if (entry.SetSalary(salary) != false) { break; } else { Console.WriteLine("Please re-enter a valid employee's salary (example 45000.54):"); } } catch { Console.WriteLine("Please re-enter a valid employee's salary (example 45000.54):"); } } // get the date of termination if the employee was fired Console.WriteLine("Please enter a date of termination or enter a '0' if the employee is still employed at your company:"); result = entry.SetDateOfTermination(Console.ReadLine()); while (result == false) { Console.WriteLine("Please re-enter a valid date of termination or enter a '0' if the employee is still employed at your company:"); result = entry.SetDateOfTermination(Console.ReadLine()); } // validate the employee information if (entry.Validate() == false) { logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'A', 'F', "Full-Time Employee"); Console.WriteLine("There was an error with the employee entered. Please add the employee again."); return false; } // add the entry to the database try { databaseContainer.Add(entry); } catch { // if there was an error indicate to the user that the employee could not be added to the database Console.WriteLine("The employee could not be added to the database."); logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'A', 'F', "Full-Time Employee"); return false; } Console.Clear(); Console.WriteLine("\nThe employee added was:\n"); logfile.Log(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name, 'A', 'S', "Full-Time Employee"); entry.Details(); return true; }
/// <summary> /// Method Name: LoadDatabase. /// The purpose of this method is to parse an input string from a file into objects to be added to the database. This method /// ensures that all of the database items it is creating are valid, else it will not create them. The format /// in which a database item is read in is as such: /// (Employee Type)|(Last Name)|(First Name)|(SIN)|(SubField1)|(SubField2)|(SubField3)| /// </summary> /// <returns>A boolean value of true upon completion.</returns> public bool LoadDatabase() { String fileInput = ""; FullTimeEmployee ft = new FullTimeEmployee(); PartTimeEmployee pt = new PartTimeEmployee(); ContractEmployee c = new ContractEmployee(); SeasonalEmployee s = new SeasonalEmployee(); String currentType = ""; String tempSin = ""; Boolean sinValid = true; String[] objects; //Read in the data from the database file. FileStream db = databaseFile.Openfile("dbase.dtb", 'R'); fileInput = databaseFile.ReadFromFile(db); databaseFile.CloseFile(db); //Remove null terminations and carrige returns. fileInput = fileInput.Replace("\0", ""); fileInput = fileInput.Replace("\r", ""); //Split up the fields for each new line. objects = fileInput.Split('\n'); //Initialize an multi-array for each attribute. String[][] attributes = new String[objects.Length][]; for (int k = 0; k < objects.Length; k++) { attributes[k] = new String[10]; } //For each object to be entered into the database. for (int i = 0; i < objects.Length; i++) { //Reset the valid SIN flag to true. sinValid = true; //Split up the object into attributes. attributes[i] = objects[i].Split('|'); //For each attribute in the current object. for (int j = 0; j < attributes[i].Length; j++) { //If the current attribute is the employee identifier. if (j == 0) { //Check what type of employee the object is. switch (attributes[i][0]) { //If the employee is a Full Time employee. case "FT": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the full Time employee object to house the attributes. ft = new FullTimeEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //If the employee is a Part Time employee. case "PT": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the Part Time employee object to house the attributes. pt = new PartTimeEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //If the employee is a Contract Employee. case "CT": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the Contract employee object to house the attributes. c = new ContractEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //If the employee is a Seasonal Employee. case "SN": //If the SIN number is valid. if (ft.CheckSinNumber(attributes[i][3])) { //Reset the Seasonal Employee object to house the attributes. s = new SeasonalEmployee(); //Insert the employee type into the current employee object. currentType = attributes[i][0]; } else { //Set the valid SIN flag to false. sinValid = false; //Break the current object's cycle of the for loop. j = attributes.Length; } break; //Not a valid employee type. default: //Nullify the current employee type. currentType = ""; //Break the current object's cycle of the for loop. j = attributes.Length; break; } } //If the current attribute is not the employee identifier. else { //Check the current employee type. switch (currentType) { //If the current employee is a Full Time employee case "FT": //Switch based the the current attribute being read in. switch (j) { //Set the first name. case 1: //Make sure there are no spaces. attributes[i][j] = attributes[i][j].Replace(" ", ""); ft.SetLastName(attributes[i][j]); break; //Set the last name. case 2: //Make sure there are no spaces. attributes[i][j] = attributes[i][j].Replace(" ", ""); ft.SetFirstName(attributes[i][j]); break; //Set the SIN number. case 3: if (ft.CheckSinNumber(attributes[i][j])) { //Make sure there are no spaces in the SIN number. attributes[i][j] = attributes[i][j].Replace(" ", ""); ft.SetSocialNumber(attributes[i][j]); } break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { ft.SetDateOfBirth(new DateTime(0)); } else { ft.SetDateOfBirth(attributes[i][j]); } break; //Set the Date of Hire. case 5: if (attributes[i][j] == "N/A") { ft.SetDateOfHire(new DateTime(0)); } else { ft.SetDateOfHire(attributes[i][j]); } break; //Set the Date of Termination. case 6: if (attributes[i][j] == "N/A") { ft.SetDateOfTermination(new DateTime(0)); } else { ft.SetDateOfTermination(attributes[i][j]); } break; //Set the current Salary. case 7: try { ft.SetSalary(float.Parse(attributes[i][j])); } catch { } break; } break; //If the current employee is a Part Time employee. case "PT": //Switch based on the current attribute. switch (j) { //Set the first name. case 1: attributes[i][j] = attributes[i][j].Replace(" ", ""); pt.SetLastName(attributes[i][j]); break; //Set the last name. case 2: attributes[i][j] = attributes[i][j].Replace(" ", ""); pt.SetFirstName(attributes[i][j]); break; //Set the sin number. case 3: if (pt.CheckSinNumber(attributes[i][j])) { attributes[i][j] = attributes[i][j].Replace(" ", ""); pt.SetSocialNumber(attributes[i][j]); } break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { pt.SetDateOfBirth(new DateTime(0)); } else { pt.SetDateOfBirth(attributes[i][j]); } break; //Set the Date of Hire. case 5: if (attributes[i][j] == "N/A") { pt.SetDateOfHire(new DateTime(0)); } else { pt.SetDateOfHire(attributes[i][j]); } break; //Set the Date of Termination. case 6: if (attributes[i][j] == "N/A") { pt.SetDateOfTermination(new DateTime(0)); } else { pt.SetDateOfTermination(attributes[i][j]); } break; //Set the Hourly Rate. case 7: try { pt.SetHourlyRate(float.Parse(attributes[i][j])); } catch { } break; } break; //If the current employee is a Contract Employee. case "CT": switch (j) { //Set the last name. case 1: attributes[i][j] = attributes[i][j].Replace(" ", ""); c.SetLastName(attributes[i][j]); break; //Set the first name. case 2: attributes[i][j] = attributes[i][j].Replace(" ", ""); c.SetFirstName(attributes[i][j]); break; //Set the SIN number. case 3: tempSin = attributes[i][j]; break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { c.SetDateOfBirth(new DateTime(0)); } else { c.SetDateOfBirth(attributes[i][j]); } if (c.CheckSinNumber(tempSin)) { tempSin = tempSin.Replace(" ", ""); c.SetSocialNumber(tempSin); } break; //Set the Contract Start Date. case 5: if (attributes[i][j] == "N/A") { c.SetContractStartDate(new DateTime(0)); } else { c.SetContractStartDate(attributes[i][j]); } break; //Set the Contract End Date. case 6: if (attributes[i][j] == "N/A") { c.SetContractStartDate(new DateTime(0)); } else { c.SetContractStopDate(attributes[i][j]); } break; case 7: try { c.SetFixedContractAmount(float.Parse(attributes[i][j])); } catch { } break; } break; //If the current employee is a Seasonal Employee. case "SN": //Switch based on the current attribute. switch (j) { //Set the last name. case 1: attributes[i][j] = attributes[i][j].Replace(" ", ""); s.SetLastName(attributes[i][j]); break; //Set the first name. case 2: attributes[i][j] = attributes[i][j].Replace(" ", ""); s.SetFirstName(attributes[i][j]); break; //Set the SIN number. case 3: if (s.CheckSinNumber(attributes[i][j])) { attributes[i][j] = attributes[i][j].Replace(" ", ""); s.SetSocialNumber(attributes[i][j]); } break; //Set the Date of Birth. case 4: if (attributes[i][j] == "N/A") { s.SetDateOfBirth(new DateTime(0)); } else { s.SetDateOfBirth(attributes[i][j]); } break; //Set the Season. case 5: s.SetSeason(attributes[i][j]); break; //Set the piece pay. case 6: try { s.SetPiecePay(float.Parse(attributes[i][j])); } catch { } break; } break; } } } //If the valid SIN flag was not invalidated. if (sinValid) { //Check the current employee type. switch (currentType) { //If the current employee is a Full Time Employee. case "FT": //Validate the full time employee. if (ft.Validate()) { //Add the employee to the database. databaseContainer.Add(ft); } break; //If the current employee is a Part Time employee. case "PT": //Validate the part tiem employee. if (pt.Validate()) { //Add the employee to the database. databaseContainer.Add(pt); } break; //If the current employee is a Contract employee. case "CT": //Validate the COntract employee. if (c.Validate()) { //Add the employee to the database. databaseContainer.Add(c); } break; //If the current employee is a Seasonal Employee. case "SN": //Validate the seasonal Employee. if (s.Validate()) { //Add the employee to the database. databaseContainer.Add(s); } break; } } } return true; }
/// <summary> /// Method Name: SaveDatabase. /// The purpose of this method is to parse the database into an output string to save to a file. This method /// ensures that all of the database items it is outputting are valid, else it will not ouptut them. The format /// in which a database item is outputted is as such: /// (Employee Type)|(Last Name)|(First Name)|(SIN)|(SubField1)|(SubField2)|(SubField3)| /// </summary> /// <returns></returns> public bool SaveDatabase() { String fileOutput; FullTimeEmployee ft = new FullTimeEmployee(); PartTimeEmployee pt = new PartTimeEmployee(); ContractEmployee c = new ContractEmployee(); SeasonalEmployee s = new SeasonalEmployee(); //Clear the file. FileStream db = databaseFile.Openfile("dbase.dtb", 'W'); databaseFile.WriteToFile(db, ""); databaseFile.CloseFile(db); //Insert a default header comment. fileOutput = ";\r\n;EMS Database File\r\n;Save Date: " + DateTime.Now.ToString() + "\r\n;Comments:\r\n;\r\n"; //For each employee in the database. databaseContainer.ForEach(delegate(Employee entry) { //If the employee is valid. if (entry.Validate()) { //Parse each field for output. fileOutput = fileOutput + entry.GetEmployeeType(); fileOutput = fileOutput + "|" + entry.GetLastName(); fileOutput = fileOutput + "|" + entry.GetFirstName(); fileOutput = fileOutput + "|" + entry.GetSocialNumber(); //If the date is 0 if (entry.GetDateOfBirth() == new DateTime(0)) { //Output N/A fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + entry.GetDateOfBirth().Year + "-" + entry.GetDateOfBirth().Month + "-" + entry.GetDateOfBirth().Day; } //Get the employee type. switch (entry.GetEmployeeType()) { //If the employee is a Full Time employee. case "FT": ft = (FullTimeEmployee)entry; //If the date is 0. if (ft.GetDateOfHire() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + ft.GetDateOfHire().Year + "-" + ft.GetDateOfHire().Month + "-" + ft.GetDateOfHire().Day; } //If the date is 0. if (ft.GetDateOfTermination() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + ft.GetDateOfTermination().Year + "-" + ft.GetDateOfTermination().Month + "-" + ft.GetDateOfTermination().Day; } fileOutput = fileOutput + "|" + ft.GetSalary(); break; //If the employee is a Part Time employee. case "PT": pt = (PartTimeEmployee)entry; //If the date is 0. if (pt.GetDateOfHire() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + pt.GetDateOfHire().Year + "-" + pt.GetDateOfHire().Month + "-" + pt.GetDateOfHire().Day; } //If the date is 0. if (pt.GetDateOfTermination() == new DateTime(0)) { //Out N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + pt.GetDateOfTermination().Year + "-" + pt.GetDateOfTermination().Month + "-" + pt.GetDateOfTermination().Day; } fileOutput = fileOutput + "|" + pt.GetHourlyWage(); break; //If the employee is a Contract Employee. case "CT": c = (ContractEmployee)entry; //If the date is 0. if (c.GetContractStartDate() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + c.GetContractStartDate().Year + "-" + c.GetContractStartDate().Month + "-" + c.GetContractStartDate().Day; } //If the date is 0. if (c.GetContractStopDate() == new DateTime(0)) { //Output N/A. fileOutput = fileOutput + "|" + "N/A"; } else { fileOutput = fileOutput + "|" + c.GetContractStopDate().Year + "-" + c.GetContractStartDate().Month + "-" + c.GetContractStartDate().Day; } fileOutput = fileOutput + "|" + c.GetFixedContractAmount(); break; //The the employee is a Seasonal Employee. case "SN": s = (SeasonalEmployee)entry; fileOutput = fileOutput + "|" + Enum.GetName(typeof(Season), (s.GetSeason())); fileOutput = fileOutput + "|" + s.GetPiecePay(); break; } fileOutput = fileOutput + "|\r\n"; } }); //Write the parsed output string to a file. db = databaseFile.Openfile("dbase.dtb", 'W'); databaseFile.WriteToFile(db, fileOutput); databaseFile.CloseFile(db); return true; }