Esempio n. 1
0
        private void lblNextQuestion_Click(object sender, EventArgs e)
        {
            int currentSelect = CurrentSelectRadio();

            if (currentSelect == -1)
            {
                return;
            }

            if (index + 1 == exam.QuestionQuantity)
            {
                this.lblNextQuestion.Text = "Submit Exam";
            }

            StoreAnswer storeAnswer = new StoreAnswer();

            storeAnswer.UserId     = SessionUtil.User.Id;
            storeAnswer.ExamId     = exam.Id;
            storeAnswer.QuestionId = currentQuestion.Id;
            storeAnswer.Answer     = currentSelect;

            try
            {
                examClient.SaveExamAnswer(storeAnswer);
            }
            catch (FaultException <DBException> faultDbException)
            {
                ShowAlertWindow(faultDbException.Message);
                HideQuestionRelativeControls();
            }
            catch (CommunicationException communicationException)
            {
                ShowAlertWindow(Constants.CannotConnServer);
                HideQuestionRelativeControls();
            }
            catch (TimeoutException timeoutException)
            {
                ShowAlertWindow(Constants.NetworkTimeout);
                HideQuestionRelativeControls();
            }

            if (index == exam.QuestionQuantity)
            {
                SubmitExam();
            }

            //load next question
            index++;

            if (index <= exam.QuestionQuantity)
            {
                currentQuestion              = questions[index - 1];
                this.lblQuestionIndex.Text   = index.ToString();
                this.lblCurrentAndTotal.Text = index + "/" + exam.QuestionQuantity;
                InitialQuestionRelateText(currentQuestion);
            }
            ClearSelectRadio();
        }
Esempio n. 2
0
        public void SaveExamAnswer(StoreAnswer storeAnswer)
        {
            SqlConnection connection = DBUtil.GetSqlConnection();

            try
            {
                connection.Open();
                SqlCommand command = new SqlCommand(Constants.ProcSaveExamAnswer, connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add(new SqlParameter(Constants.SqlParameterUserId, storeAnswer.UserId));
                command.Parameters.Add(new SqlParameter(Constants.SqlParameterExamId, storeAnswer.ExamId));
                command.Parameters.Add(new SqlParameter(Constants.SqlParameterQuestionId, storeAnswer.QuestionId));
                command.Parameters.Add(new SqlParameter(Constants.SqlParameterAnswer, storeAnswer.Answer));
                command.Parameters.Add(new SqlParameter(Constants.SqlParameterAnswerScore, storeAnswer.AnswerScore));
                command.ExecuteNonQuery();
            }
            finally
            {
                DBUtil.ColseSqlConnection(connection);
            }
        }
Esempio n. 3
0
 public void SaveExamAnswer(StoreAnswer storeAnswer)
 {
     try
     {
         int correctAnswer = questionDal.GetQuestionAnswerByQuestionId(storeAnswer.QuestionId);
         if (storeAnswer.Answer == correctAnswer)
         {
             storeAnswer.AnswerScore = 1;
         }
         else
         {
             storeAnswer.AnswerScore = 0;
         }
         examDal.SaveExamAnswer(storeAnswer);
     }
     catch (SqlException sqlException)
     {
         log.Error(sqlException.StackTrace);
         throw new FaultException <DBException>(new DBException(), Constants.ServerError);
     }
 }