示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Program");

            List <Staff> myStaff;
            FileReader   reader = new FileReader();
            int          month  = 0;
            int          year   = 0;

            while (year == 0)
            {
                Console.Write("\nPlease enter the year: ");
                try {
                    // Code to conver the input to an integer
                    year = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException e) {
                    Console.WriteLine(e.Message);
                }
            }

            while (month == 0)
            {
                Console.Write("\nPlease enter the month: ");
                try
                {
                    month = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException e) {
                    Console.WriteLine(e.Message);
                }
            }

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

            PaySlip slip = new PaySlip(month, year);

            slip.GeneratePaySlip(myStaff);
            slip.GenerateSummary(myStaff);

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            int month = 0, year = 0;

            while (year == 0)
            {
                Console.Write("Please enter the year: ");
                if (!int.TryParse(Console.ReadLine(), out year))
                {
                    Console.WriteLine("ERROR: Not a number.");
                    continue;
                }
            }
            while (month == 0)
            {
                Console.Write("Please enter the month (1-12): ");
                if (!int.TryParse(Console.ReadLine(), out month))
                {
                    Console.WriteLine("ERROR: Not a number.");
                    continue;
                }
                if (month < 1 || month > 12)
                {
                    Console.WriteLine("ERROR: Not a valid month.");
                    month = 0;
                    continue;
                }
            }
            var myStaff = FileReader.ReadStaffFile("StaffNames.txt");

            for (int i = 0; i < myStaff.Count; ++i)
            {
                Console.Write("Enter hours worked of {0}: ",
                              myStaff[i].NameOfStaff);
                int hoursWorked = 0;
                if (!int.TryParse(Console.ReadLine(), out hoursWorked))
                {
                    Console.WriteLine("ERROR: Not a number.");
                    --i;                     // Retry current staff member.
                    continue;
                }
                myStaff[i].HoursWorked = hoursWorked;
                myStaff[i].CalculatePay();
                Console.WriteLine(myStaff[i].ToString());
            }
            var ps = new PaySlip(month, year);

            ps.GeneratePaySlip(myStaff);
            ps.GenerateSummary(myStaff);
        }
示例#3
0
        static void Main(string[] args)
        {
            List <Staff> myStaff = new List <Staff>();
            FileReader   fr = new FileReader();
            int          month = 0, 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.Write("\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();
        }