예제 #1
0
        static void Main(string[] args)
        {
            List <Staff> StaffList;
            FileReader   fr    = new FileReader();
            int          year  = GetInt("Enter valid year", 2020, 0);
            int          month = GetInt("Enter valid month", 12, 1);

            // Get file and read contents into list.
            Console.WriteLine("Enter path of staff txt file: ");
            string path = Console.ReadLine();

            StaffList = fr.ReadFile(path);

            GetHoursWorked(StaffList);

            PaySlip ps = new PaySlip(month, year);

            ps.GeneratePaySlip(StaffList);
            ps.PrintSummary(ps.GenerateSummary(StaffList));

            Console.ReadKey();   // Don't close console immediately
        }
예제 #2
0
        static void Main(string[] args)
        {
            List <Staff> myStaff = new List <Staff>();
            FileReader   fr      = new FileReader();
            int          month   = 0;
            int          year    = 0;

            while (year == 0)
            {
                Console.Write("\nPlease enter the year: ");

                try
                {
                    year = Convert.ToInt32(Console.ReadLine());
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message + " Please try again.");
                }
            }

            while (month == 0)
            {
                Console.WriteLine("\nPlease enter the month: ");

                try
                {
                    month = Convert.ToInt32(Console.ReadLine());

                    if (month < 1 || month > 12)
                    {
                        Console.WriteLine("Month must be from 1 to 12. Please try again.");
                        month = 0;
                    }
                }

                catch (Exception e)
                {
                    Console.WriteLine(e.Message + " Please try again");
                }
            }

            myStaff = fr.ReadFile();

            for (int i = 0; i < myStaff.Count; i++)
            {
                try
                {
                    Console.Write("\nEnter hours worked for {0}: ", myStaff[i].NameOfStaff);
                    myStaff[i].HoursWorked = Convert.ToInt32(Console.ReadLine());
                    myStaff[i].CalculatePay();
                    Console.WriteLine(myStaff[i].ToString());
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    i--;
                }
            }

            PaySlip ps = new PaySlip(month, year);

            ps.GeneratePaySlip(myStaff);
            ps.GenerateSummary(myStaff);

            Console.Read();
        }