private void btn_SaveQuestion_Click(object sender, EventArgs e)
{
QuestionBL questionBl = new QuestionBL();
Question question = new Question();
Answer answer = new Answer();
int NumAnswer = flp_addAnswer.Controls.Count;
if (txt_ContentQuestion.Text.Trim() == "" ||txt_NameQuestion.Text.Trim()=="" || NumAnswer < 2)
{
if (txt_ContentQuestion.Text.Trim() == "" || txt_NameQuestion.Text.Trim() == "")
{
MessageBox.Show("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("Vui lòng nhập hơn một đáp án!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
else
{
if (checkAnswerEmpty() == true)
{
MessageBox.Show("Không lưu câu hỏi vì tồn tại đáp án rỗng!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
if (checkBlankCorrectAnswer()==true)
{
MessageBox.Show("Vui lòng chọn đáp án cho câu hỏi!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
question.QuestionTitle = txt_NameQuestion.Text.Trim();
question.NameQuestion = txt_ContentQuestion.Text.Trim();
question.TypeQuestion = "onechoice";
question.IDCatalogue = IDCat;
question.Date = DateTime.Now;
if (questionBl.AddQuestion(question))
{
foreach (Answer_OnlyOneSelect item in flp_addAnswer.Controls)
{
if (item.txt_Answercontent.Text.Trim() != "")
{
answer.ContentAnswer = item.txt_Answercontent.Text.Trim();
//answer.IsCorrect = item.rad_check.Checked;
if (item.rad_check.Checked == true)
{
answer.Check = 1;
}
else
{
answer.Check = 0;
}
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(1000);
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();
}
}
}
}
}