Beispiel #1
0
        //=======================================method to schedule a class===================================================
        public static void ScheduleClass()
        {
            //declare variables to pass to classItem constructors here.
            Cours courseToSchedule = null;
            Classroom roomToSchedule = null;
            CourseTime timeToSchedule = null;
            Teacher teacherToSchedule = null;
            List<Student> studentsToSchedule = new List<Student>();

            if (hasTeacher == false || hasStudent == false)//condition to check if student and teacher have been created
            {
                Console.WriteLine("You can't schedule a class until a student and a teacher have been added.");
                return;
            }

            //--------------------------display courses and get ID of course--------------------------------------------------
            foreach (Cours c in dm.DBCourses)
            {
                Console.WriteLine("Course ID: {0}\tName: {1}", c.CourseID, c.CourseName);
            }
            Console.WriteLine("Enter the Course ID number of the course to schedule");
            string IDAnswer = Console.ReadLine();
            int courseID;
            bool IDResult = int.TryParse(IDAnswer, out courseID);
            if (IDResult == false || courseID > 14 || courseID <= 0)
            {
                Console.WriteLine("Invalid ID entered");
                return;
            }
            else
            {
                foreach (Cours c in dm.DBCourses)
                {
                    if (courseID.CompareTo(c.CourseID) == 0)
                    {
                        courseToSchedule = c;
                    }
                }
            }
            //create a list of just teachers to scan through to make sure there's one that can teach selected course
            List<Person> tempList = new List<Person>();
            foreach (Person p in people)
            {
                if (p.IsTeacher == true)
                {
                    tempList.Add(p);
                }
            }
            //Make sure there's a teacher in the system that can teach the course or the program will loop indefinitely later on waiting for a valid teacher input that isn't in the system
            bool teacherExists = false;
            foreach (Teacher t in tempList)
            {
                if (t.ApprovedCourses.Contains(courseToSchedule))
                {
                    teacherExists = true;
                }
            }
            if (teacherExists == false)
            {
                Console.WriteLine("There is no teacher as yet able to teach this course in the system.  Unable to schedule course at this time");
                return;
            }

            //Start of time selection--------------------------------------------------------------------------------------------------------------------------------
            foreach (CourseTime ct in dm.DBTimes)
            {
                Console.WriteLine("Time ID: {0}, Timeframe: {1}", ct.TimeID, ct.TimeFrame);
            }
            Console.WriteLine("Select a time ID");
            string timeAnswer = Console.ReadLine();
            int timeID;
            bool timeIDResult = int.TryParse(timeAnswer, out timeID);
            if (timeIDResult == false)
            {
                Console.WriteLine("invalid time ID entered");
                return;
            }
            else if (courseToSchedule.HoursPerSession == 2 && timeID == 14)
            {
                Console.WriteLine("Scheduling a 2 hour class at that time is too late");
                return;
            }
            else if (courseToSchedule.HoursPerSession == 3 && (timeID == 13 || timeID == 14))
            {
                Console.WriteLine("Scheduling a 3 hour class at that time is too late");
                return;
            }
            else
            {
                //bool to determine if a match was found between input and database info
                bool validID = false;
                foreach (CourseTime ct in dm.DBTimes)
                {
                    if (timeID.CompareTo(ct.TimeID) == 0)
                    {
                        timeToSchedule = ct;
                        //if match was found, set success to true
                        validID = true;
                    }
                }
                if (validID == false)
                {
                    Console.WriteLine("The time ID entered did not match a valid option");
                    return;
                }
            }
            //Start of classroom selection--------------------------------------------------------
            bool validRoom = false;
            foreach (Classroom c in courseToSchedule.Classrooms)
            {

                //checks if those teachers that can teach the course are already teaching at that time
                if (c.TimesUsed.Contains(timeToSchedule))
                {
                    Console.WriteLine("{0} is already scheduled during that time", c.RoomNumber);
                }
                else
                {
                    Console.WriteLine("Classroom ID: {0}, Classroom Number: {1}, Maximum students: {2}", c.ClassroomID, c.RoomNumber, c.RoomSize);
                    validRoom = true;
                }
            }
            if (validRoom == false)
            {
                Console.WriteLine("No rooms are available for the time selected");
                return;
            }
            Console.WriteLine("Enter classroom ID");
            string ClassroomAnswer = Console.ReadLine();
            int roomID;
            bool roomIDResult = int.TryParse(ClassroomAnswer, out roomID);
            if (roomIDResult == false)
            {
                Console.WriteLine("Enter a valid course ID");
                return;
            }
            else
            {
                bool success = false;
                Classroom temp = null;
                foreach (Classroom c in courseToSchedule.Classrooms)
                {
                    if (roomID.CompareTo(c.ClassroomID) == 0)
                    {
                        success = true;
                        temp = c;
                    }
                }
                if (success == true)
                {
                    roomToSchedule = temp;
                }
                else
                {
                    Console.WriteLine("Entry did not match a valid room ID");
                    return;
                }
            }
            //Start of teacher selection---------------------------------------------------------------------------------------------------------
            //temporary list of teachers to access teacher-specific approvedCourses list
            List<Person> teacherList = new List<Person>();
            //filters teachers out into list to compare to
            foreach (Person p in people)
            {
                if (p.IsTeacher == true)
                {
                    teacherList.Add(p);
                }
            }
            teacherList.Sort();
            bool validTeacher = false;
            foreach (Teacher t in teacherList)
            {
                //checks each teacher's list of approved courses
                if (t.ApprovedCourses.Contains(courseToSchedule))
                {
                    //checks if those teachers that can teach the course are already teaching at that time
                    if (t.TimesUsed.Contains(timeToSchedule))
                    {
                        Console.WriteLine("{0} is already scheduled during that time", t.Name);
                    }
                    else
                    {
                        Console.WriteLine("Teacher ID: {0}, teacher name: {1}", t.ID, t.Name);
                        validTeacher = true;
                    }
                }
            }
            if (validTeacher == false)
            {
                Console.WriteLine("No teachers entered are able to teach at the time selected");
                return;
            }
            Console.WriteLine("Enter ID of teacher to teach course");
            string teacherAnswer = Console.ReadLine();
            int teacherID;
            bool teacherIDResult = int.TryParse(teacherAnswer, out teacherID);
            if (teacherIDResult == false)
            {
                Console.WriteLine("Enter a valid teacher ID");
                return;
            }
            else
            {
                bool validID = false;
                foreach (Teacher t in teacherList)
                {
                    if (teacherID.CompareTo(t.ID) == 0)
                    {
                        teacherToSchedule = t;
                        validID = true;
                    }
                }
                if (validID == false)
                {
                    Console.WriteLine("Entry did not match a valid teacher ID");
                    return;
                }
            }
            //Start of student selection-----------------------------------------------------------
            //temporary list of students to be able to manipulate only students
            List<Person> studentList = new List<Person>();
            //populate studentList with only students
            foreach (Person p in people)
            {
                if (p.IsTeacher == false)
                {
                    studentList.Add(p);
                }
            }
            studentList.Sort();
            bool validStudent = false;
            //display students' data
            foreach (Student s in studentList)
            {
                //checks if students are already taking a class at that time
                if (s.TimesUsed.Contains(timeToSchedule))
                {
                    Console.WriteLine("{0} is already scheduled during that time", s.Name);
                }
                else
                {
                    Console.WriteLine("Student ID: {0}, student name: {1}", s.ID, s.Name);
                    validStudent = true;
                }
            }
            if (validStudent == false)
            {
                Console.WriteLine("There are no students that can take this class at this time");
                return;
            }
            Console.WriteLine("Classroom selected can have {0} students", roomToSchedule.RoomSize);
            //while loop so we can add as many students as desired
            bool moreStudents = true;
            while (moreStudents == true && studentsToSchedule.Count <= roomToSchedule.RoomSize)
            {
                Console.WriteLine("Enter ID of a student to take course");
                string studentAnswer = Console.ReadLine();
                int studentID;
                bool studentIDResult = int.TryParse(studentAnswer, out studentID);
                if (studentIDResult == false)
                {
                    Console.WriteLine("Invalid entry");
                }
                else
                {
                    bool success = false;
                    foreach (Student s in studentList)
                    {
                        //if input matches a valid student AND isn't already in the studentsToSchedule list, add him/her
                        if (studentID.CompareTo(s.ID) == 0)// && studentsToSchedule.Contains(s) == false)
                        {
                            if (studentsToSchedule.Contains(s) == false)
                            {
                                studentsToSchedule.Add(s);
                                Console.WriteLine("{0} added successfully!", s.Name);
                                success = true;
                            }
                            else
                            {
                                Console.WriteLine("This student has already been added to this class");
                            }
                        }
                    }
                    if (success == false)
                    {
                        Console.WriteLine("Invalid ID entered, student not added");
                    }
                    Console.WriteLine("{0} students in this class out of a possible {1}.  Add another student?\n1...Yes\n2...No", studentsToSchedule.Count, roomToSchedule.RoomSize);
                    string answer = Console.ReadLine();
                    switch (answer)
                    {
                        case "1":
                            if (studentsToSchedule.Count >= roomToSchedule.RoomSize)
                            {
                                Console.WriteLine("Class is full, no more students will be enrolled.");
                                moreStudents = false;
                            }
                            else
                            {
                                moreStudents = true;
                            }
                            break;
                        case "2":
                            moreStudents = false;
                            break;
                        default:
                            Console.WriteLine("Invalid input");
                            break;
                    }
                }
            }
            //------------------start of displaying info---------------------------------------------------------------
            Console.WriteLine("\nSo here's what we have so far:");
            Console.WriteLine("Course ID number: {0}", courseToSchedule.CourseID);
            Console.WriteLine("Course name: {0}", courseToSchedule.CourseName);
            Console.WriteLine("Teacher's ID: {0}, Teacher's name: {1}", teacherToSchedule.ID, teacherToSchedule.Name);
            Console.WriteLine("Classroom ID: {0}, Classroom number: {1}, Classroom size: {2}", roomToSchedule.ClassroomID, roomToSchedule.RoomNumber, roomToSchedule.RoomSize);
            Console.WriteLine("Course time: {0}", timeToSchedule.StartTime.ToString());
            Console.WriteLine("Students enrolled:");
            foreach (Student s in studentsToSchedule)
            {
                Console.WriteLine("\tStudent's ID: {0}, Student's name: {1}", s.ID, s.Name);
            }
            //double check info is correct and scheduling is desired
            Console.WriteLine("Would you like to schedule this class?\n1...Yes\n2...No");
            string scheduleClass = Console.ReadLine();
            //if yes, schedule class, if no, start over
            bool addClass = true;
            while (addClass == true)
            {
                switch (scheduleClass)
                {
                    case "1":
                        //create new classItem passing in all needed info to create a new class.
                        classItem newClass = new classItem(timeToSchedule, teacherToSchedule, studentsToSchedule, roomToSchedule, courseToSchedule);
                        scheduledClasses.Add(newClass);
                        //register class in the teacher's classItem collection
                        teacherToSchedule.CoursesWith.Add(newClass);

                        //register time used in the teacher's and students' coursetime collection
                        int ID = timeToSchedule.TimeID;
                        CourseTime usedTime = null;
                        //for loop to increment time ID equal to the number of hours in the class session
                        for (int i = 0; i < courseToSchedule.HoursPerSession; i++)
                        {
                            foreach (CourseTime ct in dm.DBTimes)
                            {
                                if (ID == ct.TimeID)
                                {
                                    usedTime = ct;
                                }
                            }
                            roomToSchedule.TimesUsed.Add(usedTime);
                            teacherToSchedule.TimesUsed.Add(usedTime);
                            foreach (Student st in studentsToSchedule)
                            {
                                st.TimesUsed.Add(usedTime);
                            }
                            ID++;
                        }
                        Console.WriteLine("Class successfully added!");
                        hasClass = true;
                        addClass = false;
                        break;
                    case "2":
                        Console.WriteLine("Deleting data...");
                        addClass = false;
                        break;
                    default:
                        Console.WriteLine("Invalid input, please try again");
                        scheduleClass = Console.ReadLine();
                        break;
                }
            }
        }
Beispiel #2
0
 //displays course information
 public static void displayCourseInfo(classItem ci)
 {
     Console.WriteLine("ID: {0}, Course name: {1}\nTeacher's ID: {2}\nTeacher's name: {3}\nClassroom ID: {4}\nClassroom number: {5}\nClassroom size: {6}\nCourse time: {7}", ci.ItemNumber, ci.Course.CourseName, ci.Teacher.ID, ci.Teacher.Name, ci.Room.ClassroomID, ci.Room.RoomNumber, ci.Room.RoomSize, ci.CourseTimes.TimeFrame);
     Console.WriteLine("Students enrolled:");
     foreach (Student s in ci.EnrolledStudents)
     {
         Console.WriteLine("\tID: {0}, Name: {1}", s.ID, s.Name);
     }
 }