Пример #1
0
        public string insert_score(ScoreProvider score)
        {
            string        user_message;
            SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString);

            try
            {
                SqlCommand sqlCmd = new SqlCommand("[insert_score]", sqlConnection);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@student_course_fk_student_uid", SqlDbType.Int).Value = score.student_course_fk_student_uid;
                sqlCmd.Parameters.Add("@student_course_fk_course_id", SqlDbType.Int).Value   = score.student_course_fk_course_id;
                sqlCmd.Parameters.Add("@student_course_grade", SqlDbType.Decimal).Value      = score.student_course_grade;


                sqlConnection.Open();
                sqlCmd.ExecuteNonQuery();
                return(user_message = "Score Submitted!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(user_message = "Failure!");
            }
            finally
            {
                sqlConnection.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.");
            }
        }