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

AddAnswer() public méthode

public AddAnswer ( Answer Answer ) : bool
Answer CapDemo.DO.Answer
Résultat bool
        public bool AddAnswer( Answer Answer)
        {
            string query= " INSERT INTO Answer (Answer_Name, Correct_Answer, Question_ID, Catalogue_ID)"
                        + " VALUES ('" + Answer.ContentAnswer.Replace("'", "''") + "'," + Answer.Check + ",'" + Answer.IDQuestion + "','" + Answer.IDCatalogue + "')";
            return DA.InsertDatabase(query);
        }

Usage Example

        //SAVE AND CONTINUE TO ADD QUESTION
        private void btn_SaveAndCreateNewQuestion_Click(object sender, EventArgs e)
        {
            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);
                    //Refesh form
                    txt_ContentQuestion.Text = "";
                    txt_AnswerContent.Text = "";
                }

            }
        }
All Usage Examples Of CapDemo.BL.QuestionBL::AddAnswer