Пример #1
0
        static void ShowSubMenuStudentManagement()
        {
            string userChoose = String.Empty;

            Console.Clear();
            do
            {
                // Sub menu Student Management
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("====STUDENT MANAGEMENT MENU====");
                Console.WriteLine("===============================");
                Console.WriteLine("1. Add new Student");
                Console.WriteLine("2. View all Students");
                Console.WriteLine("3. Search Student");
                Console.WriteLine("4. Delete Student");
                Console.WriteLine("5. Update Student");
                Console.WriteLine("6. Back to main menu");
                Console.WriteLine("===============================");

                // User choose
                Console.BackgroundColor = ConsoleColor.Red;
                Console.Write("Please choose: ");
                userChoose = Console.ReadLine();
                Console.ResetColor();

                // Initialize command
                StudentReceiver studentReciever = new StudentReceiver(Program.ListStudents);
                StudentInvoker  studentInvoker  = new StudentInvoker();

                switch (userChoose)
                {
                case "1":     // Add new Student menu
                              // Create new object Student
                    ExecuteStudent(studentInvoker, new StudentCommand(studentReciever, CommandAction.Add));
                    break;

                case "2":     // View all students menu
                              // Empty list -> show waring message
                    ExecuteStudent(studentInvoker, new StudentCommand(studentReciever, CommandAction.ViewAll));
                    break;

                case "3":     // Search student menu
                              // Empty list -> show waring message
                    ExecuteStudent(studentInvoker, new StudentCommand(studentReciever, CommandAction.Search));
                    break;

                case "4":     // Delete student menu
                              // Empty list -> show waring message
                    ExecuteStudent(studentInvoker, new StudentCommand(studentReciever, CommandAction.Delete));
                    break;

                case "5":     // Update student menu
                    // Empty list -> show waring message
                    ExecuteStudent(studentInvoker, new StudentCommand(studentReciever, CommandAction.Update));
                    break;

                case "6":     // Back to main menu
                    ShowMainMenu();
                    break;

                default:
                    Console.WriteLine("Not correct command. Please input only number (1, 2, 3, 4, 5 or 6)");
                    ShowSubMenuStudentManagement();
                    break;
                }
            } while (userChoose != "6");
        }
Пример #2
0
 private static void ExecuteStudent(StudentInvoker invoker, ICommand command)
 {
     invoker.SetCommand(command);
     invoker.Invoke();
 }