//SAVE QUESTION private void btn_Save_Click(object sender, EventArgs e) { QuestionBL questionBl = new QuestionBL(); Question question = new Question(); Answer answer = new Answer(); if (txt_ContentQuestion.Text.Trim() == "" || txt_ContentAnswer.Text.Trim() == "") { if (txt_ContentQuestion.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 { //Update question question.NameQuestion = txt_ContentQuestion.Text.Trim(); question.IDQuestion = IDQuestion; questionBl.EditQuestionbyID(question); //Update answer answer.IDQuestion = IDQuestion; answer.ContentAnswer = txt_ContentAnswer.Text.Trim(); //answer.IsCorrect = true; answer.Check = 1; questionBl.EditAnswerbyID(answer); //Show notify //notifyIcon1.Icon = SystemIcons.Information; //notifyIcon1.BalloonTipText = "Chỉnh sửa câu hỏi thành công"; //notifyIcon1.ShowBalloonTip(2000); //Close form Form FindForm = this.FindForm(); FindForm.Close(); } }
//Save Question private void btn_Save_Click(object sender, EventArgs e) { int NumAnswer = flp_Answer.Controls.Count; if (txt_ContentQuestion.Text.Trim() == "" || NumAnswer < 2) { if (txt_ContentQuestion.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 { QuestionBL questionBl = new QuestionBL(); Question question = new Question(); Answer answer = new Answer(); //Update question question.NameQuestion = txt_ContentQuestion.Text.Trim(); question.IDQuestion = IDQuestion; questionBl.EditQuestionbyID(question); //DELETE ANSWER question.IDQuestion = IDQuestion; questionBl.DeleteAnswerByIDQuestion(question); foreach (Answer_MultiSelect item in flp_Answer.Controls) { if (item.txt_AnswerContent.Text.Trim() != "") { answer.ContentAnswer = item.txt_AnswerContent.Text.Trim(); //answer.IsCorrect = item.chk_Check.Checked; if (item.chk_Check.Checked == true ) { answer.Check = 1; } else { answer.Check = 0; } answer.IDQuestion = IDQuestion; answer.IDCatalogue = IDCatalogue; questionBl.AddAnswer(answer); } } //Show notify //notifyIcon1.Icon = SystemIcons.Information; //notifyIcon1.BalloonTipText = " Chỉnh sửa câu hỏi thành công"; //notifyIcon1.ShowBalloonTip(2000); //Close form this.Close(); } } } }