CapDemo.BL.QuestionBL.EditAnswerbyID C# (CSharp) Méthode

EditAnswerbyID() public méthode

public EditAnswerbyID ( Answer Answer ) : bool
Answer CapDemo.DO.Answer
Résultat bool
        public bool EditAnswerbyID(Answer Answer)
        {
            string query = "UPDATE Answer"
                         + " SET Answer_Name ='" + Answer.ContentAnswer.Replace("'", "''") + "', Correct_Answer='" + Answer.Check + "'"
                         + " WHERE Question_ID = '" + Answer.IDQuestion + "'";
            return DA.UpdateDatabase(query);
        }

Usage Example

        //Save Question
        private void btn_SaveEditQuestion_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();
            }
        }