private void BtnXoaCauHoi_Click(object sender, EventArgs e) { if (ListCauHoi == null || ListCauHoi.Count == 0) { UICommon.ShowMsgWarningString("Bạn phải tạo câu hỏi trước"); return; } else if (ListCauHoi.Count == 1) { UICommon.ShowMsgWarningString("Số lượng câu hỏi quá ít bạn không thể xóa"); return; } if (UICommon.ShowMsgQuestionString("Bạn muốn xóa câu hỏi này?") == DialogResult.Yes) { var cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == IdCauHoiCurent); if (cauHoi != null) { //Xóa toàn cục ListCauHoi.Remove(cauHoi); //Xoa duoi db IsChanged = _business.DeleteCauHoiByLstId(new List <long>() { cauHoi.Id }) > 0; //Set lai data var cauHoiKeTiep = ListCauHoi.FirstOrDefault(); IdCauHoiCurent = 0; if (cauHoiKeTiep != null) { CauHoiCurent = cauHoiKeTiep; } var lstDataCbo = new List <DM_STT>(); //int i = 1; foreach (var item in ListCauHoi) { lstDataCbo.Add(new DM_STT { Id = item.IDEx, Ten = "Câu hỏi " + item.IDEx }); } txtSoCauHoi.Text = lstDataCbo.Count().ToString(); SetDataChonCauHoi(lstDataCbo); if (cauHoiKeTiep != null) { cboChonCauHoi.CategoryID = cauHoiKeTiep.IDEx; } else { cboChonCauHoi.CategoryID = null; txtSoCauHoi.Enabled = true; btnTaoCauHoi.Enabled = true; } } } }
private void LoadCauHoiNew(int idCauHoi) { EX_CauHoi cauHoi = new EX_CauHoi(); cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == idCauHoi); IdCauHoiCurent = cauHoi.IDEx; txtNoiDungCauHoiCon.Rtf = cauHoi.NoiDung; ckbKhongDaoCauHoi.Checked = cauHoi.IsKhongDao ?? false; LoadCauTraLoiNew(IdCauHoiCurent); }
private void LoadCauTraLoiNew(long idCauHoi) { // Load danh sách đáp án var lstDapAn = ListCauHoi.Where(m => m.IDEx == idCauHoi).Select(m => m.ListCauTraLoi).FirstOrDefault(); if (lstDapAn != null && lstDapAn.Count > 0) { var cautraLoi = lstDapAn.FirstOrDefault(); txtNoiDungCauTraLoi.Rtf = cautraLoi.NoiDung; } }
private void LoadCauHoiNew(long idCauHoi) { //Load cau hoi EX_CauHoi cauHoi = new EX_CauHoi(); cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == idCauHoi); IdCauHoiCurent = cauHoi.IDEx; if (!txtCtrlNoiDungCauHoi.IsEmpty) { LoadCauTraLoiNew(IdCauHoiCurent); } }
private void LoadCauTraLoiNew(long idCauHoi) { // Load danh sách đáp án List <EX_CauTraLoi> listDapAn = new List <EX_CauTraLoi>(); listDapAn = ListCauHoi.Where(m => m.IDEx == idCauHoi).Select(m => m.ListCauTraLoi).FirstOrDefault(); foreach (var dapAn in listDapAn) { ThemCauTraLoi(dapAn); } }
private void LoadCauHoiNew(long?idCauHoi) { var cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == idCauHoi); if (cauHoi == null) { cauHoi = new EX_CauHoi(); } IdCauHoiCurent = cauHoi.IDEx; txtNoiDungCauHoiCon.Rtf = cauHoi.NoiDung; ckbKhongDaoCauHoi.Checked = cauHoi.IsKhongDao ?? false; LoadCauTraLoiNew(IdCauHoiCurent); }
private void BtnThem_Click(object sender, EventArgs e) { if (ListCauHoi == null || ListCauHoi.Count == 0) { UICommon.ShowMsgWarningString("Bạn phải tạo câu hỏi trước"); return; } var cauHoi = new EX_CauHoi(); for (int i = 1; i <= 4; i++) { EX_CauTraLoi cauTraLoi = new EX_CauTraLoi(); cauTraLoi.IdEx = i; cauTraLoi.IDCauHoi = cauHoi.Id; cauTraLoi.NoiDung = ""; cauHoi.ListCauTraLoi.Add(cauTraLoi); } var cauHoiLast = ListCauHoi.LastOrDefault(); if (cauHoiLast != null) { cauHoi.IDEx = cauHoiLast.IDEx + 1; cauHoi.NoiDung = ""; cauHoi.IDChuong = IdDanhMuc; cauHoi.DoKho = IdMucDoNhanThuc; cauHoi.IsSuDung = true; cauHoi.IsKhongDao = ckbKhongDaoCauHoi.Checked; ListCauHoi.Add(cauHoi); //Set lai data var lstDataCbo = new List <DM_STT>(); //int i = 1; foreach (var item in ListCauHoi) { lstDataCbo.Add(new DM_STT { Id = item.IDEx, Ten = "Câu hỏi " + item.IDEx }); } txtSoCauHoi.Text = lstDataCbo.Count().ToString(); SetDataChonCauHoi(lstDataCbo); cboChonCauHoi.CategoryID = cauHoi.IDEx; } }
private void LoadCauTraLoiNew(long idCauHoi) { // Load danh sách đáp án CauHoiCurent = ListCauHoi.Where(m => m.IDEx == idCauHoi).FirstOrDefault(); //IdCauHoiCurent = CauHoiCurent.IDEx; List <EX_CauTraLoi> listDapAn = new List <EX_CauTraLoi>(); listDapAn = CauHoiCurent.ListCauTraLoi; //Load cau hoi (bên trái) var cauTraLoiDau = listDapAn.FirstOrDefault(); ThemCauTraLoi(cauTraLoiDau); //Load cau tra lời gây nhieu for (int i = 1; i < listDapAn.Count; i++) { ThemCauTraLoiGayNhieu(listDapAn[i]); } }
private bool SaveNewCauHoiTemp(long idCauHoiEx) { #region Save new câu hỏi //Cau hoi cha EX_CauHoi cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == IdCauHoiCurent); cauHoi.IDChuong = IdDanhMuc; cauHoi.DoKho = IdMucDoNhanThuc; cauHoi.NoiDung = txtNoiDungCauHoiCon.Rtf; cauHoi.IsSuDung = true; cauHoi.IsKhongDao = ckbKhongDaoCauHoi.Checked; cauHoi.NgaySoan = DateTime.Now; var cauTraLoi = cauHoi.ListCauTraLoi.FirstOrDefault(); cauTraLoi.NoiDung = txtNoiDungCauTraLoi.Rtf; #endregion return(true); }
private bool SaveNewCauHoiTemp(long idCauHoiEx) { var lstCauTraLoi = new List <EX_CauTraLoi>(); //Cau tra loi dau tien if (_lstTablePanelCauHoi.Count == 0) { return(false); } var tblPanelDapAn = _lstTablePanelCauHoi.FirstOrDefault(); EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl; Label btnDapAn = tblPanelDapAn.Controls[_nameLabelDapAn] as Label; lstCauTraLoi.Add(new EX_CauTraLoi() { NoiDung = txtDapAn.Rtf, IsDung = true, IsKhongDao = true }); foreach (var tblPanelDapAnGayNhieu in _lstTablePanelGayNhieu) { EditorControl txtDapAnGayNhieu = tblPanelDapAnGayNhieu.Controls[_nameTextNoiDungDapAn] as EditorControl; Label btnDapAnGayNhieu = tblPanelDapAnGayNhieu.Controls[_nameLabelDapAn] as Label; lstCauTraLoi.Add(new EX_CauTraLoi() { NoiDung = txtDapAnGayNhieu.Rtf, IsDung = false, IsKhongDao = true }); } #region Save new câu hỏi //Cau hoi cha EX_CauHoi cauHoiCha = new EX_CauHoi(); cauHoiCha.IDChuong = IdDanhMuc; cauHoiCha.NoiDung = txtCtrlNoiDungCauHoi.Rtf; cauHoiCha.IDLoaiCauHoi = (int)LoaiCauHoi.CauHoiDienKhuyet; EX_CauHoi cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == IdCauHoiCurent); cauHoi.IDChuong = IdDanhMuc; cauHoi.DoKho = IdMucDoNhanThuc; cauHoi.IsSuDung = true; cauHoi.NgaySoan = DateTime.Now; // Danh sách câu trả lời int i = 1; cauHoi.ListCauTraLoi.OrderBy(m => m.IdEx).ToList(); cauHoi.ListCauTraLoi.ForEach(m => { m.IdEx = i++; }); i = 1; foreach (var esCauTraLoi in lstCauTraLoi) { if (cauHoi.ListCauTraLoi.Any(m => m.IdEx == i)) { var cauTraLoi = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.IdEx == i); cauTraLoi.IdEx = i; cauTraLoi.NoiDung = esCauTraLoi.NoiDung; cauTraLoi.IsDung = esCauTraLoi.IsDung; cauTraLoi.IsKhongDao = esCauTraLoi.IsKhongDao; } else { esCauTraLoi.IDCauHoi = cauHoi.IDEx; esCauTraLoi.IdEx = i; cauHoi.ListCauTraLoi.Add(esCauTraLoi); } i++; } // Xoa cau tra loi foreach (int idCauTraLoiBiXoa in ListIdCauHoiBiXoa) { if (idCauTraLoiBiXoa != 0) { var cauTraLoiBiXoa = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.Id == idCauTraLoiBiXoa); cauHoi.ListCauTraLoi.Remove(cauTraLoiBiXoa); } } #endregion return(true); }
private void XoaCauTraLoi(object sender, EventArgs e) { if (ListCauHoi.Count == 1) { UICommon.ShowMsgWarningString("Số lượng câu hỏi không thể nhỏ hơn 1 \nBạn không thể xóa câu hỏi này"); return; } if (UICommon.ShowMsgQuestionString("Bạn có chắc muốn xóa câu trả lời này không ?", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } SimpleButton button = sender as SimpleButton; TableLayoutPanel tblPanelDapAn = button.Parent as TableLayoutPanel; int rowIndex = tblPanelMain.GetRow(tblPanelDapAn); ListIdCauHoiBiXoa.Add(CauHoiCurent.Id); //remove old controls foreach (Control ctrl in tblPanelDapAn.Controls) { ctrl.Dispose(); } tblPanelDapAn.Controls.Clear(); tblPanelDapAn.Dispose(); tblPanelMain.Controls.Remove(tblPanelDapAn); _lstTablePanelCauHoi.Remove(tblPanelDapAn); //decrease row index of panels down 2 //rename panel for (int i = rowIndex + 2; i < tblPanelMain.RowStyles.Count; i = i + 2) { tblPanelDapAn = tblPanelMain.Controls[_nameTablePanelDapAn + i] as TableLayoutPanel; if (tblPanelDapAn != null) { tblPanelMain.SetRow(tblPanelDapAn, i - 2); tblPanelDapAn.Name = _nameTablePanelDapAn + (i - 2); } } //remove 2 last rows tblPanelMain.RowStyles.RemoveAt(tblPanelMain.RowStyles.Count - 2); tblPanelMain.RowCount--; tblPanelMain.RowStyles.RemoveAt(tblPanelMain.RowStyles.Count - 2); tblPanelMain.RowCount--; //Tìm vị trí điền khuyết var noiDungReply = CauHoiCurent.ListCauTraLoi.FirstOrDefault(); var textReply = (string.Format("({0})_____", CauHoiCurent.IDEx)); txtCtrlNoiDungCauHoi.Focus(); txtCtrlNoiDungCauHoi.Find(textReply, RichTextBoxFinds.MatchCase); txtCtrlNoiDungCauHoi.Cut(); Clipboard.Clear(); //Tra lai noi dung cho text box cau hoi if (noiDungReply == null) { return; } var noiDungText = UICommon.ConvertRftToText(noiDungReply.NoiDung).Trim(); Clipboard.SetText(noiDungText); txtCtrlNoiDungCauHoi.Paste(); txtCtrlNoiDungCauHoi.Refresh(); Clipboard.Clear(); ListCauHoi.Remove(CauHoiCurent); int idEx = 1; foreach (var viTri in ListCauHoi) { var textFind = (string.Format("({0})_____", viTri.IDEx)); var textRepalce = (string.Format("({0})_____", idEx)); txtCtrlNoiDungCauHoi.Find(textFind, RichTextBoxFinds.MatchCase); txtCtrlNoiDungCauHoi.Focus(); txtCtrlNoiDungCauHoi.Cut(); Clipboard.Clear(); Clipboard.SetText(textRepalce); txtCtrlNoiDungCauHoi.Paste(); txtCtrlNoiDungCauHoi.Refresh(); viTri.IDEx = idEx++; } SetDataToCboCauHoi(); var cauHoiKeTiep = ListCauHoi.LastOrDefault(); //Xoa het du lieu cau hoi ClearAllCauTraLoi(); ClearAllCauTraLoiGayNhieu(); cboCauHoi.EditValueChanged -= CboCauHoi_EditValueChanged;; if (cauHoiKeTiep != null) { CauHoiCurent = cauHoiKeTiep; IdCauHoiCurent = cauHoiKeTiep.IDEx; LoadCauHoiNew(IdCauHoiCurent); cboCauHoi.CategoryID = cauHoiKeTiep.IDEx; } else { cboCauHoi.CategoryID = null; } cboCauHoi.EditValueChanged += CboCauHoi_EditValueChanged; _mathCollection = _parsing.ParseDienKhuyet2(txtCtrlNoiDungCauHoi.Text); IsChanged = true; }
private void BtnDienKhuyet_Click(object sender, EventArgs e) { txtCtrlNoiDungCauHoi.Focus(); //Them vao cau tra loi if (txtCtrlNoiDungCauHoi.SelectionLength == 0) { UICommon.ShowMsgWarningString("Bạn chưa chọn nội dung cần điền khuyết"); return; } var textStart = txtCtrlNoiDungCauHoi.SelectionStart; //Kiem tra vi tri dien khuyet if (_mathCollection != null) { for (int i = 0; i < _mathCollection.Count; i++) { var viTriNext = _mathCollection[i].Index + _mathCollection[i].Length; if (textStart >= _mathCollection[i].Index && textStart <= viTriNext) { UICommon.ShowMsgWarningString("Vị trí điền khuyết không hợp lệ!"); if (txtCtrlNoiDungCauHoi.SelectionLength == 0) { txtCtrlNoiDungCauHoi.Undo(); } return; } } } var tmp = txtCtrlNoiDungCauHoi.SelectedRtf; //Buoc 2: Add cau tra loi dau tien cho cau hoi hien tai => vi trí diền khuyết if (txtCtrlNoiDungCauHoi.SelectionLength != 0) { //Gan du lieu toan cuc và cboCauHoi CauHoiCurent = new EX_CauHoi { IDEx = ListCauHoi.Count + 1, DoKho = IdMucDoNhanThuc }; //Buoc 1 ListCauHoi.Add(CauHoiCurent); CauHoiCurent.ListCauTraLoi.Add(new EX_CauTraLoi { IdEx = 1, NoiDung = txtCtrlNoiDungCauHoi.SelectedRtf, IndexEx = textStart }); var textStt = string.Format("({0})_____", ListCauHoi.Count); PasteClipboard: { try { Clipboard.SetText(textStt); } catch (Exception) { goto PasteClipboard; } } txtCtrlNoiDungCauHoi.Paste(); } else { UICommon.ShowMsgWarningString("Nội dung chọn không hợp lệ"); if (txtCtrlNoiDungCauHoi.SelectionLength == 0) { txtCtrlNoiDungCauHoi.Undo(); } return; } //Buoc 3: do du lieu len cbo if (ListCauHoi.Count > 0) { SetDataToCboCauHoi(); } //Buoc 4 => changCategoryID _isDienKhuyet = true; cboCauHoi.CategoryID = ListCauHoi.Count; IdCauHoiCurent = (int)cboCauHoi.CategoryID; //Ve lai cau hoi => phan ben trai ClearAllCauTraLoi(); ClearAllCauTraLoiGayNhieu(); ThemCauTraLoi(); CurrentControl.Focus(); CurrentControl.Rtf = tmp; CurrentControl.ReadOnly = true; // Nhận dạng lại vị trí _mathCollection = _parsing.ParseDienKhuyet2(txtCtrlNoiDungCauHoi.Text); }
private void XoaCauTraLoi(object sender, EventArgs e) { if (UICommon.ShowMsgQuestionString("Bạn có chắc muốn xóa câu trả lời này không ?", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } SimpleButton button = sender as SimpleButton; TableLayoutPanel tblPanelDapAn = button.Parent as TableLayoutPanel; int rowIndex = tblPanelMain.GetRow(tblPanelDapAn); //get id cau hoi bi xoa int idCauHoiBiXoa = Convert.ToInt32(button.Tag); int idCauTraLoiEx = 0; try { idCauTraLoiEx = Convert.ToInt32(tblPanelDapAn.Tag); } catch { } //Xoa cau tra loi trong lstCauHoi var cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == IdCauHoiCurent); if (cauHoi != null) { var cauTraLoi = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.IdEx == idCauTraLoiEx); if (cauTraLoi != null) { cauHoi.ListCauTraLoi.Remove(cauTraLoi); } int idEx = 1; //Reset lai idEx = bắt đầu từ 1 => nhớ phải reset tag của tblPanelDapAn ở phần reset text foreach (var item in cauHoi.ListCauTraLoi) { item.IdEx = idEx++; } } //neu khac 0 la cau hoi da ton tai, can xoa if (idCauHoiBiXoa != 0) { ListIdCauHoiBiXoa.Add(idCauHoiBiXoa); IsChanged = true; } //remove old controls foreach (Control ctrl in tblPanelDapAn.Controls) { ctrl.Dispose(); } tblPanelDapAn.Controls.Clear(); tblPanelDapAn.Dispose(); tblPanelMain.Controls.Remove(tblPanelDapAn); _lstTablePanelDapAn.Remove(tblPanelDapAn); //rename panel for (int i = rowIndex + 2; i < tblPanelMain.RowStyles.Count; i = i + 2) { tblPanelDapAn = tblPanelMain.Controls[_nameTablePanelDapAn + i] as TableLayoutPanel; if (tblPanelDapAn != null) { tblPanelMain.SetRow(tblPanelDapAn, i - 2); tblPanelDapAn.Name = _nameTablePanelDapAn + (i - 2); } } //remove 2 last rows tblPanelMain.RowStyles.RemoveAt(tblPanelMain.RowStyles.Count - 2); tblPanelMain.RowCount--; tblPanelMain.RowStyles.RemoveAt(tblPanelMain.RowStyles.Count - 2); tblPanelMain.RowCount--; // Reset text ResetTextCauTraLoi(); ResizeLayoutCauTraLoi(false); }
private bool SaveNewCauHoiTemp(long idCauHoiEx) { var lstCauTraLoi = new List <EX_CauTraLoi>(); foreach (var tblPanelDapAn in _lstTablePanelDapAn) { EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl; SimpleButton btnDapAn = tblPanelDapAn.Controls[_nameButtonDapAn] as SimpleButton; CheckBox chkKhongDao = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox; lstCauTraLoi.Add(new EX_CauTraLoi() { NoiDung = txtDapAn.Rtf, IsDung = Convert.ToBoolean(btnDapAn.Tag), IsKhongDao = chkKhongDao.Checked }); } #region Save new câu hỏi //Cau hoi cha if (ListCauHoi == null) { return(false); } EX_CauHoi cauHoi = ListCauHoi.FirstOrDefault(m => m.IDEx == IdCauHoiCurent); cauHoi.IDChuong = IdDanhMuc; cauHoi.DoKho = IdMucDoNhanThuc; cauHoi.NoiDung = txtNoiDungCauHoiCon.Rtf; cauHoi.IsSuDung = true; cauHoi.IsKhongDao = ckbKhongDaoCauHoi.Checked; cauHoi.NgaySoan = DateTime.Now; // Danh sách câu trả lời int i = 1; cauHoi.ListCauTraLoi.OrderBy(m => m.IdEx).ToList(); cauHoi.ListCauTraLoi.ForEach(m => { m.IdEx = i++; }); i = 1; foreach (var esCauTraLoi in lstCauTraLoi) { if (cauHoi.ListCauTraLoi.Any(m => m.IdEx == i)) { var cauTraLoi = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.IdEx == i); cauTraLoi.NoiDung = esCauTraLoi.NoiDung; cauTraLoi.IsDung = esCauTraLoi.IsDung; cauTraLoi.IsKhongDao = esCauTraLoi.IsKhongDao; } else { esCauTraLoi.IDCauHoi = cauHoi.IDEx; esCauTraLoi.IdEx = i; cauHoi.ListCauTraLoi.Add(esCauTraLoi); } i++; } // Xoa cau tra loi foreach (int idCauTraLoiBiXoa in ListIdCauHoiBiXoa) { var cauTraLoiBiXoa = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.Id == idCauTraLoiBiXoa); cauHoi.ListCauTraLoi.Remove(cauTraLoiBiXoa); _bus.DeleteCauTraLoiById(idCauTraLoiBiXoa); } #endregion return(true); }