/// <summary> /// Handles posted answers and make sure /// to post answers if there aren't any in the section /// or delete all unvalidated answers if answers exist /// in the section /// </summary> override protected void PostedAnswersHandler(PostedAnswerDataCollection answers) { _postedAnswers = answers; if (RepeatMode == RepeatableSectionMode.GridAnswers) { int sectionCount = GetSectionCountFromAnswers(answers); // if update, add modes and update, add buttons as not been // used or at least one section already exisits // delete all updated answers if ((GridMode == SectionGridMode.Edit && Context.Request[_updateSectionButton.UniqueID] == null) || (GridMode == SectionGridMode.AddNew && Context.Request[_addSectionButton.UniqueID] == null && sectionCount >= 0)) { // Delete all answers as we dont want to post unvalidated answers DeleteSectionAnswers(-1, answers); } // are we currently add an existing section ? else if (GridMode == SectionGridMode.AddNew) { // Reorder the posted answer sections based on // the current target section number OrderTargetSectionAnswers(TargetSection, answers); } } }
/// <summary> /// Check if any selection was left /// </summary> /// <param name="questionEventArgs"></param> /// <returns></returns> protected override bool MinSelectionsRequired(PostedAnswerDataCollection answers) { if (base.MinSelectionRequired > 0) { Hashtable hashtable = this.CountSectionSelections(answers); int sectionCount = base.SectionCount; if (base.RepeatMode == RepeatableSectionMode.GridAnswers) { sectionCount = base.GetSectionCountFromAnswers(answers); if (sectionCount == -1) { sectionCount = 0; } else if (base.GridMode != SectionGridMode.None) { sectionCount++; } } if ((base.MinSelectionRequired > 0) && (hashtable.Keys.Count <= sectionCount)) { return(true); } foreach (DictionaryEntry entry in hashtable) { if (int.Parse(entry.Value.ToString()) < base.MinSelectionRequired) { return(true); } } } return(false); }
protected override PostedAnswerDataCollection GetPostedAnswerData() { this.ServerValidation(); PostedAnswerDataCollection userAnswers = this.GetUserAnswers(); this.OnAnswerPublished(new AnswerItemEventArgs(userAnswers)); return userAnswers; }
/// <summary> /// Check if any selection was left /// </summary> /// <param name="questionEventArgs"></param> /// <returns></returns> protected override bool MinSelectionsRequired(PostedAnswerDataCollection answers) { if (base.MinSelectionRequired > 0) { base.MinAnswerSelectionMessage = ResourceManager.GetString("MinMatrixAnswerSelection", base.LanguageCode); Hashtable hashtable = this.CountSectionChildQuestionsSelections(answers); if ((base.MinSelectionRequired > 0) && (hashtable.Keys.Count < ((MatrixChildQuestionData)this.DataSource).ChildQuestions.Rows.Count)) { return(true); } foreach (DictionaryEntry entry in hashtable) { Hashtable hashtable2 = (Hashtable)entry.Value; if ((base.MinSelectionRequired > 0) && (hashtable2.Keys.Count <= base.SectionCount)) { return(true); } foreach (DictionaryEntry entry2 in hashtable2) { if (int.Parse(entry2.Value.ToString()) < base.MinSelectionRequired) { return(true); } } } } return(false); }
/// <summary> /// Returns the all answers stored in the grid to the event subscribers /// once the survey's page get posted /// </summary> protected override PostedAnswerDataCollection GetPostedAnswerData() { PostedAnswerDataCollection datas = new PostedAnswerDataCollection(); foreach (GridAnswerData data in this.GridVoterAnswers) { datas.Add(new PostedAnswerData(this, data.AnswerId, data.SectionNumber, data.FieldText, data.TypeMode)); } return(datas); }
/// <summary> /// Returns the answeritem user's answers /// </summary> protected virtual PostedAnswerDataCollection GetUserAnswers() { PostedAnswerDataCollection datas = null; if (this._fieldTextBox.Text.Length != 0) { datas = new PostedAnswerDataCollection(); datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._fieldTextBox.Text, AnswerTypeMode.RegExValidator | AnswerTypeMode.Mandatory | AnswerTypeMode.Publisher | AnswerTypeMode.Field)); } return(datas); }
/// <summary> /// Returns the answeritem user's answers /// </summary> protected virtual PostedAnswerDataCollection GetUserAnswers() { PostedAnswerDataCollection datas = null; if (this._xmlAnswerDropDownList.SelectedValue.Length != 0) { datas = new PostedAnswerDataCollection(); datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._xmlAnswerDropDownList.SelectedValue, AnswerTypeMode.Mandatory | AnswerTypeMode.Publisher | AnswerTypeMode.DataSource)); } return(datas); }
protected override PostedAnswerDataCollection GetPostedAnswerData() { PostedAnswerDataCollection datas = new PostedAnswerDataCollection(); if ((this._answerItemDropDownList.SelectedValue != null) && (this._answerItemDropDownList.SelectedValue != "-1")) { datas.Add(new PostedAnswerData(this.AnswerItems[this._answerItemDropDownList.SelectedIndex - 1], int.Parse(this._answerItemDropDownList.SelectedValue), base.SectionContainer.SectionNumber, null, AnswerTypeMode.Selection)); return(datas); } return(null); }
/// <summary> /// Removes all answers related to the target section number /// </summary> protected void DeleteSectionAnswers(int targetSection, PostedAnswerDataCollection answers) { for (int i = answers.Count - 1; i >= 0; i--) { // Find and update the section number if (answers[i].SectionNumber == targetSection) { answers.RemoveAt(i); } } }
/// <summary> /// Returns the selected value of the dropdown to the subscribers /// </summary> protected override PostedAnswerDataCollection GetPostedAnswerData() { if (this.Mandatory && (this._xmlAnswerDropDownList.SelectedValue.Length == 0)) { this.OnInvalidAnswer(new AnswerItemInvalidEventArgs(string.Format(ResourceManager.GetString("XMLAnswerSelectionRequired", base.LanguageCode), this.Text))); } PostedAnswerDataCollection userAnswers = this.GetUserAnswers(); this.OnAnswerPublished(new AnswerItemEventArgs(userAnswers)); return(userAnswers); }
/// <summary> /// Retur ns the selected value of the dropdown to the subscribers /// </summary> protected override PostedAnswerDataCollection GetPostedAnswerData() { PostedAnswerDataCollection answerValues = this.GetAnswerValues(); if ((this.Mandatory && (answerValues != null)) && (answerValues.Count == 0)) { this.OnInvalidAnswer(new AnswerItemInvalidEventArgs(string.Format(ResourceManager.GetString("XMLAnswerSelectionRequired", base.LanguageCode), this.Text))); } this.OnAnswerPublished(new AnswerItemEventArgs(answerValues)); return(answerValues); }
protected virtual PostedAnswerDataCollection GetUserAnswers() { PostedAnswerDataCollection datas = null; //if ((this.Context.Request[this._freeTextBox.ClientID] != null) && (this.Context.Request[this._freeTextBox.ClientID].Length != 0)) if ((this.Context.Request[this._freeTextBox.UniqueID] != null) && (this.Context.Request[this._freeTextBox.UniqueID].Length != 0)) { datas = new PostedAnswerDataCollection(); //datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this.Context.Request[this._freeTextBox.ClientID], AnswerTypeMode.RegExValidator | AnswerTypeMode.Mandatory | AnswerTypeMode.Publisher | AnswerTypeMode.Field)); datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this.Context.Request[this._freeTextBox.UniqueID], AnswerTypeMode.RegExValidator | AnswerTypeMode.Mandatory | AnswerTypeMode.Publisher | AnswerTypeMode.Field)); } return datas; }
public bool LoadPostData(string postDataKey, NameValueCollection postCollection) { this.EnsureChildControls(); PostedAnswerDataCollection postedAnswerData = this.GetPostedAnswerData(); if (postedAnswerData != null) { AnswerItemEventArgs e = new AnswerItemEventArgs(postedAnswerData); this.OnAnswerPost(e); } return(false); }
/// <summary> /// Check if too much selections were made /// </summary> /// <param name="questionEventArgs"></param> /// <returns></returns> protected override bool MaxSelectionsReached(PostedAnswerDataCollection answers) { if (base.MaxSelectionAllowed > 0) { foreach (DictionaryEntry entry in this.CountSectionSelections(answers)) { if ((base.MaxSelectionAllowed != 0) && (int.Parse(entry.Value.ToString()) > base.MaxSelectionAllowed)) { return(true); } } } return(false); }
/// <summary> /// Returns the check box status to the event subscribers /// once the survey's page get posted /// </summary> protected override PostedAnswerDataCollection GetPostedAnswerData() { int answerFileCount = new Answers().GetAnswerFileCount(this.GroupGuid); if (this.Mandatory && (answerFileCount == 0)) { this.OnInvalidAnswer(new AnswerItemInvalidEventArgs(string.Format(ResourceManager.GetString("UploadFileRequiredMessage", base.LanguageCode), this.Text))); } PostedAnswerDataCollection datas = new PostedAnswerDataCollection(); datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this.GroupGuid, AnswerTypeMode.ExtendedType | AnswerTypeMode.Upload | AnswerTypeMode.Mandatory)); return(datas); }
/// <summary> /// Retrieves the available postback values /// </summary> /// <returns></returns> protected PostedAnswerDataCollection GetAnswerValues() { PostedAnswerDataCollection datas = null; if ((this._xmlAnswerDropDownList != null) && (this._xmlAnswerDropDownList.Items.Count > 0)) { datas = new PostedAnswerDataCollection(); if (this._xmlAnswerDropDownList.SelectedValue.Length > 0) { datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._xmlAnswerDropDownList.SelectedValue, AnswerTypeMode.Mandatory | AnswerTypeMode.Publisher | AnswerTypeMode.DataSource)); } } return(datas); }
/// <summary> /// Returns a hashtable containing using the section /// number as hash key which each value being the number /// of answers /// </summary> /// <param name="answers"></param> /// <returns></returns> private Hashtable CountSectionSelections(PostedAnswerDataCollection answers) { Hashtable hashtable = new Hashtable(); for (int i = 0; i < answers.Count; i++) { if ((answers[i].TypeMode & AnswerTypeMode.Selection) > AnswerTypeMode.None) { int sectionNumber = answers[i].SectionNumber; hashtable[sectionNumber] = (hashtable[sectionNumber] == null) ? 1 : (int.Parse(hashtable[sectionNumber].ToString()) + 1); } } return(hashtable); }
/// <summary> /// Builds and populates the dropdown list with the current /// Xml filename gathered from the answer publisher /// </summary> protected virtual void GenerateDropDownList() { this.Controls.Clear(); this._xmlAnswerDropDownList = new DropDownList(); NSurveyDataSource xmlAnswers = new XmlFileManager(this.XmlFileName).GetXmlAnswers(base.LanguageCode); if ((xmlAnswers != null) && (xmlAnswers.XmlAnswer.Count > 0)) { if (((xmlAnswers.XmlDataSource.Rows.Count > 0) && (xmlAnswers.XmlDataSource[0].RunTimeAnswerLabel != null)) && (xmlAnswers.XmlDataSource[0].RunTimeAnswerLabel.Length > 0)) { this.Text = xmlAnswers.XmlDataSource[0].RunTimeAnswerLabel; } if (this.ShowAnswerText) { if ((this.ImageUrl != null) && (this.ImageUrl.Length != 0)) { Image child = new Image(); child.ImageUrl = this.ImageUrl; child.ImageAlign = ImageAlign.Middle; child.ToolTip = this.Text; this.Controls.Add(child); this.Controls.Add(new LiteralControl("<br />")); } else if ((this.Text != null) && (this.Text.Length != 0)) { //JJ this.Controls.Add(new LiteralControl(string.Format("{0}<br />", this.Text))); Label label = new Label(); label.Text = string.Format("{0}<br />", this.Text); label.CssClass = "AnswerTextRender"; this.Controls.Add(label); } } this.BindDropDownList(xmlAnswers); if ((this.DefaultText != null) && (this._xmlAnswerDropDownList.Items.FindByValue(this.DefaultText) != null)) { this._xmlAnswerDropDownList.SelectedValue = this.DefaultText; } if (this.HasSubscribers) { this._xmlAnswerDropDownList.AutoPostBack = true; } this.Controls.Add(this._xmlAnswerDropDownList); PostedAnswerDataCollection answerValues = this.GetAnswerValues(); if (answerValues != null) { this.OnAnswerPublisherCreated(new AnswerItemEventArgs(answerValues)); } } }
/// <summary> /// Returns the answer if it was checked /// </summary> /// <returns></returns> protected override PostedAnswerDataCollection GetPostedAnswerData() { PostedAnswerDataCollection datas = new PostedAnswerDataCollection(); if ((this.SelectionMode == AnswerSelectionMode.Radio) && ((SelectionRadioButton)this.SelectionControl).IsChecked()) { datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, null, AnswerTypeMode.Selection)); return(datas); } if ((this.SelectionMode == AnswerSelectionMode.CheckBox) && (this.Context.Request[((SelectionCheckBox)this.SelectionControl).UniqueID] != null)) { datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, null, AnswerTypeMode.Selection)); return(datas); } return(null); }
/// <summary> /// Returns the section based count on the /// current posted answer's data, doesnt include /// the count of any "add new section" only counted /// are the section already posted, validated and stored in /// the grid /// </summary> public int GetSectionCountFromAnswers(PostedAnswerDataCollection postedAnswers) { int sectionCount = -1; if (postedAnswers != null) { for (int i = 0; i < postedAnswers.Count; i++) { if (postedAnswers[i].SectionNumber > sectionCount) { sectionCount = postedAnswers[i].SectionNumber; } } } return(sectionCount); }
/// <summary> /// Returns the answeritem user's answers /// </summary> protected virtual PostedAnswerDataCollection GetUserAnswers() { PostedAnswerDataCollection datas = new PostedAnswerDataCollection(); if (this.RenderMode == ControlRenderMode.Edit) { if (this._fieldTextBox.Text.Length != 0) { datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._fieldTextBox.Text, AnswerTypeMode.Publisher | AnswerTypeMode.Custom)); return(datas); } return(null); } PostedAnswerData postedAnswerData = new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this.DefaultText, AnswerTypeMode.Publisher | AnswerTypeMode.Custom); datas.Add(postedAnswerData); return(datas); }
protected override PostedAnswerDataCollection GetPostedAnswerData() { this.EnsureChildControls(); PostedAnswerDataCollection datas = new PostedAnswerDataCollection(); if ((base.SelectionMode == AnswerSelectionMode.Radio) && ((SelectionRadioButton)base.SelectionControl).IsChecked()) { this.ServerValidation(); datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._fieldTextBox.Text, AnswerTypeMode.RegExValidator | AnswerTypeMode.Mandatory | AnswerTypeMode.Other)); return(datas); } if ((base.SelectionMode == AnswerSelectionMode.CheckBox) && (this.Context.Request[((SelectionCheckBox)base.SelectionControl).UniqueID] != null)) { this.ServerValidation(); datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._fieldTextBox.Text, AnswerTypeMode.RegExValidator | AnswerTypeMode.Mandatory | AnswerTypeMode.Other)); return(datas); } return(null); }
/// <summary> /// Check if any selection was left /// </summary> /// <param name="questionEventArgs"></param> /// <returns></returns> protected override bool MaxSelectionsReached(PostedAnswerDataCollection answers) { if (base.MaxSelectionAllowed > 0) { base.MaxAnswerSelectionMessage = ResourceManager.GetString("MaxMatrixAnswerSelection", base.LanguageCode); foreach (DictionaryEntry entry in this.CountSectionChildQuestionsSelections(answers)) { Hashtable hashtable2 = (Hashtable)entry.Value; foreach (DictionaryEntry entry2 in hashtable2) { if ((base.MaxSelectionAllowed != 0) && (int.Parse(entry2.Value.ToString()) > base.MaxSelectionAllowed)) { return(true); } } } } return(false); }
private Hashtable CountSectionChildQuestionsSelections(PostedAnswerDataCollection answers) { Hashtable hashtable = new Hashtable(); new Hashtable(); for (int i = 0; i < answers.Count; i++) { if ((answers[i].TypeMode & AnswerTypeMode.Selection) > AnswerTypeMode.None) { int questionId = answers[i].Item.QuestionId; int sectionNumber = answers[i].SectionNumber; if (hashtable[questionId] == null) { hashtable[questionId] = new Hashtable(); } ((Hashtable)hashtable[questionId])[sectionNumber] = (((Hashtable)hashtable[questionId])[sectionNumber] == null) ? 1 : (int.Parse(((Hashtable)hashtable[questionId])[sectionNumber].ToString()) + 1); } } return(hashtable); }
/// <summary> /// Returns the check box status to the event subscribers /// once the survey's page get posted /// </summary> protected override PostedAnswerDataCollection GetPostedAnswerData() { PostedAnswerData data; bool flag; PostedAnswerDataCollection postedAnswers = new PostedAnswerDataCollection(); if (this.Context.Request[this._boolCheckBox.UniqueID] != null) { flag = true; data = new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, flag.ToString(), AnswerTypeMode.Publisher | AnswerTypeMode.Custom); } else { flag = false; data = new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, flag.ToString(), AnswerTypeMode.Publisher | AnswerTypeMode.Custom); } postedAnswers.Add(data); this.OnAnswerPublished(new AnswerItemEventArgs(postedAnswers)); return(postedAnswers); }
/// <summary> /// Gets the answer send by the publisher and use /// them as the source name of the xml file to load /// </summary> public void ProcessPublishedAnswers(object sender, AnswerItemEventArgs e) { if (((e != null) && (e.PostedAnswers != null)) && (e.PostedAnswers.Count > 0)) { string str = e.PostedAnswers[0].FieldText.ToLower() + ".xml"; if (this.XmlFileName != str) { this.XmlFileName = str; this.GenerateDropDownList(); base.ChildControlsCreated = true; PostedAnswerDataCollection answerValues = this.GetAnswerValues(); this.OnAnswerPublished(new AnswerItemEventArgs(answerValues)); } } else { this.XmlFileName = string.Empty; this._xmlAnswerDropDownList = null; this.Controls.Clear(); this.OnAnswerPublished(new AnswerItemEventArgs(null)); } }
/// <summary> /// Reorder the posted section in the correct /// order based on the target section's new section number /// new section answers are marked with a -1 sectionnumber /// </summary> /// <param name="targetSection"></param> protected void OrderTargetSectionAnswers(int targetSection, PostedAnswerDataCollection answers) { int sectionCount = GetSectionCountFromAnswers(answers); // Is this the first section ever posted ? if ((targetSection == -1 || targetSection == 0) && sectionCount == -1) { foreach (PostedAnswerData postedAnswer in answers) { // Find and update the new section posted answers if (postedAnswer.SectionNumber == -1) { postedAnswer.SectionNumber = 0; } } } else if (targetSection != -1 && targetSection <= sectionCount) { // increment all user answers section numbers for (int i = sectionCount; i >= targetSection; i--) { SwitchAnswerSectionNumber(i, i + 1, answers); } } if (targetSection != -1) { // Inserts the new section answers foreach (PostedAnswerData postedAnswer in answers) { // Find and update the new section posted answers if (postedAnswer.SectionNumber == -1) { postedAnswer.SectionNumber = targetSection; } } } }
/// <summary> /// A new section has been requested for edit /// Show a "new section" area with the section's answers /// </summary> protected virtual void AnswersGrid_EditSection(object sender, SectionAnswersItemEventArgs e) { _sectionTable.Controls.Clear(); if (e.SectionAnswers != null) { PostedAnswerDataCollection postedAnswers = new PostedAnswerDataCollection(); foreach (GridAnswerData answer in e.SectionAnswers) { if (VoterAnswersState == null) { VoterAnswersData voterAnswersData = new VoterAnswersData(); voterAnswersData.EnforceConstraints = false; VoterAnswersState = voterAnswersData.VotersAnswers; } VoterAnswersData.VotersAnswersRow voterAnswer = VoterAnswersState.NewVotersAnswersRow(); voterAnswer.AnswerId = answer.AnswerId; voterAnswer.QuestionId = QuestionId; voterAnswer.SectionNumber = -1; voterAnswer.AnswerText = answer.FieldText; voterAnswer.VoterId = -1; VoterAnswersState.AddVotersAnswersRow(voterAnswer); } } // Dont use any default answers as we have // setup an existing answer set EnableAnswersDefault = false; AddSection(-1, 0); SectionCount = 0; TargetSection = int.Parse(e.SectionNumber.ToString()); AddSubmitSectionButtons(true); GridMode = SectionGridMode.Edit; }
/// <summary> /// Creates the checkbox control "layout" and adds /// it to the overall control tree /// </summary> protected override void CreateChildControls() { if (this.ShowAnswerText) { if ((this.ImageUrl != null) && (this.ImageUrl.Length != 0)) { Image child = new Image(); child.ImageUrl = this.ImageUrl; child.ImageAlign = ImageAlign.Middle; child.ToolTip = this.Text; this.Controls.Add(child); } else { //JJ this.Controls.Add(new LiteralControl(this.Text)); Label label = new Label(); label.Text = this.Text; label.CssClass = "AnswerTextRender"; this.Controls.Add(label); } } if (this.DefaultText != null) { bool flag = true; if (this.DefaultText == flag.ToString()) { this._boolCheckBox.Checked = true; } } this.Controls.Add(this._boolCheckBox); PostedAnswerDataCollection postedAnswers = new PostedAnswerDataCollection(); postedAnswers.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._boolCheckBox.Checked.ToString(), AnswerTypeMode.Custom)); this.OnAnswerPublisherCreated(new AnswerItemEventArgs(postedAnswers)); }
public AnswerItemEventArgs(PostedAnswerDataCollection postedAnswers) { this.PostedAnswers = postedAnswers; }