示例#1
0
        private void ManageCourse()
        {
            bool validSelection = false;

            while (!validSelection)
            {
                Console.Clear();
                Console.WriteLine("\t\t* You are working on course management *");
                Console.WriteLine("\t\t* 1. Add course                        *");
                Console.WriteLine("\t\t* 2. Modify course                     *");
                Console.WriteLine("\t\t* 3. Delete course                     *");
                Console.WriteLine("\t\t* 4. Display courses                   *");
                Console.WriteLine("\t\t* 5. Back to main menu                 *");
                Console.WriteLine("\t\t****************************************");
                Console.Write("Enter an option(1-5): ");
                int decision = 0;
                try
                {
                    decision = System.Int32.Parse(Console.ReadLine());
                }
                catch (Exception)
                {
                    decision = 0;
                }
                //var decision = System.Int32.Parse(Console.ReadLine());
                if (decision >= 1 && decision <= 5)
                {
                    validSelection = true;
                }
                Console.WriteLine();
                switch (decision)
                {
                case 1:
                    courseManagementView.AddCourse();
                    ManageCourse();
                    break;

                case 2:
                    courseManagementView.EditCourse();
                    ManageCourse();
                    break;

                case 3:
                    courseManagementView.DeleteCourse();
                    ManageCourse();
                    break;

                case 4:
                    courseManagementView.DisplayCourses();
                    Console.Write("[Enter] to continue...");
                    Console.ReadLine();
                    ManageCourse();
                    break;

                case 5:
                    Console.WriteLine("You select backing to main management selection");
                    ProcessManagementSelection();
                    break;
                }
            }
        }
示例#2
0
        internal void AddClass()
        {
            Console.WriteLine("Add new class");
            Course   course   = null;
            Lecturer lecturer = null;

            if (courseController.CourseCount() == 0)
            {
                Console.WriteLine("There are no courses yet. You should add some courses firstly.");
            }
            else if (lecturerController.LecturerCount() == 0)
            {
                Console.WriteLine("There are no lecturers yet. You should add some lecturers firstly.");
            }
            else if (roomController.RoomCount() == 0)
            {
                Console.WriteLine("There are no rooms yet. You should add some rooms firstly");
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("\t\tCourse List\t\t");
                cmv.DisplayCourses();
                Console.Write("Enter course id: ");
                string courseId = Console.ReadLine();
                while (courseController.SearchCourse(courseId) == null)
                {
                    Console.Write("This course never exists. Enter course id: ");
                    courseId = Console.ReadLine();
                }
                course = courseController.SearchCourse(courseId);

                Console.WriteLine();
                Console.WriteLine("\t\tLecturer List\t\t");
                lmv.DisplayLecturer();
                Console.Write("Enter lecturer id: ");
                string lecturerId = Console.ReadLine();
                while (lecturerController.SearchLecturer(lecturerId) == null)
                {
                    Console.Write("This lecturer never exists. Enter lecturer id: ");
                    lecturerId = Console.ReadLine();
                }
                lecturer = lecturerController.SearchLecturer(lecturerId);

                ClassPeriod classPeriod = CreateClassPeriod();

                if (classController.ClassesCount() > 0)
                {
                    while (true)
                    {
                        // check whether new class period will clash with others in classes list
                        if (classController.ConflictTime(classPeriod))
                        {
                            Console.WriteLine("Your chosen class Period has clashed with the others.");
                            Console.WriteLine("Please justify to other class period!");
                            classPeriod = CreateClassPeriod();
                        }
                        else if (classController.ConflictLecturer(lecturer.Id, classPeriod))
                        {
                            Console.WriteLine("Sorry! At your chosen class time, Lecturer has id \"{0}\" will teaching other class", lecturer.Id);
                            Console.WriteLine("Please justify to other class period!");
                            classPeriod = CreateClassPeriod();
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                if (classController.CreateClass(course, lecturer, classPeriod))
                {
                    Console.WriteLine("Congratulation! you added a new class.");
                }
                else
                {
                    Console.WriteLine("Sorry! you failed to add a class.");
                    Console.WriteLine("This class is taken by other lecturer.");
                }
            }
            Console.WriteLine("[Enter] to continue...");
            Console.ReadLine();
        }
        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();
        }
示例#4
0
        internal void EditClass()
        {
            if (classController.ClassesCount() == 0)
            {
                Console.WriteLine("No class found! you need to add class.");
                Console.WriteLine("[Enter] to continue...");
                Console.ReadLine();
            }
            else
            {
                DisplayClasses();
                Console.Write("Enter only one class name as shown above: ");
                string editClassName = Console.ReadLine();
                Class  expectedClass = classController.SearchClass(editClassName);
                while (expectedClass == null)
                {
                    Console.Write("\nNot class found! Enter class name again: ");
                    editClassName = Console.ReadLine();
                    expectedClass = classController.SearchClass(editClassName);
                }

                /* Backup information of class that will be updated.
                 * Recreate that class if something go wrong during update process
                 */
                var                lecturerInfo = expectedClass.Lecturer;
                var                courseInfo   = expectedClass.Course;
                string             className    = expectedClass.ToString();
                List <ClassPeriod> cpList       = expectedClass.ClassPeriodList;

                //Console.WriteLine("*******Lecturer id list******** ");
                //List<Lecturer> lecturerList = lecturerController.GetLecturers();
                //foreach (Lecturer l in lecturerList)
                //{
                //    Console.WriteLine(l.Id);
                //}
                LecturerManagementView lmv = new LecturerManagementView(lecturerController);
                Console.WriteLine("\n\t\t Lecturer list");
                lmv.DisplayLecturer();
                Console.Write("\nEnter one of above id to change \"{0}\"[Enter to keep]: ", lecturerInfo.Id);
                string   nLecId   = Console.ReadLine();
                Lecturer lecturer = null;
                if (nLecId != "")
                {
                    lecturer = lecturerController.SearchLecturer(nLecId);
                    while (lecturer == null)
                    {
                        Console.Write("\nNot found this lecture! Enter again: ");
                        nLecId   = Console.ReadLine();
                        lecturer = lecturerController.SearchLecturer(nLecId);
                    }
                    lecturerInfo = lecturer;
                }

                //Console.WriteLine("*******Course id list******** ");
                //List<Course> courseList = courseController.GetCourses();
                //foreach (Course c in courseList)
                //{
                //    Console.WriteLine(c.Id);
                //}
                CourseManagementView cmv = new CourseManagementView(courseController);
                Console.WriteLine("\n\t\t Course list");
                cmv.DisplayCourses();
                Console.Write("\nEnter one of above id to change \"{0}\"[Enter to keep]: ", courseInfo.Id);
                string nCourseId = Console.ReadLine();
                Course course    = null;
                if (nCourseId != "")
                {
                    course = courseController.SearchCourse(nCourseId);
                    while (course == null)
                    {
                        Console.Write("\nNot found this course! Enter again: ");
                        nCourseId = Console.ReadLine();
                        course    = courseController.SearchCourse(nCourseId);
                    }
                    courseInfo = course;
                }

                Console.WriteLine();
                Console.WriteLine("********** Class Periods ***********");
                int classPeriodCount = cpList.Count;
                for (int i = 0; i < classPeriodCount; i++)
                {
                    Console.WriteLine("\nClass period number \"{0}\"", i + 1);
                    Console.WriteLine(cpList[i].ToString());
                    Console.WriteLine();
                }
                int  number = 0;
                bool valid  = false;
                while (!valid)
                {
                    try
                    {
                        Console.Write("\nEnter period number to update: ");
                        number = int.Parse(Console.ReadLine());
                        valid  = true;
                    }
                    catch (Exception)
                    {
                        Console.Write("\nUnexisted period number!Try again: ");
                    }
                }
                number -= 1;
                ClassPeriod backupCP = cpList[number];
                cpList.RemoveAt(number);

                ClassPeriod nCp        = CreateClassPeriod();
                bool        conflicted = true;
                while (conflicted)
                {
                    if (cpList.Count == 0)
                    {
                        conflicted = false;
                    }
                    foreach (ClassPeriod cp in cpList)
                    {
                        conflicted = nCp.TimeConflict(cp);
                        if (conflicted)
                        {
                            break;
                        }
                    }
                    if (conflicted)
                    {
                        Console.WriteLine("\nNew period has clashed with other remaining period of class to update.");
                        nCp = CreateClassPeriod();
                    }
                }
                while (true)
                {
                    if (classController.ConflictTime(nCp))
                    {
                        Console.WriteLine("\nNew period has clashed with other period of different classes.");
                        nCp = CreateClassPeriod();
                    }
                    else if (classController.ConflictLecturer(nLecId, nCp))
                    {
                        Console.WriteLine("\nNew lecturer \"{0}\" teaches a class at the same time of new period.");
                        nCp = CreateClassPeriod();
                    }
                    else
                    {
                        break;
                    }
                }
                cpList.Add(nCp);
                classController.DeleteClassName(editClassName);
                if (classController.UpdateClass(lecturerInfo, courseInfo, nCp))
                {
                    Console.WriteLine("\nUpdated class({0})", lecturerInfo.Id + courseInfo.Id);
                    Console.Write("[Enter] to continue...");
                    Console.ReadLine();
                }
                else
                {
                    classController.CreateClass(expectedClass.Course, expectedClass.Lecturer, backupCP);
                    Console.WriteLine("\nUpdate failed!");
                    Console.Write("[Enter] to continue...");
                    Console.ReadLine();
                }
            }
        }