CapDemo.GUI.CopyQuestion.btn_SaveCopy_Click C# (CSharp) Method

btn_SaveCopy_Click() private method

private btn_SaveCopy_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void btn_SaveCopy_Click(object sender, EventArgs e)
        {
            if (cmb_Catalogue.SelectedItem != null)
            {
                //GET ID CATALOGUE AFTER SELECT COMMOBOX
                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())
                        {
                            IDCatSelected = Convert.ToInt32(CatList.ElementAt(i).IDCatalogue);
                        }
                    }
                //ADD QUESTION
                QuestionBL QuestionBL = new QuestionBL();
                List<DO.Question> QuestionList;
                QuestionList = QuestionBL.GetQuestion();
                if (QuestionList != null)
                {
                    for (int i = 0; i < QuestionList.Count; i++)
                    {
                        int count = 0;
                        for (int j = 0; j < IdQ.Length; j++)
                        {
                            if (QuestionList.ElementAt(i).IDQuestion == Convert.ToInt32(IdQ[j]))
                            {
                                count++;
                            }
                        }
                        if (count > 0)
                        {
                            Question question = new Question();
                            question.QuestionTitle = QuestionList.ElementAt(i).QuestionTitle;
                            question.NameQuestion = QuestionList.ElementAt(i).NameQuestion;
                            question.TypeQuestion = QuestionList.ElementAt(i).TypeQuestion;
                            question.IDCatalogue = IDCatSelected;
                            IDQuestion = QuestionList.ElementAt(i).IDQuestion;
                            question.Date = DateTime.Now;

                            if (QuestionBL.AddQuestion(question)==true)
                            {
                                //ADD ANSWER
                                Question Question = new Question();
                                Question.IDQuestion = IDQuestion;
                                List<DO.Answer> AnswerList;
                                AnswerList = QuestionBL.GetAnswerByQuestionID(Question);
                                if (AnswerList != null)
                                    for (int ii = 0; ii < AnswerList.Count; ii++)
                                    {
                                        if (AnswerList.ElementAt(ii).IDQuestion == IDQuestion)
                                        {
                                            Answer answer = new Answer();
                                            answer.ContentAnswer = AnswerList.ElementAt(ii).ContentAnswer;
                                            if (AnswerList.ElementAt(ii).IsCorrect == true)
                                            {
                                                answer.Check = 1;
                                            }
                                            else
                                            {
                                                answer.Check = 0;
                                            }
                                            answer.IDQuestion = QuestionBL.MaxIDQuestion();
                                            answer.IDCatalogue = IDCatSelected;
                                            QuestionBL.AddAnswer(answer);
                                        }
                                    }
                            }
                        }
                    }
                    //Notify
                    //notifyIcon1.Icon = SystemIcons.Information;
                    //notifyIcon1.BalloonTipText = "Sao Chép câu hỏi sang chủ đề \"" + cmb_Catalogue.SelectedItem.ToString() + "\" thành công.";
                    //notifyIcon1.ShowBalloonTip(2000);
                    MessageBox.Show("Sao Chép câu hỏi sang chủ đề \"" + cmb_Catalogue.SelectedItem.ToString() + "\" thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Vui lòng chọn chủ đề!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }