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();
        }
Exemple #2
0
        private void ManageLecturer()
        {
            bool validSelection = false;

            while (!validSelection)
            {
                Console.Clear();
                Console.WriteLine("\t\t* You are working on lecturer management *");
                Console.WriteLine("\t\t* 1. Add lecturer                        *");
                Console.WriteLine("\t\t* 2. Modify lecturer                     *");
                Console.WriteLine("\t\t* 3. Delete lecturer                     *");
                Console.WriteLine("\t\t* 4. Display lecturers                   *");
                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:
                    lecturerManagementView.AddLecturer();
                    ManageLecturer();
                    break;

                case 2:
                    lecturerManagementView.EditLecturer();
                    ManageLecturer();
                    break;

                case 3:
                    lecturerManagementView.DeleteLecturer();
                    ManageLecturer();
                    break;

                case 4:
                    lecturerManagementView.DisplayLecturer();
                    Console.Write("[Enter] to continue...");
                    Console.ReadLine();
                    ManageLecturer();
                    break;

                case 5:
                    Console.WriteLine("You select backing to main management selection");
                    ProcessManagementSelection();
                    break;
                }
            }
        }
        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();
                }
            }
        }