Пример #1
0
 //EDIT ANSWER
 public bool EditAnswerbyID(Answer Answer)
 {
     string query = "UPDATE Answer"
                  + " SET Answer_Name ='" + Answer.ContentAnswer.Replace("'", "''") + "', Correct_Answer='" + Answer.Check + "'"
                  + " WHERE Question_ID = '" + Answer.IDQuestion + "'";
     return DA.UpdateDatabase(query);
 }
        //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 = "";
                }

            }
        }
        //Copy Question
        public void CopyQuestion()
        {
            Question question = new Question();
            Answer answer = new Answer();
            QuestionBL questionBL = new QuestionBL();
            foreach (DataGridViewRow row in dgv_Question.Rows)
            {
                if (row.Cells["Check"].Value != null && (bool)row.Cells["Check"].Value == true)
                {
                    question.QuestionTitle = row.Cells["QuestionTitle"].Value.ToString();
                    question.NameQuestion = row.Cells["QuestionName"].Value.ToString();
                    question.TypeQuestion = row.Cells["QuestionType"].Value.ToString();
                    question.IDCatalogue = IDCat;
                    question.Date = DateTime.Now;

                    if (questionBL.AddQuestion(question))
                    {
                        question.IDQuestion = Convert.ToInt32(row.Cells["IDQuestion"].Value);
                        List<DO.Answer> AnswerList;
                        AnswerList = questionBL.GetAnswerByQuestionID(question);
                        if (AnswerList != null)
                        {
                            for (int i = 0; i < AnswerList.Count; i++)
                            {
                                answer.ContentAnswer = AnswerList.ElementAt(i).ContentAnswer;
                                if (AnswerList.ElementAt(i).IsCorrect == true)
                                {
                                    answer.Check = 1;
                                }
                                else
                                {
                                    answer.Check = 0;
                                }
                                answer.IDQuestion = questionBL.MaxIDQuestion();
                                answer.IDCatalogue = IDCat;
                                questionBL.AddAnswer(answer);
                            }
                        }
                    }

                }
            }
        }
        //SAVE QUESTION
        private void btn_Save_Click(object sender, EventArgs e)
        {
            QuestionBL questionBl = new QuestionBL();
            Question question = new Question();
            Answer answer = new Answer();
            if (txt_ContentQuestion.Text.Trim() == "" || txt_ContentAnswer.Text.Trim() == "")
            {
                if (txt_ContentQuestion.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
            {
                //Update question
                question.NameQuestion = txt_ContentQuestion.Text.Trim();
                question.IDQuestion = IDQuestion;
                questionBl.EditQuestionbyID(question);
                //Update  answer
                answer.IDQuestion = IDQuestion;
                answer.ContentAnswer = txt_ContentAnswer.Text.Trim();
                //answer.IsCorrect = true;
                answer.Check = 1;
                questionBl.EditAnswerbyID(answer);

                //Show notify
                //notifyIcon1.Icon = SystemIcons.Information;
                //notifyIcon1.BalloonTipText = "Chỉnh sửa câu hỏi thành công";
                //notifyIcon1.ShowBalloonTip(2000);
                //Close form
                Form FindForm = this.FindForm();
                FindForm.Close();
            }
        }
        //Load Form
        private void ViewQuestionShortAnswer_Load(object sender, EventArgs e)
        {
            //GET QUESTION BY ID Question
            QuestionBL QuestionBL = new QuestionBL();
            List<DO.Question> QuestionList;
            Question question = new Question();
            QuestionList = QuestionBL.GetQuestion();
            if (QuestionList != null)
            {
                for (int i = 0; i < QuestionList.Count; i++)
                {
                    if (QuestionList.ElementAt(i).IDQuestion == IDQuestion)
                    {
                        txt_Catalogue.Text = QuestionList.ElementAt(i).NameCatalogue;
                        txt_ContentQuestion.Text = QuestionList.ElementAt(i).NameQuestion;
                        txt_QuestionType.Text = QuestionList.ElementAt(i).TypeQuestion;
                        txt_Date.Text = QuestionList.ElementAt(i).Date.ToString("d");
                    }

                }
                //GET ANSWER BY ID QUESTION
                List<DO.Answer> AnswerList;
                Answer answer = new Answer();
                question.IDQuestion = IDQuestion;
                AnswerList = QuestionBL.GetAnswerByQuestionID(question);
                if (AnswerList != null)
                {
                    for (int j = 0; j < AnswerList.Count; j++)
                    {
                        txt_ContentAnswer.Text = AnswerList.ElementAt(j).ContentAnswer;
                    }
                }
            }
        }
        //SAVE QUESTION AND ANSWER. CONTINUE INPUT
        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 = "onechoice";
                        question.IDCatalogue = IDCat;
                        question.Date = DateTime.Now;

                        if (questionBl.AddQuestion(question))
                        {
                            foreach (Answer_OnlyOneSelect item in flp_addAnswer.Controls)
                            {
                                answer.ContentAnswer = item.txt_Answercontent.Text.Trim();
                                if (item.rad_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_OnlyOneSelect OneChoiceAnswer = new Answer_OnlyOneSelect();
                                i++;
                                OneChoiceAnswer.Tag = i;
                                OneChoiceAnswer.ID_Answer = i;
                                OneChoiceAnswer.onDelete += OneChoiceAnswer_onDelete;
                                OneChoiceAnswer.onCheck += OneChoiceAnswer_onCheck;
                                OneChoiceAnswer.rad_check.Text = Convert.ToChar(a + j).ToString();
                                flp_addAnswer.Controls.Add(OneChoiceAnswer);
                            }
                        }
                    }
                }
            }
        }
 public void MoveQuestion()
 {
     Question question = new Question();
     Answer answer = new Answer();
     QuestionBL questionBL = new QuestionBL();
     foreach (DataGridViewRow row in dgv_Question.Rows)
     {
         if (row.Cells["Check"].Value != null && (bool)row.Cells["Check"].Value == true)
         {
             question.IDCatalogue = IDCat;
             question.IDQuestion = Convert.ToInt32(row.Cells["IDQuestion"].Value);
             questionBL.EditIDCatalogueAnswerByIDQuestion(question);
             questionBL.EditIDCatalogueQuestionByIDQuestion(question);
             ////add question
             //question.QuestionTitle = row.Cells["QuestionTitle"].Value.ToString();
             //question.NameQuestion = row.Cells["QuestionName"].Value.ToString();
             //question.TypeQuestion = row.Cells["QuestionType"].Value.ToString();
             //question.IDCatalogue = IDCat;
             //question.Date = DateTime.Now;
             //if (questionBL.AddQuestion(question))
             //{
             //    //add answer
             //    question.IDQuestion = Convert.ToInt32(row.Cells["IDQuestion"].Value);
             //    List<DO.Answer> AnswerList;
             //    AnswerList = questionBL.GetAnswerByQuestionID(question);
             //    if (AnswerList != null)
             //    {
             //        for (int i = 0; i < AnswerList.Count; i++)
             //        {
             //            answer.ContentAnswer = AnswerList.ElementAt(i).ContentAnswer;
             //            if (AnswerList.ElementAt(i).IsCorrect == true)
             //            {
             //                answer.Check = 1;
             //            }
             //            else
             //            {
             //                answer.Check = 0;
             //            }
             //            answer.IDQuestion = questionBL.MaxIDQuestion();
             //            answer.IDCatalogue = IDCat;
             //            questionBL.AddAnswer(answer);
             //        }
             //    }
             //    //Delete answer and question
             //    questionBL.DeleteAnswerByIDQuestion(question);
             //    questionBL.DeleteQuestionByID(question);
             //}
         }
     }
 }
Пример #8
0
        //EDIT QUESTION
        private void btn_EditQuestion_Click(object sender, EventArgs e)
        {
            btn_EditQuestion.Visible = false;
            btn_Save.Visible = true;
            btn_addAnswer.Visible = true;
            flp_Answer.Controls.Clear();
            txt_ContentQuestion.ReadOnly = false;

            //GET QUESTION BY ID Question
            QuestionBL QuestionBL = new QuestionBL();
            List<DO.Question> QuestionList;
            Question question = new Question();
            QuestionList = QuestionBL.GetQuestion();
            if (QuestionList != null)
            {
                for (int i = 0; i < QuestionList.Count; i++)
                {
                    if (QuestionList.ElementAt(i).IDQuestion == IDQuestion)
                    {
                        txt_Catalogue.Text = QuestionList.ElementAt(i).NameCatalogue;
                        txt_ContentQuestion.Text = QuestionList.ElementAt(i).NameQuestion;
                        txt_QuestionType.Text = QuestionList.ElementAt(i).TypeQuestion;
                        txt_Date.Text = QuestionList.ElementAt(i).Date.ToString("d");
                    }
                }
                //GET ANSWER BY ID QUESTION
                List<DO.Answer> AnswerList;
                Answer answer = new Answer();
                question.IDQuestion = IDQuestion;
                AnswerList = QuestionBL.GetAnswerByQuestionID(question);
                if (AnswerList != null)
                {
                    for (int j = 0; j < AnswerList.Count; j++)
                    {
                        Answer_OnlyOneSelect OneChoiceAnswer = new Answer_OnlyOneSelect();
                        i++;
                        OneChoiceAnswer.Tag = i;
                        OneChoiceAnswer.ID_Answer = i;
                        OneChoiceAnswer.onDelete += OneChoiceAnswer_onDelete;
                        OneChoiceAnswer.onCheck += OneChoiceAnswer_onCheck;
                        OneChoiceAnswer.rad_check.Text = Convert.ToChar(a+j).ToString();

                        OneChoiceAnswer.txt_Answercontent.Text = AnswerList.ElementAt(j).ContentAnswer;
                        OneChoiceAnswer.rad_check.Checked = AnswerList.ElementAt(j).IsCorrect;

                        flp_Answer.Controls.Add(OneChoiceAnswer);
                    }
                }
            }
        }
        //Save Question
        private void btn_Save_Click(object sender, EventArgs e)
        {
            int NumAnswer = flp_Answer.Controls.Count;
            if (txt_ContentQuestion.Text.Trim() == "" || NumAnswer < 2)
            {
                if (txt_ContentQuestion.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
                    {
                        QuestionBL questionBl = new QuestionBL();
                        Question question = new Question();
                        Answer answer = new Answer();
                        //Update question
                        question.NameQuestion = txt_ContentQuestion.Text.Trim();
                        question.IDQuestion = IDQuestion;
                        questionBl.EditQuestionbyID(question);

                        //DELETE ANSWER
                        question.IDQuestion = IDQuestion;
                        questionBl.DeleteAnswerByIDQuestion(question);

                        foreach (Answer_MultiSelect item in flp_Answer.Controls)
                        {
                            if (item.txt_AnswerContent.Text.Trim() != "")
                            {
                                answer.ContentAnswer = item.txt_AnswerContent.Text.Trim();
                                //answer.IsCorrect = item.chk_Check.Checked;
                                if (item.chk_Check.Checked == true )
                                {
                                    answer.Check = 1;
                                }
                                else
                                {
                                    answer.Check = 0;
                                }
                                answer.IDQuestion = IDQuestion;
                                answer.IDCatalogue = IDCatalogue;
                                questionBl.AddAnswer(answer);
                            }
                        }
                        //Show notify
                        //notifyIcon1.Icon = SystemIcons.Information;
                        //notifyIcon1.BalloonTipText = " Chỉnh sửa câu hỏi thành công";
                        //notifyIcon1.ShowBalloonTip(2000);
                        //Close form
                        this.Close();
                    }
                }
            }
        }
Пример #10
0
        //SAVE QUESTION
        private void btn_SaveImport_Click(object sender, EventArgs e)
        {
            try
            {
                if (txt_FilePath.Text == "")
                {
                    MessageBox.Show("Vui lòng chọn đường dẫn đến tập tin trước khi lưu!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    int count = 0;
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        if (row.Cells["Check"].Value != null && (bool)row.Cells["Check"].Value== true)
                        {
                            count++;
                        }
                    }
                    if (count>0)
                    {
                        int CheckQuestion = 0;
                        Question question = new Question();
                        Answer answer = new Answer();
                        QuestionBL questionBL = new QuestionBL();

                        foreach (DataGridViewRow row in dataGridView1.Rows)
                        {
                            if (row.Cells["Check"].Value != null && (bool)row.Cells["Check"].Value == true)
                            {
                                if (row.Cells["TypeQuestion"].Value.ToString().Trim() == "shortanswer")
                                {
                                    string[] AnswerContent = row.Cells["AnswerContent"].Value.ToString().Trim().Split(new string[] { "</answer>" }, StringSplitOptions.None);
                                    string[] AnswerItem = AnswerContent[0].Split(new string[] { "---" }, StringSplitOptions.None);

                                    //question.QuestionTitle =
                                    question.QuestionTitle = row.Cells["QuestionTitle"].Value.ToString().Trim();
                                    question.NameQuestion = row.Cells["NameQuestion"].Value.ToString().Trim();
                                    question.TypeQuestion = row.Cells["TypeQuestion"].Value.ToString().Trim();
                                    question.IDCatalogue = IDCat;
                                    question.Date = DateTime.Now;
                                    questionBL.AddQuestion(question);

                                    //answer.IsCorrect = true;
                                    answer.Check = 1;
                                    answer.ContentAnswer = AnswerItem[1].ToString().Trim();
                                    answer.IDQuestion = questionBL.MaxIDQuestion();
                                    answer.IDCatalogue = IDCat;
                                    questionBL.AddAnswer(answer);

                                    CheckQuestion++;

                                }
                                else
                                {
                                    string[] AnswerContent = row.Cells["AnswerContent"].Value.ToString().Trim().Split(new string[] { "</answer>" }, StringSplitOptions.None);
                                    //ADD QUESTION MULTIPLE CHOICE
                                    question.QuestionTitle = row.Cells["QuestionTitle"].Value.ToString().Trim();
                                    question.NameQuestion = row.Cells["NameQuestion"].Value.ToString().Trim();
                                    question.TypeQuestion = "";
                                    question.IDCatalogue = IDCat;
                                    question.Date = DateTime.Now;
                                    questionBL.AddQuestion(question);
                                    CheckQuestion++;

                                    int countMultipleChoice = 0;

                                    for (int i = 0; i < AnswerContent.Length - 1; i++)
                                    {
                                        string[] AnswerItem = AnswerContent[i].Split(new string[] { "---" }, StringSplitOptions.None);

                                        if (Convert.ToInt32(AnswerItem[0].ToString().Trim()) > 0)
                                        {
                                            //answer.IsCorrect = true;
                                            answer.Check = 1;
                                            answer.ContentAnswer = AnswerItem[1].ToString().Trim();
                                            answer.IDQuestion = questionBL.MaxIDQuestion();
                                            answer.IDCatalogue = IDCat;
                                            questionBL.AddAnswer(answer);
                                            countMultipleChoice++;
                                        }
                                        else
                                        {
                                            //answer.IsCorrect = false;
                                            answer.Check = 0;
                                            answer.ContentAnswer = AnswerItem[1].ToString().Trim();
                                            answer.IDQuestion = questionBL.MaxIDQuestion();
                                            answer.IDCatalogue = IDCat;
                                            questionBL.AddAnswer(answer);
                                        }//end if
                                    }//end for

                                    //UPDATE QUESTION TYPE
                                    if (countMultipleChoice == 1)
                                    {
                                        question.TypeQuestion = "onechoice";
                                        question.IDQuestion = questionBL.MaxIDQuestion();
                                        questionBL.EditQuestionTypebyID(question);
                                    }
                                    else
                                    {
                                        question.TypeQuestion = "multichoice";
                                        question.IDQuestion = questionBL.MaxIDQuestion();
                                        questionBL.EditQuestionTypebyID(question);
                                    }
                                }
                            }

                        }//end foreach

                        //CLOSE FORM
                        if (CheckQuestion > 0)
                        {

                            MessageBox.Show("Nhập " + CheckQuestion + " câu hỏi từ file thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            CheckQuestion = 0;
                            Form FindForm = this.FindForm();
                            FindForm.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Vui lòng chọn câu hỏi trước khi lưu!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
            }
            catch (Exception)
            {
                MessageBox.Show("Hệ thống lưu không thành công vì do định dạng file không đúng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #11
0
 //INSERT ANSWER
 public bool AddAnswer( Answer Answer)
 {
     string query= " INSERT INTO Answer (Answer_Name, Correct_Answer, Question_ID, Catalogue_ID)"
                 + " VALUES ('" + Answer.ContentAnswer.Replace("'", "''") + "'," + Answer.Check + ",'" + Answer.IDQuestion + "','" + Answer.IDCatalogue + "')";
     return DA.InsertDatabase(query);
 }
Пример #12
0
 //Select Answer by Question ID
 public List<Answer> GetAnswerByQuestionID(Question Question)
 {
     List<Answer> AnswerList = new List<Answer>();
     string query = "SELECT a.Answer_ID, a.Answer_Name, a.Question_ID, a.Correct_Answer"
                  + " FROM Answer a "
                  + " WHERE a.Question_ID='" + Question.IDQuestion + "'";
     //string query = "SELECT *"
     //            + " FROM Answer a "
     //            + " WHERE a.Question_ID='" + Question.IDQuestion + "'";
     DataTable dt = DA.SelectDatabase(query);
     if (dt != null)
     {
         foreach (DataRow item in dt.Rows)
         {
             Answer Answer = new Answer();
             Answer.IDAnswer = Convert.ToInt32(item["Answer_ID"]);
             Answer.ContentAnswer = item["Answer_Name"].ToString() ;
             Answer.IDQuestion = Convert.ToInt32(item["Question_ID"].ToString());
             Answer.IsCorrect = (bool)item["Correct_Answer"];
             AnswerList.Add(Answer);
         }
     }
     return AnswerList;
 }
        //SAVE QUESTION
        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);
            }
        }
        //SAVE QUESTION AND CONTINUE ADD QUESTION
        private void btn_SaveAndCreateNewQuestion_Click(object sender, EventArgs e)
        {
            if (cmb_Catalogue.SelectedItem != null)
            {
                //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();
                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 = "";
                    }

                }
            }
            else
            {
                MessageBox.Show("Vui lòng chọn chủ đề cho câu hỏi!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #15
0
        public void CheckQuestion()
        {
            WrongQuestion = 0;
            //int CheckQuestion = 0;
            Question question = new Question();
            Answer answer = new Answer();
            QuestionBL questionBL = new QuestionBL();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                    if ( row.Cells["QuestionTitle"].Value.ToString().Trim() != "" && row.Cells["NameQuestion"].Value.ToString().Trim() != "" && row.Cells["AnswerContent"].Value.ToString().Trim() != "" && row.Cells["TypeQuestion"].Value.ToString().Trim() != "")
                    {
                        if (row.Cells["TypeQuestion"].Value.ToString().Trim() == "shortanswer" || row.Cells["TypeQuestion"].Value.ToString().Trim() == "multichoice")
                        {
                            if (row.Cells["TypeQuestion"].Value.ToString().Trim() == "shortanswer")
                            {
                                string[] AnswerContent = row.Cells["AnswerContent"].Value.ToString().Trim().Split(new string[] { "</answer>" }, StringSplitOptions.None);
                                int NumAnswer = AnswerContent.Length - 1;
                                if (NumAnswer == 1)
                                {
                                    string[] AnswerItem = AnswerContent[0].Split(new string[] { "---" }, StringSplitOptions.None);

                                    if (AnswerItem[1].ToString().Trim() != "" && AnswerItem[1].ToString().Trim().Contains("</span>")==false && AnswerItem[0].ToString().Trim() != "")
                                    {
                                        int PointAnswer;
                                        bool isNum = int.TryParse(AnswerItem[0].ToString().Trim(), out PointAnswer);
                                        if (isNum = true && Convert.ToInt32(AnswerItem[0].ToString().Trim()) > 0)
                                        {
                                            row.DefaultCellStyle.BackColor = Color.LightSkyBlue ;
                                        }
                                        else
                                        {
                                            row.DefaultCellStyle.BackColor = Color.LightCoral;
                                            row.ReadOnly = true;
                                            WrongQuestion++;
                                        }
                                    }
                                    else
                                    {
                                        row.DefaultCellStyle.BackColor = Color.LightCoral;
                                        row.ReadOnly = true;
                                        WrongQuestion++;
                                    }
                                }
                                else
                                {
                                    row.DefaultCellStyle.BackColor = Color.LightCoral;
                                    row.ReadOnly = true;
                                    WrongQuestion++;
                                }
                            }
                            else
                            {
                                string[] AnswerContent = row.Cells["AnswerContent"].Value.ToString().Trim().Split(new string[] { "</answer>" }, StringSplitOptions.None);
                                int Numanswer = AnswerContent.Length - 1;
                                if (Numanswer < 2)
                                {
                                    row.DefaultCellStyle.BackColor = Color.LightCoral;
                                    row.ReadOnly = true;
                                    WrongQuestion++;
                                }
                                else
                                {
                                    int empty = 0;
                                    int CountNumberOfIncorrect = 0;
                                    int TotalAnswer = 0;

                                    for (int i = 0; i < AnswerContent.Length - 1; i++)
                                    {
                                        string[] AnswerItem = AnswerContent[i].Split(new string[] { "---" }, StringSplitOptions.None);
                                        int PointAnswer;
                                        bool isNum = int.TryParse(AnswerItem[0].ToString().Trim(), out PointAnswer);
                                        //check null answer or invalid answer
                                        if (AnswerItem[1].ToString().Trim() == "" || AnswerItem[1].ToString().Trim().Contains("</span>") == true || AnswerItem[0].ToString().Trim() == "" || isNum == false)
                                        {
                                            empty++;
                                        }
                                        //check don't have any correct answer
                                        if (int.TryParse(AnswerItem[0].ToString().Trim(), out PointAnswer))
                                        {
                                            if (Convert.ToInt32(AnswerItem[0].ToString().Trim()) == 0)
                                            {
                                                CountNumberOfIncorrect++;
                                            }
                                        }
                                        TotalAnswer++;
                                    }

                                    if (empty > 0 || TotalAnswer == CountNumberOfIncorrect)
                                    {
                                        row.DefaultCellStyle.BackColor = Color.LightCoral;
                                        row.ReadOnly = true;
                                        WrongQuestion++;
                                    }
                                    else
                                    {
                                        row.DefaultCellStyle.BackColor = Color.LightSkyBlue ;
                                    }
                                }
                            }
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.LightCoral;
                            row.ReadOnly = true;
                            WrongQuestion++;
                        }
                    }
                    else
                    {
                        row.DefaultCellStyle.BackColor = Color.LightCoral;
                        row.ReadOnly = true;
                        WrongQuestion++;
                    }

            }//end foreach
        }
        //SAVE QUESTION AND ANSWER
        private void btn_SaveQuestion_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);
                            //Close form
                            Form FindForm = this.FindForm();
                            FindForm.Close();
                        }
                    }
                }
            }
        }
        //LOAD FORM
        private void EditQuestion_MultiSelect_Load(object sender, EventArgs e)
        {
            //GET QUESTION BY ID Question
            QuestionBL QuestionBL = new QuestionBL();
            List<DO.Question> QuestionList;
            Question question = new Question();
            QuestionList = QuestionBL.GetQuestion();
            if (QuestionList != null)
            {
                for (int i = 0; i < QuestionList.Count; i++)
                {
                    if (QuestionList.ElementAt(i).IDQuestion == IDQuestion)
                    {
                        txt_ContentQuestion.Text = QuestionList.ElementAt(i).NameQuestion;
                        txt_Date.Text = QuestionList.ElementAt(i).Date.ToString("d");
                    }

                }
                //GET ANSWER BY ID QUESTION
                List<DO.Answer> AnswerList;
                Answer answer = new Answer();
                question.IDQuestion = IDQuestion;
                AnswerList = QuestionBL.GetAnswerByQuestionID(question);
                if (AnswerList != null)
                {
                    for (int j = 0; j < AnswerList.Count; 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);

                        MultiSelectAnswer.txt_AnswerContent.Text = AnswerList.ElementAt(j).ContentAnswer;
                        MultiSelectAnswer.chk_Check.Checked = AnswerList.ElementAt(j).IsCorrect;
                        flp_addAnswer.Controls.Add(MultiSelectAnswer);
                    }
                }
            }
        }
        //LOAD FORM
        private void ViewQuestionMultiple_Load(object sender, EventArgs e)
        {
            //GET QUESTION BY ID Question
            QuestionBL QuestionBL = new QuestionBL();
            List<DO.Question> QuestionList;
            Question question = new Question();
            QuestionList = QuestionBL.GetQuestion();
            if (QuestionList != null)
            {
                for (int i = 0; i < QuestionList.Count; i++)
                {
                    if (QuestionList.ElementAt(i).IDQuestion == IDQuestion)
                    {
                        txt_Catalogue.Text = QuestionList.ElementAt(i).NameCatalogue;
                        txt_ContentQuestion.Text = QuestionList.ElementAt(i).NameQuestion;
                        txt_QuestionType.Text = QuestionList.ElementAt(i).TypeQuestion;
                        txt_Date.Text = QuestionList.ElementAt(i).Date.ToString("d");
                    }

                }
                //GET ANSWER BY ID QUESTION
                List<DO.Answer> AnswerList;
                Answer answer = new Answer();
                question.IDQuestion = IDQuestion;
                AnswerList = QuestionBL.GetAnswerByQuestionID(question);
                if (AnswerList != null)
                {
                    for (int j = 0; j < AnswerList.Count; j++)
                    {
                        Answer_MultiSelect MultiChoiceAnswer = new Answer_MultiSelect();
                        i++;
                        MultiChoiceAnswer.Tag = i;
                        MultiChoiceAnswer.ID_Answer = i;
                        MultiChoiceAnswer.onDelete += OneChoiceAnswer_onDelete;
                        MultiChoiceAnswer.chk_Check.Text = Convert.ToChar(a + j).ToString();

                        MultiChoiceAnswer.txt_AnswerContent.Text = AnswerList.ElementAt(j).ContentAnswer;
                        MultiChoiceAnswer.chk_Check.Checked = AnswerList.ElementAt(j).IsCorrect;

                        MultiChoiceAnswer.txt_AnswerContent.ReadOnly = true;
                        MultiChoiceAnswer.chk_Check.Enabled = false;
                        MultiChoiceAnswer.btn_DelAnswer.Visible = false;
                        flp_Answer.Controls.Add(MultiChoiceAnswer);
                    }
                }
            }
        }
Пример #19
0
        //SAVE QUESTION
        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);
            }
        }