コード例 #1
0
ファイル: Survey.aspx.cs プロジェクト: kennedias/SurveyAIT
        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());
            }
        }
コード例 #2
0
ファイル: Survey.aspx.cs プロジェクト: kennedias/SurveyAIT
        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);
        }