CapDemo.GUI.User_Controls.Question_MultiSelect_1.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)
        {
            if (cmb_Catalogue.SelectedItem != null)
            {
                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
                        {
                            //GET CATALOGUE ID
                            this.Dock = DockStyle.Fill;
                            CatalogueBL CatBL = new CatalogueBL();
                            List<DO.Catalogue> CatList;
                            CatList = CatBL.GetCatalogue();
                            if (CatList != null)
                                for (int i = 0; i < CatList.Count; i++)
                                {
                                    if (CatList.ElementAt(i).NameCatalogue == cmb_Catalogue.SelectedItem.ToString())
                                    {
                                        IDCat = Convert.ToInt32(CatList.ElementAt(i).IDCatalogue);
                                    }
                                }
                            //SAVE QUESTION
                            QuestionBL questionBl = new QuestionBL();
                            Question question = new Question();
                            Answer answer = new Answer();

                            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(2000);
                                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);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Vui lòng chọn chủ đề cho câu hỏi!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }