private void bwRemoveCategory_DoWork(object sender, DoWorkEventArgs e) { if (DB_Delete.DeleteCategory(game.Categories[game.NumCategories].Id) > 0) { game.Categories.RemoveAt(game.NumCategories); } }
private void bwDeleteChoices_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i < currentQuestion.Choices.Count; i++) { DB_Delete.DeleteChoice(currentQuestion.Choices[i].Id); } }
private void bwRemoveChoices_DoWork(object sender, DoWorkEventArgs e) //now only runs on form close { if (!bwCreateChoices.IsBusy && question.Choices != null && question.Choices.Count > 0) { foreach (Choice c in question.Choices) { DB_Delete.DeleteChoice(c.Id); } } }
private void bwRemoveQuestions_DoWork(object sender, DoWorkEventArgs e) { for (int i = 0; i < game.NumCategories; i++) { if (DB_Delete.DeleteQuestion(game.Categories[i].Questions[game.NumQuestionsPerCategory].Id) > 0) //deleting question happens here { game.Categories[i].Questions.RemoveAt(game.NumQuestionsPerCategory); //if deleting from db was successful, also remove from game object } else { MessageBox.Show("Failed to delete questions"); } } }
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 btnImport_Click(object sender, EventArgs e) { frmImportQuestion importQuestionForm = new frmImportQuestion(); DialogResult dialogResult = importQuestionForm.ShowDialog(); if (dialogResult == DialogResult.OK) { //if going from multiple choice to another type, delete the choices if (question.Type == "mc" && importQuestionForm.selectedQuestion.Type != "mc") { for (int j = 0; j < 4 && j < question.Choices.Count; j++) { DB_Delete.DeleteChoice(question.Choices[j].Id); } } // going from other type of question to multiple choice, make the choices else if (question.Type != "mc" && importQuestionForm.selectedQuestion.Type == "mc") { question.Choices = new List <Choice>(new Choice[4]); for (int j = 0; j < 4 && j < question.Choices.Count; j++) { question.Choices[j] = new Choice(); question.Choices[j].QuestionId = (int)question.Id; question.Choices[j].Index = j; question.Choices[j].Text = importQuestionForm.selectedQuestion.Choices[j].Text; question.Choices[j].Id = DB_Insert.InsertChoice(question.Choices[j]); } } //if both are multiple choice, just do a simple update else if (question.Type == "mc" && importQuestionForm.selectedQuestion.Type == "mc") { for (int j = 0; j < 4; j++) { question.Choices[j].Text = importQuestionForm.selectedQuestion.Choices[j].Text; DB_Update.UpdateChoice(question.Choices[j]); } } //get info from the selected question (not a complete clone because the IDs have to be different) question.Type = importQuestionForm.selectedQuestion.Type; question.QuestionText = importQuestionForm.selectedQuestion.QuestionText; question.Answer = importQuestionForm.selectedQuestion.Answer; frmEditQuestion_Load(sender, e); //reload this form with the info } }
private void bwDeleteGame_DoWork(object sender, DoWorkEventArgs e) { int numRows = DB_Delete.DeleteGame(selectedGame.Id); }