/// <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; } }
/// <summary> /// Verify the type and show the correspondent control with /// the answers options on the pageSurvey page. /// Controls type are: /// TextBox for text answers /// CheckBox for multiple answers between options /// RadioBox for unique answer between options /// DropDownList for unique answer between options /// </summary> /// <param name="question">Question question</param> /// <exception cref="Exception">Exception</exception> /// <exception cref="AppPageException">AppPageException</exception> private void displayQuestion(Question question) { try { if (question.SurveyQuestionDomainId == AppConstants.fieldTypeTextId) { TextBoxControl textControl = (TextBoxControl)LoadControl(AppConstants.controlTextBoxControl); textControl = (TextBoxControl)LoadControl(AppConstants.controlTextBoxControl); textControl.ID = AppConstants.controlTextBoxControl; textControl.QuestionDescriptionLabel.Text = question.QuestionDescription; textControl.QuestionAnswerTextBox.Text = ""; SurveyCheckboxPlaceHolder.Controls.Clear(); SurveyTextPlaceHolder.Controls.Add(textControl); } else if (question.SurveyQuestionDomainId == AppConstants.fieldTypeCheckBoxId) { CheckBoxControl checkBoxControl = (CheckBoxControl)LoadControl(AppConstants.controlCheckBoxControl); checkBoxControl = (CheckBoxControl)LoadControl(AppConstants.controlCheckBoxControl); checkBoxControl.ID = AppConstants.controlCheckBoxControl; checkBoxControl.QuestionDescriptionLabel.Text = question.QuestionDescription; for (var i = 0; i < question.AnswerOptionsList.Count; i++) { ListItem item = new ListItem(question.AnswerOptionsList[i].AnswerDescription, question.AnswerOptionsList[i].SurveyAnswerOptionId.ToString()); checkBoxControl.QuestionAnswerCheckBoxList.Items.Add(item); } checkBoxControl.QuestionAnswerCheckBoxList.ClearSelection(); SurveyCheckboxPlaceHolder.Controls.Clear(); SurveyCheckboxPlaceHolder.Controls.Add(checkBoxControl); } else if (question.SurveyQuestionDomainId == AppConstants.fieldTypeRadioButtonId) { RadioButtonControl radioButtonControl = (RadioButtonControl)LoadControl(AppConstants.controlRadioButtonControl); radioButtonControl.ID = AppConstants.controlRadioButtonControl; radioButtonControl.QuestionDescriptionLabel.Text = question.QuestionDescription; SurveyRadioButtonPlaceHolder.Controls.Add(radioButtonControl); for (var i = 0; i < question.AnswerOptionsList.Count; i++) { ListItem item = new ListItem(question.AnswerOptionsList[i].AnswerDescription, question.AnswerOptionsList[i].SurveyAnswerOptionId.ToString()); radioButtonControl.QuestionAnswerRadioButtonList.Items.Add(item); } } else if (question.SurveyQuestionDomainId == AppConstants.fieldTypeDropDownListId) { DropDownListControl dropDownListControl = (DropDownListControl)LoadControl(AppConstants.controlDropDownListControl); dropDownListControl.ID = AppConstants.controlDropDownListControl; dropDownListControl.QuestionDescriptionLabel.Text = question.QuestionDescription; SurveyDropDownListPlaceHolder.Controls.Add(dropDownListControl); for (var i = 0; i < question.AnswerOptionsList.Count; i++) { ListItem item = new ListItem(question.AnswerOptionsList[i].AnswerDescription, question.AnswerOptionsList[i].SurveyAnswerOptionId.ToString()); dropDownListControl.QuestionAnswerDropDownList.Items.Add(item); } } else { throw new AppPageException(AppConstants.errorInvalidQuestionDomain + " " + question.SurveyQuestionDomainId); } } catch (Exception ex) { //Error log simulated Console.WriteLine(ex.ToString()); Console.WriteLine(ex.GetBaseException().ToString()); throw; } }