Beispiel #1
0
 /// <summary>
 /// saves a course
 /// </summary>
 /// <param name="course">course to save</param>
 public static void SaveCourse(CourseData course)
 {
     if (course.Id == 0)
         courseEntity.CreateCourse(course);
     else
         courseEntity.UpdateCourse(course);
 }
Beispiel #2
0
        public static List<QuizData> GetQuizzes(CourseData course)
        {
            // TODO replace with entity retrieving

            List<QuizData> quizzes = new List<QuizData>();
            QuizData quiz = new QuizData();
            quiz.Name = "My New Quiz";

            quizzes.Add(quiz);
            return quizzes;
        }
Beispiel #3
0
        public QuizzesView(CourseData course)
        {
            InitializeComponent();

            //erase all items in list
            lvwQuizzes.Items.Clear();

            //add items in the course to the list
            quizzes = QuizController.GetQuizzes(course);
            foreach (QuizData quiz in quizzes)
            {
                lvwQuizzes.Items.Add(quiz.Name,0);
            }
        }
Beispiel #4
0
        public void AddUser(CourseData theCourse, UserData theUser)
        {
            if (DataReader != null)
                DataReader.Close();

            SQL = "INSERT INTO `rel_courses_users` (`course_id`, `user_id`) VALUES (\"" +
                theCourse.Id + "\", \"" +
                theUser.Id + "\");";

            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
                throw new Exception("The user could not be added to the course");
        }
Beispiel #5
0
        /// <summary>
        /// Create c Course on the Database
        /// </summary>
        /// <param name="theCourse">a Course object to create on Database</param>
        public void CreateCourse(CourseData theCourse)
        {
            theCourse.Id = NextId;

            if (DataReader != null)
                DataReader.Close();

            SQL = "INSERT INTO `courses` (`course_id`, `name`) VALUES (\"" + theCourse.Id + "\", \"" + theCourse.Name + "\");";

            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
                throw new Exception("Unable to add Course to Database");
        }
Beispiel #6
0
        public void AddQuiz(CourseData theCourse, QuizData theQuiz)
        {
            if (DataReader != null)
                DataReader.Close();

            SQL = "INSERT INTO `rel_courses_quizzes` (`course_id`, `quiz_id`) VALUES (\"" +
                theCourse.Id + "\", \"" +
                theQuiz.Id + "\");";

            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
                throw new Exception("The Quiz could not be added to the Course");
        }
Beispiel #7
0
        /// <summary>
        /// handles add course button click. allows user to add a new course.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //prompt user for name of new course
            string courseName = "";
            var result = HelperUI.InputBox("New Course", "Enter name of course", ref courseName);

            //if user selected okay
            if (result == DialogResult.OK)
            {
                //add to database
                CourseData courseToAdd = new CourseData();
                courseToAdd.Name = courseName;
                CourseController.SaveCourse(courseToAdd);
                CourseController.AddUser(courseToAdd, GlobalData.currentUser);

                //add to list
                ListViewItem item = lvwCourses.Items.Add(courseToAdd.Name,0);
                item.Tag = courseToAdd;
            }
        }
Beispiel #8
0
 /// <summary>
 /// removes a specified user from a specified course
 /// </summary>
 /// <param name="course">course to remove user from</param>
 /// <param name="user">user to be removed</param>
 public static void RemoveUser(CourseData course, UserData user)
 {
     courseEntity.RemoveUser(course, user);
 }
Beispiel #9
0
 /// <summary>
 /// Deletes a specified course from the database
 /// </summary>
 /// <param name="course">course to delete</param>
 public static void DeleteCourse(CourseData course)
 {
     courseEntity.DeleteCourse(course);
 }
Beispiel #10
0
 /// <summary>
 /// adds a user to a specified course
 /// </summary>
 /// <param name="course">the course to add the user to</param>
 /// <param name="user">the user to add to the course</param>
 public static void AddUser(CourseData course, UserData user)
 {
     courseEntity.AddUser(course, user);
 }
Beispiel #11
0
 /// <summary>
 /// adds a quiz to a course
 /// </summary>
 /// <param name="course">course to add quiz to</param>
 /// <param name="quiz">quiz to add</param>
 public static void AddQuiz(CourseData course, QuizData quiz)
 {
     courseEntity.AddQuiz(course, quiz);
 }
Beispiel #12
0
        public List<QuizData> ReadQuizzes(CourseData theCourse)
        {
            List<QuizData> return_data = new List<QuizData>();

            if (DataReader != null)
                DataReader.Close();

            SQL = "SELECT r.`quiz_id` FROM `rel_courses_quizzes` r WHERE r.`course_id` = \"" + theCourse.Id + "\";";

            InitializeCommand();
            OpenConnection();

            DataReader = Command.ExecuteReader();

            List<int> temp = new List<int>();

            if (DataReader.HasRows)
                while (DataReader.Read())
                    temp.Add(DataReader.GetInt16("quiz_id"));

            for (int i = 0; i < temp.Count; i++)
                return_data.Add(ReadQuiz(temp[i]));

            CloseConnection();

            return return_data;
        }
Beispiel #13
0
        public void RemoveUser(CourseData theCourse, UserData theUser)
        {
            if (DataReader != null)
                DataReader.Close();

            SQL = "DELETE FROM `rel_courses_users` WHERE `rel_courses_users`.`course_id` = \"" + theCourse.Id + "\" and `rel_courses_users`.`user_id` = \"" + theUser.Id + "\";";

            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
                throw new Exception("Unable to remove the user from the course");
        }
Beispiel #14
0
 /// <summary>
 /// gets the list of all students in a specified course
 /// </summary>
 /// <param name="course">the course to search in</param>
 /// <returns>list of student in the course</returns>
 public static List<UserData> GetStudents(CourseData course)
 {
     return userEntity.GetStudentsByCourse(course.Id);
 }
Beispiel #15
0
        /// <summary>
        /// Gets a List of courses a given user is enrolled in
        /// </summary>
        /// <param name="theUser">a User object that is being queried</param>
        /// <returns>A List of Course objects</returns>
        public List<CourseData> ReadCourses(UserData theUser)
        {
            List<CourseData> return_data = new List<CourseData>();

            if (DataReader != null)
                DataReader.Close();

            SQL = "SELECT * FROM `courses` c INNER JOIN `rel_courses_users` r ON r.`course_id` = c.`course_id` WHERE r.`user_id` = \"" + theUser.ID + "\";";

            InitializeCommand();

            OpenConnection();

            DataReader = Command.ExecuteReader();

            if (DataReader.HasRows) {
                while (DataReader.Read()) {
                    CourseData temp = new CourseData(DataReader.GetUInt16("`course_id`"));
                    temp.Name = DataReader.GetString("`name`");
                    return_data.Add(temp);
                }
            }
            CloseConnection();

            return return_data;
        }
Beispiel #16
0
        /// <summary>
        /// Reads a Course from the database given the CourseName
        /// </summary>
        /// <param name="courseName">name of the Course to search</param>
        /// <returns>A Course object</returns>
        /// 
        public CourseData ReadCourse(String courseName)
        {
            CourseData return_data = null;

            if (DataReader != null)
                DataReader.Close();

            SQL = "SELECT * FROM `courses` c WHERE c.`name` = \"" + courseName + "\";";

            InitializeCommand();
            OpenConnection();

            DataReader = Command.ExecuteReader();

            if (DataReader.HasRows) {
                DataReader.Read();
                return_data = new CourseData(DataReader.GetUInt16("`course_id`"));
                return_data.Name = DataReader.GetString("`name`");
            }

            CloseConnection();

            return return_data;
        }
Beispiel #17
0
 /// <summary>
 /// gets a list of all the quizzes associated with a course from the database
 /// through the quiz entity
 /// </summary>
 /// <param name="course">course to get quizzes in</param>
 /// <returns></returns>
 public static List<QuizData> GetQuizzes(CourseData course)
 {
     return entity.ReadQuizzes(course);
 }
Beispiel #18
0
        private void lvwCourses_ItemActivate(object sender, EventArgs e)
        {
            mySelectedCourse = CourseController.getCourse(lvwCourses.SelectedItems[0].Text);

            this.Dispose();
        }
Beispiel #19
0
 /// <summary>
 /// Delete a Course from the database
 /// </summary>
 /// <param name="theCourse">a Course object to delete from the Database</param>
 public void DeleteCourse(CourseData theCourse)
 {
 }
Beispiel #20
0
        /// <summary>
        /// Update a Course on the Database given the Course data
        /// </summary>
        /// <param name="theCourse">a Course object of the Course to be updated</param>
        public void UpdateCourse(CourseData theCourse)
        {
            if (DataReader != null)
                DataReader.Close();

            SQL = "UPDATE `courses` c SET c.'name' = \"" + theCourse.Name + "\" WHERE c.`course_id` = \"" + theCourse.Id + "\";";

            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
                throw new Exception("Unable to update course information");
        }
Beispiel #21
0
        /// <summary>
        /// Delete a Course from the database
        /// </summary>
        /// <param name="theCourse">a Course object to delete from the Database</param>
        public void DeleteCourse(CourseData theCourse)
        {
            QuizEntity temp = new QuizEntity();

            List<QuizData> quizzes = temp.ReadQuizzes(theCourse);

            for (int i = 0; i < quizzes.Count; i++)
                temp.DeleteQuiz(quizzes[i]);

            if (DataReader != null)
                DataReader.Close();

            SQL = "DELETE FROM `courses` WHERE `courses`.`course_id` = \"" + theCourse.Id + "\";";

            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
                throw new Exception("Could not delete Course from the database");
        }