示例#1
0
        public void UpdateQuestion(QuestionData theQuestion)
        {
            AnswerEntity temp = new AnswerEntity();

            for (int i = 0; i < theQuestion.Answers.Count; i++)
            {
                temp.UpdateAnswer(theQuestion.Answers[i]);
            }

            temp.Dispose();

            if (DataReader != null)
            {
                DataReader.Close();
            }


            SQL = "UPDATE `questions` q SET q.`question` = \"" + theQuestion.Text + "\" WHERE q.`question_id` = \"" + theQuestion.Id + "\";";

            OpenConnection();
            InitializeCommand();



            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
            {
                throw new Exception("Unable to edit the question on database");
            }
        }
示例#2
0
        public void CreateQuestion(QuestionData theQuestion)
        {
            theQuestion.id = NextId;

            AnswerEntity temp;

            temp = new AnswerEntity();

            for (int i = 0; i < theQuestion.answers.Count; i++)
            {
                temp.CreateAnswer(theQuestion.answers[i]);
            }
            temp.Dispose();

            if (DataReader != null)
            {
                DataReader.Close();
            }

            SQL = "INSERT INTO `questions` (`question_id`, `question`) VALUES (\"" + theQuestion.id + "\", \"" + theQuestion.Text + "\");";

            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            if (DataReader != null)
            {
                DataReader.Close();
            }

            if (result == 0)
            {
                throw new Exception("Cannot add the selected question to the database");
            }

            for (int i = 0; i < theQuestion.answers.Count; i++)
            {
                if (DataReader != null)
                {
                    DataReader.Close();
                }

                SQL = "INSERT INTO `rel_questions_answers` (`question_id`, `answer_id`) VALUES (\"" +
                      theQuestion.id +
                      "\", \"" +
                      theQuestion.answers[i].Id +
                      "\");";
                InitializeCommand();
                OpenConnection();

                result = ExecuteStoredProcedure();
                if (result == 0)
                {
                    throw new Exception("One or more of the answers could not be added to the database");
                }
            }
            CloseConnection();
        }
示例#3
0
        public void CreateQuestion(QuestionData theQuestion)
        {
            theQuestion.Id = NextId;

            AnswerEntity temp;

            temp = new AnswerEntity();

            for (int i = 0; i < theQuestion.Answers.Count; i++) {
                temp.CreateAnswer(theQuestion.Answers[i]);
            }
            temp.Dispose();

            if (DataReader != null)
                DataReader.Close();

            SQL = "INSERT INTO `questions` (`question_id`, `question`) VALUES (\"" + theQuestion.Id + "\", \"" + theQuestion.Text + "\");";

            OpenConnection();
            InitializeCommand();

            int result = ExecuteStoredProcedure();

            if (DataReader != null)
                DataReader.Close();

            if (result == 0)
                throw new Exception("Cannot add the selected question to the database");

            for (int i = 0; i < theQuestion.Answers.Count; i++) {
                if (DataReader != null)
                    DataReader.Close();

                SQL = "INSERT INTO `rel_questions_answers` (`question_id`, `answer_id`) VALUES (\"" +
                    theQuestion.Id +
                    "\", \"" +
                    theQuestion.Answers[i].Id +
                    "\");";
                InitializeCommand();

                result = ExecuteStoredProcedure();
                if (result == 0)
                    throw new Exception("One or more of the answers could not be added to the database");

            }

            CloseConnection();
        }
示例#4
0
        public QuestionData ReadQuestion(int id)
        {
            QuestionData return_data = null;

            if (DataReader != null)
            {
                DataReader.Close();
            }

            SQL = "SELECT * FROM `questions` q WHERE q.`question_id` = \"" + id + "\";";

            InitializeCommand();
            OpenConnection();
            DataReader = Command.ExecuteReader();

            if (DataReader.HasRows)
            {
                DataReader.Read();
                return_data      = new QuestionData(DataReader.GetUInt16("question_id"));
                return_data.Text = DataReader.GetString("question");
                DataReader.Close();
            }

            if (return_data != null)
            {
                AnswerEntity      temp  = new AnswerEntity();
                List <AnswerData> temp1 = temp.ReadAnswers(return_data);
                for (int i = 0; i < temp1.Count; i++)
                {
                    return_data.AddAnswer(temp1[i]);
                }
                temp.Dispose();
            }

            CloseConnection();

            return(return_data);
        }
示例#5
0
        public void UpdateQuestion(QuestionData theQuestion)
        {
            AnswerEntity temp = new AnswerEntity();

            for (int i = 0; i < theQuestion.Answers.Count; i++)
                temp.UpdateAnswer(theQuestion.Answers[i]);

            temp.Dispose();

            if (DataReader != null)
                DataReader.Close();

            SQL = "UPDATE `questions` q SET q.`question` = \"" + theQuestion.Text + "\" WHERE q.`question_id` = \"" + theQuestion.Id + "\";";

            OpenConnection();
            InitializeCommand();

            int result = ExecuteStoredProcedure();
            CloseConnection();

            if (result == 0)
                throw new Exception("Unable to edit the question on database");
        }
示例#6
0
        public QuestionData ReadQuestion(int id)
        {
            QuestionData return_data = null;

            if (DataReader != null)
                DataReader.Close();

            SQL = "SELECT * FROM `questions` q WHERE q.`question_id` = \"" + id + "\";";

            InitializeCommand();
            OpenConnection();
            DataReader = Command.ExecuteReader();

            if (DataReader.HasRows) {
                DataReader.Read();
                return_data = new QuestionData(DataReader.GetUInt16("question_id"));
                return_data.Text = DataReader.GetString("question");
                DataReader.Close();
            }

            if (return_data != null) {
                AnswerEntity temp = new AnswerEntity();
                List<AnswerData> temp1 = temp.ReadAnswers(return_data);
                for (int i = 0; i < temp1.Count; i++)
                    return_data.AddAnswer(temp1[i]);
                temp.Dispose();
            }

            CloseConnection();

            return return_data;
        }