Beispiel #1
0
        protected void ConfirmRegistrationButton_Click(object sender, EventArgs e)
        {
            try
            {
                int userId = SessionControlUtil.getUserID();

                Respondent respondent = new Respondent();
                respondent.RespondentId = userId;
                respondent.GivenNames   = GivenNameTextBox.Text;
                respondent.LastName     = LastNameTextBox.Text;
                respondent.PhoneNumber  = PhoneNumberTextBox.Text;

                if (DateOfBirthCustomValidator.IsValid)
                {
                    DateTime dateOfBirth = DateTime.Parse(DateOfBirthTextBox.Text);
                    respondent.DateOfBirth = dateOfBirth;
                }
                else
                {
                    return;
                }

                SurveyLogicControl surveyLogicControl = new SurveyLogicControl();
                surveyLogicControl.updateRespondent(respondent);
                Response.Redirect(AppConstants.pageRegisterComplete);
            }
            catch (Exception ex)
            {
                ErrorMessageLabel.Text      = AppConstants.errorSystemError;
                ErrorMessageLabel.ForeColor = System.Drawing.Color.Red;

                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
                throw;
            }
        }
Beispiel #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ErrorMessageLabel.ForeColor = System.Drawing.Color.Black;
                int userId = SessionControlUtil.getUserID();

                if (userId == 0)
                {
                    // To pageRegister is necessary to complete a pageSurvey
                    Response.Redirect(AppConstants.pageSurvey);
                }
            }
            catch (Exception ex)
            {
                ErrorMessageLabel.Text      = AppConstants.errorSystemError;
                ErrorMessageLabel.ForeColor = System.Drawing.Color.Red;

                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
                throw;
            }
        }
Beispiel #3
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;
            }
        }