/// <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));
        }
 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>
 /// 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>
 /// 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>
 /// 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;
 }
 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;
 }
 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;
 }
 /// <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>
 /// Last chance to change any answer that was posted
 /// by child answeritems before they get posted to 
 /// subscribers
 /// </summary>
 protected abstract void PostedAnswersHandler(PostedAnswerDataCollection answers);
 /// <summary>
 /// Returns the answeritem user's answers
 /// </summary>
 protected virtual PostedAnswerDataCollection GetUserAnswers()
 {
     PostedAnswerDataCollection datas = new PostedAnswerDataCollection();
     if (this._sqlAnswerDropDownList.SelectedValue.Length == 0)
     {
         return null;
     }
     datas.Add(new PostedAnswerData(this, this.AnswerId, base.SectionContainer.SectionNumber, this._sqlAnswerDropDownList.SelectedValue, AnswerTypeMode.Mandatory | AnswerTypeMode.Publisher | AnswerTypeMode.DataSource));
     return datas;
 }
 /// <summary>
 /// Check if selections has reached the max quota
 /// </summary>
 protected abstract bool MaxSelectionsReached(PostedAnswerDataCollection answers);
 /// <summary>
 /// Check if enough selections have been made
 /// </summary>
 protected abstract bool MinSelectionsRequired(PostedAnswerDataCollection answers);
 /// <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>
        /// 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>
 /// 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 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>
        /// 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>
 /// 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>
        /// 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>
 /// 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 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>
 /// 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;
 }
 /// <summary>
 /// Change the all answers with the section number to the new section number
 /// </summary>
 private void SwitchAnswerSectionNumber(int sectionNumber, int newSectionNumber, PostedAnswerDataCollection answers)
 {
     // Inserts the new section answers
     foreach (PostedAnswerData postedAnswer in answers)
     {
         // Find and update the new section posted answers
         if (postedAnswer.SectionNumber == sectionNumber)
         {
             postedAnswer.SectionNumber = newSectionNumber;
         }
     }
 }
 /// <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;
 }
 /// <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;
 }
 public AnswerItemEventArgs(PostedAnswerDataCollection postedAnswers)
 {
     this.PostedAnswers = postedAnswers;
 }
        /// <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;
        }