private void btn_SaveQuestion_Click(object sender, EventArgs e)
{
if (cmb_Catalogue.SelectedItem != null)
{
//GET CATALOGUE ID
CatalogueBL CatBL = new CatalogueBL();
List<DO.Catalogue> CatList;
CatList = CatBL.GetCatalogue();
if (CatList != null)
for (int i = 0; i < CatList.Count; i++)
{
if (CatList.ElementAt(i).NameCatalogue == cmb_Catalogue.SelectedItem.ToString())
{
IDCat = Convert.ToInt32(CatList.ElementAt(i).IDCatalogue);
}
}
//SAVE QUESTION
QuestionBL questionBl = new QuestionBL();
Question question = new Question();
Answer answer = new Answer();
if (txt_ContentQuestion.Text.Trim() == "" || txt_NameQuestion.Text.Trim() == "" || txt_AnswerContent.Text.Trim() == "")
{
if (txt_ContentQuestion.Text.Trim() == "" || txt_NameQuestion.Text.Trim() == "")
{
MessageBox.Show("Câu hỏi không được rỗng. Vui lòng nhập thông tin câu hỏi trước khi lưu.", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
MessageBox.Show("Đáp án không được rỗng. Vui lòng nhập thông tin đáp án trước khi lưu.", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
question.QuestionTitle = txt_NameQuestion.Text.Trim();
question.NameQuestion = txt_ContentQuestion.Text.Trim();
question.TypeQuestion = "shortanswer";
question.IDCatalogue = IDCat;
question.Date = DateTime.Now;
if (questionBl.AddQuestion(question))
{
answer.ContentAnswer = txt_AnswerContent.Text.Trim();
answer.Check =1;
answer.IDQuestion = questionBl.MaxIDQuestion();
answer.IDCatalogue = IDCat;
questionBl.AddAnswer(answer);
//Show notify
//notifyIcon1.Icon = SystemIcons.Information;
//notifyIcon1.BalloonTipText = "Thêm câu hỏi thành công";
//notifyIcon1.ShowBalloonTip(2000);
MessageBox.Show("Thêm câu hỏi thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
//Close form
Form FindForm = this.FindForm();
FindForm.Close();
}
}
}
else
{
MessageBox.Show("Vui lòng chọn chủ đề cho câu hỏi!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}