private void btn_addNew_Click(object sender, EventArgs e) { try { int questionId = 0; NewQuestionForm questionForm = new NewQuestionForm(testID, questionId); questionForm.ShowDialog(); DisplayQuestions(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }
private void btn_editQuestion_Click(object sender, EventArgs e) { try { if (lv_questionList.SelectedItems.Count > 0) { var question = (QuestionModel)lv_questionList.SelectedItems[0].Tag; NewQuestionForm newQuestionForm = new NewQuestionForm(testID, question.QuestionID); newQuestionForm.rbtn_yes.Checked = question.isOpen == true ? true : false; newQuestionForm.rbtn_yes.Visible = false; newQuestionForm.rbtn_no.Visible = false; newQuestionForm.lbl_isOpen.Visible = false; newQuestionForm.btn_save.Text = "Update"; var allAnswer = answerService.GetAll(); newQuestionForm.txt_correctAnswer.Text = allAnswer.Where(x => x.QuestionID == question.QuestionID && x.isCorrect == true).Single().AnswerText; newQuestionForm.txt_question.Text = question.QuestionName; if (question.isOpen) { newQuestionForm.txt_secondAnswer.Visible = false; newQuestionForm.txt_thirdAnswer.Visible = false; newQuestionForm.txt_fourthAnswer.Visible = false; } else { var wrongAnswers = allAnswer.Where(x => x.QuestionID == question.QuestionID && x.isCorrect == false).ToList(); newQuestionForm.txt_secondAnswer.Text = wrongAnswers[0].AnswerText; newQuestionForm.txt_thirdAnswer.Text = wrongAnswers[1].AnswerText; newQuestionForm.txt_fourthAnswer.Text = wrongAnswers[2].AnswerText; } newQuestionForm.ShowDialog(); DisplayQuestions(); } else { MessageBox.Show("Please select a question", "Error"); } } catch (Exception ex) { MessageBox.Show(ex.Message, ex.GetType().ToString()); } }