Beispiel #1
0
        private void CreateQuizButton_Click(object sender, EventArgs e)
        {
            //Once the user has decided that they want to create the quiz then a few validity checks are ran
            Name = QuizNameTextBox.Text;
            if (Name == "")
            {
                MessageBox.Show("Error Enter A Quiz Name", "Error", MessageBoxButtons.OK);
                return;
            }
            else if (NewQuiz.Count() < 3 || NewQuiz.Count > 15)
            {
                MessageBox.Show("Error, Invalid number of items, please select between 3 and 15 questions. Remove items or create multiple quizzes.", "Error", MessageBoxButtons.OK);
                return;
            }

            //If all criteria is passed then the number of questions in the quiz is added to the int[] array with their question ID
            int[] IdNum = new int[NewQuiz.Count()];

            foreach (StoredQuestions id in NewQuiz)
            {
                IdNum[NewQuiz.IndexOf(id)] = id.QuestionId;
            }

            QuestionClass qc = new QuestionClass();

            //Queries the SQL database to create the quiz
            qc.CreateQuiz(IdNum, Name);

            MessageBox.Show("Quiz Created!", "Success", MessageBoxButtons.OK);
        }
        private void CreateQuizButton_Click(object sender, EventArgs e)
        {
            //User names the quiz
            Name = QuizNameTextBox.Text;
            if (Name == "")
            {
                MessageBox.Show("Error Enter A Quiz Name", "Error", MessageBoxButtons.OK);
                return;
            }
            else if (questions.Count() < 3 || questions.Count > 15)
            {
                //If the program has returned an invalid number of questions this error message will be displayed
                MessageBox.Show("Error, Invalid number of items, please select between 3 and 15 questions. Remove items or create multiple quizzes.", "Error", MessageBoxButtons.OK);
                return;
            }

            //Holds the ID`s of the question that have been selected
            int[] IdNum = new int[questions.Count()];

            foreach (StoredQuestions id in questions)
            {
                IdNum[questions.IndexOf(id)] = id.QuestionId;
            }

            //The questions that have been returned based upon the criteria are passed into the CreateQuiz Method of questionclass
            QuestionClass qc = new QuestionClass();

            qc.CreateQuiz(IdNum, Name);

            //Displays a success message
            MessageBox.Show("Quiz Created!", "Success", MessageBoxButtons.OK);
        }