//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) { 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(); } } } }
//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(); } } } } }
//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); } } } } } }
//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); } }
//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); } }
//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); } }