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

            while (year == 0)
            {
                Console.Write("\nPlease enter the year: ");
                try {
                    year = Int16.Parse(Console.ReadLine());
                } catch (FormatException) {
                    Console.WriteLine("\nPlease enter a valid number");
                }
            }

            while (month == 0)
            {
                Console.Write("\nPlease enter the month: ");
                try {
                    month = Int16.Parse(Console.ReadLine());
                    if (month < 1 || month > 12)
                    {
                        month = 0;
                        Console.WriteLine("Please enter a number between 1-12");
                    }
                } catch (FormatException) {
                    Console.WriteLine("\nPlease enter a valid number");
                }
            }
            for (int i = 0; i < myStaff.Count; i++)
            {
                try {
                    Console.WriteLine("Please enter the hours worked for " + myStaff[i].NameOfStaff + ":");
                    int input = Int16.Parse(Console.ReadLine());
                    myStaff[i].HoursWorked = input;
                    myStaff[i].CalculatePay();
                    Console.WriteLine("\n" + myStaff[i].ToString());
                }catch (Exception) {
                    Console.WriteLine("Please input a valid integer");
                    i--;
                }
            }

            PaySlip slip = new PaySlip(month, year);

            slip.GeneratePaySlip(myStaff);
            slip.GenerateSummary(myStaff);
            Console.Read();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            List <Staff> myStaff = new List <Staff>();
            var          fr      = new FileReader();
            int          month   = 0;
            int          year    = 0;

            while (year == 0)
            {
                Console.WriteLine("\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.WriteLine($"\nEnter hours worked for {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--;
                }
            }

            var ps = new PaySlip(month, year);

            ps.GeneratePaySlip(myStaff);
            ps.GenerateSummary(myStaff);
            Console.Read();
        }