public static void GetEmployee() { Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "employees.txt"); string curFile = filePath; //Console.WriteLine(File.Exists(curFile) ? "File exists." : "File does not exist."); //List<Employee> employeeList = new List<Employee>(); using StreamReader streamread = new StreamReader(filePath); var allEmployees = streamread.ReadToEnd(); //split each item on new line string[] lines = allEmployees.Split("\n"); foreach (var employee in lines) { if (!String.IsNullOrWhiteSpace(employee)) { string[] createEmployee = employee.Split("|"); string employeeName = createEmployee[0]; string employeeAddress = createEmployee[1]; string payPerHour = createEmployee[2]; decimal payPerHourDec = Convert.ToDecimal(payPerHour); string hoursPerWeek = createEmployee[3]; decimal hoursPerWeekDec = Convert.ToDecimal(hoursPerWeek); string employeeSalary = createEmployee[4]; decimal employeeSalaryDec = Convert.ToDecimal(employeeSalary); string employeeBonus = createEmployee[5]; decimal employeeBonusDec = Convert.ToDecimal(employeeBonus); //var employeeToAdd = new object[] { employeeName, employeeAddress, payPerHourDec, hoursPerWeekDec, employeeSalaryDec, employeeBonusDec }; if (employeeSalaryDec == 00 && hoursPerWeekDec < 39) { PartTime partTime = new PartTime(employeeName, employeeAddress, payPerHourDec, hoursPerWeekDec); employeeList.Add(partTime); } if (employeeSalaryDec == 00 && hoursPerWeekDec >= 40) { FullTime fullTime = new FullTime(employeeName, employeeAddress, payPerHourDec, hoursPerWeekDec); employeeList.Add(fullTime); } if (employeeSalaryDec != 00 && payPerHourDec == 00) { Manager manager = new Manager(employeeName, employeeAddress, employeeSalaryDec, employeeBonusDec); employeeList.Add(manager); } } } //return employeeList; }
public static void AddEmployee() { DisplayHeader("add employee"); Console.Write("\nWhat is the name of the employee? > "); string employeeName = Console.ReadLine(); bool empNameValid = Validation.ValidateString(employeeName); while (!empNameValid) { DisplayHeader("add employee"); Console.WriteLine("\nInvalid entry!"); Console.Write("What is the name of the employee? > "); employeeName = Console.ReadLine(); empNameValid = Validation.ValidateString(employeeName); } DisplayHeader("add employee"); Console.Write("\nWhat is the address of the employee? > "); string employeeAddress = Console.ReadLine(); bool empAddrValid = Validation.ValidateString(employeeAddress); while (!empAddrValid) { DisplayHeader("add employee"); Console.WriteLine("\nInvalid entry!"); Console.Write("What is the address of the employee? > "); employeeAddress = Console.ReadLine(); empAddrValid = Validation.ValidateString(employeeAddress); } DisplayHeader("add employee"); Console.Write("\nIs the employee hourly? Yes/No > "); string isHourly = Console.ReadLine(); bool isHourlyValid = Validation.ValidateString(isHourly); while (!isHourlyValid || (isHourly.ToLower() != "yes" && isHourly.ToLower() != "no")) { DisplayHeader("add employee"); Console.WriteLine("\nInvalid entry!"); Console.Write("Is the employee hourly? > "); isHourly = Console.ReadLine(); isHourlyValid = Validation.ValidateString(isHourly); } if (isHourly.ToLower() == "yes") { DisplayHeader("add employee"); Console.Write("\nHow much does the employee make per hour? > "); payPerHour = Console.ReadLine(); isHourlyPayValid = Validation.CheckDecimal(payPerHour); while (!isHourlyPayValid) { DisplayHeader("add employee"); Console.WriteLine("\nInvalid entry!"); Console.Write("\nHow much does the employee make per hour? > "); payPerHour = Console.ReadLine(); isHourlyPayValid = Validation.CheckDecimal(payPerHour); } payPerHourDec = Convert.ToDecimal(payPerHour); DisplayHeader("add employee"); Console.Write("\nHow many hours does the employee work per work? > "); hoursWorked = Console.ReadLine(); bool hoursWorkedValid = Validation.CheckDecimal(hoursWorked); while (!hoursWorkedValid) { DisplayHeader("add employee"); Console.WriteLine("\nInvalid entry!"); Console.Write("\nHow many hours does the employee work per work? > "); hoursWorked = Console.ReadLine(); hoursWorkedValid = Validation.CheckDecimal(hoursWorked); } hoursWorkedDec = Convert.ToDecimal(payPerHour); } if (isHourly.ToLower() == "no") { hoursWorkedDec = 40; payPerHourDec = 00; DisplayHeader("add employee"); Console.Write("\nWhat is the employees salary? > "); string salary = Console.ReadLine(); bool salaryValid = Validation.CheckDecimal(salary); while (!salaryValid) { DisplayHeader("add employee"); Console.WriteLine("\nInvalid entry!"); Console.Write("\nHow many hours does the employee work per work? > "); salary = Console.ReadLine(); salaryValid = Validation.CheckDecimal(salary); } salaryDecimal = Convert.ToDecimal(salary); DisplayHeader("add employee"); Console.Write("\nWhat is the employees yearly bonus? > "); string yearlyBonus = Console.ReadLine(); bool bonusValid = Validation.CheckDecimal(yearlyBonus); while (!bonusValid) { DisplayHeader("add employee"); Console.WriteLine("\nInvalid entry!"); Console.Write("\nWhat is the employees yearly bonus? > "); yearlyBonus = Console.ReadLine(); bonusValid = Validation.CheckDecimal(yearlyBonus); } yearlyBonusDecimal = Convert.ToDecimal(yearlyBonus); } if (salaryDecimal == 00 && hoursWorkedDec < 39) { PartTime partTime = new PartTime(employeeName, employeeAddress, payPerHourDec, hoursWorkedDec); employeeList.Add(partTime); } if (salaryDecimal == 00 && hoursWorkedDec >= 40) { FullTime fullTime = new FullTime(employeeName, employeeAddress, payPerHourDec, hoursWorkedDec); employeeList.Add(fullTime); } if (salaryDecimal != 00 && payPerHourDec == 00) { Manager manager = new Manager(employeeName, employeeAddress, salaryDecimal, yearlyBonusDecimal); employeeList.Add(manager); } DisplayHeader("add employee"); Console.WriteLine($"Employee entry for {employeeName} added!"); Console.WriteLine($"Press any key to return to the menu...."); Console.ReadKey(); }