コード例 #1
0
ファイル: QuizController.cs プロジェクト: rnovak/JiTU-CS
        public static void GetQuestions(QuizData quiz)
        {
            //TODO replace code to get questions from database

            quiz.questions.Clear();

            QuestionData newQuestion = new QuestionData(0);
            AnswerData correctAnswer = new AnswerData(0);
            AnswerData wrongAnswer = new AnswerData(0);
            correctAnswer.Correct = true;
            correctAnswer.Text = "This is the correct answer";
            wrongAnswer.Text = "This is a wrong answer";

            newQuestion.Text = "This is a question";

            newQuestion.answers.Add(correctAnswer);
            newQuestion.answers.Add(wrongAnswer);
            newQuestion.answers.Add(wrongAnswer);
            newQuestion.answers.Add(wrongAnswer);

            for (int i = 0; i < 10; i++)
            {
                quiz.questions.Add(newQuestion);
            }
        }
コード例 #2
0
ファイル: frmSubmit.cs プロジェクト: bubber11/JiTU-CS
        QuizData myQuiz; //quiz we are submitting

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="quiz"></param>
        public frmSubmit(QuizData quiz)
        {
            InitializeComponent();

            myQuiz = quiz;

            this.Text = "Submitting " + myQuiz.Name;
        }
コード例 #3
0
ファイル: QuizController.cs プロジェクト: rnovak/JiTU-CS
        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;
        }
コード例 #4
0
ファイル: QuizController.cs プロジェクト: bubber11/JiTU-CS
 /// <summary>
 /// saves a quiz
 /// </summary>
 /// <param name="quiz"></param>
 public static void SaveQuiz(QuizData quiz)
 {
     try {
         if (quiz.Id == 0) {
             entity.CreateQuiz(quiz);
         } else {
             entity.UpdateQuiz(quiz);
         }
     } catch (System.Exception e) {
         System.Windows.Forms.MessageBox.Show(e.Message);
     }
 }
コード例 #5
0
ファイル: QuizEntity.cs プロジェクト: bubber11/JiTU-CS
        public void AddQuestion(QuizData theQuiz, QuestionData theQuestion)
        {
            if (DataReader != null)
                DataReader.Close();

            SQL = "INSERT INTO `rel_quizzes_questions` (`quiz_id`, `question_id`) VALUES (\"" + theQuiz.Id + "\", \"" + theQuestion.Id + "\");";

            InitializeCommand();

            int result = ExecuteStoredProcedure();

            if (result == 0)
                throw new Exception("Unable to add question to quiz");
        }
コード例 #6
0
ファイル: QuizView.cs プロジェクト: rnovak/JiTU-CS
        public QuizView(QuizData quiz)
        {
            InitializeComponent();
            //set title
            lblMessage.Text = quiz.Name;

            //get questions, and display them
            QuizController.GetQuestions(quiz);

            for (int i = quiz.questions.Count - 1; i >= 0; i--)
            {
                QuestionBox questionBox = new QuestionBox(quiz.questions[i], i + 1);
                questionBox.Dock = DockStyle.Top;
                pnlMain.Controls.Add(questionBox);
            }
        }
コード例 #7
0
ファイル: QuizController.cs プロジェクト: bubber11/JiTU-CS
        /// <summary>
        /// validates data and if good saves it
        /// </summary>
        /// <param name="quiz">quiz to submit</param>
        /// <exception cref="Exception">data not correct.</exception>
        public static void SubmitQuiz(QuizData quiz)
        {
            QuestionEntity temp = new QuestionEntity();
            quiz.Questions.AddRange(temp.ReadQuestions(quiz));
            temp.Dispose();
            //Validate data
            if (quiz.Due < quiz.Open)
                throw new Exception("The due date must be after the open date.");

            if (quiz.Questions.Count == 0)
                throw new Exception("The quiz must contain at least one question.");

            // Validation for questions takes place when creating the individual questions

            //Now that we validated save the quiz
            SaveQuiz(quiz);
        }
コード例 #8
0
ファイル: CourseEntity.cs プロジェクト: bubber11/JiTU-CS
        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");
        }
コード例 #9
0
ファイル: QuizzesView.cs プロジェクト: rnovak/JiTU-CS
        private void addToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string quizName = "";
            var result = Helper.InputBox("", "Enter name of quiz", ref quizName);

            if (result != DialogResult.Cancel)
            {
                //add to list
                lvwQuizzes.Items.Add(quizName, 0);

                //add to database
                QuizData quizToAdd = new QuizData();
                quizToAdd.Name = quizName;
                QuizController.SaveQuiz(quizToAdd);

                //add to list
                quizzes.Add(quizToAdd);
            }
        }
コード例 #10
0
ファイル: QuizEntity.cs プロジェクト: bubber11/JiTU-CS
        public void CreateQuiz(QuizData theQuiz)
        {
            theQuiz.Id = NextId;
            if (DataReader != null)
                DataReader.Close();

            SQL = "INSERT INTO `quizzes` (`quiz_id`, `name`, `open_date`, `due_date`) VALUES " +
                "(\"" + theQuiz.Id + "\", \"" + theQuiz.Name + "\", \"" + theQuiz.Open.ToString("yyyy-MM-dd") +
                "\", \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\");";

            InitializeCommand();

            int result = ExecuteStoredProcedure();

            if (result == 0)
                throw new Exception("Could Not add the quiz to the database");

            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++) {

                temp.CreateQuestion(theQuiz.Questions[i]);
                if (DataReader != null)
                    DataReader.Close();

                SQL = "INSERT INTO `rel_quizzes_questions` (`quiz_id`, `question_id`) VALUES (\"" +
                    theQuiz.Id + "\", \"" + theQuiz.Questions[i].Id + "\");";

                InitializeCommand();

                result = ExecuteStoredProcedure();

                if (result == 0)
                    throw new Exception("Cannot associate this question with this quiz");

            }
        }
コード例 #11
0
ファイル: ResultsController.cs プロジェクト: bubber11/JiTU-CS
 public static double GetStudentPercentage(UserData student, QuizData quiz)
 {
     return theEntity.StudentResults(student, quiz);
 }
コード例 #12
0
ファイル: ResultsEntity.cs プロジェクト: bubber11/JiTU-CS
        public double StudentResults(UserData theUser, QuizData theQuiz)
        {
            double return_val = 100.00;

            int quest_count;
            int correct_count;

            if (DataReader != null)
            {
                DataReader.Close();
                DataReader.Dispose();
                Command.Dispose();
                Command = null;
            }

            SQL = "SELECT IFNULL(COUNT(`question_id`), 0) FROM `rel_quizzes_questions` WHERE `rel_quizzes_questions`.`quiz_id` = " + theQuiz.Id + ";";

            InitializeCommand();
            OpenConnection();
            DataReader = Command.ExecuteReader();
            DataReader.Read();
            quest_count = DataReader.GetUInt16("IFNULL(COUNT(`question_id`), 0)");

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

            SQL = "SELECT IFNULL(COUNT(r.`question_id`), 0) FROM `rel_quizzes_questions` r INNER JOIN `questions` q on q.`question_id` = r.`question_id` INNER JOIN `rel_questions_answers` s ON s.`question_id` = q.`question_id` INNER JOIN `answers` a ON a.`answer_id` = s.`answer_id` INNER JOIN `rel_answers_users` t ON t.`answer_id` = a.`answer_id` WHERE r.`quiz_id` = \"" + theQuiz.Id + "\" and a.`is_correct` = \"1\" and t.`user_id` = \"" + theUser.Id + "\";";

            InitializeCommand();

            DataReader = Command.ExecuteReader();
            DataReader.Read();

            correct_count = DataReader.GetUInt16("IFNULL(COUNT(r.`question_id`), 0)");

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

            if (correct_count == 0)
                return_val = 0;

            else {
                if (quest_count == 0)
                    return_val = 0;
                else
                    return_val = ((double)correct_count / (double)quest_count) * 100.00;
            }
            CloseConnection();

            return return_val;
        }
コード例 #13
0
ファイル: QuizController.cs プロジェクト: rnovak/JiTU-CS
 public static void DeleteQuiz(QuizData quiz)
 {
     // TODO add code to remove quiz from database
 }
コード例 #14
0
ファイル: UserEntity.cs プロジェクト: bubber11/JiTU-CS
        /// <summary>
        /// Checks to see if the user has taken the given test
        /// </summary>
        /// <param name="theUser"></param>
        /// <param name="theQuiz"></param>
        /// <returns></returns>
        public bool TestTaken(UserData theUser, QuizData theQuiz)
        {
            bool return_val = false;

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

            SQL = "select IFNULL(COUNT(`user_id`), 0) FROM `rel_quizzes_users` r WHERE r.`user_id` = \"" + theUser.Id + "\" and r.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            DataReader = Command.ExecuteReader();

            DataReader.Read();
            return_val = DataReader.GetUInt16("IFNULL(COUNT(`user_id`), 0)") == 1;
            CloseConnection();

            return return_val;
        }
コード例 #15
0
ファイル: CourseController.cs プロジェクト: bubber11/JiTU-CS
 /// <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);
 }
コード例 #16
0
ファイル: QuizEntity.cs プロジェクト: bubber11/JiTU-CS
        public void UpdateQuiz(QuizData theQuiz)
        {
            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
            {
                QuestionData questionToSave;
                questionToSave = theQuiz.Questions[i];
                if (questionToSave.Id == 0)
                {
                    temp.CreateQuestion(questionToSave);
                    AddQuestion(theQuiz, questionToSave);

                }
                else
                    temp.UpdateQuestion(questionToSave);

            }

            temp.Dispose();

            SQL = "UPDATE `quizzes` q SET q.`name` = \"" + theQuiz.Name + "\", q.`open_date` = \"" + theQuiz.Open.ToString("yyyy-MM-dd") + "\", q.`due_date` = \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\" WHERE q.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();
            CloseConnection();

            if (result == 0)
                throw new Exception("Unable to update the quiz on the database");
        }
コード例 #17
0
 public ResultData(UserData theUser, QuizData theQuiz)
 {
     __Answers = new List <AnswerData>();
     __Student = theUser;
     __Quiz    = theQuiz;
 }
コード例 #18
0
ファイル: QuizEntity.cs プロジェクト: bubber11/JiTU-CS
        public void DeleteQuiz(QuizData theQuiz)
        {
            if (DataReader != null)
                DataReader.Close();

            QuestionEntity quest = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
                quest.DeleteQuestion(theQuiz.Questions[i]);

            quest.Dispose();

            SQL = "DELETE `quizzes`, `rel_courses_quizzes` FROM `quizzes` INNER JOIN `rel_courses_quizzes` ON `quizzes`.`quiz_id` = `rel_courses_quizzes`.`quiz_id` WHERE `quizzes`.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();
            CloseConnection();

            if (result == 0)
                throw new Exception("Could not delete the Quiz from Database");
        }
コード例 #19
0
ファイル: QuizEntity.cs プロジェクト: bubber11/JiTU-CS
        public QuizData ReadQuiz(int id)
        {
            QuizData return_value = null;

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

            SQL = "SELECT * FROM `quizzes` q WHERE q.`quiz_id` = \"" + id + "\";";

            InitializeCommand();
            OpenConnection();

            DataReader = Command.ExecuteReader();

            if (DataReader.HasRows) {
                DataReader.Read();
                return_value = new QuizData(DataReader.GetUInt16("quiz_id"));
                return_value.Name = DataReader.GetString("name");
                return_value.Open = DataReader.GetDateTime("open_date");
                return_value.Due = DataReader.GetDateTime("due_date");
            }

            //QuestionEntity temp = new QuestionEntity();

            //return_value.Questions.AddRange(temp.ReadQuestions(return_value));

            CloseConnection();

            if (return_value == null)
                throw new Exception("Could not find specified Quiz");

            return return_value;
        }
コード例 #20
0
ファイル: ResultsEntity.cs プロジェクト: bubber11/JiTU-CS
        /// <summary>
        /// Gets the number of correct answers for each question with in a quiz.
        /// </summary>
        /// <param name="theQuiz"></param>
        /// <returns></returns>
        public DataTable CountWrong(QuizData theQuiz)
        {
            DataTable myTable = new DataTable();
            myTable.Columns.Add("Question", typeof(QuestionData));
            myTable.Columns.Add("Count", typeof(int));

            DataRow myNewRow;

            foreach (QuestionData theQuestion in theQuiz.Questions)
            {
                myNewRow = myTable.NewRow();
                myNewRow[0] = theQuestion;
                myNewRow[1] = CountWrong(theQuestion);
            }

            return myTable;
        }
コード例 #21
0
ファイル: QuizController.cs プロジェクト: rnovak/JiTU-CS
 public static void SaveQuiz(QuizData quiz)
 {
     // TODO add code to add quiz to database
 }
コード例 #22
0
ファイル: ResultsController.cs プロジェクト: bubber11/JiTU-CS
 public static DataTable GetCorrectCount(QuizData theQuiz)
 {
     return theEntity.CountCorrect(theQuiz);
 }
コード例 #23
0
ファイル: ResultData.cs プロジェクト: bubber11/JiTU-CS
 public ResultData(UserData theUser, QuizData theQuiz)
 {
     __Answers = new List<AnswerData>();
     __Student = theUser;
     __Quiz = theQuiz;
 }
コード例 #24
0
ファイル: QuizController.cs プロジェクト: bubber11/JiTU-CS
 /// <summary>
 /// deletes a quiz from the database using the quiz entity
 /// </summary>
 /// <param name="quiz">the quiz to be removed</param>
 public static void DeleteQuiz(QuizData quiz)
 {
     entity.DeleteQuiz(quiz);
 }
コード例 #25
0
ファイル: QuestionEntity.cs プロジェクト: bubber11/JiTU-CS
        public List<QuestionData> ReadQuestions(QuizData theQuiz)
        {
            List<QuestionData> return_data = new List<QuestionData>();

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

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

            SQL = "SELECT r.`question_id` FROM `rel_quizzes_questions` r WHERE r.`quiz_id` = \"" + theQuiz.Id + "\";";

            InitializeCommand();
            OpenConnection();

            DataReader = Command.ExecuteReader();

            if (DataReader.HasRows)
                while (DataReader.Read())
                    quest_ids.Add(DataReader.GetUInt16("question_id"));

            CloseConnection();

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

            return return_data;
        }
コード例 #26
0
ファイル: ResultsController.cs プロジェクト: bubber11/JiTU-CS
 public static DataTable GetWrongCount(QuizData theQuiz)
 {
     return theEntity.CountWrong(theQuiz);
 }