Пример #1
0
        /// <summary>
        ///   To get all questions by filtering with type (objective, descriptive or action-based)
        /// </summary>
        /// <param name="type">question type</param>
        /// <returns>
        ///   arraylist of questions with specified type
        /// </returns>
        public static ArrayList getAllQuestionsByType(byte type)
        {
            CTVIATBankDataSet.QuestionsDataTable allQuestionsTable = questionsAdapter.GetAllQuestionsByType(type);
            ArrayList questions = new ArrayList();

            if (type == 1)
            {
                foreach (DataRow row in allQuestionsTable)
                {
                    String[] choices = new String[4];
                    choices[0] = Convert.ToString(row["objectiveChoiceOne"]);
                    choices[1] = Convert.ToString(row["objectiveChoiceTwo"]);
                    choices[2] = Convert.ToString(row["objectiveChoiceThree"]);
                    choices[3] = Convert.ToString(row["objectiveChoiceFour"]);
                    ObjectiveQuestion temp =
                        new ObjectiveQuestion(Convert.ToString(row["question"]), choices,
                                              new ObjectiveAnswer(Convert.ToByte(row["objectiveAnswer"])),
                                              Convert.ToInt32(row["questionID"]),
                                              Convert.ToInt32(row["questionSubject"]));
                    questions.Add(temp);
                }
            }
            else if (type == 2)
            {
                foreach (DataRow row in allQuestionsTable)
                {
                    DescriptiveQuestion temp =
                        new DescriptiveQuestion(Convert.ToString(row["question"]),
                                                new DescriptiveAnswer(Convert.ToString(row["descriptiveAnswer"])),
                                                Convert.ToInt32(row["questionID"]),
                                                Convert.ToInt32(row["questionSubject"]));
                    questions.Add(temp);
                }
            }
            else
            {
                foreach (DataRow row in allQuestionsTable)
                {
                    ActionBasedQuestion temp =
                        new ActionBasedQuestion(Convert.ToString(row["question"]),
                                                Convert.ToInt32(row["actionType"]),
                                                Convert.ToString(row["actionParameterOne"]),
                                                Convert.ToString(row["actionParameterTwo"]),
                                                Convert.ToInt32(row["questionID"]),
                                                Convert.ToInt32(row["questionSubject"]));
                    questions.Add(temp);
                }
            }
            return(questions);
        }
Пример #2
0
        /// <summary>
        ///  question ID is unique, so question object is created by querying question ID
        /// </summary>
        /// <param name="questionId">question ID</param>
        /// <returns>
        ///     question object, can be cast to Objective, Descriptive or Action-based
        /// </returns>
        public static Question getQuestionById(int questionId)
        {
            CTVIATBankDataSet.QuestionsDataTable table =
                questionsAdapter.GetQuestionByID(questionId);

            DataRow row  = table.Rows[0];
            byte    type = Convert.ToByte(row["questionType"]);

            if (type == 1)
            {
                String[] choices = new String[4];
                choices[0] = Convert.ToString(row["objectiveChoiceOne"]);
                choices[1] = Convert.ToString(row["objectiveChoiceTwo"]);
                choices[2] = Convert.ToString(row["objectiveChoiceThree"]);
                choices[3] = Convert.ToString(row["objectiveChoiceFour"]);

                return(new ObjectiveQuestion(Convert.ToString(row["question"]), choices,
                                             new ObjectiveAnswer(Convert.ToByte(row["objectiveAnswer"])),
                                             Convert.ToInt32(row["questionID"]),
                                             Convert.ToInt32(row["questionSubject"])));
            }
            else if (type == 2)
            {
                return(new DescriptiveQuestion(Convert.ToString(row["question"]),
                                               new DescriptiveAnswer(Convert.ToString(row["descriptiveAnswer"])),
                                               Convert.ToInt32(row["questionID"]),
                                               Convert.ToInt32(row["questionSubject"])));
            }
            else
            {
                return(new ActionBasedQuestion(Convert.ToString(row["question"]),
                                               Convert.ToInt32(row["actionType"]),
                                               Convert.ToString(row["actionParameterOne"]),
                                               Convert.ToString(row["actionParameterTwo"]),
                                               Convert.ToInt32(row["questionID"]),
                                               Convert.ToInt32(row["questionSubject"])));
            }
        }