//Edit catalouge public void Editcatalogue() { if (txt_NameCatalogue.Text.Trim() == "") { MessageBox.Show("Vui lòng nhập tên chủ đề!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { CatalogueBL CatBL = new CatalogueBL(); Catalogue Cat = new Catalogue(); Cat.IDCatalogue = IDCat; Cat.NameCatalogue = txt_NameCatalogue.Text.Trim(); if (CatBL.EditCataloguebyID(Cat) == true) { //notifyIcon1.Icon = SystemIcons.Information; //notifyIcon1.BalloonTipText = "Chỉnh sửa chủ đề thành công"; //notifyIcon1.ShowBalloonTip(1000); this.Close(); } else { MessageBox.Show("Chủ đề này đã tồn tại trong hệ thống!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
//click enter private void txt_NameCatalogue_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { if (txt_NameCatalogue.Text.Trim() == "") { MessageBox.Show("Vui lòng nhập tên chủ đề!", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { CatalogueBL CatBL = new CatalogueBL(); Catalogue Cat = new Catalogue(); Cat.NameCatalogue = txt_NameCatalogue.Text.Trim(); if (CatBL.AddCatalogue(Cat) == true) { //notifyIcon1.Icon = SystemIcons.Information; //notifyIcon1.BalloonTipText = "Thêm chủ đề \"" + txt_NameCatalogue.Text.Trim() + "\" thành công"; //notifyIcon1.ShowBalloonTip(5000); this.Close(); } else { MessageBox.Show("Chủ đề này đã tồn tại trong hệ thống!", "Cảnh Báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } }
//LOAD QUESTION public void LoadQuestion() { QuestionBL QuestionBL = new QuestionBL(); Catalogue Cat = new Catalogue(); Cat.IDCatalogue = IDCat; List<DO.Question> QuestionList; QuestionList = QuestionBL.GetQuestionByCatalogue(Cat); if (QuestionList != null) dgv_Question1.DataSource = QuestionList; dgv_Question1.Columns["IDCatalogue"].Visible = false; dgv_Question1.Columns["IDQuestion"].Visible = false; dgv_Question1.Columns["AnswerContent"].Visible = false; dgv_Question1.Columns["Catalogue"].Visible = false; dgv_Question1.Columns["Date"].Visible = false; dgv_Question1.Columns["Sequence"].HeaderText = "STT"; dgv_Question1.Columns["QuestionTitle"].HeaderText = "Tên câu Hỏi"; dgv_Question1.Columns["NameQuestion"].HeaderText = "Nội dung câu Hỏi"; dgv_Question1.Columns["TypeQuestion"].HeaderText = "Loại Câu Hỏi"; dgv_Question1.Columns["NameCatalogue"].HeaderText = "Tên Chủ Đề"; dgv_Question1.Columns["Sequence"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question1.Columns["NameCatalogue"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question1.Columns["TypeQuestion"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question1.Columns["QuestionTitle"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; }
//SELECT ITEM IN COMMOBOX private void cmb_Catalogue_SelectedIndexChanged(object sender, EventArgs e) { //dgv_Question.Columns.Clear(); Catalogue catalogue = new Catalogue(); CatalogueBL CatBL = new CatalogueBL(); List<DO.Catalogue> CatList; CatList = CatBL.GetCatalogue(); if (CatList != null) for (int i = 0; i < CatList.Count; i++) { if (cmb_Catalogue.SelectedItem.ToString() == CatList.ElementAt(i).NameCatalogue) { catalogue.IDCatalogue = CatList.ElementAt(i).IDCatalogue; } } QuestionBL QuestionBL = new QuestionBL(); List<DO.Question> QuestionList; QuestionList = QuestionBL.GetQuestionByCatalogue(catalogue); if (QuestionList != null) { dgv_Question.DataSource = QuestionList; dgv_Question.Columns["IDCatalogue"].Visible = false; dgv_Question.Columns["IDQuestion"].Visible = false; dgv_Question.Columns["AnswerContent"].Visible = false; dgv_Question.Columns["Catalogue"].Visible = false; dgv_Question.Columns["NameCatalogue"].Visible = false; dgv_Question.Columns["Date"].Visible = false; } chk_CheckAll.Checked = false; }
//Select question follow catalogue private void cmb_Catalogue_SelectedIndexChanged(object sender, EventArgs e) { dgv_Question.Columns.Clear(); Catalogue catalogue = new Catalogue(); CatalogueBL CatBL = new CatalogueBL(); List<DO.Catalogue> CatList; CatList = CatBL.GetCatalogue(); if (CatList != null) for (int i = 0; i < CatList.Count; i++) { if (cmb_Catalogue.SelectedItem.ToString() == CatList.ElementAt(i).NameCatalogue) { catalogue.IDCatalogue = CatList.ElementAt(i).IDCatalogue; } } QuestionBL QuestionBL = new QuestionBL(); List<DO.Question> QuestionList; QuestionList = QuestionBL.GetQuestionByCatalogue(catalogue); if (QuestionList != null) { dgv_Question.DataSource = QuestionList; } dgv_Question.Columns["IDCatalogue"].Visible = false; dgv_Question.Columns["IDQuestion"].Visible = false; dgv_Question.Columns["AnswerContent"].Visible = false; dgv_Question.Columns["Date"].Visible = false; dgv_Question.Columns["NameCatalogue"].Visible = false; dgv_Question.Columns["Catalogue"].Visible = false; dgv_Question.Columns["Sequence"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question.Columns["TypeQuestion"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question.Columns["NameCatalogue"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question.Columns["QuestionTitle"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question.Columns["Sequence"].HeaderText = "STT"; dgv_Question.Columns["TypeQuestion"].HeaderText = "Loại Câu Hỏi"; dgv_Question.Columns["NameQuestion"].HeaderText = "Nội Dung Câu Hỏi"; dgv_Question.Columns["QuestionTitle"].HeaderText = "Tên Câu Hỏi"; dgv_Question.Columns["Sequence"].ReadOnly = true; dgv_Question.Columns["TypeQuestion"].ReadOnly = true; dgv_Question.Columns["NameQuestion"].ReadOnly = true; dgv_Question.Columns["QuestionTitle"].ReadOnly = true; DataGridViewCheckBoxColumn CheckColumn = new DataGridViewCheckBoxColumn(); CheckColumn.Name = "Check"; dgv_Question.Columns.Add(CheckColumn); dgv_Question.Columns["Check"].HeaderText = "Chọn"; dgv_Question.Columns["Check"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; chk_CheckAll.Checked = false; }
//Select question by ID catalogue public List<Question> GetQuestionByCatalogue(Catalogue Catalogue) { List<Question> QuestionList = new List<Question>(); string query = "SELECT q.Question_ID, q.Question_Title, q.Question_Name, q.Question_Type, c.Catalogue_Name" + " FROM Question q " + " INNER JOIN Catalogue c ON c.Catalogue_ID = q.Catalogue_ID" + " WHERE q.Catalogue_ID='"+Catalogue.IDCatalogue+"'"; DataTable dt = DA.SelectDatabase(query); int i=1; if (dt != null) { foreach (DataRow item in dt.Rows) { Question Question = new Question(); Question.IDQuestion = Convert.ToInt32(item["Question_ID"]); Question.QuestionTitle = item["Question_Title"].ToString(); Question.NameQuestion = item["Question_Name"].ToString(); Question.TypeQuestion = item["Question_Type"].ToString(); Question.NameCatalogue = item["Catalogue_Name"].ToString(); Question.Sequence = i; QuestionList.Add(Question); i++; } } return QuestionList; }
public Question() { catalogue = new Catalogue(); }
private void txt_SearchCatalogue_TextChanged(object sender, EventArgs e) { //QuestionBL questionBL = new QuestionBL(); //List<DO.Question> ListQuestion = questionBL.GetQuestion(); QuestionBL QuestionBL = new QuestionBL(); Catalogue Cat = new Catalogue(); Cat.IDCatalogue = IDCat; List<DO.Question> QuestionList; QuestionList = QuestionBL.GetQuestionByCatalogue(Cat); //if (QuestionList != null) //dgv_Question1.DataSource = QuestionList; //loadQuestion(); ListtoDataTableConverter converter = new ListtoDataTableConverter(); DataTable dt = converter.ToDataTable(QuestionList); dgv_Question1.DataSource = dt; dt.DefaultView.RowFilter = string.Format("NameQuestion LIKE '%{0}%' or TypeQuestion LIKE '%{0}%' or NameCatalogue LIKE '%{0}%' or QuestionTitle LIKE '%{0}%'or Sequence LIKE '%{0}%'", txt_SearchCatalogue.Text); dgv_Question1.Columns["IDCatalogue"].Visible = false; dgv_Question1.Columns["IDQuestion"].Visible = false; dgv_Question1.Columns["IDCatalogue"].Visible = false; dgv_Question1.Columns["AnswerContent"].Visible = false; dgv_Question1.Columns["AnswerList"].Visible = false; dgv_Question1.Columns["Date"].Visible = false; dgv_Question1.Columns["Sequence"].HeaderText = "STT"; dgv_Question1.Columns["NameQuestion"].HeaderText = "Tên Câu Hỏi"; dgv_Question1.Columns["NameCatalogue"].HeaderText = "Tên chủ Đề"; dgv_Question1.Columns["TypeQuestion"].HeaderText = "Loại Câu hỏi"; dgv_Question1.Columns["Sequence"].ReadOnly = true; dgv_Question1.Columns["NameQuestion"].ReadOnly = false; dgv_Question1.Columns["NameCatalogue"].ReadOnly = true; dgv_Question1.Columns["TypeQuestion"].ReadOnly = true; dgv_Question1.Columns["Sequence"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question1.Columns["NameCatalogue"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; dgv_Question1.Columns["TypeQuestion"].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells; }