//MARK: Button Event Handlers private void btnOK_Click(object sender, EventArgs e) { DialogResult dialogResult = DialogResult.OK; //error / warning checking if (txtQuestionText.Text.Length > 1 && txtAnswer.Text.Trim() == "") { dialogResult = MessageBox.Show("You have not given this question an answer yet.\n\nThis question will appear Red until you give it an answer.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (rdoMultipleChoice.Checked && (txtChoiceA.Text.Trim() == "" || txtChoiceB.Text.Trim() == "" || txtChoiceC.Text.Trim() == "" || txtChoiceD.Text.Trim() == "")) { dialogResult = MessageBox.Show("You have not given this multiple choice question all 4 Choices yet.\n\nThis question will appear Orange until you give it 4 choices.", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } if (dialogResult == DialogResult.OK) { if (rdoFillInTheBlank.Checked) { question.Type = "fb"; } else if (rdoMultipleChoice.Checked) { question.Type = "mc"; question.Choices[0].Text = txtChoiceA.Text; question.Choices[1].Text = txtChoiceB.Text; question.Choices[2].Text = txtChoiceC.Text; question.Choices[3].Text = txtChoiceD.Text; for (int i = 0; i < 4; i++) { DB_Update.UpdateChoiceText(question.Choices[i].Text, question.Choices[i].Id); } } else if (rdoTrueFalse.Checked) { question.Type = "tf"; } question.QuestionText = txtQuestionText.Text; question.Answer = txtAnswer.Text; if (!DB_Update.UpdateQuestion(question)) { MessageBox.Show("Updating Question failed"); } else { DialogResult = DialogResult.OK; Close(); } } }
private void bwUpdateCategory_DoWork(object sender, DoWorkEventArgs e) //also updates questions { int i = (int)e.Argument; // i is category index DB_Update.UpdateCategory(currentCategory); for (int j = 0; j < game.NumQuestionsPerCategory; j++) // j is question index { game.Categories[i].Questions[j].ResetQuestionToDefaults(); DB_Update.UpdateQuestion(game.Categories[i].Questions[j]); } }
private void bwImportCategory_DoWork(object sender, DoWorkEventArgs e) { if (importCategoryForm.SelectedCategory.Questions.Count > 0) //only import questions if there are any { //only imports questions to the max size of the grid and the max size of the other game grid for (int i = 0; i < category.Questions.Count && i < importCategoryForm.SelectedCategory.Questions.Count; i++) { //if going from multiple choice to another type, delete the choices if (category.Questions[i].Type == "mc" && importCategoryForm.SelectedCategory.Questions[i].Type != "mc") { for (int j = 0; j < 4 && j < category.Questions[i].Choices.Count; j++) { DB_Delete.DeleteChoice(category.Questions[i].Choices[j].Id); } } // going from other type of question to multiple choice, make the choices else if (category.Questions[i].Type != "mc" && importCategoryForm.SelectedCategory.Questions[i].Type == "mc") { category.Questions[i].Choices = new List <Choice>(new Choice[4]); for (int j = 0; j < 4 && j < category.Questions[i].Choices.Count; j++) { category.Questions[i].Choices[j] = new Choice(); category.Questions[i].Choices[j].QuestionId = (int)category.Questions[i].Id; category.Questions[i].Choices[j].Index = j; category.Questions[i].Choices[j].Text = importCategoryForm.SelectedCategory.Questions[i].Choices[j].Text; category.Questions[i].Choices[j].Id = DB_Insert.InsertChoice(category.Questions[i].Choices[j]); } } //if both are multiple choice, just do a simple update else if (category.Questions[i].Type == "mc" && importCategoryForm.SelectedCategory.Questions[i].Type == "mc") { for (int j = 0; j < 4; j++) { category.Questions[i].Choices[j].Text = importCategoryForm.SelectedCategory.Questions[i].Choices[j].Text; DB_Update.UpdateChoice(category.Questions[i].Choices[j]); } } //set the other new properties of the importing questions. This needs to go after the previous code category.Questions[i].Type = importCategoryForm.SelectedCategory.Questions[i].Type; category.Questions[i].QuestionText = importCategoryForm.SelectedCategory.Questions[i].QuestionText; category.Questions[i].Answer = importCategoryForm.SelectedCategory.Questions[i].Answer; //update the question (import the question) DB_Update.UpdateQuestion(category.Questions[i]); } } }
private void bwUpdateQuestion_DoWork(object sender, DoWorkEventArgs e) { DB_Update.UpdateQuestion(currentQuestion); }