Exemple #1
0
        public void UpdateQuiz(QuizData theQuiz)
        {
            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
            {
                QuestionData questionToSave;
                questionToSave = theQuiz.Questions[i];
                if (questionToSave.Id == 0)
                {
                    temp.CreateQuestion(questionToSave);
                    AddQuestion(theQuiz, questionToSave);
                }
                else
                {
                    temp.UpdateQuestion(questionToSave);
                }
            }


            temp.Dispose();

            SQL = "UPDATE `quizzes` q SET q.`name` = \"" + theQuiz.Name + "\", q.`open_date` = \"" + theQuiz.Open.ToString("yyyy-MM-dd") + "\", q.`due_date` = \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\" WHERE q.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
            {
                throw new Exception("Unable to update the quiz on the database");
            }
        }
Exemple #2
0
        public void DeleteQuiz(QuizData theQuiz)
        {
            if (DataReader != null)
            {
                DataReader.Close();
            }

            QuestionEntity quest = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
            {
                quest.DeleteQuestion(theQuiz.Questions[i]);
            }

            quest.Dispose();

            SQL = "DELETE `quizzes`, `rel_courses_quizzes` FROM `quizzes` INNER JOIN `rel_courses_quizzes` ON `quizzes`.`quiz_id` = `rel_courses_quizzes`.`quiz_id` WHERE `quizzes`.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();

            CloseConnection();

            if (result == 0)
            {
                throw new Exception("Could not delete the Quiz from Database");
            }
        }
Exemple #3
0
        public void CreateQuiz(QuizData theQuiz)
        {
            theQuiz.id = NextId;
            if (DataReader != null)
            {
                DataReader.Close();
            }

            SQL = "INSERT INTO `quizzes` (`quiz_id`, `name`, `open_date`, `due_date`) VALUES " +
                  "(\"" + theQuiz.id + "\", \"" + theQuiz.Name + "\", \"" + theQuiz.Added.ToString("yyyy-MM-dd") +
                  "\", \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\");";

            InitializeCommand();

            OpenConnection();
            int result = ExecuteStoredProcedure();

            if (result == 0)
            {
                throw new Exception("Could Not add the quiz to the database");
            }

            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.questions.Count; i++)
            {
                temp.CreateQuestion(theQuiz.questions[i]);
                if (DataReader != null)
                {
                    DataReader.Close();
                }

                SQL = "INSERT INTO `rel_quizzes_questions` (`quiz_id`, `question_id`) VALUES (\"" +
                      theQuiz.id + "\", \"" + theQuiz.questions[i].id + "\");";

                InitializeCommand();
                OpenConnection();

                result = ExecuteStoredProcedure();

                if (result == 0)
                {
                    throw new Exception("Cannot associate this question with this quiz");
                }
            }

            CloseConnection();
        }
Exemple #4
0
        /// <summary>
        /// validates data and if good saves it
        /// </summary>
        /// <param name="quiz">quiz to submit</param>
        /// <exception cref="Exception">data not correct.</exception>
        public static void SubmitQuiz(QuizData quiz)
        {
            QuestionEntity temp = new QuestionEntity();
            quiz.Questions.AddRange(temp.ReadQuestions(quiz));
            temp.Dispose();
            //Validate data
            if (quiz.Due < quiz.Open)
                throw new Exception("The due date must be after the open date.");

            if (quiz.Questions.Count == 0)
                throw new Exception("The quiz must contain at least one question.");

            // Validation for questions takes place when creating the individual questions

            //Now that we validated save the quiz
            SaveQuiz(quiz);
        }
Exemple #5
0
        public QuizData ReadQuiz(int id)
        {
            QuizData return_value = null;

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

            SQL = "SELECT * FROM `quizzes` q WHERE q.`quiz_id` = \"" + id + "\";";

            InitializeCommand();
            OpenConnection();

            DataReader = Command.ExecuteReader();

            if (DataReader.HasRows)
            {
                DataReader.Read();
                return_value       = new QuizData(DataReader.GetUInt16("quiz_id"));
                return_value.Name  = DataReader.GetString("name");
                return_value.Added = DataReader.GetDateTime("open_date");
                return_value.Due   = DataReader.GetDateTime("due_date");
            }

            CloseConnection();

            QuestionEntity temp = new QuestionEntity();

            return_value.questions.AddRange(temp.ReadQuestions(return_value));

            if (return_value == null)
            {
                throw new Exception("Could not find specified Quiz");
            }



            return(return_value);
        }
Exemple #6
0
        public void CreateQuiz(QuizData theQuiz)
        {
            theQuiz.Id = NextId;
            if (DataReader != null)
                DataReader.Close();

            SQL = "INSERT INTO `quizzes` (`quiz_id`, `name`, `open_date`, `due_date`) VALUES " +
                "(\"" + theQuiz.Id + "\", \"" + theQuiz.Name + "\", \"" + theQuiz.Open.ToString("yyyy-MM-dd") +
                "\", \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\");";

            InitializeCommand();

            int result = ExecuteStoredProcedure();

            if (result == 0)
                throw new Exception("Could Not add the quiz to the database");

            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++) {

                temp.CreateQuestion(theQuiz.Questions[i]);
                if (DataReader != null)
                    DataReader.Close();

                SQL = "INSERT INTO `rel_quizzes_questions` (`quiz_id`, `question_id`) VALUES (\"" +
                    theQuiz.Id + "\", \"" + theQuiz.Questions[i].Id + "\");";

                InitializeCommand();

                result = ExecuteStoredProcedure();

                if (result == 0)
                    throw new Exception("Cannot associate this question with this quiz");

            }
        }
Exemple #7
0
        public void UpdateQuiz(QuizData theQuiz)
        {
            QuestionEntity temp = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
            {
                QuestionData questionToSave;
                questionToSave = theQuiz.Questions[i];
                if (questionToSave.Id == 0)
                {
                    temp.CreateQuestion(questionToSave);
                    AddQuestion(theQuiz, questionToSave);

                }
                else
                    temp.UpdateQuestion(questionToSave);

            }

            temp.Dispose();

            SQL = "UPDATE `quizzes` q SET q.`name` = \"" + theQuiz.Name + "\", q.`open_date` = \"" + theQuiz.Open.ToString("yyyy-MM-dd") + "\", q.`due_date` = \"" + theQuiz.Due.ToString("yyyy-MM-dd") + "\" WHERE q.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();
            CloseConnection();

            if (result == 0)
                throw new Exception("Unable to update the quiz on the database");
        }
Exemple #8
0
        public void DeleteQuiz(QuizData theQuiz)
        {
            if (DataReader != null)
                DataReader.Close();

            QuestionEntity quest = new QuestionEntity();

            for (int i = 0; i < theQuiz.Questions.Count; i++)
                quest.DeleteQuestion(theQuiz.Questions[i]);

            quest.Dispose();

            SQL = "DELETE `quizzes`, `rel_courses_quizzes` FROM `quizzes` INNER JOIN `rel_courses_quizzes` ON `quizzes`.`quiz_id` = `rel_courses_quizzes`.`quiz_id` WHERE `quizzes`.`quiz_id` = \"" + theQuiz.Id + "\";";
            InitializeCommand();
            OpenConnection();

            int result = ExecuteStoredProcedure();
            CloseConnection();

            if (result == 0)
                throw new Exception("Could not delete the Quiz from Database");
        }
Exemple #9
0
        public QuizView(Objective objective)
            : base(objective)
        {
            InitializeComponent();
            questionsToDeleteOnSave = new List<QuestionData>();

            //set title
            lblMessage.Text = GlobalData.currentQuiz.Name;

            QuestionEntity temp = new QuestionEntity();
            GlobalData.currentQuiz.Questions.AddRange(temp.ReadQuestions(GlobalData.currentQuiz));

            //create our questions and add them
            questionBoxes = new List<QuestionBox>();
            for (int i = 0; i < GlobalData.currentQuiz.Questions.Count; i++)
            {
                QuestionBox questionBox = new QuestionBox(GlobalData.currentQuiz.Questions[i], i + 1, myObjective);
                questionBox.Disposed += new EventHandler(questionBox_Disposed);
                questionBoxes.Add(questionBox);
            }

            pnlMain.Controls.AddRange(questionBoxes.ToArray());

            //add objective specific objects
            #region Edit Quiz
            if (myObjective == Objective.ManageQuizzes)
            {
                BackToolStripMenuItem.Visible = false;
                //
                // btnAddQuestion
                //
                this.btnAddQuestion = new Button();
                this.btnAddQuestion.BackgroundImage = global::JiTU_CS.Properties.Resources.add_question;
                this.btnAddQuestion.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
                this.btnAddQuestion.Name = "btnAddQuestion";
                this.btnAddQuestion.Size = new System.Drawing.Size(32, 32);
                this.btnAddQuestion.UseVisualStyleBackColor = true;
                this.btnAddQuestion.FlatAppearance.BorderSize = 0;
                this.btnAddQuestion.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                this.btnAddQuestion.Click += new EventHandler(btnAddQuestion_Click);
                pnlMain.Controls.Add(btnAddQuestion);
            }
            #endregion
            #region Take Quiz
            else if (myObjective == Objective.TakeQuiz)
            {
                mnsMain.Visible = false;
                //
                // btnSubmit
                //
                this.btnSubmit = new Button();
                this.btnSubmit.Name = "btnSubmit";
                this.btnSubmit.UseVisualStyleBackColor = true;
                this.btnSubmit.Text = "Submit";
                this.btnSubmit.Width = 100;
                this.btnSubmit.Click += new EventHandler(btnSubmit_Click);
                pnlMain.Controls.Add(btnSubmit);
            }
            #endregion
            #region View All Results
            else if (myObjective == Objective.ViewAllResults)
            {
                saveToolStripMenuItem.Visible = false;
                discardToolStripMenuItem.Visible = false;

            }
            #endregion

            //finish up by installing resize handler
            this.pnlMain.Resize += new System.EventHandler(this.pnlMain_Resize);
        }