context: namespace Votations.NSurvey.SQLServerDAL
  {
      using Microsoft.Practices.EnterpriseLibrary.Common;
      using Microsoft.Practices.EnterpriseLibrary.Data;
      using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
      // using Microsoft.ApplicationBlocks.Data;
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.Data;
      using System.Data.SqlClient;
      using Votations.NSurvey.Data;
      using Votations.NSurvey.IDAL;
      using System.Linq;
      /// <summary>
      /// SQL Server DAL implementation.
      /// </summary>
      public class Question : IQuestion
      {
          /// <summary>
          /// Adds a new child question to the parent question specified by the parent questio id in the database
          /// </summary>
          /// <param name="newChildQuestion">Question object with information about what to add. Only Id must be ommited</param>
          public void AddChildQuestion(MatrixChildQuestionData newChildQuestion)
          {
              SqlConnection sqlConnection = new SqlConnection(DbConnection.NewDbConnectionString);
              DbConnection.db.UpdateDataSet(newChildQuestion, "ChildQuestions", this.GetInsertChildQuestionCommand(sqlConnection, null), new SqlCommand(), new SqlCommand(), UpdateBehavior.Transactional);
          }
  
          /// <summary>
          /// Adds a new question to the survey specified by the survey id in the database
          /// </summary>
          /// <param name="newQuestion">Question object with information about what to add. Only Id must be ommited</param>
          public void AddQuestion(QuestionData newQuestion)
          {
              SqlConnection sqlConnection = new SqlConnection(DbConnection.NewDbConnectionString);
              DbConnection.db.UpdateDataSet(newQuestion, "Questions", this.GetInsertQuestionCommand(sqlConnection, null), new SqlCommand(), new SqlCommand(), UpdateBehavior.Transactional);
          }
  
          /// <summary>
          /// Adds a new answer to be shown in the section grid
          /// </summary>
          public void AddQuestionSectionGridAnswers(int questionId, int answerId)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{   new SqlParameter("@QuestionId", questionId), 
              //    new SqlParameter("@AnswerId", answerId) 
              //};
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionId", questionId).SqlValue);
                  commandParameters.Add(new SqlParameter("@AnswerId", answerId).SqlValue);
              }
              
              DbConnection.db.ExecuteNonQuery("vts_spQuestionSectionGridAnswerAddNew", commandParameters.ToArray());
          }
  
          /// <summary>
          /// Add a new skip logic rule
          /// </summary>
          public void AddSkipLogicRule(SkipLogicRuleData newSkipLogicRule)
          {
              SqlConnection connection = new SqlConnection(DbConnection.NewDbConnectionString);
              SqlCommand insertCommand = new SqlCommand("vts_spQuestionSkipLogicRuleAddNew", connection);
              insertCommand.CommandType = CommandType.StoredProcedure;
              insertCommand.Parameters.Add(new SqlParameter("@SkipQuestionId", SqlDbType.Int, 4, "SkipQuestionId"));
              insertCommand.Parameters.Add(new SqlParameter("@QuestionID", SqlDbType.Int, 4, "QuestionID"));
              insertCommand.Parameters.Add(new SqlParameter("@AnswerID", SqlDbType.Int, 4, "AnswerID"));
              insertCommand.Parameters.Add(new SqlParameter("@TextFilter", SqlDbType.NVarChar, 0xfa0, "TextFilter"));
              insertCommand.Parameters.Add(new SqlParameter("@ConditionalOperator", SqlDbType.Int, 4, "ConditionalOperator"));
              insertCommand.Parameters.Add(new SqlParameter("@ExpressionOperator", SqlDbType.Int, 4, "ExpressionOperator"));
              insertCommand.Parameters.Add(new SqlParameter("@Score", SqlDbType.Int, 4, "Score"));
              insertCommand.Parameters.Add(new SqlParameter("@ScoreMax", SqlDbType.Int, 4, "ScoreMax"));
              insertCommand.Parameters.Add(new SqlParameter("@SkipLogicRuleID", SqlDbType.Int, 4, "SkipLogicRuleID"));
              insertCommand.Parameters["@SkipLogicRuleID"].Direction = ParameterDirection.Output;
              DbConnection.db.UpdateDataSet(newSkipLogicRule, "SkipLogicRules", insertCommand, new SqlCommand(), new SqlCommand(), UpdateBehavior.Transactional);
          }
  
          /// <summary>
          /// Check if the user has this question assigned
          /// </summary>
          public bool CheckQuestionUser(int questionId, int userId)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{ new SqlParameter("@QuestionId", questionId), 
              //    new SqlParameter("@UserId", userId) 
              //};
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionId", questionId).SqlValue);
                  commandParameters.Add(new SqlParameter("@UserId", userId).SqlValue);
              }
              
              object obj2 = DbConnection.db.ExecuteScalar("vts_spQuestionCheckUserAssigned", commandParameters.ToArray());
              return ((obj2 != null) && (obj2 != DBNull.Value));
          }
  
          /// <summary>
          /// Clones a question in the DB and returns the cloned question object 
          /// </summary>
          /// <param name="questionId">Id of the question you want to clone</param>
          /// <returns>A questiondata object with the cloned question</returns>
          public QuestionData CloneQuestionById(int questionId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionId", questionId).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionCloneById", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Copy a question to the given target survey
          /// </summary>
          public void CopyQuestionById(int questionId, int targetSurveyId, int targetDisplayOrder, int targetPageNumber)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{ new SqlParameter("@QuestionId", questionId), 
              //    new SqlParameter("@NewSurveyId", targetSurveyId), 
              //    new SqlParameter("@DisplayOrder", targetDisplayOrder), 
              //    new SqlParameter("@PageNumber", targetPageNumber), 
              //    new SqlParameter("@QuestionCopyId", SqlDbType.Int) 
              //};
              //commandParameters[4].Direction = ParameterDirection.Output;
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionId", questionId).SqlValue);
                  commandParameters.Add(new SqlParameter("@NewSurveyId", targetSurveyId).SqlValue);
                  commandParameters.Add(new SqlParameter("@DisplayOrder", targetDisplayOrder).SqlValue);
                  commandParameters.Add(new SqlParameter("@PageNumber", targetPageNumber).SqlValue);
                  commandParameters.Add(new SqlParameter("@QuestionCopyId", SqlDbType.Int) { Direction = ParameterDirection.Output}.SqlValue);
              }
  
              DbConnection.db.ExecuteNonQuery("vts_spQuestionCopy", commandParameters.ToArray());
              //return int.Parse(commandParameters[4].ToString());
          }
  
          /// <summary>
          /// Copy a question to the library
          /// </summary>
          public void CopyQuestionToLibrary(int questionId, int libraryId)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{ new SqlParameter("@QuestionId", questionId), 
              //    new SqlParameter("@LibraryId", libraryId), 
              //    new SqlParameter("@QuestionCopyId", SqlDbType.Int) 
              //};
              //commandParameters[2].Direction = ParameterDirection.Output;
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionId", questionId).SqlValue);
                  commandParameters.Add(new SqlParameter("@LibraryId", libraryId).SqlValue);
                  commandParameters.Add(new SqlParameter("@QuestionCopyId", SqlDbType.Int){Direction = ParameterDirection.Output}.SqlValue);
              }
              
              DbConnection.db.ExecuteNonQuery("vts_spQuestionCopyToLibrary", commandParameters.ToArray());
              //return int.Parse(commandParameters[2].ToString());
          }
  
          /// <summary>
          /// Remove all the matrix answers from the database
          /// </summary>
          /// <param name="parentQuestionId">Matrix question id</param>
          public void DeleteMatrixAnswers(int parentQuestionId)
          {
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@ParentQuestionID", parentQuestionId).SqlValue);
              }
  
              DbConnection.db.ExecuteNonQuery("vts_spAnswerMatrixDelete", commandParameters.ToArray());
          }
  
          /// <summary>
          /// Remove the question and all its answers from the database
          /// </summary>
          /// <param name="questionId">Question to delete from the database</param>
          public void DeleteQuestionById(int questionId)
          {
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionID", questionId).SqlValue);
              }
  
              DbConnection.db.ExecuteNonQuery("vts_spQuestionDeleteById", commandParameters.ToArray());
          }
  
          /// <summary>
          /// Delete an answer to be shown in the section grid
          /// </summary>
          public void DeleteQuestionSectionGridAnswers(int questionId, int answerId)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{   new SqlParameter("@QuestionId", questionId), 
              //    new SqlParameter("@AnswerId", answerId) 
              //};
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionID", questionId).SqlValue);
                  commandParameters.Add(new SqlParameter("@AnswerId", answerId).SqlValue);
              }
  
              DbConnection.db.ExecuteNonQuery("vts_spQuestionSectionGridAnswerDelete", commandParameters.ToArray());
          }
  
          /// <summary>
          /// Deletes the question's sections option
          /// </summary>
          public void DeleteQuestionSectionOptions(int questionId)
          {
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@QuestionID", questionId).SqlValue);
              }
  
              DbConnection.db.ExecuteNonQuery("vts_spQuestionSectionOptionDelete", commandParameters.ToArray());
          }
  
          /// <summary>
          /// Deletes the skip logic rule
          /// </summary>
          public void DeleteSkipLogicRuleById(int skipLogicRuleId)
          {
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@SkipLogicRuleId", skipLogicRuleId).SqlValue);
              }
  
              DbConnection.db.ExecuteNonQuery("vts_spQuestionSkipLogicRuleDeleteByID", commandParameters.ToArray());
          }
  
          /// <summary>
          /// Returns a question list that can be answered 
          /// </summary>
          /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
          /// <returns>A question object collection</returns>
          public QuestionData GetAnswerableQuestionList(int surveyId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@SurveyId", surveyId).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionanswerableList", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns a question list of the given page that can be answered 
          /// </summary>
          /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
          /// <returns>A question object collection</returns>
          public QuestionData GetAnswerableQuestionList(int surveyId, int pageNumber)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{ new SqlParameter("@surveyid", surveyId), 
              //    new SqlParameter("@pageNumber", pageNumber) 
              //};
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@SurveyId", surveyId).SqlValue);
                  commandParameters.Add(new SqlParameter("@pageNumber", pageNumber).SqlValue);
              }
              
              QuestionData dataSet = new QuestionData();
              DbConnection.db.LoadDataSet("vts_spQuestionanswerableListForPage", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns a question list of the given page range that can be answered 
          /// </summary>
          public QuestionData GetAnswerableQuestionListInPageRange(int surveyId, int startPageNumber, int endPageNumber)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{ new SqlParameter("@surveyid", surveyId), 
              //    new SqlParameter("@StartPageNumber", startPageNumber), 
              //    new SqlParameter("@EndPageNumber", endPageNumber) 
              //};
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@SurveyId", surveyId).SqlValue);
                  commandParameters.Add(new SqlParameter("@StartPageNumber", startPageNumber).SqlValue);
                  commandParameters.Add(new SqlParameter("@EndPageNumber", endPageNumber).SqlValue);
              }
              
              QuestionData dataSet = new QuestionData();
              DbConnection.db.LoadDataSet("vts_spQuestionanswerableListForPageRange", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns a question list that can be answered without their childs
          /// </summary>
          /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
          /// <returns>A question object collection</returns>
          public QuestionData GetAnswerableQuestionListWithoutChilds(int surveyId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@SurveyId", surveyId).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionAnswerableListWithoutChilds", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns the questions that can be answered without their childs
          /// </summary>
          /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
          /// <returns>A question object collection</returns>
          public QuestionData GetAnswerableQuestionWithoutChilds(int surveyId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@SurveyId", surveyId).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionAnswerableWithoutChilds", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns a question list that can be answered and that don't have any questions
          /// </summary>
          /// <param name="surveyId">Survey id from which you want to retrieve the questions</param>
          /// <returns>A question object collection</returns>
          public QuestionData GetAnswerableSingleQuestionListWithoutChilds(int surveyId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@SurveyId", surveyId).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionSingleAnswerableListWithoutChilds", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// returns a results set with the compare question's answers number of voter 
          /// that have also answered the base question answer
          /// </summary>
          public DataSet GetCrossTabResults(int compareQuestionId, int baseAnswerId)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{ new SqlParameter("@CompareQuestionId", compareQuestionId), 
              //    new SqlParameter("@BaseQuestionAnswerId", baseAnswerId) 
              //};
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@CompareQuestionId", compareQuestionId).SqlValue);
                  commandParameters.Add(new SqlParameter("@BaseQuestionAnswerId", baseAnswerId).SqlValue);
              }
  
              return DbConnection.db.ExecuteDataSet("vts_spQuestionGetCrossTabResults", commandParameters.ToArray());
          }
  
          /// <summary>
          /// Creates and return an insert command for a question
          /// </summary>
          public SqlCommand GetInsertChildQuestionCommand(SqlConnection sqlConnection, SqlTransaction sqlTransaction)
          {
              SqlCommand command = (sqlTransaction == null) ? new SqlCommand("vts_spQuestionChildAddNew", sqlConnection) : new SqlCommand("vts_spQuestionChildAddNew", sqlConnection, sqlTransaction);
              command.CommandType = CommandType.StoredProcedure;
              command.Parameters.Add(new SqlParameter("@ParentQuestionId", SqlDbType.Int, 4, "ParentQuestionID"));
              command.Parameters.Add(new SqlParameter("@QuestionText", SqlDbType.NVarChar, 0xfa0, "QuestionText"));
              command.Parameters.Add(new SqlParameter("@QuestionID", SqlDbType.Int, 4, "QuestionID"));
              command.Parameters["@QuestionID"].Direction = ParameterDirection.Output;
              return command;
          }
  
          /// <summary>
          /// Creates and return an insert command for a question
          /// </summary>
          public SqlCommand GetInsertQuestionCommand(SqlConnection sqlConnection, SqlTransaction sqlTransaction)
          {
              SqlCommand command = (sqlTransaction == null) ? new SqlCommand("vts_spQuestionAddNew", sqlConnection) : new SqlCommand("vts_spQuestionAddNew", sqlConnection, sqlTransaction);
              command.CommandType = CommandType.StoredProcedure;
              command.Parameters.Add(new SqlParameter("@SurveyID", SqlDbType.Int, 4, "SurveyId"));
              command.Parameters.Add(new SqlParameter("@LibraryId", SqlDbType.Int, 4, "LibraryId"));
              command.Parameters.Add(new SqlParameter("@SelectionModeId", SqlDbType.Int, 4, "SelectionModeId"));
              command.Parameters.Add(new SqlParameter("@LayoutModeId", SqlDbType.Int, 4, "LayoutModeId"));
              command.Parameters.Add(new SqlParameter("@DisplayOrder", SqlDbType.Int, 4, "DisplayOrder"));
              command.Parameters.Add(new SqlParameter("@PageNumber", SqlDbType.Int, 4, "PageNumber"));
              command.Parameters.Add(new SqlParameter("@QuestionText", SqlDbType.NVarChar, 0xfa0, "QuestionText"));
              command.Parameters.Add(new SqlParameter("@ColumnsNumber", SqlDbType.Int, 4, "ColumnsNumber"));
              command.Parameters.Add(new SqlParameter("@QuestionPipeAlias", SqlDbType.NVarChar, 0xff, "QuestionPipeAlias"));
              command.Parameters.Add(new SqlParameter("@MinSelectionRequired", SqlDbType.Int, 4, "MinSelectionRequired"));
              command.Parameters.Add(new SqlParameter("@MaxSelectionAllowed", SqlDbType.Int, 4, "MaxSelectionAllowed"));
              command.Parameters.Add(new SqlParameter("@RandomizeAnswers", SqlDbType.Bit, 1, "RandomizeAnswers"));
              command.Parameters.Add(new SqlParameter("@RatingEnabled", SqlDbType.Bit, 1, "RatingEnabled"));
              command.Parameters.Add(new SqlParameter("@QuestionID", SqlDbType.Int, 4, "QuestionId"));
              command.Parameters.Add(new SqlParameter("@QuestionIDText", SqlDbType.NVarChar, 255, "QuestionIDText"));
              command.Parameters.Add(new SqlParameter("@Alias", SqlDbType.NVarChar, 255, "Alias"));
              command.Parameters.Add(new SqlParameter("@HelpText", SqlDbType.NVarChar, 255, "HelpText"));
              command.Parameters.Add(new SqlParameter("@ShowHelpText", SqlDbType.Bit, 1, "ShowHelpText"));
              command.Parameters.Add(new SqlParameter("@QuestionGroupId", SqlDbType.Int, 4, "QuestionGroupId"));
  
              //command.Parameters["@SurveyID"].IsNullable = true;
              command.Parameters["@QuestionID"].Direction = ParameterDirection.Output;
              return command;
          }
  
          /// <summary>
          /// Creates and return an insert command for a question's section
          /// </summary>
          public SqlCommand GetInsertQuestionSectionCommand(SqlConnection sqlConnection, SqlTransaction sqlTransaction, string languageCode)
          {
              SqlCommand command = (sqlTransaction == null) ? new SqlCommand("vts_spQuestionSectionOptionUpdate", sqlConnection) : new SqlCommand("vts_spQuestionSectionOptionUpdate", sqlConnection, sqlTransaction);
              command.CommandType = CommandType.StoredProcedure;
              command.Parameters.Add(new SqlParameter("@LanguageCode", languageCode));
              command.Parameters.Add(new SqlParameter("@QuestionId", SqlDbType.Int, 4, "QuestionId"));
              command.Parameters.Add(new SqlParameter("@RepeatableSectionModeId", SqlDbType.Int, 4, "RepeatableSectionModeId"));
              command.Parameters.Add(new SqlParameter("@AddSectionLinkText", SqlDbType.NVarChar, 0xff, "AddSectionLinkText"));
              command.Parameters.Add(new SqlParameter("@DeleteSectionLinkText", SqlDbType.NVarChar, 0xff, "DeleteSectionLinkText"));
              command.Parameters.Add(new SqlParameter("@EditSectionLinkText", SqlDbType.NVarChar, 0xff, "EditSectionLinkText"));
              command.Parameters.Add(new SqlParameter("@UpdateSectionLinkText", SqlDbType.NVarChar, 0xff, "UpdateSectionLinkText"));
              command.Parameters.Add(new SqlParameter("@MaxSections", SqlDbType.Int, 4, "MaxSections"));
              return command;
          }
  
          /// <summary>
          /// Creates and return an insert command for a question's grid section answers
          /// </summary>
          public SqlCommand GetInsertQuestionSectionGridAnswersCommand(SqlConnection sqlConnection, SqlTransaction sqlTransaction)
          {
              SqlCommand command = (sqlTransaction == null) ? new SqlCommand("vts_spQuestionSectionGridAnswerAddNew", sqlConnection) : new SqlCommand("vts_spQuestionSectionGridAnswerAddNew", sqlConnection, sqlTransaction);
              command.CommandType = CommandType.StoredProcedure;
              command.Parameters.Add(new SqlParameter("@QuestionId", SqlDbType.Int, 4, "QuestionId"));
              command.Parameters.Add(new SqlParameter("@AnswerId", SqlDbType.Int, 4, "AnswerId"));
              return command;
          }
  
          /// <summary>
          /// Returns a question list for the given library 
          /// that can be answered and that don't have any child questions
          /// </summary>
          /// <returns>A question object collection</returns>
          public QuestionData GetLibraryAnswerableSingleQuestionListWithoutChilds(int libraryId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@LibraryId", libraryId).SqlValue);
              }
              
              DbConnection.db.LoadDataSet("vts_spQuestionLibrarySingleAnswerableListWithoutChilds", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns all question listed in the library
          /// </summary>
          public QuestionData GetLibraryQuestionList(int libraryId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@LibraryId", libraryId).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionsGetListForLibrary", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns all question listed in the library without their child questions
          /// </summary>
          public QuestionData GetLibraryQuestionListWithoutChilds(int libraryId)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@LibraryId", libraryId).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionsGetListForLibraryWithoutChilds", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns all question listed in the library with their details
          /// </summary>
          public QuestionData GetLibraryQuestions(int libraryId, string languageCode)
          {
              QuestionData dataSet = new QuestionData();
  
              ArrayList commandParameters = new ArrayList();
              {
                  commandParameters.Add(new SqlParameter("@LibraryId", libraryId).SqlValue);
                  commandParameters.Add(new SqlParameter("@LanguageCode", languageCode).SqlValue);
              }
  
              DbConnection.db.LoadDataSet("vts_spQuestionsGetForLibrary", dataSet, new string[] { "Questions" }, commandParameters.ToArray());
              return dataSet;
          }
  
          /// <summary>
          /// Returns all question childs from the question
          /// </summary>
          /// <param name="parentQuestionId">Question id from which you want to retrieve the child questions</param>
          /// <returns>A question object collection</returns>
          public MatrixChildQuestionData GetMatrixChildQuestions(int parentQuestionId, string languageCode)
          {
              //SqlParameter[] commandParameters = new SqlParameter[] 
              //{ new SqlParameter("@ParentQuestionId", parentQuestionId), 
              //    new SqlParameter("@LanguageCode", languageCode) 
              //};
  
  
gt:             ArrayList commandParameters = new ArrayList();