示例#1
0
        /// <summary>
        /// Adds the New Question into the Database
        /// </summary>
        /// <param name="objQuestionData"></param>
        private void AddNewQuestion(QuestionsModel objQuestionData)
        {
            var Question = new SectionQuestion();

            Question.Question    = objQuestionData.NewQuestion;
            Question.IsDeteled   = false;
            Question.SectionId   = objQuestionData.SectionID;
            Question.Description = objQuestionData.Description;
            this._sectionQuestions.Add(Question);

            AddAnswerOption(objQuestionData.Option1, Question.QuestionId, objQuestionData.CorrectAnswer == "Option1" ? true : false);
            AddAnswerOption(objQuestionData.Option2, Question.QuestionId, objQuestionData.CorrectAnswer == "Option2" ? true : false);
            AddAnswerOption(objQuestionData.Option3, Question.QuestionId, objQuestionData.CorrectAnswer == "Option3" ? true : false);
            AddAnswerOption(objQuestionData.Option4, Question.QuestionId, objQuestionData.CorrectAnswer == "Option4" ? true : false);
        }
        public static QuestionItem Create(QuestionData.QuestionsRow question, string languageCode, string parentControlUniqueID,
                                          int questionRandomSeed, VoterAnswersData.VotersAnswersDataTable voterAnswersState,
                                          bool enableAnswerDefaults, bool isDesignMode = false)
        {
            QuestionItem item;

            if ((question.TypeAssembly.Length == 0) || (question.TypeAssembly == null))
            {
                throw new ApplicationException("Could not create an instance because the question data has no assembly type specified");
            }
            try
            {
                item = (QuestionItem)Assembly.Load(question.TypeAssembly).CreateInstance(question.TypeNameSpace);
            }
            catch (InvalidCastException)
            {
                throw new InvalidCastException("Concrete type " + question.TypeNameSpace + " is not a child of the questionitem abstract class");
            }
            catch (NullReferenceException)
            {
                throw new InvalidCastException("specfied type " + question.TypeNameSpace + " could not be found in the specifed assembly " + question.TypeAssembly);
            }
            item.ID         = "Question" + question.QuestionId.ToString();
            item.QuestionId = question.QuestionId;
            item.Text       = new PipeManager().PipeValuesInText(question.QuestionId, question.QuestionText +
                                                                 ((question.ShowHelpText && !isDesignMode)?(
                                                                      question.IsHelpTextNull()?string.Empty: HelpTextInSmallFont(question.HelpText)):string.Empty)//JJSurveyBoxChange
                                                                 , voterAnswersState, languageCode);
            item.LanguageCode    = languageCode;
            item.QuestionId_Text = question.QuestionIdText;
            item.HelpText        = question.HelpText;
            SectionQuestion question2 = item as SectionQuestion;

            if ((question2 != null) && (question.RepeatableSectionModeId != 0))
            {
                question2.RepeatMode  = (RepeatableSectionMode)question.RepeatableSectionModeId;
                question2.MaxSections = question.MaxSections;
                question2.GridAnswers = new Questions().GetQuestionSectionGridAnswers(question.QuestionId);
                if ((question.AddSectionLinkText != null) && (question.AddSectionLinkText.Length > 0))
                {
                    question2.AddSectionLinkText = question.AddSectionLinkText;
                }
                if ((question.DeleteSectionLinkText != null) && (question.DeleteSectionLinkText.Length > 0))
                {
                    question2.DeleteSectionLinkText = question.DeleteSectionLinkText;
                }
                if ((question.EditSectionLinkText != null) && (question.EditSectionLinkText.Length > 0))
                {
                    question2.EditSectionLinkText = question.EditSectionLinkText;
                }
                if ((question.UpdateSectionLinkText != null) && (question.UpdateSectionLinkText.Length > 0))
                {
                    question2.UpdateSectionLinkText = question.UpdateSectionLinkText;
                }
            }
            SingleQuestion question3 = item as SingleQuestion;

            if (question3 != null)
            {
                question3.VoterAnswersState    = voterAnswersState;
                question3.EnableAnswersDefault = enableAnswerDefaults;
                question3.MinSelectionRequired = question.MinSelectionRequired;
                question3.MaxSelectionAllowed  = question.MaxSelectionAllowed;
                question3.ColumnsNumber        = question.ColumnsNumber;
                question3.LayoutMode           = question.IsLayoutModeIdNull() ? QuestionLayoutMode.Vertical : ((QuestionLayoutMode)question.LayoutModeId);
                if (question.RandomizeAnswers)
                {
                    question3.DataSource = new Answers().GetRandomAnswers(question.QuestionId, questionRandomSeed, languageCode);
                    return(question3);
                }
                question3.DataSource = new Answers().GetAnswers(question.QuestionId, languageCode);
                return(question3);
            }
            MatrixQuestion question4 = item as MatrixQuestion;

            if (question4 != null)
            {
                question4.VoterAnswersState    = voterAnswersState;
                question4.EnableAnswersDefault = enableAnswerDefaults;
                question4.MinSelectionRequired = question.MinSelectionRequired;
                question4.MaxSelectionAllowed  = question.MaxSelectionAllowed;
                question4.DataSource           = new Questions().GetMatrixChildQuestions(question.QuestionId, languageCode);
                return(question4);
            }
            return(item);
        }