Exemple #1
0
        ///////
        /// <summary>
        /// Get the next question ID from Additional Questions Current Level List.
        /// </summary>
        /// <returns>int</returns>
        /// <exception cref="AppPageException">AppPageException</exception>
        /// <exception cref="Exception">Exception</exception>
        public static int getNexQuestionIdFromAdditionalQuestionCurrentLevelList()
        {
            try
            {
                string     currentQuestionsLevelKey = getCurrentQuestionsLevelKey();
                List <int> additionalQuestionsList  = new List <int>();
                int        nextQuestion             = 0;

                if (HttpContext.Current.Session[currentQuestionsLevelKey] != null)
                {
                    additionalQuestionsList = (List <int>)HttpContext.Current.Session[currentQuestionsLevelKey];
                    if (additionalQuestionsList.Count > 0)
                    {
                        nextQuestion = AppUtil.convertStringToInt(additionalQuestionsList[0].ToString());
                        SessionControlUtil.removeQuestionIdFromAdditionalQuestionCurrentLevelList(nextQuestion);
                    }
                }

                return(nextQuestion);
            }
            catch (Exception ex)
            {
                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
                throw;
            }
        }
Exemple #2
0
        ///////
        /// <summary>
        /// Remove question ID on Additional Questions Current Level List.
        /// </summary>
        /// <param name="questionID">int questionID</param>
        /// <exception cref="AppPageException">AppPageException</exception>
        /// <exception cref="Exception">Exception</exception>
        public static void removeQuestionIdFromAdditionalQuestionCurrentLevelList(int questionID)
        {
            try
            {
                string     currentQuestionsLevelKey = getCurrentQuestionsLevelKey();
                List <int> additionlQuestionsList   = new List <int>();

                if (HttpContext.Current.Session[currentQuestionsLevelKey] != null)
                {
                    additionlQuestionsList = (List <int>)HttpContext.Current.Session[currentQuestionsLevelKey];
                    additionlQuestionsList.Remove(questionID);

                    if (additionlQuestionsList.Count == 0)
                    {
                        SessionControlUtil.decrementCurrentQuestionLevel();
                        HttpContext.Current.Session[currentQuestionsLevelKey] = null;
                    }
                    else
                    {
                        HttpContext.Current.Session[currentQuestionsLevelKey] = additionlQuestionsList;
                    }
                }
            }
            catch (Exception ex)
            {
                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
                throw;
            }
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                ErrorMessageLabel.Text      = "";
                ErrorMessageLabel.ForeColor = System.Drawing.Color.Black;
                SurveyLogicControl surveyLogicControl = new SurveyLogicControl();
                Question           question           = new Question();
                int currentQuestionSequence           = 0;

                if (string.IsNullOrEmpty(SessionControlUtil.getUserIPAddress()))
                {
                    string userIPAddress = AppUtil.getUserIPAddress();

                    if (!string.IsNullOrEmpty(userIPAddress))
                    {
                        Respondent respondent = new Respondent();
                        respondent.IpAddress = userIPAddress;
                        int userID = surveyLogicControl.insertRespondent(respondent);
                        SessionControlUtil.setUserID(userID);
                        SessionControlUtil.setUserIPAddress(userIPAddress);
                    }

                    // First time.
                    // Get the first question and set the session attributes control
                    question = surveyLogicControl.getNextQuestionBySequence(currentQuestionSequence);
                    SessionControlUtil.setCurrentQuestion(question);
                    SessionControlUtil.setCurrentQuestionSequence(question.QuestionSequence);
                    SessionControlUtil.incrementCurrentQuestionLevel();
                    HttpContext.Current.Session[AppConstants.sessionQuestionsAnswerList] = new List <SurveyQuestionAnswer>();
                }
                else
                {
                    question = SessionControlUtil.getCurrentQuestion();
                }

                this.displayQuestion(question);
            }
            catch (Exception ex)
            {
                /* IMPORTANT !!
                 * // No matter what was the error, user can not start, continue or
                 * // finalize the pageSurvey. So:
                 * // - A log (simulation) with the exception was done on the place that have occurred
                 * // - The exception comes till the final layer, shows a generic error to the user
                 * // - Insert more information on the log (simulation)
                 * */
                ErrorMessageLabel.Text      = AppConstants.errorSystemError;
                ErrorMessageLabel.ForeColor = System.Drawing.Color.Red;

                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
            }
        }
Exemple #4
0
        protected void NextButton_Click(object sender, EventArgs e)
        {
            // Get the answer from last question and store on session
            // after pageload and all ui elements re-built dynamically and viewstate copied over
            this.setSurveyQuestionAnswer();

            //Get the next question
            int                currentQuestionSequence = SessionControlUtil.getCurrentQuestionSequence();
            Question           question           = null;
            SurveyLogicControl surveyLogicControl = new SurveyLogicControl();

            // Verify the level and additional questions to show before continuing
            // the sequence of the main questions
            if (SessionControlUtil.getCurrentQuestionsLevel() > 1)
            {
                int nextQuestionId = SessionControlUtil.getNexQuestionIdFromAdditionalQuestionCurrentLevelList();
                question = surveyLogicControl.getQuestionAndAnswersByIQuestionID(nextQuestionId);
            }
            else
            {
                question = surveyLogicControl.getNextQuestionBySequence(currentQuestionSequence);

                //If there is not more questions the method surveyLogicControl.getNextQuestionBySequence
                // will return zero that means there are no more questions on sequence.
                if (question.QuestionSequence == 0)
                {
                    // Get the list of questions answered from session
                    List <SurveyQuestionAnswer> surveyQuestionAnswerList = new List <SurveyQuestionAnswer>();
                    surveyQuestionAnswerList = SessionControlUtil.getSurveyQuestionAnswerList();

                    // Call the logic control to record the complete pageSurvey in the database
                    surveyLogicControl.insertAnsweredSurvey(surveyQuestionAnswerList);

                    Response.Redirect(AppConstants.pageSurveyComplete);
                }
                else
                {
                    SessionControlUtil.setCurrentQuestionSequence(question.QuestionSequence);
                }
            }

            // Store the next question to be showed on the session
            // as current question.
            SessionControlUtil.setCurrentQuestion(question);


            // Redirect back to pageSurvey.aspx to continue the pageSurvey
            // on next question.
            Response.Redirect(AppConstants.pageSurvey);
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SessionControlUtil.IsLoggedIn() == false)
            {
                Response.Redirect(AppConstants.pageHome, false);
            }

            ErrorMessageLabel.Text      = "";
            ErrorMessageLabel.ForeColor = System.Drawing.Color.Black;

            if (!IsPostBack)
            {
                this.createCheckBoxes();
            }
        }
Exemple #6
0
        ///////
        /// <summary>
        /// Insert an question ID List on Additional Questions Current Level List.
        /// </summary>
        /// <param name="questionIDList">List<int> questionIDList</param>
        /// <exception cref="AppPageException">AppPageException</exception>
        /// <exception cref="Exception">Exception</exception>
        public static void insertAdditionalQuestionsCurrentLevelList(List <int> questionIDList)
        {
            try
            {
                SessionControlUtil.incrementCurrentQuestionLevel();
                string currentQuestionsLevelKey = getCurrentQuestionsLevelKey();

                if (HttpContext.Current.Session[currentQuestionsLevelKey] == null)
                {
                    HttpContext.Current.Session[currentQuestionsLevelKey] = new ArrayList();
                }

                HttpContext.Current.Session[currentQuestionsLevelKey] = questionIDList;
            }
            catch (Exception ex)
            {
                //Error log simulated
                Console.WriteLine(ex.ToString());
                Console.WriteLine(ex.GetBaseException().ToString());
                throw;
            }
        }
Exemple #7
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;
            }
        }
Exemple #8
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;
            }
        }
Exemple #9
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                int    staffId       = AppUtil.convertStringToInt(UserIdTextBox.Text);
                String staffPassword = PasswordTextBox.Text;

                SurveyLogicControl surveyLogicControl = new SurveyLogicControl();
                if (surveyLogicControl.staffLoginValidation(staffId, staffPassword))
                {
                    SessionControlUtil.setUserID(staffId);
                    Response.Redirect(AppConstants.pageSearch, false);
                }
                else
                {
                    ErrorMessageLabel.ForeColor = System.Drawing.Color.Red;
                    ErrorMessageLabel.Text      = AppConstants.errorInvalidLogin;
                }
            }
            catch (Exception ex)
            {
                /* IMPORTANT !!
                 * // No matter what was the error, user can not start, continue or
                 * // finalize the pageSurvey. So:
                 * // - A log (simulation) with the exception was done on the place that have occurred
                 * // - The exception comes till the final layer, shows a generic error to the user
                 * // - Insert more information on the log (simulation)
                 * */
                ErrorMessageLabel.Text      = AppConstants.errorSystemError;
                ErrorMessageLabel.ForeColor = System.Drawing.Color.Red;

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