Ejemplo n.º 1
0
 public static void SaveResults(ResultData theResults)
 {
     if (theResults.Answers.Count == 0)
         System.Windows.Forms.MessageBox.Show("There are no answers to save.", "JiTU", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
     else
         if (theResults.Student.Id == 0)
             System.Windows.Forms.MessageBox.Show("The user id is invalid.", "JiTU", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         else
             theEntity.AddResult(theResults);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Writes the result of the quiz to the database
        /// </summary>
        /// <param name="theResults"></param>
        public void AddResult(ResultData theResults)
        {
            try
            {
                int result;
                if (theResults.Answers.Count > 0) {
                    this.SQL = "INSERT INTO `rel_answers_users` (`user_id`, `answer_id`) VALUES ";

                    this.SQL += "(\"" + theResults.Student.Id + "\", \"" + theResults.Answers[0].Id + "\")";

                    for (int index = 1; index < theResults.Answers.Count - 1; index++)
                        this.SQL += ", (\"" + theResults.Student.Id + "\", \"" + theResults.Answers[index].Id + "\")";

                    SQL += ", (\"" + theResults.Student.Id + "\", \"" + theResults.Answers[theResults.Answers.Count - 1].Id + "\");";

                    this.InitializeCommand();
                    OpenConnection();

                    result = ExecuteStoredProcedure();

                    if (result == 0)
                        throw new System.Exception("Unable to save the user's answers.");
                }
                if (DataReader != null)
                    DataReader.Close();

                SQL = "INSERT INTO `rel_quizzes_users` (`quiz_id`, `user_id`) VALUES (\"" + theResults.Quiz.Id + "\", \"" + theResults.Student.Id + "\");";
                InitializeCommand();
                OpenConnection();

                result = ExecuteStoredProcedure();

                CloseConnection();

                if (result == 0)
                    throw new Exception("Unable to save the user\'s answers");

            }
            catch (System.Exception e)
            {
                throw new System.Exception(e.Message, e.InnerException);
            }
            finally
            {

            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// handles submit buttons click event.
        /// Allows student to submit a quiz they are taking.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnSubmit_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to submit this quiz?", "Submit", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    ResultData temp = new ResultData(GlobalData.currentUser, GlobalData.currentQuiz);
                    foreach (QuestionBox ind in questionBoxes) {
                    for (int i = 0; i < ind.rbtnAnswers.Length; i++)
                    {
                        if (ind.rbtnAnswers[i].Checked)
                            temp.Answers.Add((AnswerData)ind.rbtnAnswers[i].Tag);
                    }
                }
                ResultsEntity res = new ResultsEntity();
                res.AddResult(temp);
                res.Dispose();

                MessageBox.Show ("You scored " + ResultsController.GetStudentPercentage(GlobalData.currentUser, GlobalData.currentQuiz) + "%");
                GoBackToQuizzesView();
            }
        }