private void btnCreate_Click(object sender, EventArgs e) { question iNewQuestion = new question(); bool iAddQuestion = true; // Do some error checking // nested ifs :( if (txtQuestion.Text.Length > 44) if (MessageBox.Show("The question title entered is longer than 44 chars, this may make the question hard to read in the question window.", "Warning: Long Question", MessageBoxButtons.OKCancel) == DialogResult.Cancel) { if (mModifying != false) { if (!mQuestionManager.IsQuestionInDictionary(txtQuestion.Text)) { iAddQuestion = false; } else { MessageBox.Show("The question supplied is already in use, please provide a different one", "Question in use"); } } } // If no problems have been found, add the question if (iAddQuestion == true) { iNewQuestion.Question = txtQuestion.Text; switch (cbQuestionTypes.SelectedIndex) { case 0: // Multi-choice iNewQuestion.QuestionType = "MC"; iNewQuestion.PossibleAnswers = new string[4]; iNewQuestion.PossibleAnswers[0] = txtField1.Text; iNewQuestion.PossibleAnswers[1] = txtField2.Text; iNewQuestion.PossibleAnswers[2] = txtField3.Text; iNewQuestion.PossibleAnswers[3] = txtField4.Text; iNewQuestion.Answer = txtAnswer.Text; break; case 1: // Short Answer iNewQuestion.QuestionType = "SA"; iNewQuestion.PossibleAnswers = new string[1]; iNewQuestion.PossibleAnswers[0] = "NA"; // Not applicable for this question break; case 2: // True/False iNewQuestion.QuestionType = "TF"; iNewQuestion.Answer = txtTFAnswer.Text; iNewQuestion.PossibleAnswers = new string[2]; iNewQuestion.PossibleAnswers[0] = "True"; iNewQuestion.PossibleAnswers[1] = "False"; break; case 3: // Matching iNewQuestion.QuestionType = "MA"; iNewQuestion.PossibleAnswers = new string[1]; iNewQuestion.PossibleAnswers[0] = "NA"; break; } // Add the question to the queue to be sent mQuestionManager.AddQuestionToQueue(iNewQuestion); mQuestionManager.NewQuestionDataAvailable = true; Close(); } }
// Add a question to the queue public void AddQuestionToQueue(question prQuestion) { mQuestionsToSend.Enqueue(prQuestion); }