/** * Method to delete answer in tab Answer when the button "Delete" is clicked */ private void DeleteAnswer_Click(object sender, EventArgs e) { if (MessageBox.Show("You will delete an answer. Are you sure you want to continue ?", "DELETE A ANSWER", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { try { DAOAnswer.DeleteAnswer(textBoxAnswerDelete.Text); DisplayAllAnswers(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
/** * Method to display all answers present in database * Used in tab Answers */ public void DisplayAllAnswers() { List <Answer> answers = new List <Answer>(); listViewAnswers.Items.Clear(); answers = DAOAnswer.SelectAllAnswers(); foreach (Answer a in answers) { ListViewItem item = new ListViewItem(a.Member.Username); item.SubItems.Add(a.AnswerText); item.SubItems.Add(a.Question.QuestionText); item.SubItems.Add(a.AnswerDate.ToString()); listViewAnswers.Items.Add(item); } }
/** * Method to post a answer in tab Post a Answer when the button "Post a answer" is clicked */ private void buttonPostAnswer_Click(object sender, EventArgs e) { if (comboBoxQuestions.Equals("") || textBoxAnswer.Text != null) { try { //Call method to create a answer with pass in arguments the id of question selected in combobox and the the content of answer written DAOAnswer.CreateAnswer(comboBoxQuestions.SelectedIndex, textBoxAnswer.Text); MessageBox.Show("Answer posted"); comboBoxQuestions.Text = ""; textBoxAnswer.Text = ""; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Your can't post empty Answer"); } }