Пример #1
0
        private void bt_test_Click(object sender, RoutedEventArgs e)
        {
            TestSelector testSelector = new TestSelector();

            testSelector.Show();
            this.Close();
        }
Пример #2
0
        private void bt_submit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (rbt_answer_a.IsChecked == true)
                {
                    selected_answer = Convert.ToString(rbt_answer_a.Content);
                }
                else if (rbt_answer_b.IsChecked == true)
                {
                    selected_answer = Convert.ToString(rbt_answer_b.Content);
                }
                else if (rbt_answer_c.IsChecked == true)
                {
                    selected_answer = Convert.ToString(rbt_answer_c.Content);
                }
                else if (rbt_answer_d.IsChecked == true)
                {
                    selected_answer = Convert.ToString(rbt_answer_d.Content);
                }


                if (selected_answer.Equals(correct_answer))
                {
                    current_score++;
                    lbl_score.Content = "Score : " + Convert.ToString(current_score);
                }


                next_question_number = connect.returnconnection_string("SELECT min(question_id) FROM Questions WHERE question_fk_course =" + current_course_id + " AND question_id > " + question_key);
                if (next_question_number.Equals(""))
                {
                    AnswerProvider answer = new AnswerProvider();
                    answer.student_results_fk_student      = StudentLogin.student_uid;
                    answer.student_results_fk_question     = question_key;
                    answer.student_results_selected_answer = selected_answer;
                    answer.student_results_date            = System.DateTime.Now;

                    AnswerHandler answerHandler = new AnswerHandler();
                    string        user_message  = answerHandler.insert_answer(answer);

                    ScoreProvider score = new ScoreProvider();
                    score.student_course_fk_student_uid = StudentLogin.student_uid;
                    score.student_course_fk_course_id   = current_course_id;
                    score.student_course_grade          = Convert.ToDecimal(current_score / total_questions);

                    ScoreHandler scoreHandler = new ScoreHandler();
                    string       use_message  = scoreHandler.insert_score(score);

                    MessageBox.Show(user_message);
                    MessageBox.Show("Exam is over. Please wait.");

                    TestSelector testSelector = new TestSelector();
                    testSelector.Show();
                }
                else
                {
                    AnswerProvider answer = new AnswerProvider();
                    answer.student_results_fk_student      = StudentLogin.student_uid;
                    answer.student_results_fk_question     = question_key;
                    answer.student_results_selected_answer = selected_answer;
                    answer.student_results_date            = System.DateTime.Now;

                    AnswerHandler answerHandler = new AnswerHandler();
                    string        user_message  = answerHandler.insert_answer(answer);
                    MessageBox.Show(user_message);

                    load_page(current_course_id);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please select an answer.");
            }
        }