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

AddQuestion() public méthode

public AddQuestion ( Question Question ) : bool
Question CapDemo.DO.Question
Résultat bool
        public bool AddQuestion(Question Question)
        {
            string query = "INSERT INTO Question (Question_Title,Question_Name, Question_Type, Catalogue_ID, Date_Create)"
                        + " VALUES ('" + Question.QuestionTitle.Replace("'", "''") + "','" + Question.NameQuestion.Replace("'", "''") + "','" + Question.TypeQuestion + "','" + Question.IDCatalogue + "','" + Question.Date.ToString("yyyy-MM-dd hh:mm:ss") + "')";

            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::AddQuestion