//ADD ANSWER private void btn_addAnswer_Click(object sender, EventArgs e) { 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).ToString(); flp_addAnswer.Controls.Add(OneChoiceAnswer); for (int j = 0; j < flp_addAnswer.Controls.Count; j++) { OneChoiceAnswer.rad_check.Text = Convert.ToChar(a+j).ToString(); } }
//LOAD FORM private void Question_OnlyOneSelect_Load(object sender, EventArgs e) { this.Dock = DockStyle.Fill; txt_Date.Text = DateTime.Now.ToString("d"); //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); } }
//Eventhanlder click Del button void OneChoiceAnswer_onDelete(object sender, EventArgs e) { Answer_OnlyOneSelect OneChoiceAnswer = new Answer_OnlyOneSelect(); int answerID = (e as MyEventArgs).IDAnswer; foreach (Answer_OnlyOneSelect item in flp_addAnswer.Controls) { if (item.ID_Answer == answerID) { flp_addAnswer.Controls.Remove(item); } } int alp = 0; foreach (Answer_OnlyOneSelect item in flp_addAnswer.Controls) { item.rad_check.Text = Convert.ToChar(a + alp++).ToString(); } }
//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); } } } } } }
//LOAD FORM private void EditQuestion_OnlyOneSelect_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_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_addAnswer.Controls.Add(OneChoiceAnswer); } } } }
//LOAD CATALOGUE TO COMMOBOX private void Question_OnlyOneSelect_1_Load(object sender, EventArgs e) { txt_ContentQuestion.Text = ""; flp_addAnswer.Controls.Clear(); cmb_Catalogue.Items.Clear(); cmb_Catalogue.Text = ""; 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++) { this.cmb_Catalogue.Items.Add(CatList.ElementAt(i).NameCatalogue); } if (cmb_Catalogue.Items.Count >0 ) { cmb_Catalogue.SelectedIndex = 0; } txt_Date.Text = DateTime.Now.ToString("d"); //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); } }