CapDemo.GUI.User_Controls.Question_MultiSelect_1.btn_SaveQuestion_Click C# (CSharp) Метод

btn_SaveQuestion_Click() приватный Метод

private btn_SaveQuestion_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
Результат void
        private void btn_SaveQuestion_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
                           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);
                               //Close Form
                               Form FindForm = this.FindForm();
                               FindForm.Close();
                           }
                       }
                   }
               }
            }
            else
            {
                MessageBox.Show("Vui lòng chọn chủ đề cho câu hỏi!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }