Пример #1
0
        // Operator for Add Employee Menu
        public List <Employee> AddEmpOperator(string userSelection, List <Employee> employees)
        {
            switch (userSelection)
            {
            case "fulltime":
                FullTime ftEmp = AddFullTimeEmp();
                employees.Add(ftEmp);
                UI.Alert($"Full time employee: {ftEmp.Name}, added!");
                UI.Footer("Press any key to continue:");
                break;

            case "parttime":
                PartTime ptEmp = AddPartTimeEmp();
                employees.Add(ptEmp);
                UI.Alert($"Part time employee: {ptEmp.Name}, added!");
                UI.Footer("Press any key to continue:");
                break;

            case "manager":
                Manager manager = AddManager();
                employees.Add(manager);
                UI.Alert($"Manager: {manager.Name}, added!");
                UI.Footer("Press any key to continue:");
                break;
            }

            return(employees);
        }
Пример #2
0
        // Add Employee - Functions///////////////////////////////
        public FullTime AddFullTimeEmp()
        {
            UI.Header("Full Time Employee info");
            string  name    = Validate.String("Please enter the employee's name:");
            string  address = Validate.String($"Please enter {name}'s address:");
            decimal pph     = Validate.Decimal($"Please enter {name}'s pay per hour:", 40);
            decimal hpw     = Validate.Decimal($"Full time employee's must work 40 or more hours.\nPlease enter the amount of hours {name} works per week:", 40);

            FullTime ftEmp = new FullTime(name, address, pph, hpw);

            return(ftEmp);
        }
Пример #3
0
        } // End Constructor

        // The following method will load all employees from the txt file and save them into '_employees'
        // This load function is smart enough to detemine the difference between Fulltime, Parttime, and Manager employees
        private static void Load()
        {
            // ressetting List of employees
            _employees = new List <Employee>();

            // - The text file should be checked if it exists and then loaded when the assignment executes.
            if (File.Exists(_ioPath))
            {
                // Variables
                Employee employee;


                using (StreamReader sr = new StreamReader(_ioPath))
                {
                    string   line;
                    string[] lineSplit;

                    // This loop will continue until all employees are added into the list: '_employees'
                    while ((line = sr.ReadLine()) != null)
                    {
                        // Spliting line at '|' and saving seperate string into a temp string array
                        lineSplit = line.Split('|');

                        // The following conditional will run through all employees in the employees.txt and load them according to their ...
                        // ... types. (Fulltime, PartTime, and Manager)

                        // Differentiating between manager and hourly
                        if (decimal.Parse(lineSplit[3]) != 0)
                        {
                            // Differentiating between Fulltime and Parttime
                            if (decimal.Parse(lineSplit[3]) < 40)
                            {
                                // Creating a Parttime employee with newly obtained info
                                // (The info will be validated before being saved, therefore no need for further validation)
                                employee = new PartTime(lineSplit[0], lineSplit[1], decimal.Parse(lineSplit[2]), decimal.Parse(lineSplit[3]));

                                // Adding employee to list: '_employees'
                                _employees.Add(employee);
                            }
                            else
                            {
                                // Creating a Fulltime employee with newly obtained info
                                // (The info will be validated before being saved, therefore no need for further validation)
                                employee = new FullTime(lineSplit[0], lineSplit[1], decimal.Parse(lineSplit[2]), decimal.Parse(lineSplit[3]));

                                // Adding employee to list: '_employees'
                                _employees.Add(employee);
                            }
                        }
                        else
                        {
                            // Creating a Manager employee with newly obtained info
                            // (The info will be validated before being saved, therefore no need for further validation)
                            employee = new Manager(lineSplit[0], lineSplit[1], decimal.Parse(lineSplit[4]), decimal.Parse(lineSplit[5]));

                            // Adding employee to list: '_employees'
                            _employees.Add(employee);
                        }
                    }
                }
            }
            else
            {
                UI.Alert("(Error) Your path file does not exist. No data was uploaded!");
                UI.Footer("Press any key to continue");
            }
        }