Пример #1
0
        private void EndTest()
        {
            // stop the times
            timerTest.Stop();
            timerQuestion.Stop();

            // variables
            string studentAnswer = "";
            int    n;
            bool   isNumeric = int.TryParse(txtStudentAnswer.Text, out n);

            // Because if the user clicks submit on the very last problem, and waits out the time
            // it'll throw an errow if we don't check for this.
            if (currentQuestionNum < gradedPracticeTest.PracticeTest.Questions.Count())
            {
                // We still want this code to grab the student's answer if they have anything on the current question
                if (txtStudentAnswer.Text == "" || txtStudentAnswer.Text == null || isNumeric == false)
                {
                    studentAnswer = "0";
                }
                else
                {
                    studentAnswer = txtStudentAnswer.Text.Trim();
                }

                if (Convert.ToInt32(studentAnswer) == gradedPracticeTest.PracticeTest.Questions[currentQuestionNum].CorrectAnswer)
                {
                    GradedQuestion correctlyAnsweredQuestion = new GradedQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum], studentAnswer, true, new TimeSpan(0, 1, 1));
                    gradedPracticeTest.CorrectlyAnsweredQuestions.Add(correctlyAnsweredQuestion);
                }
                else
                {
                    GradedQuestion wronglyAnsweredQuestion = new GradedQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum], studentAnswer, false, new TimeSpan(0, 1, 1));
                    gradedPracticeTest.WronglyAnsweredQuestions.Add(wronglyAnsweredQuestion);
                }
            }


            currentQuestionNum++;
            lblCorrectAnswer.Show();

            //If the timer ends and the student isn't on the last question then..
            if (currentQuestionNum < gradedPracticeTest.PracticeTest.Questions.Count())
            {
                // Have the rest of the unanswered questions end up as automatic wrongly answered questions
                // and add them to the graded test
                // Don't know if having student answer be null would be bad, so I threw a 0 in there which will
                // result in the question being wrong 99% of the time.
                for (int x = currentQuestionNum; x < gradedPracticeTest.PracticeTest.Questions.Count(); x++)
                {
                    GradedQuestion wronglyAnsweredQuestion = new GradedQuestion(gradedPracticeTest.PracticeTest.Questions[x], "0", false, new TimeSpan(0, 1, 1));
                    gradedPracticeTest.WronglyAnsweredQuestions.Add(wronglyAnsweredQuestion);
                }
            }

            btnStartFinish.Text = "Finish Test";
            btnStartFinish.Show();
            btnSubmitAnswer.Enabled = false;
        }
Пример #2
0
        private void EndQuestion()
        {
            timerQuestion.Stop();
            string studentAnswer = "";
            int    n;
            bool   isNumeric = int.TryParse(txtStudentAnswer.Text, out n);

            if (currentQuestionNum < gradedPracticeTest.PracticeTest.Questions.Count())
            {
                // We still want this code to grab the student's answer if they have anything on the current question
                if (txtStudentAnswer.Text == "" || txtStudentAnswer.Text == null || isNumeric == false)
                {
                    studentAnswer = "0";
                }
                else
                {
                    studentAnswer = txtStudentAnswer.Text.Trim();
                }

                if (Convert.ToInt32(studentAnswer) == gradedPracticeTest.PracticeTest.Questions[currentQuestionNum].CorrectAnswer)
                {
                    GradedQuestion correctlyAnsweredQuestion = new GradedQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum], studentAnswer, true, new TimeSpan(0, 1, 1));
                    gradedPracticeTest.CorrectlyAnsweredQuestions.Add(correctlyAnsweredQuestion);
                }
                else
                {
                    GradedQuestion wronglyAnsweredQuestion = new GradedQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum], studentAnswer, false, new TimeSpan(0, 1, 1));
                    gradedPracticeTest.WronglyAnsweredQuestions.Add(wronglyAnsweredQuestion);
                }
            }

            lblCorrectAnswer.Show();

            currentQuestionNum++;

            if (currentQuestionNum <= gradedPracticeTest.PracticeTest.Questions.Count)
            {
                ShowQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum]);
                // reset the timer if there is a next question
                lblTimerQuestion.Text = "01:00";
            }
            else //the test if finished
            {
                btnStartFinish.Show();
                btnSubmitAnswer.Enabled = false;
            }
        }
Пример #3
0
        public static GradedQuestion SelectGradeQuestion(int id)
        {
            GradedQuestion gradeQuestion = new GradedQuestion();

            //make the query the safe way by binding values to prevent SQL injection
            string     query         = "SELECT * FROM GradedQuestions WHERE ID = @ID";
            SqlCommand selectCommand = new SqlCommand(query, conn);

            selectCommand.Parameters.AddWithValue("@BranchName", id);


            try
            {
                conn.Open();

                SqlDataReader reader = selectCommand.ExecuteReader();

                if (reader.Read())
                {
                    gradeQuestion.Id                = Convert.ToInt32(reader["QuestionID"]);
                    gradeQuestion.StudentAnswer     = Convert.ToString(reader["StudentAnswer"]);
                    gradeQuestion.Correct           = Convert.ToBoolean(reader["Correct"]);
                    gradeQuestion.TimeTakenToAnswer = TimeSpan.Parse(reader["TimeTakenToAnswer"].ToString());
                }
                reader.Close();
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Database SQL Exception\n\n" + ex.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Generic Exception.\n\n" + ex.ToString());
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(gradeQuestion);
        }
Пример #4
0
        public static void InsertGradedQuestion(GradedQuestion gradedQuestion, int gradedTestID)
        {
            string insertStatement = "INSERT INTO graded_questions (GradedTestID, QuestionID, StudentAnswer, Correct, TimeTakenToAnswer) " +
                                     "VALUES(@TestID, @QuestionID, @StudentAnswer, @Correct, @Time)";

            // create command object with SQL query and link to connection object
            SqlCommand Cmd = new SqlCommand(insertStatement, conn);

            // create your parameters and add values from object
            Cmd.Parameters.AddWithValue("@TestID", gradedTestID);
            Cmd.Parameters.AddWithValue("@QuestionID", gradedQuestion.Question.Id);
            Cmd.Parameters.AddWithValue("@StudentAnswer", gradedQuestion.StudentAnswer);
            Cmd.Parameters.AddWithValue("@Correct", gradedQuestion.Correct);
            Cmd.Parameters.AddWithValue("@Time", gradedQuestion.TimeTakenToAnswer);

            try
            {
                // Open the connection
                conn.Open();

                // execute the query
                Cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
        }
Пример #5
0
        private async void btnSubmitAnswer_Click(object sender, EventArgs e)
        {
            if (Validation.IsInteger(txtStudentAnswer))
            {
                string         studentAnswer = txtStudentAnswer.Text;
                TimeSpan       timeTakenToAnswer;
                GradedQuestion correctlyAnsweredQuestion;
                GradedQuestion wronglyAnsweredQuestion;

                switch (this.Tag.ToString())
                {
                case "placement":

                    timeTakenToAnswer = gradedPlacementTest.PlacementTest.Questions[currentQuestionNum].TimeLimit - TimeSpan.ParseExact(lblTimerQuestion.Text, "mm\\:ss", CultureInfo.InvariantCulture);

                    if (Convert.ToInt32(txtStudentAnswer.Text.Trim()) == gradedPlacementTest.PlacementTest.Questions[currentQuestionNum].CorrectAnswer)
                    {
                        correctlyAnsweredQuestion = new GradedQuestion(gradedPlacementTest.PlacementTest.Questions[currentQuestionNum], studentAnswer, true, timeTakenToAnswer);
                        gradedPlacementTest.CorrectlyAnsweredQuestions.Add(correctlyAnsweredQuestion);

                        txtStudentAnswer.ForeColor = Color.FromArgb(0, 255, 0);
                    }
                    else
                    {
                        wronglyAnsweredQuestion = new GradedQuestion(gradedPlacementTest.PlacementTest.Questions[currentQuestionNum], studentAnswer, false, timeTakenToAnswer);
                        gradedPlacementTest.WronglyAnsweredQuestions.Add(wronglyAnsweredQuestion);

                        txtStudentAnswer.ForeColor = Color.FromArgb(255, 0, 0);
                    }

                    lblCorrectAnswer.Show();
                    await Task.Delay(1000);     //show the answer for a bit

                    currentQuestionNum++;

                    if (currentQuestionNum < gradedPlacementTest.PlacementTest.Questions.Count)
                    {
                        ShowQuestion(gradedPlacementTest.PlacementTest.Questions[currentQuestionNum]);
                    }
                    else     //the test if finished
                    {
                        btnStartFinish.Show();
                        btnStartFinish.Focus();
                        txtStudentAnswer.Enabled = false;
                        btnSubmitAnswer.Enabled  = false;

                        timerQuestion.Stop();
                        timerTest.Stop();
                    }

                    break;

                case "practice":

                    timeTakenToAnswer = gradedPracticeTest.PracticeTest.Questions[currentQuestionNum].TimeLimit - TimeSpan.ParseExact(lblTimerQuestion.Text, "mm\\:ss", CultureInfo.InvariantCulture);

                    if (Convert.ToInt32(txtStudentAnswer.Text.Trim()) == gradedPracticeTest.PracticeTest.Questions[currentQuestionNum].CorrectAnswer)
                    {
                        correctlyAnsweredQuestion = new GradedQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum], studentAnswer, true, timeTakenToAnswer);
                        gradedPracticeTest.CorrectlyAnsweredQuestions.Add(correctlyAnsweredQuestion);

                        txtStudentAnswer.ForeColor = Color.FromArgb(0, 255, 0);
                    }
                    else
                    {
                        wronglyAnsweredQuestion = new GradedQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum], studentAnswer, false, timeTakenToAnswer);
                        gradedPracticeTest.WronglyAnsweredQuestions.Add(wronglyAnsweredQuestion);

                        txtStudentAnswer.ForeColor = Color.FromArgb(255, 0, 0);
                    }

                    lblCorrectAnswer.Show();
                    await Task.Delay(1000);     //show the answer for a bit

                    currentQuestionNum++;

                    if (currentQuestionNum < gradedPracticeTest.PracticeTest.Questions.Count)
                    {
                        ShowQuestion(gradedPracticeTest.PracticeTest.Questions[currentQuestionNum]);
                    }
                    else     //the test if finished
                    {
                        btnStartFinish.Show();
                        btnStartFinish.Focus();
                        txtStudentAnswer.Enabled = false;
                        btnSubmitAnswer.Enabled  = false;

                        timerQuestion.Stop();
                        timerTest.Stop();
                    }

                    break;

                case "mastery":

                    timeTakenToAnswer = gradedMasteryTest.MasteryTest.Questions[currentQuestionNum].TimeLimit - TimeSpan.ParseExact(lblTimerQuestion.Text, "mm\\:ss", CultureInfo.InvariantCulture);

                    if (Convert.ToInt32(txtStudentAnswer.Text.Trim()) == gradedMasteryTest.MasteryTest.Questions[currentQuestionNum].CorrectAnswer)
                    {
                        correctlyAnsweredQuestion = new GradedQuestion(gradedMasteryTest.MasteryTest.Questions[currentQuestionNum], studentAnswer, true, timeTakenToAnswer);
                        gradedMasteryTest.CorrectlyAnsweredQuestions.Add(correctlyAnsweredQuestion);

                        txtStudentAnswer.ForeColor = Color.FromArgb(0, 255, 0);
                    }
                    else
                    {
                        wronglyAnsweredQuestion = new GradedQuestion(gradedMasteryTest.MasteryTest.Questions[currentQuestionNum], studentAnswer, false, timeTakenToAnswer);
                        gradedMasteryTest.WronglyAnsweredQuestions.Add(wronglyAnsweredQuestion);

                        txtStudentAnswer.ForeColor = Color.FromArgb(255, 0, 0);
                    }

                    lblCorrectAnswer.Show();
                    await Task.Delay(1000);     //show the answer for a bit

                    currentQuestionNum++;

                    if (currentQuestionNum < gradedMasteryTest.MasteryTest.Questions.Count)
                    {
                        ShowQuestion(gradedMasteryTest.MasteryTest.Questions[currentQuestionNum]);
                    }
                    else     //the test if finished
                    {
                        btnStartFinish.Show();
                        btnStartFinish.Focus();
                        txtStudentAnswer.Enabled = false;
                        btnSubmitAnswer.Enabled  = false;

                        timerQuestion.Stop();
                        timerTest.Stop();
                    }

                    break;
                }

                txtStudentAnswer.Text = "";
            }
        }