示例#1
0
        /// <summary>
        /// Returns the Answers Options from Question by Question ID.
        /// </summary>
        /// <param name="questionId">int questionId</param>
        /// <returns>List<QuestionAnswerOptions></returns>
        /// <exception cref="Exception">Exception</exception>
        public List <QuestionAnswerOptions> getListOfQuestionAnswerOptionByQuestionId(int questionId)
        {
            try
            {
                List <QuestionAnswerOptions> answersOptions = new List <QuestionAnswerOptions>();

                // Fill query parameters
                SqlCommand command = new SqlCommand(AppDAOConstants.getAnswerOptions, databaseConnector.connection);
                command.Parameters.AddWithValue(AppDAOConstants.questionId, questionId);

                SqlDataReader reader = command.ExecuteReader();

                while (reader.Read())
                {
                    //Fill the Question object with the correspondent values.
                    QuestionAnswerOptions questionAnswerOptions = new QuestionAnswerOptions();
                    questionAnswerOptions.SurveyQuestionId     = questionId;
                    questionAnswerOptions.AnswerDescription    = reader[AppDAOConstants.answerDescription].ToString();
                    questionAnswerOptions.SurveyAnswerOptionId = Convert.ToInt32(reader[AppDAOConstants.answerOptionId].ToString());
                    String value = reader[AppDAOConstants.additionalQuestion].ToString();
                    if (reader[AppDAOConstants.additionalQuestion].ToString() != "")
                    {
                        questionAnswerOptions.AdditionalQuestion = Convert.ToInt32(reader[AppDAOConstants.additionalQuestion].ToString());
                    }

                    answersOptions.Add(questionAnswerOptions);
                }
                databaseConnector.connection.Close();
                return(answersOptions);
            }
            catch (Exception ex)
            {
                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Read and store the answers of last question and set in the session.
        /// Get answers options from the pageSurvey page.
        /// Read the controls type:
        ///     TextBox for text answers
        ///     CheckBox for multiple answers between options
        ///     RadioBox for unique answer between options
        ///     DropDownList for unique answer between options
        /// </summary>
        /// <exception cref="Exception">Exception</exception>
        /// <exception cref="AppPageException">AppPageException</exception>
        private void setSurveyQuestionAnswer()
        {
            try
            {
                List <SurveyQuestionAnswer> surveyQuestionAnswerList = SessionControlUtil.getSurveyQuestionAnswerList();
                Question   currentQuestion         = SessionControlUtil.getCurrentQuestion();
                ArrayList  additionalQuestions     = new ArrayList();
                List <int> additionalQuestionsList = new List <int>();

                if (currentQuestion.SurveyQuestionDomainId == AppConstants.fieldTypeTextId)
                {
                    TextBoxControl textBoxControl =
                        (TextBoxControl)SurveyCheckboxPlaceHolder.FindControl(AppConstants.controlTextBoxControl);

                    if (textBoxControl != null)
                    {
                        SurveyQuestionAnswer surveyQuestionAnswer = new SurveyQuestionAnswer();
                        surveyQuestionAnswer.RespondentId     = SessionControlUtil.getUserID();
                        surveyQuestionAnswer.SurveyQuestionId = currentQuestion.QuestionId;

                        if (textBoxControl.QuestionAnswerTextBox.Text.Trim() != null)
                        {
                            surveyQuestionAnswer.AnswerDescription = textBoxControl.QuestionAnswerTextBox.Text.Trim();
                        }

                        surveyQuestionAnswerList.Add(surveyQuestionAnswer);
                        SessionControlUtil.setSurveyQuestionAnswerList(surveyQuestionAnswerList);
                    }
                }
                else if (currentQuestion.SurveyQuestionDomainId == AppConstants.fieldTypeCheckBoxId)
                {
                    CheckBoxControl checkBoxControl =
                        (CheckBoxControl)SurveyCheckboxPlaceHolder.FindControl(AppConstants.controlCheckBoxControl);

                    if (checkBoxControl != null)
                    {
                        int optionsSelected = 0;

                        foreach (ListItem item in checkBoxControl.QuestionAnswerCheckBoxList.Items)
                        {
                            if (item.Selected == true)
                            {
                                optionsSelected++;

                                SurveyQuestionAnswer surveyQuestionAnswer = new SurveyQuestionAnswer();
                                surveyQuestionAnswer.RespondentId         = SessionControlUtil.getUserID();
                                surveyQuestionAnswer.SurveyQuestionId     = currentQuestion.QuestionId;
                                surveyQuestionAnswer.SurveyAnswerOptionId = AppUtil.convertStringToInt(item.Value);
                                surveyQuestionAnswer.AnswerDescription    = null;

                                surveyQuestionAnswerList.Add(surveyQuestionAnswer);
                                SessionControlUtil.setSurveyQuestionAnswerList(surveyQuestionAnswerList);

                                QuestionAnswerOptions answerOption = currentQuestion.AnswerOptionsList.Find(
                                    QuestionAnswerOptions => QuestionAnswerOptions.SurveyAnswerOptionId == surveyQuestionAnswer.SurveyAnswerOptionId);

                                if (answerOption.AdditionalQuestion > 0)
                                {
                                    additionalQuestions.Add(answerOption.AdditionalQuestion);

                                    if (additionalQuestionsList.IndexOf(answerOption.AdditionalQuestion) != 0)
                                    {
                                        additionalQuestionsList.Add(answerOption.AdditionalQuestion);
                                    }
                                }
                            }
                        }

                        // If there is not answer for this question, it is recorded the question with answer null.
                        // So it is possible to verify that respondent do not answer this question,
                        // however it was asked to him
                        if (optionsSelected == 0)
                        {
                            SurveyQuestionAnswer surveyQuestionAnswer = new SurveyQuestionAnswer();
                            surveyQuestionAnswer.RespondentId      = SessionControlUtil.getUserID();
                            surveyQuestionAnswer.SurveyQuestionId  = currentQuestion.QuestionId;
                            surveyQuestionAnswer.AnswerDescription = null;

                            surveyQuestionAnswerList.Add(surveyQuestionAnswer);
                            SessionControlUtil.setSurveyQuestionAnswerList(surveyQuestionAnswerList);
                        }
                    }
                }
                else if (currentQuestion.SurveyQuestionDomainId == AppConstants.fieldTypeRadioButtonId)
                {
                    RadioButtonControl radioButtonControl =
                        (RadioButtonControl)SurveyCheckboxPlaceHolder.FindControl(AppConstants.controlRadioButtonControl);

                    if (radioButtonControl != null)
                    {
                        SurveyQuestionAnswer surveyQuestionAnswer = new SurveyQuestionAnswer();
                        surveyQuestionAnswer.RespondentId         = SessionControlUtil.getUserID();
                        surveyQuestionAnswer.SurveyQuestionId     = currentQuestion.QuestionId;
                        surveyQuestionAnswer.SurveyAnswerOptionId =
                            AppUtil.convertStringToInt(radioButtonControl.QuestionAnswerRadioButtonList.SelectedValue);
                        surveyQuestionAnswer.AnswerDescription = null;

                        QuestionAnswerOptions answerOption = currentQuestion.AnswerOptionsList.Find(
                            QuestionAnswerOptions => QuestionAnswerOptions.SurveyAnswerOptionId == surveyQuestionAnswer.SurveyAnswerOptionId);

                        if (answerOption.AdditionalQuestion > 0)
                        {
                            additionalQuestions.Add(answerOption.AdditionalQuestion);
                        }

                        surveyQuestionAnswerList.Add(surveyQuestionAnswer);
                        SessionControlUtil.setSurveyQuestionAnswerList(surveyQuestionAnswerList);
                    }
                }
                else if (currentQuestion.SurveyQuestionDomainId == AppConstants.fieldTypeDropDownListId)
                {
                    DropDownListControl dropDownListControl =
                        (DropDownListControl)SurveyCheckboxPlaceHolder.FindControl(AppConstants.controlDropDownListControl);

                    if (dropDownListControl != null)
                    {
                        SurveyQuestionAnswer surveyQuestionAnswer = new SurveyQuestionAnswer();
                        surveyQuestionAnswer.RespondentId         = SessionControlUtil.getUserID();
                        surveyQuestionAnswer.SurveyQuestionId     = currentQuestion.QuestionId;
                        surveyQuestionAnswer.SurveyAnswerOptionId =
                            AppUtil.convertStringToInt(dropDownListControl.QuestionAnswerDropDownList.SelectedValue);
                        surveyQuestionAnswer.AnswerDescription = null;

                        QuestionAnswerOptions answerOption = currentQuestion.AnswerOptionsList.Find(
                            QuestionAnswerOptions => QuestionAnswerOptions.SurveyAnswerOptionId == surveyQuestionAnswer.SurveyAnswerOptionId);

                        if (answerOption.AdditionalQuestion > 0)
                        {
                            additionalQuestions.Add(answerOption.AdditionalQuestion);
                        }

                        surveyQuestionAnswerList.Add(surveyQuestionAnswer);
                        SessionControlUtil.setSurveyQuestionAnswerList(surveyQuestionAnswerList);
                    }
                }
                else
                {
                    throw new AppPageException(AppConstants.errorInvalidQuestionDomain
                                               + " "
                                               + currentQuestion.SurveyQuestionDomainId);
                }


                if (additionalQuestionsList.Count > 0)
                {
                    SessionControlUtil.insertAdditionalQuestionsCurrentLevelList(additionalQuestionsList);
                }
            }
            catch (Exception ex)
            {
                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
                throw;
            }
        }