Exemple #1
0
 public void RemoveCourse(Course course)
 {
     if (Courses.Contains(course))
     {
         Courses.Remove(course);
     }
 }
Exemple #2
0
 public void ImportInfo(Student student)
 {
     if (!Courses.Contains(student.CourseId))
     {
         Courses.Add(student.CourseId);
     }
 }
Exemple #3
0
        public void EnrollCourse(Course course)
        {
            if (Courses.Contains(course))
            {
                throw new InvalidOperationException("Student is already enrolled in this course");
            }

            Courses.Add(course);
        }
Exemple #4
0
        public void UnEnrollCourse(Course course)
        {
            if (!Courses.Contains(course))
            {
                throw new InvalidOperationException("Student is not enrolled in this course");
            }

            Courses.Remove(course);
        }
Exemple #5
0
        public void ListUpdate()
        {
            Courses.Add("-");
            Professors.Add("-");
            SqlConnection sqlConnection = new SqlConnection("Data Source=localhost; Integrated Security=SSPI; Initial Catalog=TeachersTimetable;");

            sqlConnection.Open();
            SqlCommand command = sqlConnection.CreateCommand();

            command.CommandText = "select name from " + Tables[5];
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataTable      data    = new DataTable();

            adapter.Fill(data);
            foreach (DataRow row in data.Rows)
            {
                string str = row[0].ToString().Trim();
                if (!Professors.Contains(str))
                {
                    Professors.Add(str);
                }
            }

            command.CommandText = "select name from " + Tables[2];
            adapter             = new SqlDataAdapter(command);
            data = new DataTable();
            adapter.Fill(data);
            foreach (DataRow row in data.Rows)
            {
                string str = row[0].ToString().Trim();
                if (!Courses.Contains(str))
                {
                    Courses.Add(str);
                }
            }

            Courses.Sort();
            Professors.Sort();
        }
Exemple #6
0
        //======================================method to add teacher==========================================
        public static void AddTeacher()
        {
            string name;
            string phone;
            string email;
            Courses approvedCourses = new Courses();
            long check;
            Console.Write("Enter Name\n");
            name = Console.ReadLine();
            Console.Write("Enter 10 digit Phone number\n");
            string input = Console.ReadLine();
            try
            {
                check = Convert.ToInt64(input);
            }
            catch
            {
                Console.WriteLine("Phone number must be 10 numerical digits");
                return;
            }
            if (input.ToString().Length != 10)
            {
                Console.WriteLine("Phone number entered is not 10 digits, please try again");
                return;
            }
            else
            {
                phone = input;
            }
            Console.Write("Enter Email address\n");
            email = Console.ReadLine();
            //display all course options
            if (name == "" || email == "")
            {
                Console.WriteLine("One or more fields left empty, please try again");
                return;
            }
            foreach (Cours c in dm.DBCourses)
            {
                Console.WriteLine("Course ID: {0}\tName: {1}", c.CourseID, c.CourseName);
            }

            //bool and while loop to keep adding courses until the user stops
            bool keepAdding = true;
            //loops through all courses comparing entered ID to courseIDs.  If a match is found, bool is set to true and if statement is entered, assigning match
            //to the list.  After this is completed, ask user if they want to add more classes and loop again.
            while (keepAdding)
            {
                Console.WriteLine("Enter ID of a course this teacher can teach");

                //setting up tryparse for error checking
                string answer = Console.ReadLine();
                int id;
                bool result = int.TryParse(answer, out id);

                bool match = false;
                Cours matchedCourse = null;
                foreach (Cours c in dm.DBCourses)
                {
                    if (id == c.CourseID)
                    {
                        match = true;
                        matchedCourse = c;
                    }
                }
                if (match == true)
                {
                    //nested if statement checks for duplicates and writes and error message if found.
                    if (approvedCourses.Contains(matchedCourse))
                    {
                        Console.WriteLine("this course has already been added, you can't add it twice!");
                    }
                    else
                    {
                        approvedCourses.Add(matchedCourse);
                        Console.WriteLine("class successfully added");
                    }
                }
                else
                {
                    Console.WriteLine("invalid class number entered");
                    return;
                }
                Console.WriteLine("Can this teacher teach another course?\n1...Yes\n2...No");
                string anotherClass = Console.ReadLine();
                switch (anotherClass)
                {
                    case "1":
                        break;
                    case "2":
                        keepAdding = false;
                        break;
                }
            }
            //once all classes are assigned, check for null, then create teacher with those classes
            //and add him/her to list
            if (approvedCourses.CourseCollection.Count != 0)
            {
                //create empty list of classes to be used when scheduling a class
                List<classItem> classesWith = new List<classItem>();
                //set bool value to true on all teachers
                bool isTeacher = true;
                Teacher t = new Teacher(name, phone, email, isTeacher, classesWith, approvedCourses);
                if (people.Contains(t))
                {
                    Console.WriteLine("The name, phone number, or email entered is already taken, please enter a new one");
                    return;
                }
                else
                {
                    people.Add(t);
                    //bool used in scheduling a class for error checking
                    hasTeacher = true;
                    Console.WriteLine("{0} added Successfully!", t.Name);
                }
            }
            else
            {
                Console.WriteLine("No courses were successfully added that this teacher can teach.  Teacher was not added.");
            }
        }