private void CloneButton_Click(object sender, System.EventArgs e)
        {
            SurveyData clonedSurvey = new Survey().CloneSurvey(SurveyId);

            //Retrieve the new survey ID
            SurveyId = clonedSurvey.Surveys[0].SurveyId;

            // Assign the cloned survey to the user
            AssignSurveyToUser(SurveyId);

            // Update the form fields
            BindFields();
            ((Wap)Page.Master.Master).isTreeStale = true;
            ((Wap)Page.Master.Master).RebuildTree();
            // Let the subscribers know that something has changed
            OnOptionChanged();

        }
 /// <summary>
 /// Returns the previous page index of the page specified 
 /// as a parameter and based the voter's answers
 /// </summary>
 public int GetPreviousPage(int surveyId, int pageNumber, VoterAnswersData voterAnswers, bool evaluateScores)
 {
     int num = 1;
     int num2 = 1;
     while (num2 < pageNumber)
     {
         num2 = new Survey().GetNextPage(surveyId, num, voterAnswers, evaluateScores);
         if (num2 >= pageNumber)
         {
             return num;
         }
         num = num2;
     }
     return num;
 }
        /// <summary>
        /// Check if we need to hide / skip the question depending on the
        /// skip logic rules rules
        /// </summary>
        public bool SkipQuestion(int questionId, VoterAnswersData voterAnswers, bool evaluateScores)
        {
            SkipLogicRuleData questionSkipLogicRules = new Questions().GetQuestionSkipLogicRules(questionId);
            if (questionSkipLogicRules.SkipLogicRules.Rows.Count <= 0)
            {
                return false;
            }
            DataRow[] rowArray = null;
            foreach (SkipLogicRuleData.SkipLogicRulesRow row in questionSkipLogicRules.SkipLogicRules.Rows)
            {
                int num = evaluateScores ? this.GetQuestionAnswersScore(row.QuestionId, voterAnswers) : 0;
                if ((evaluateScores && (row.ConditionalOperator == 3)) && (num == row.Score))
                {
                    return true;
                }
                if ((evaluateScores && (row.ConditionalOperator == 4)) && (num < row.Score))
                {
                    return true;
                }
                if ((evaluateScores && (row.ConditionalOperator == 5)) && (num > row.Score))
                {
                    return true;
                }
                if ((evaluateScores && (row.ConditionalOperator == 6)) && ((num >= row.Score) && (num <= row.ScoreMax)))
                {
                    return true;
                }
                if (!row.IsAnswerIdNull() && !row.IsTextFilterNull())
                {
                    string expression = new Survey().EscapeFilterString(row.TextFilter);
                    if ((!row.IsExpressionOperatorNull() && (row.ExpressionOperator != 2)) && Information.IsDate(expression))
                    {
                        expression = "#" + expression + "#";
                    }
                    else if ((row.ExpressionOperator != 2) && !Information.IsNumeric(expression))
                    {
                        expression = "'" + expression + "'";
                    }
                    try
                    {
                        switch (row.ExpressionOperator)
                        {
                            case 1:
                                rowArray = voterAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText = ", expression }));
                                goto Label_02FD;

                            case 3:
                                rowArray = voterAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText > ", expression }));
                                goto Label_02FD;

                            case 4:
                                rowArray = voterAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText < ", expression }));
                                goto Label_02FD;
                        }
                        rowArray = voterAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText like '%", expression, "%'" }));
                    }
                    catch (EvaluateException)
                    {
                    }
                }
                else if (!row.IsAnswerIdNull())
                {
                    rowArray = voterAnswers.VotersAnswers.Select("AnswerId=" + row.AnswerId);
                }
                else if (row.IsAnswerIdNull())
                {
                    rowArray = voterAnswers.VotersAnswers.Select("QuestionId=" + row.QuestionId);
                }
                else
                {
                    rowArray = null;
                }
            Label_02FD:
                if ((((rowArray != null) && (row.ConditionalOperator == 1)) && (rowArray.Length > 0)) || ((row.ConditionalOperator == 2) && (rowArray.Length == 0)))
                {
                    return true;
                }
            }
            return false;
        }
 /// <summary>
 /// If all min/max selections are completed, 
 /// store the temp answers into the final storage 
 /// and loads the next set of questions and render the new page
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnPageChangeClick(object sender, EventArgs e)
 {
     if (!this._selectionsAreRequired)
     {
         if (this.currentVisitorAnswerSet.VotersAnswers.Rows.Count > 0)
         {
             this.VoterAnswers.Merge(this.currentVisitorAnswerSet, false);
         }
         int targetPage = new Survey().GetNextPage(this.SurveyId, this.CurrentPageIndex, this.VoterAnswers, this._isScored);
         int currentPageIndex = this.CurrentPageIndex;
         int questionNumber = this.QuestionNumber;
         if (targetPage == -1)
         {
             foreach (QuestionData.QuestionsRow row in new Questions().GetQuestionListForPageRange(this.SurveyId, this.CurrentPageIndex + 1, this.TotalPageNumber).Questions.Rows)
             {
                 this.DeleteVoterAnswers(row.QuestionId);
             }
             this.SubmitAnswersToDb();
         }
         else
         {
             if (targetPage > (this.CurrentPageIndex + 1))
             {
                 foreach (QuestionData.QuestionsRow row2 in new Questions().GetQuestionListForPageRange(this.SurveyId, this.CurrentPageIndex + 1, targetPage - 1).Questions.Rows)
                 {
                     this.DeleteVoterAnswers(row2.QuestionId);
                 }
             }
             this.CurrentPageIndex = targetPage;
             this.QuestionNumber += this._questionNumbers - 1;
             this._questionNumbers = 1;
             this.OnPageChanging(new FormNavigationEventArgs(this.VoterAnswers, currentPageIndex, targetPage, questionNumber, this.QuestionNumber, FormNavigationMode.Forward));
             this.Controls.Clear();
             this._questionClientValidationCalls = new StringBuilder();
             if (this.CurrentPageIndex > this.HighestPageNumber)
             {
                 this.BuildSurveyBox(true);
                 this.HighestPageNumber = this.CurrentPageIndex;
             }
             else
             {
                 this.BuildSurveyBox(false);
             }
             this.OnPageChanged(new FormNavigationEventArgs(this.VoterAnswers, currentPageIndex, targetPage, questionNumber, this.QuestionNumber, FormNavigationMode.Forward));
         }
     }
 }
 /// <summary>
 /// Renders the thank you message box 
 /// </summary>
 protected virtual void BuildThanksBox(bool showConditionalMessage)
 {
     this.EnableValidation = false;
     string text = null;
     Table child = new Table();
     child.CssClass = "ThanksboxCss";
     //child.ControlStyle.Font.CopyFrom(base.ControlStyle.Font);
     //child.Width = Unit.Percentage(100.0);
     if (showConditionalMessage)
     {
         text = new Survey().GetThanksMessage(this.SurveyId, this.VoterAnswers, this._isScored);
     }
     if (text == null)
     {
         child.Rows.Add(this.BuildRow(new LiteralControl(this._thankYouMessage), null));
     }
     else
     {
         child.Rows.Add(this.BuildRow(new LiteralControl(text), null));
     }
     this.Controls.Clear();
     this.Controls.Add(child);
 }
 /// <summary>
 /// store the temp answers into the final storage 
 /// and loads the previous page set of questions
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected virtual void OnPreviousPageChangeClick(object sender, EventArgs e)
 {
     int targetPage = new Survey().GetPreviousPage(this.SurveyId, this.CurrentPageIndex, this.VoterAnswers, this._isScored);
     int currentPageIndex = this.CurrentPageIndex;
     if (this.currentVisitorAnswerSet.VotersAnswers.Rows.Count > 0)
     {
         this.VoterAnswers.Merge(this.currentVisitorAnswerSet, false);
     }
     this.CurrentPageIndex = targetPage;
     this.OnPageChanging(new FormNavigationEventArgs(this.VoterAnswers, currentPageIndex, targetPage, this.QuestionNumber, -1, FormNavigationMode.Backward));
     this._previousQuestionNumbering = true;
     this._questionNumbers = 1;
     this.Controls.Clear();
     this._questionClientValidationCalls = new StringBuilder();
     this.BuildSurveyBox(false);
     this.OnPageChanged(new FormNavigationEventArgs(this.VoterAnswers, currentPageIndex, targetPage, this.QuestionNumber, -1, FormNavigationMode.Backward));
 }