Esempio n. 1
0
        static void Main(string[] args)
        {
            List <Staff> listOfStaffObjects = new List <Staff>();
            int          month = 0; int year = 0;

            while (year == 0)
            {
                try
                {
                    Console.Write("Please enter the year: ");
                    year = Convert.ToInt32(Console.ReadLine());

                    while (month == 0)
                    {
                        try
                        {
                            Console.Write("Please enter the month: ");
                            month = Convert.ToInt32(Console.ReadLine());

                            if (month < 1 || month > 12)
                            {
                                Console.WriteLine("Invalid month entered.");
                                month = 0;
                            }
                            else
                            {
                                FileReaderManager fileReaderManager = new FileReaderManager();
                                listOfStaffObjects = fileReaderManager.ReadFile();
                                for (int i = 0; i < listOfStaffObjects.Count; i++)
                                {
                                    try
                                    {
                                        Console.WriteLine("Enter the hours work for " + listOfStaffObjects[i].NameOfStaff + ": ");
                                        listOfStaffObjects[i].HoursWorked = Convert.ToInt32(Console.ReadLine());

                                        listOfStaffObjects[i].CalculatePay();
                                        Console.WriteLine(listOfStaffObjects[i].ToString());

                                        Payslip ps = new Payslip(year, month);
                                        ps.GeneratePaySlip(listOfStaffObjects);
                                        ps.GenerateSummary(listOfStaffObjects);
                                        Console.Read();
                                    }
                                    catch (Exception ex)
                                    {
                                        i--;
                                        Console.WriteLine(ex.Message);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                }
                catch (FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Generating payslips...");
            List <Staff> staffs;
            int          month = 0;
            int          year  = 0;

            while (year == 0)
            {
                Console.Write("\nPlease enter the year; ");
                try
                {
                    year = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.Write("\nPlease enter a valid year; ");
                }
            }

            while (month == 0)
            {
                Console.Write("\nPlease enter the month; ");
                try
                {
                    month = Convert.ToInt32(Console.ReadLine());
                    if (month < 1 || month > 12)
                    {
                        Console.Write("\nPlease enter a month between 1 & 12; ");
                        month = 0;
                    }
                }
                catch (FormatException)
                {
                    Console.Write("\nPlease enter a valid month; ");
                }
            }

            staffs = FileReader.ReadFile();
            for (int i = 0; i < staffs.Count; i++)
            {
                var staff = staffs[i];
                try
                {
                    Console.Write($"Enter hours worked for {staff.NameOfStaff}; ");
                    int hoursWorked = Convert.ToInt32(Console.ReadLine());
                    staff.HoursWorked = hoursWorked;
                    staff.CalculatePay();
                    Console.WriteLine(staff);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error occurred");
                    Console.WriteLine(e);
                    i--;
                }
            }
            Payslip ps = new Payslip(month, year);

            ps.GeneratePaySlip(staffs);
            ps.GenerateSummary(staffs);
            Console.WriteLine("DONE!");
        }