Beispiel #1
0
        public void SurveyQuestionSelected(object sender, EventArgs e)
        {
            var ddlSurveyQuestion = sender as DropDownList;
            var listView          = this.Page.FindControlRecursive("InnerListView") as ListView;

            if (ddlSurveyQuestion == null || listView == null)
            {
                return;
            }

            if (ddlSurveyQuestion.SelectedValue == "-1" || ddlSurveyQuestion.SelectedValue == "-100")
            {
                listView.DataSource = null;
                listView.DataBind();
                if (this.QuestionSelected != null)
                {
                    this.QuestionSelected(this, EventArgs.Empty);
                }

                return;
            }

            var survey = ContentRepository.Content.Create(PortalContext.Current.ContextNode);

            var customFields = survey.Fields["FieldSettingContents"] as ReferenceField;

            if (customFields == null)
            {
                return;
            }

            var questions = customFields.OriginalValue as List <ContentRepository.Storage.Node>;

            var selectedQuestion = from q in questions where q.Name == ddlSurveyQuestion.SelectedValue select q;
            var pageBreaks       = (from q in questions where q.NodeType.Name == "PageBreakFieldSetting" select q).Count();
            var choiceFS         = (ChoiceFieldSetting)((FieldSettingContent)selectedQuestion.First()).FieldSetting;
            var answers          = choiceFS.Options;
            var rules            = answers.Select(opt => new SurveyRule(opt.Text, opt.Value, "", pageBreaks)).ToList();

            if (choiceFS.AllowExtraValue.HasValue && choiceFS.AllowExtraValue.Value && !rules.Any(sr => sr.AnswerId == SurveyRule.EXTRAVALUEID))
            {
                //add extra value as a possible option
                rules.Add(new SurveyRule(SurveyRule.GetExtraValueText(), SurveyRule.EXTRAVALUEID, "", pageBreaks));
            }

            listView.DataSource = rules;
            listView.DataBind();

            if (this.QuestionSelected != null)
            {
                this.QuestionSelected(this, EventArgs.Empty);
            }
        }
Beispiel #2
0
        private void ParseRules(string xml)
        {
            var survey       = SenseNet.ContentRepository.Content.Create(PortalContext.Current.ContextNode);
            var customFields = survey.Fields["FieldSettingContents"] as ReferenceField;
            var questions    = customFields.OriginalValue as List <Node>;
            var pageBreaks   = (from q in questions where q.NodeType.Name == "PageBreakFieldSetting" select q).Count();

            var doc = new XmlDocument();

            try
            {
                doc.LoadXml(xml);
            }
            catch
            {
                return;
            }

            _selectedQuestion = doc.DocumentElement.GetAttribute("Question");

            if (_selectedQuestion == "-100")
            {
                DataListView.DataSource = null;
                DataListView.DataBind();
                return;
            }

            foreach (XPathNavigator node in doc.DocumentElement.CreateNavigator().SelectChildren(XPathNodeType.Element))
            {
                var answer     = node.GetAttribute("Answer", "");
                var answerId   = node.GetAttribute("AnswerId", "");
                var jumpToPage = node.Value;
                SurveyRulesList.Add(new SurveyRule(answer, answerId, jumpToPage, pageBreaks));
            }

            var chfs       = ChoiceFieldSettings.FirstOrDefault(fs => fs.Name == _selectedQuestion);
            var allowExtra = chfs != null && chfs.AllowExtraValue.HasValue && chfs.AllowExtraValue.Value;

            if (allowExtra && !SurveyRulesList.Any(sr => sr.AnswerId == SurveyRule.EXTRAVALUEID))
            {
                SurveyRulesList.Add(new SurveyRule(SurveyRule.GetExtraValueText(), SurveyRule.EXTRAVALUEID, "", pageBreaks));
            }
            else if (!allowExtra)
            {
                SurveyRulesList.RemoveAll(sr => sr.AnswerId == SurveyRule.EXTRAVALUEID);
            }

            DdlSurveyQuestions.SelectedValue = _selectedQuestion;

            DataListView.DataSource = SurveyRulesList;
            DataListView.DataBind();
        }