Example #1
0
 public MainView()
 {
     classManagementView    = new ClassManagementView(classController, courseController, lecturerController, roomController);
     roomManagementView     = new RoomManagementView(roomController);
     studentManagementView  = new StudentManagementView(studentController, courseController, classController, lecturerController, roomController);
     courseManagementView   = new CourseManagementView(courseController);
     lecturerManagementView = new LecturerManagementView(lecturerController);
 }
        internal void WithdrawStudent()
        {
            //ConsoleKeyInfo keypress;
            if (studentController.StudentCount() == 0)
            {
                Console.WriteLine("Student list is empty. Please add some student first!");
                Console.WriteLine("[Enter] to continue...");
                Console.ReadLine();
            }
            else if (classController.ClassesCount() == 0)
            {
                Console.WriteLine("Please come back and add class first!");
                Console.WriteLine("[Enter] to continue...");
                Console.ReadLine();
            }
            else
            {
                DisplayStudent();
                Console.Write("Enter only one student id as shown above to make change for that student: ");
                string studentIdChange = Console.ReadLine();
                while (studentController.SearchStudent(studentIdChange) == null)
                {
                    Console.Write("Not found student! Enter student id again: ");
                    studentIdChange = Console.ReadLine();
                    //found = controller.FindStudent(studentIdChange);
                }
                Student student = studentController.SearchStudent(studentIdChange);

                List <Class> studentClassList = student.GetMyClasses();
                if (studentClassList.Count > 0)
                {
                    for (int i = 0; i < studentClassList.Count; i++)
                    {
                        Console.WriteLine("Class name: {0}", studentClassList[i].ToString());
                        Class myEnrolClass = studentClassList[i];

                        bool validDecision = false;
                        while (!validDecision)
                        {
                            Console.WriteLine("\t\t* 1. Edit class");
                            Console.WriteLine("\t\t* 2. Delete class");
                            Console.Write("Enter an option(1-2): ");
                            int decision = 0;
                            try
                            {
                                decision = System.Int32.Parse(Console.ReadLine());
                            }
                            catch (Exception)
                            {
                                decision = 0;
                            }
                            if (decision >= 1 && decision <= 2)
                            {
                                validDecision = true;
                            }
                            Console.WriteLine();
                            switch (decision)
                            {
                            case 1:
                                ClassManagementView cmv = new ClassManagementView(classController, courseController, lecturerController, roomController);
                                cmv.DisplayClasses();
                                Console.Write("Enter an above class name to enrol it: ");
                                string classname = Console.ReadLine();
                                while (classController.SearchClass(classname) == null)
                                {
                                    Console.Write("Not found class! Try again: ");
                                    classname = Console.ReadLine();
                                }
                                Class foundClass = classController.SearchClass(classname);
                                while (studentController.CheckClashTime(foundClass, student, classController))
                                {
                                    Console.WriteLine("You selected a class that has clashed with other classes.");
                                    Console.Write("Enter class name again: ");
                                    classname = Console.ReadLine();
                                    while (classController.SearchClass(classname) == null)
                                    {
                                        Console.Write("Not found class! Try again: ");
                                        classname = Console.ReadLine();
                                    }
                                    foundClass = classController.SearchClass(classname);
                                }
                                myEnrolClass.WithDrawStudent(student);
                                student.RemoveClass(myEnrolClass);
                                if (studentController.EnrolClass(foundClass, student, classController))
                                {
                                    Console.WriteLine("You are enrolled that class.");
                                }
                                else
                                {
                                    myEnrolClass.EnrolStudent(student);
                                    student.AddClass(myEnrolClass);
                                    Console.WriteLine("You could not enrol to that class.");
                                }
                                break;

                            case 2:
                                myEnrolClass.WithDrawStudent(student);
                                student.RemoveClass(myEnrolClass);
                                Console.WriteLine("You are withdrawn from that class.");
                                break;
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("There are no enrolment records for \"{0}\" student", student.Id);
                }
            }
        }
        internal void EnrolStudent()
        {
            if (courseController.CourseCount() == 0)
            {
                Console.WriteLine("Please add course!");
            }
            else if (lecturerController.LecturerCount() == 0)
            {
                Console.WriteLine("Please add lecture!");
            }
            else if (roomController.RoomCount() == 0)
            {
                Console.WriteLine("Please add room!");
            }
            else if (studentController.StudentCount() == 0)
            {
                Console.WriteLine("Please add some students!");
            }
            else if (classController.ClassesCount() == 0)
            {
                Console.WriteLine("Please add class!");
            }
            else
            {
                Console.WriteLine("\t\t** Student List **");
                DisplayStudent();
                Console.Write("\nSelect one student id: ");
                string id = Console.ReadLine();
                while (studentController.SearchStudent(id) == null)
                {
                    Console.WriteLine("student not found!Please try again");
                    Console.Write("> ");
                    id = Console.ReadLine();
                }
                Student student = studentController.SearchStudent(id);

                Console.WriteLine("\t\t** Course List **");
                CourseManagementView coursemv = new CourseManagementView(courseController);
                coursemv.DisplayCourses();
                Console.Write("\nSelect one course id: ");
                string crid = Console.ReadLine();
                while (courseController.SearchCourse(crid) == null)
                {
                    Console.WriteLine("\ncourse not found!Please try again");
                    Console.Write("> ");
                    crid = Console.ReadLine();
                }
                Course course = courseController.SearchCourse(crid);

                ClassManagementView classmv = new ClassManagementView(classController, courseController, lecturerController, roomController);
                classmv.PrintClassOfCourse(crid);
                Console.Write("Please enter a class name to enrol in: ");
                string className = Console.ReadLine();
                //while (classController.SearchClass(className) == null)
                //{
                //    Console.Write("\nClass not found. Try again");
                //    Console.Write("> ");
                //    className = Console.ReadLine();
                //}
                //Class enrolClass = classController.SearchClass(className);
                Class enrolClass = null;
                bool  clashed    = false;
                while (true)
                {
                    enrolClass = classController.SearchClass(className);
                    if (classController.SearchClass(className) == null)
                    {
                        Console.Write("\nClass not found. Try again");
                        Console.Write("> ");
                        className = Console.ReadLine();
                        if (className == "")
                        {
                            clashed = true;
                            break;
                        }
                    }
                    else if (studentController.CheckClashTime(enrolClass, student, classController))
                    {
                        Console.WriteLine("You select a class has period that clashed with your current classes.");
                        Console.Write("You should select different class: ");
                        className = Console.ReadLine();
                        if (className == "")
                        {
                            clashed = true;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }


                //while (studentController.CheckClashTime(enrolClass, student, classController))
                //{
                //    Console.WriteLine("You select a class has period that clashed with your current classes.");
                //    Console.Write("You should select different class [Enter] to exit: ");
                //    className = Console.ReadLine();
                //    if (className != "")
                //    {
                //        while (classController.SearchClass(className) == null)
                //        {
                //            Console.Write("\nClass not found. Try again");
                //            Console.Write("> ");
                //            className = Console.ReadLine();
                //        }
                //        enrolClass = classController.SearchClass(className);
                //        if (student.GetMyClasses().Count > 4)
                //        {
                //            Console.WriteLine("You are not allowed to add class any more.");
                //        }
                //    }
                //    else
                //        break;
                //}
                if (clashed)
                {
                    Console.WriteLine("Student \"{0}\" failed to enrol class \"{1}\".", id, enrolClass.ToString());
                }
                else
                {
                    if (studentController.EnrolClass(enrolClass, student, classController))
                    {
                        Console.WriteLine("Student \"{0}\" enrolled to class \"{1}\".", id, enrolClass.ToString());
                    }
                }
            }
            Console.Write("[Enter] to continue...");
            Console.ReadLine();
        }