CapDemo.GUI.User_Controls.Question_MultiSelect.btn_SaveAndCreateNewQuestion_Click C# (CSharp) 메소드

btn_SaveAndCreateNewQuestion_Click() 개인적인 메소드

private btn_SaveAndCreateNewQuestion_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
리턴 void
        private void btn_SaveAndCreateNewQuestion_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 = "multichoice";
                        question.IDCatalogue = IDCat;
                        question.Date = DateTime.Now;
                        if (questionBl.AddQuestion(question))
                        {
                            foreach (Answer_MultiSelect item in flp_addAnswer.Controls)
                            {
                                if (item.txt_AnswerContent.Text.Trim() != "")
                                {
                                    answer.ContentAnswer = item.txt_AnswerContent.Text.Trim();
                                    if (item.chk_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);
                            //Refesh form
                            this.txt_ContentQuestion.Text = "";
                            flp_addAnswer.Controls.Clear();
                            //AUTO ADD 4 ANSWER
                            for (int j = 0; j < 4; j++)
                            {
                                Answer_MultiSelect MultiSelectAnswer = new Answer_MultiSelect();
                                i++;
                                MultiSelectAnswer.Tag = i;
                                MultiSelectAnswer.ID_Answer = i;
                                MultiSelectAnswer.onDelete += MultiSelectAnswer_onDelete;
                                MultiSelectAnswer.chk_Check.Text = Convert.ToChar(a + j).ToString();
                                flp_addAnswer.Controls.Add(MultiSelectAnswer);
                            }
                        }
                    }
                }
            }
        }