/** * Method to inialize all questions in combobox in tab Post a Answer when the main form is loaded */ public void InitializeQuestions() { List <Question> questions = new List <Question>(); questions = DAOQuestion.SelectAllQuestions(); comboBoxQuestions.Items.Clear(); comboBoxQuestions.Items.Insert(0, ""); foreach (Question q in questions) { comboBoxQuestions.Items.Insert(q.QuestionID, q.QuestionText); } }
/** * Method to delete a question in listview in tab Questions when the button "delete" is clicked */ private void buttonDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("You will delete a question. Are you sure you want to continue ?", "DELETE A QUESTION", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { try { //Call method in DAO Question to delete question with pass in argument the content of question //the content of question is selected in listViewQuestion_MouseClick DAOQuestion.DeleteQuestion(textBoxUsername.Text); DisplayAllQuestions(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
/** * Method to display all questions present in database * Used in tab Questions */ private void DisplayAllQuestions() { List <Question> list = new List <Question>(); listViewQuestion.Items.Clear(); list = DAOQuestion.SelectAllQuestions(); foreach (Question q in list) { ListViewItem item = new ListViewItem(q.Member.Username); item.SubItems.Add(q.QuestionText); item.SubItems.Add(q.Category.CategoryName); item.SubItems.Add(q.QuestionDate.ToString()); listViewQuestion.Items.Add(item); } }
/** * Method to post a question when the button "Post Question" is clicked in tab post a question */ private void PostQuestion_Click_1(object sender, EventArgs e) { if (comboBoxCategory.Equals("") || textBoxQuestion.Text != null) { try { //Call method to create question with pass in arguments the id of category selected and the content of question written DAOQuestion.CreateQuestion(comboBoxCategory.SelectedIndex, textBoxQuestion.Text); MessageBox.Show("Question posted"); comboBoxCategory.Text = ""; textBoxQuestion.Text = ""; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Your can't post empty question"); } }