/// <summary>
 /// Replace the pipe token with the answer text entered by 
 /// the user
 /// </summary>
 protected virtual string PipeAnswerText(int answerId, VoterAnswersData.VotersAnswersDataTable surveyAnswers)
 {
     VoterAnswersData.VotersAnswersRow[] rowArray = (VoterAnswersData.VotersAnswersRow[]) surveyAnswers.Select("AnswerId=" + answerId);
     if (rowArray.Length > 0)
     {
         return rowArray[0].AnswerText;
     }
     return string.Empty;
 }
 public FormNavigationEventArgs(VoterAnswersData voterAnswers, int sourcePageIndex, int targetPage, int sourceQuestionNumber, int targetQuestionNumber, FormNavigationMode navigationMode)
 {
     this._voterAnswers = voterAnswers;
     this._sourcePageIndex = sourcePageIndex;
     this._targetPageIndex = targetPage;
     this._sourceQuestionNumber = sourceQuestionNumber;
     this._targetQuestionNumber = targetQuestionNumber;
     this._navigationMode = navigationMode;
 }
 /// <summary>
 /// Parse the source text for pipe token and replace
 /// the token with the correct text depending on the
 /// given survey answers
 /// </summary>
 public string PipeValuesInText(int questionId, string sourceText, VoterAnswersData.VotersAnswersDataTable surveyAnswers, string languageCode)
 {
     Regex regex = new Regex(@"\[{2}((\S)+)\]{2}");
     if (surveyAnswers != null)
     {
         Match match = regex.Match(sourceText);
         if (match.Success)
         {
             if (HttpContext.Current != null)
             {
                 if (HttpContext.Current.Cache["NSurvey:PipeData"] == null)
                 {
                     HttpContext.Current.Cache.Insert("NSurvey:PipeData", new Surveys().GetSurveyPipeDataFromQuestionId(questionId), null, DateTime.Now.AddMinutes(1.0), TimeSpan.Zero);
                 }
                 this._pipeData = (PipeData) HttpContext.Current.Cache["NSurvey:PipeData"];
             }
             else
             {
                 this._pipeData = new Surveys().GetSurveyPipeDataFromQuestionId(questionId);
             }
             while (match.Success)
             {
                 string str = match.Groups[1].ToString();
                 if (str.Length > 0)
                 {
                     PipeData.QuestionsRow[] rowArray = (PipeData.QuestionsRow[]) this._pipeData.Questions.Select("QuestionPipeAlias='" + str + "'");
                     if (rowArray.Length > 0)
                     {
                         sourceText = sourceText.Replace("[[" + str + "]]", this.PipeQuestionAnswers(rowArray[0].QuestionId, surveyAnswers, languageCode));
                     }
                     else
                     {
                         PipeData.AnswersRow[] rowArray2 = (PipeData.AnswersRow[]) this._pipeData.Answers.Select("AnswerPipeAlias='" + str + "'");
                         if (rowArray2.Length > 0)
                         {
                             sourceText = sourceText.Replace("[[" + str + "]]", this.PipeAnswerText(rowArray2[0].AnswerId, surveyAnswers));
                         }
                     }
                 }
                 match = match.NextMatch();
             }
         }
         match = regex.Match(sourceText);
         if ((match.Length > 0) && (this.previousMatchCount != match.Length))
         {
             this.previousMatchCount = match.Length;
             return this.PipeValuesInText(questionId, sourceText, surveyAnswers, languageCode);
         }
     }
     return sourceText;
 }
        /// <summary>
        /// Add a new voter and his answers to the database 
        /// </summary>
        public void AddVoter(VoterAnswersData voterAnswers)
        {
            SqlConnection connection = new SqlConnection(DbConnection.NewDbConnectionString);
            connection.Open();
            SqlTransaction transaction = connection.BeginTransaction();

            SqlCommand insertCommand = new SqlCommand("vts_spVoterAddNew", connection, transaction);
            insertCommand.CommandType = CommandType.StoredProcedure;
            insertCommand.Parameters.Add(new SqlParameter("@SurveyID", SqlDbType.Int, 4, "SurveyID"));
            insertCommand.Parameters.Add(new SqlParameter("@IPSource", SqlDbType.NVarChar, 50, "IPSource"));
            insertCommand.Parameters.Add(new SqlParameter("@VoteDate", SqlDbType.DateTime, 8, "VoteDate"));
            insertCommand.Parameters.Add(new SqlParameter("@StartDate", SqlDbType.DateTime, 8, "StartDate"));
            insertCommand.Parameters.Add(new SqlParameter("@Validated", SqlDbType.Bit, 1, "Validated"));
            insertCommand.Parameters.Add(new SqlParameter("@UId", SqlDbType.VarChar, 50, "UId"));
            insertCommand.Parameters.Add(new SqlParameter("@VoterID", SqlDbType.Int, 4, "VoterID"));
            insertCommand.Parameters.Add(new SqlParameter("@ResumeUId", SqlDbType.VarChar, 50, "ResumeUId"));
            insertCommand.Parameters.Add(new SqlParameter("@ProgressSaveDate", SqlDbType.DateTime, 8, "ProgressSaveDate"));
            insertCommand.Parameters.Add(new SqlParameter("@ResumeAtPageNumber", SqlDbType.Int, 4, "ResumeAtPageNumber"));
            insertCommand.Parameters.Add(new SqlParameter("@ResumeQuestionNumber", SqlDbType.Int, 4, "ResumeQuestionNumber"));
            insertCommand.Parameters.Add(new SqlParameter("@ResumeHighestPageNumber", SqlDbType.Int, 4, "ResumeHighestPageNumber"));
            insertCommand.Parameters.Add(new SqlParameter("@LanguageCode", SqlDbType.VarChar, 50, "LanguageCode"));
            insertCommand.Parameters["@VoterID"].Direction = ParameterDirection.Output;

            SqlCommand command2 = new SqlCommand("vts_spVoterAnswersAddNew", connection, transaction);
            command2.CommandType = CommandType.StoredProcedure;
            command2.Parameters.Add(new SqlParameter("@AnswerID", SqlDbType.Int, 4, "AnswerID"));
            command2.Parameters.Add(new SqlParameter("@AnswerText", SqlDbType.NText, 0x3fffffff, "AnswerText"));
            command2.Parameters.Add(new SqlParameter("@VoterID", SqlDbType.Int, 4, "VoterID"));
            command2.Parameters.Add(new SqlParameter("@SectionNumber", SqlDbType.Int, 4, "SectionNumber"));
            try
            {
                //SqlHelper.UpdateDataset(insertCommand, new SqlCommand(), insertCommand, voterAnswers, "Voters", false);
                //SqlHelper.UpdateDataset(command2, new SqlCommand(), command2, voterAnswers, "VotersAnswers", false);

                DbConnection.db.UpdateDataSet(voterAnswers, "Voters", insertCommand, new SqlCommand(), insertCommand, UpdateBehavior.Transactional);
                DbConnection.db.UpdateDataSet(voterAnswers, "VotersAnswers", command2, new SqlCommand(), command2, UpdateBehavior.Transactional);
                transaction.Commit();
                connection.Close();
            }
            catch (Exception exception)
            {
                transaction.Rollback();
                throw exception;
            }
        }
 /// <summary>
 /// Replace the pipe token with the question answers
 /// </summary>
 protected virtual string PipeQuestionAnswers(int questionId, VoterAnswersData.VotersAnswersDataTable surveyAnswers, string languageCode)
 {
     StringBuilder builder = new StringBuilder();
     VoterAnswersData.VotersAnswersRow[] rowArray = (VoterAnswersData.VotersAnswersRow[]) surveyAnswers.Select("QuestionId=" + questionId);
     int index = 0;
     while (index < rowArray.Length)
     {
         PipeData.AnswersRow[] rowArray2 = (PipeData.AnswersRow[]) this._pipeData.Answers.Select("AnswerId=" + rowArray[index].AnswerId);
         if (rowArray2.Length > 0)
         {
             builder.Append(rowArray2[0].AnswerText);
         }
         index++;
         if ((index + 1) == rowArray.Length)
         {
             builder.Append(ResourceManager.GetString("PipeValuesSeparator", languageCode));
         }
         else if (index < rowArray.Length)
         {
             builder.Append(", ");
         }
     }
     return builder.ToString();
 }
 public void AddVotersRow(VoterAnswersData.VotersRow row)
 {
     base.Rows.Add(row);
 }
 public FormSessionEventArgs(VoterAnswersData voterAnswers, string resumeUId)
 {
     this.VoterAnswers = voterAnswers;
     this._resumeUId = resumeUId;
 }
        /// <summary>
        /// Get the current DB stats and fill 
        /// the label with them
        /// </summary>
        private void BindData()
        {
            isScored = new Surveys().IsSurveyScored(SurveyId);

            TimeSpan timeTaken;
            _voterAnswers = new Voters().GetVoterAnswers(_voterId);

            if (!_voterAnswers.Voters[0].IsVoteDateNull() && !_voterAnswers.Voters[0].IsStartDateNull())
            {
                timeTaken = _voterAnswers.Voters[0].VoteDate - _voterAnswers.Voters[0].StartDate;
            }
            else
            {
                timeTaken = new TimeSpan(0);
            }

            VoterUIDLabel.Text = _voterId.ToString();
            IPAddressLabel.Text = _voterAnswers.Voters[0].IPSource;
            VoteDateLabel.Text = _voterAnswers.Voters[0].VoteDate.ToString();
            VoterEmail.Text = _voterAnswers.Voters[0].IsEmailNull() ? GetPageResource("AnonymousVoteInfo") : _voterAnswers.Voters[0].Email;
            VoterUserName.Text = _voterAnswers.Voters[0].IsContextUserNameNull() ?  GetPageResource("ContextUserNameDisabled") : _voterAnswers.Voters[0].ContextUserName;
            VoterLanguageValueLabel.Text = _voterAnswers.Voters[0].IsLanguageCodeNull() || _voterAnswers.Voters[0].LanguageCode.Length == 0 ?
                GetPageResource("LanguageUndefined") : _voterAnswers.Voters[0].LanguageCode;
            TimeToTakeSurveyLabel.Text = string.Format("{0} {1}, {2} secs.", timeTaken.Minutes.ToString(), GetPageResource("MinutesInfo"), timeTaken.Seconds.ToString());

            WebSecurityAddInCollection securityAddIns = WebSecurityAddInFactory.CreateWebSecurityAddInCollection(new SecurityAddIns().GetWebSecurityAddIns(SurveyId), ViewState, null);
            NameValueCollection addInVoterData;
            for (int i=0;i<securityAddIns.Count;i++)
            {
                addInVoterData = securityAddIns[i].GetAddInVoterData(_voterId);
                if (addInVoterData != null)
                {
                    // Creates a new addin voter details page
                    SecurityAddInVoterReportControl addInVoterControl =
                        (SecurityAddInVoterReportControl)LoadControl("UserControls/SecurityAddInVoterReportControl.ascx");

                    addInVoterControl.AddInDescription = securityAddIns[i].Description;
                    addInVoterControl.AddInVoterData = addInVoterData;
                    AddInVoterDataPlaceHolder.Controls.Add(addInVoterControl);
                }
            }

            _questionData = new Questions().GetQuestionHierarchy(SurveyId);
            QuestionsDataGrid.DataSource = GetParentQuestions();
            QuestionsDataGrid.DataKeyField = "QuestionId";
            QuestionsDataGrid.DataBind();
            if (isScored)
            {
                VoterScoreTotalLabel.Text = GetPageResource("VoterScoreTotalLabel") + _totalScore.ToString();
            }
        }
 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;
 }
 /// <summary>
 /// Method to handle voter data once it has been stored in the database
 /// </summary>
 /// <param name="voter">Voter information as saved in the database and its answers</param>
 public void ProcessVoterData(VoterAnswersData voter)
 {
     new Survey().IncreaseQuotaEntries(this.SurveyId);
 }
        /// <summary>
        /// Updates voter's answer
        /// </summary>
        /// <param name="voterAnswers">Voter and all his answers information</param>
        public void UpdateVoter(VoterAnswersData updatedVoterAnswers)
        {
            SqlConnection connection = new SqlConnection(DbConnection.NewDbConnectionString);
            connection.Open();
            SqlTransaction transaction = connection.BeginTransaction();
            SqlCommand insertCommand = new SqlCommand("vts_spVoterAnswersAddNew", connection, transaction);
            insertCommand.CommandType = CommandType.StoredProcedure;
            insertCommand.Parameters.Add(new SqlParameter("@AnswerID", SqlDbType.Int, 4, "AnswerID"));
            insertCommand.Parameters.Add(new SqlParameter("@AnswerText", SqlDbType.NText, 0x3fffffff, "AnswerText"));
            insertCommand.Parameters.Add(new SqlParameter("@VoterID", SqlDbType.Int, 4, "VoterID"));
            insertCommand.Parameters.Add(new SqlParameter("@SectionNumber", SqlDbType.Int, 4, "SectionNumber"));
            try
            {
                ArrayList commandParameters = new ArrayList();
                {
                    commandParameters.Add(new SqlParameter("@voterId", updatedVoterAnswers.Voters[0].VoterId).SqlValue);
                }

                DbConnection.db.ExecuteNonQuery("vts_spVoterDeleteAnswers", commandParameters.ToArray());

                DbConnection.db.UpdateDataSet(updatedVoterAnswers, "VotersAnswers", insertCommand, new SqlCommand(), insertCommand, UpdateBehavior.Transactional);
                transaction.Commit();
                connection.Close();
            }
            catch (Exception exception)
            {
                transaction.Rollback();
                throw exception;
            }
        }
        /// <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>
 /// Method to handle voter data once it has been stored in the database
 /// </summary>
 /// <param name="voter">Voter information as saved in the database and its answers</param>
 public void ProcessVoterData(VoterAnswersData voter)
 {
     if ((this.VisitorToken != null))
         new SurveyToken().UpdateToken(this.SurveyId, this.VisitorToken,
             new Surveys().IsSurveySaveTokenUserData(this.SurveyId)?-1: voter.Voters[0].VoterId);
 }
 public int GetQuestionAnswersScore(int questionId, VoterAnswersData votersAnswers)
 {
     StringBuilder builder = new StringBuilder();
     VoterAnswersData.VotersAnswersRow[] rowArray = (VoterAnswersData.VotersAnswersRow[]) votersAnswers.VotersAnswers.Select("QuestionId=" + questionId);
     int num = 0;
     foreach (VoterAnswersData.VotersAnswersRow row in rowArray)
     {
         builder.Append(row.AnswerId);
         if ((num + 1) < rowArray.Length)
         {
             builder.Append(',');
         }
         num++;
     }
     return new Answers().GetAnswersScoreTotal(builder.ToString());
 }
 /// <summary>
 /// Unloads the available security addins and allow them
 /// to make some operations after the voter and its answers
 /// has been stored in the database
 /// </summary>
 protected virtual void UnLoadSecurityAddIns(VoterAnswersData voterData)
 {
     this._securityAddIns = WebSecurityAddInFactory.CreateWebSecurityAddInCollection(new SecurityAddIns().GetEnabledWebSecurityAddIns(this.SurveyId), this.ViewState, this.LanguageCode);
     for (int i = 0; i < this._securityAddIns.Count; i++)
     {
         this._securityAddIns[i].ProcessVoterData(voterData);
     }
 }
 public void RemoveVotersRow(VoterAnswersData.VotersRow row)
 {
     base.Rows.Remove(row);
 }
        /// <summary>
        /// Get voter's answers and voter details
        /// </summary>
        /// <param name="voterId"></param>
        /// <returns></returns>
        public VoterAnswersData GetVoterAnswers(int voterId)
        {
            VoterAnswersData dataSet = new VoterAnswersData();

            ArrayList commandParameters = new ArrayList();
            {
                commandParameters.Add(new SqlParameter("@VoterID", voterId).SqlValue);
            }

            DbConnection.db.LoadDataSet("vts_spVoterGetAnswers", dataSet, new string[] { "Voters", "VotersAnswers" }, commandParameters.ToArray());
            return dataSet;
        }
 /// <summary>
 /// Method to handle voter data once it has been stored in the database
 /// </summary>
 /// <param name="voter">Voter information as saved in the database and its answers</param>
 public void ProcessVoterData(VoterAnswersData voter)
 {
     voter.Voters[0].ContextUserName = HttpContext.Current.User.Identity.Name;
     new Voter().UpdateVoterUserName(voter.Voters[0].VoterId, NSurveyContext.Current.User.Identity.Name);
 }
        /// <summary>
        /// Get the voter's data and answers to resume a session
        /// </summary>
        public VoterAnswersData ResumeVoterAnswers(int surveyId, string resumeUid)
        {
            //SqlParameter[] commandParameters = new SqlParameter[] 
            //{ new SqlParameter("@SurveyID", surveyId), 
            //    new SqlParameter("@ResumeUid", resumeUid) 
            //};

            ArrayList commandParameters = new ArrayList();
            {
                commandParameters.Add(new SqlParameter("@SurveyID", surveyId).SqlValue);
                commandParameters.Add(new SqlParameter("@ResumeUid", resumeUid).SqlValue);
            }

            VoterAnswersData dataSet = new VoterAnswersData();
            
            //SqlHelper.FillDatasetWithoutChangesAccept(DbConnection.NewDbConnectionString, CommandType.StoredProcedure, "vts_spVoterResumeSession", dataSet, new string[] { "Voters", "VotersAnswers" }, commandParameters);
            // Note: FillDatasetWithoutChangesAccept: similar to FillDataset method except for the extra line:
            //adapter.AcceptChangesDuringFill = false;

            //AcceptChanges() : Commits all the changes made to this DataSet since it was loaded or since the last time AcceptChanges was called.
            //AcceptChangesDuringFill: Gets or sets a value indicating whether AcceptChanges is called on a DataRow after it is added to the DataTable during any of the Fill operations.
            //If false, AcceptChanges is not called, and the newly added rows are treated as inserted rows: rowstate = added instead of unchanged.

           DbConnection.db.LoadDataSetWithoutAcceptChanges("vts_spVoterResumeSession", dataSet, new string[] { "Voters", "VotersAnswers" }, commandParameters.ToArray());

               return dataSet;

        }
		public VoterTextReportGenerator(VoterAnswersData voterAnswers, int surveyId) : base(voterAnswers, surveyId)
		{
		}
 /// <summary>
 /// Method to handle voter data once it has been stored in the database
 /// </summary>
 /// <param name="voter">Voter information as saved in the database and its answers</param>
 public void ProcessVoterData(VoterAnswersData voter)
 {
 }
        /// <summary>
        /// Get next page depending depending on the
        /// branching rules
        /// </summary>
        public int GetNextPage(int surveyId, int pageNumber, VoterAnswersData voterAnswers, bool evaluateScores)
        {
            BranchingRuleData surveyPageBranchingRules = new Surveys().GetSurveyPageBranchingRules(surveyId, pageNumber);
            if (surveyPageBranchingRules.BranchingRules.Rows.Count <= 0)
            {
                pageNumber++;
                return pageNumber;
            }
            int num = pageNumber + 1;
            DataRow[] rowArray = null;
            foreach (BranchingRuleData.BranchingRulesRow row in surveyPageBranchingRules.BranchingRules.Rows)
            {
                int num2 = evaluateScores ? new Question().GetQuestionAnswersScore(row.QuestionId, voterAnswers) : 0;
                if ((evaluateScores && (row.ConditionalOperator == 3)) && (num2 == row.Score))
                {
                    return row.TargetPageNumber;
                }
                if ((evaluateScores && (row.ConditionalOperator == 4)) && (num2 < row.Score))
                {
                    return row.TargetPageNumber;
                }
                if ((evaluateScores && (row.ConditionalOperator == 5)) && (num2 > row.Score))
                {
                    return row.TargetPageNumber;
                }
                if ((evaluateScores && (row.ConditionalOperator == 6)) && ((num2 >= row.Score) && (num2 <= row.ScoreMax)))
                {
                    return row.TargetPageNumber;
                }
                if (!row.IsAnswerIdNull() && !row.IsTextFilterNull())
                {
                    string expression = this.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_0319;

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

                            case 4:
                                rowArray = voterAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText < ", expression }));
                                goto Label_0319;
                        }
                        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_0319:
                if ((((rowArray != null) && (row.ConditionalOperator == 1)) && (rowArray.Length > 0)) || ((row.ConditionalOperator == 2) && (rowArray.Length == 0)))
                {
                    return row.TargetPageNumber;
                }
            }
            return num;
        }
        /// <summary>
        /// Converts a stronlgy typed MatrixChildQuestionData dataset
        /// to a webcontrol collection
        /// </summary>
        /// <param name="childQuestions">The questions / answers data</param>
        /// <param name="parentControlUniqueID">
        /// Unique ID required to identify global groups 
        /// like radiobutton groups
        /// </param>
        /// <returns>a web control collection of MatrixChildQuestion</returns>
        public static MatrixChildCollection CreateQuestionChildCollection(MatrixChildQuestionData childQuestions, Section sectionContainer, string languageCode, string parentControlUniqueID, AnswerSelectionMode selectionMode, Style answerStyle, ControlRenderMode renderMode, VoterAnswersData.VotersAnswersDataTable voterAnswersState, bool enableAnswersDefault)
        {
            MatrixChildCollection childs = new MatrixChildCollection();
            
            foreach (MatrixChildQuestionData.ChildQuestionsRow row in childQuestions.ChildQuestions.Rows)
            {
                MatrixChildQuestion question = new MatrixChildQuestion();
                question.QuestionId = row.QuestionId;
                question.Text = new PipeManager().PipeValuesInText(row.QuestionId, row.QuestionText, voterAnswersState, languageCode);
                AnswerData answers = new AnswerData();

//                answers.Merge(row.GetAnswersRows());

				MatrixChildQuestionData.AnswersRow[] ar = row.GetAnswersRows();
					foreach (MatrixChildQuestionData.AnswersRow r in ar) {
								r.Table.Namespace = answers.Namespace; }
					answers.Merge(ar);
				
                question.Answers = AnswerItemFactory.CreateAnswerItemCollection(answers, question, sectionContainer, selectionMode, answerStyle, renderMode, languageCode, parentControlUniqueID, false, voterAnswersState, enableAnswersDefault);
                childs.Add(question);
            }
            return childs;
        }
 /// <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>
 /// Method to handle voter data once it has been stored in the database
 /// </summary>
 /// <param name="voter">Voter information as saved in the database and its answers</param>
 public void ProcessVoterData(VoterAnswersData voter)
 {
     HttpCookie cookie = new HttpCookie("VotationsSurvey" + this.SurveyId, "1");
     cookie.Expires = DateTime.Now.AddMinutes((double) new Surveys().GetCookieExpiration(this.SurveyId));
     HttpContext.Current.Response.Cookies.Add(cookie);
 }
 /// <summary>
 /// Updates voter's answer
 /// </summary>
 /// <param name="voterAnswers">Voter and all his answers information</param>
 public void UpdateVoter(VoterAnswersData updatedVoterAnswers)
 {
     VoterFactory.Create().UpdateVoter(updatedVoterAnswers);
 }
 public VoterAnswersData.VotersAnswersRow AddVotersAnswersRow(VoterAnswersData.VotersRow parentVotersRowByVoterAnswersRelation, int AnswerId, int QuestionId, string AnswerText, int SectionNumber, int TypeMode)
 {
     VoterAnswersData.VotersAnswersRow row = (VoterAnswersData.VotersAnswersRow) base.NewRow();
     row.ItemArray = new object[] { parentVotersRowByVoterAnswersRelation[0], AnswerId, QuestionId, AnswerText, SectionNumber, TypeMode };
     base.Rows.Add(row);
     return row;
 }
        /// <summary>
        /// Get conditional thanks message based
        /// on user's answers
        /// </summary>
        public string GetThanksMessage(int surveyId, VoterAnswersData surveyAnswers, bool evaluateScores)
        {
            MessageConditionData surveyMessageConditions = new Surveys().GetSurveyMessageConditions(surveyId);
            if ((surveyMessageConditions.MessageConditions.Rows.Count > 0) && (surveyAnswers.Voters.Count > 0))
            {
                DataRow[] rowArray = null;
                string thankYouMessage = null;
                int scoreTotal = evaluateScores ? this.GetScoreTotal(surveyAnswers) : 0;
                foreach (MessageConditionData.MessageConditionsRow row in surveyMessageConditions.MessageConditions.Rows)
                {
                    if ((evaluateScores && (row.MessageConditionalOperator == 3)) && (scoreTotal < row.Score))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if ((evaluateScores && (row.MessageConditionalOperator == 2)) && (scoreTotal == row.Score))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if ((evaluateScores && (row.MessageConditionalOperator == 4)) && (scoreTotal > row.Score))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if ((evaluateScores && (row.MessageConditionalOperator == 5)) && ((scoreTotal >= row.Score) && (scoreTotal <= row.ScoreMax)))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if (row.MessageConditionalOperator != 1)
                    {
                        continue;
                    }
                    int num2 = evaluateScores ? new Question().GetQuestionAnswersScore(row.QuestionId, surveyAnswers) : 0;
                    if ((evaluateScores && (row.ConditionalOperator == 3)) && (num2 == row.Score))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if ((evaluateScores && (row.ConditionalOperator == 4)) && (num2 < row.Score))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if ((evaluateScores && (row.ConditionalOperator == 5)) && (num2 > row.Score))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if ((evaluateScores && (row.ConditionalOperator == 6)) && ((num2 >= row.Score) && (num2 <= row.ScoreMax)))
                    {
                        thankYouMessage = row.ThankYouMessage;
                    }
                    if (!row.IsAnswerIdNull() && !row.IsTextFilterNull())
                    {
                        string expression = this.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 = surveyAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText = ", expression }));
                                    goto Label_03F9;

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

                                case 4:
                                    rowArray = surveyAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText < ", expression }));
                                    goto Label_03F9;
                            }
                            rowArray = surveyAnswers.VotersAnswers.Select(string.Concat(new object[] { "AnswerId = ", row.AnswerId, " AND AnswerText like '%", expression, "%'" }));
                        }
                        catch (EvaluateException)
                        {
                        }
                    }
                    else if (!row.IsAnswerIdNull())
                    {
                        rowArray = surveyAnswers.VotersAnswers.Select("AnswerId=" + row.AnswerId);
                    }
                    else if (row.IsAnswerIdNull())
                    {
                        rowArray = surveyAnswers.VotersAnswers.Select("QuestionId=" + row.QuestionId);
                    }
                    else
                    {
                        rowArray = null;
                    }
                Label_03F9:
                    if ((((rowArray != null) && (row.ConditionalOperator == 1)) && (rowArray.Length > 0)) || ((row.ConditionalOperator == 2) && (rowArray.Length == 0)))
                    {
                        thankYouMessage = row.ThankYouMessage;
                        break;
                    }
                }
                if (thankYouMessage != null)
                {
                    return ParseThankYouMessage(thankYouMessage, scoreTotal);
                }
            }
            return null;
        }
 /// <summary>
 /// Calculate the total score of the current answers set
 /// </summary>
 private int GetScoreTotal(VoterAnswersData votersAnswers)
 {
     StringBuilder builder = new StringBuilder();
     int num = 0;
     foreach (VoterAnswersData.VotersAnswersRow row in votersAnswers.VotersAnswers.Rows)
     {
         builder.Append(row.AnswerId);
         if ((num + 1) < votersAnswers.VotersAnswers.Count)
         {
             builder.Append(',');
         }
         num++;
     }
     return new Answers().GetAnswersScoreTotal(builder.ToString());
 }
 public VotersAnswersRowChangeEvent(VoterAnswersData.VotersAnswersRow row, DataRowAction action)
 {
     this.eventRow = row;
     this.eventAction = action;
 }