private void XoaCauHoiHoiVaCauTraLoi(object sender, EventArgs e) { //Nếu trái it nhất phải = 1 if (_lstTablePanelCauHoi.Count == 1) { UICommon.ShowMsgWarningString("Số câu hỏi con không được nhỏ hơn 1 \nBạn không thể xóa!"); return; } if (UICommon.ShowMsgQuestionString("Bạn có chắc muốn xóa câu hỏi này không ?") != DialogResult.Yes) { return; } SimpleButton button = sender as SimpleButton; TableLayoutPanel tblPanelCauHoi = button.Parent as TableLayoutPanel; EditorControl txtCauHoi = tblPanelCauHoi.Controls[_nameTextNoiDungCauHoi] as EditorControl; int rowIndex = tblPanelMain.GetRow(tblPanelCauHoi); //get id cau hoi bi xoa int idEx = Convert.ToInt32(button.Tag); //neu khac 0 la cau hoi da ton tai, can xoa var cauHoi = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.IDEx == idEx); if (cauHoi != null && cauHoi.Id > 0) { ListIdCauHoiBiXoa.Add((int)cauHoi.Id); ListIdCauTraLoiBiXoa.Add((int)cauHoi.ListCauTraLoi.FirstOrDefault()?.Id); } //remove old controls foreach (Control ctrl in tblPanelCauHoi.Controls) { ctrl.Dispose(); } tblPanelCauHoi.Controls.Clear(); tblPanelCauHoi.Dispose(); tblPanelMain.Controls.Remove(tblPanelCauHoi); _lstTablePanelCauHoi.Remove(tblPanelCauHoi); //decrease row index of panels down 2 //rename panel for (int i = rowIndex + 2; i < tblPanelMain.RowStyles.Count; i = i + 2) { tblPanelCauHoi = tblPanelMain.Controls[_nameTablePanelCauHoi + i] as TableLayoutPanel; if (tblPanelCauHoi != null) { tblPanelMain.SetRow(tblPanelCauHoi, i - 2); tblPanelCauHoi.Name = _nameTablePanelCauHoi + (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 ResetTextCauHoiTrai(); ResizeLayoutCauTraLoiTrai(false); SetTextSoLuongCauHoi(); XoaCauTraLoiPhai(idEx); }
private void ThemCauTraLoiPhai(EX_CauTraLoi cauTraLoi = null) { //add more 2 new rows tblPanelMain2.RowCount += 2; int rowIndex = tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 63F)); tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 0)); // Đáp án gây nhiễu sẽ tính từ a,b,c,d Label lblCauHoi = new Label() { Width = 40, Dock = DockStyle.Right, Name = _nameLableDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleCenter }; //Tag = 1 = true, Tag = 0 = false lblCauHoi.Text = (1 + _lstTablePanelCauTraLoi.Count).ToString(); // Không đảo vị trí CheckBox chkKhongDao = new CheckBox() { Text = "Không đảo", Dock = DockStyle.Fill, Name = _nameCheckBox }; //EditorControl EditorControl txtCtrl = new EditorControl() { Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BorderStyle = BorderStyle.FixedSingle }; txtCtrl.Margin = new Padding(2); txtCtrl.GotFocus += txtCtrlNoiDungCauHoi_GotFocus; // Table panel TableLayoutPanel tblPanelDapAnPhai = new TableLayoutPanel(); tblPanelDapAnPhai.Name = _nameTablePanelDapAn + rowIndex; tblPanelDapAnPhai.ColumnCount = 4; tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 102F)); tblPanelDapAnPhai.RowCount = 1; tblPanelDapAnPhai.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelDapAnPhai.Dock = DockStyle.Top; tblPanelDapAnPhai.Controls.Add(lblCauHoi, 0, 0); tblPanelDapAnPhai.Controls.Add(txtCtrl, 1, 0); tblPanelDapAnPhai.Controls.Add(chkKhongDao, 3, 0); tblPanelMain2.Controls.Add(tblPanelDapAnPhai, 0, rowIndex); //add panel to list _lstTablePanelCauTraLoi.Add(tblPanelDapAnPhai); if (cauTraLoi != null) { // Load noi dung dap an if (!string.IsNullOrEmpty(cauTraLoi.NoiDung)) { txtCtrl.Rtf = cauTraLoi.NoiDung; } // Gán check không đảo chkKhongDao.Checked = cauTraLoi.IsKhongDao ?? false; if (cauTraLoi.IdEx > 0) { tblPanelDapAnPhai.Tag = cauTraLoi.IdEx; txtCtrl.Tag = cauTraLoi.IdEx; } } ResizeLayoutCauTraLoiPhai(true); SetTextSoLuongCauHoi(); }
public int SaveCauHoiNew() { EX_CauHoi chc = new EX_CauHoi(); try { List <EX_CauHoi> lstCauHoiCon = new List <EX_CauHoi>(); List <EX_CauTraLoi> lstCauTraLoi = new List <EX_CauTraLoi>(); foreach (var tblPanelCauHoi in _lstTablePanelCauHoi) { EditorControl txtCauHoi = tblPanelCauHoi.Controls[_nameTextNoiDungCauHoi] as EditorControl; CheckBox chkKhongDaoCH = tblPanelCauHoi.Controls[_nameCheckBox] as CheckBox; SimpleButton button = tblPanelCauHoi.Controls[_nameButtonXoa] as SimpleButton; lstCauHoiCon.Add(new EX_CauHoi() { NoiDung = txtCauHoi.Rtf, IsKhongDao = chkKhongDaoCH.Checked, IDEx = (int)button.Tag }); foreach (var tblPanelDapAn in _lstTablePanelCauTraLoi) { EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl; CheckBox chkKhongDaoCTL = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox; if (Convert.ToInt32(button.Tag) == Convert.ToInt32(txtDapAn.Tag)) { lstCauTraLoi.Add(new EX_CauTraLoi() { NoiDung = txtDapAn.Rtf, IsDung = true, IsKhongDao = chkKhongDaoCTL.Checked, IdEx = (int)txtDapAn.Tag }); break; } } } #region Save new câu hỏi chc.IDChuong = IdDanhMuc; chc.NoiDung = txtCtrlNoiDungCauHoi.Rtf; chc.IDLoaiCauHoi = IdLoaiCauHoi; chc.IsCauHoiCha = true; chc.NgayTao = DateTime.Now; chc.DoKho = IdMucDoNhanThuc; // Danh sách câu hỏi foreach (var exCauHoi in lstCauHoiCon) { exCauHoi.IDCauHoiCha = chc.Id; exCauHoi.IDChuong = chc.IDChuong; exCauHoi.DoKho = IdMucDoNhanThuc; exCauHoi.IDLoaiCauHoi = IdLoaiCauHoi; exCauHoi.DoKho = IdMucDoNhanThuc; exCauHoi.IsSuDung = true; exCauHoi.NgaySoan = DateTime.Now; // Add câu trả lời tương ứng với câu hỏi foreach (var exCauTraLoi in lstCauTraLoi) { if (exCauTraLoi.IdEx == exCauHoi.IDEx) { exCauTraLoi.IDCauHoi = (int)exCauHoi.Id; exCauHoi.ListCauTraLoi.Add(exCauTraLoi); break; } } chc.ListCauHoi.Add(exCauHoi); } #endregion } catch (Exception) { return(0); } return(_cauHoiBll.UpdateCauHoi(chc.Id, chc)); }
public int SaveUpdateCauHoi() { try { #region Update câu hỏi cha //cap nhat noi dung cau hoi if (CauHoiCurent == null) { return(0); } CauHoiCurent.IDChuong = IdDanhMuc; CauHoiCurent.NoiDung = txtCtrlNoiDungCauHoi.Rtf; CauHoiCurent.IDLoaiCauHoi = IdLoaiCauHoi; CauHoiCurent.IsCauHoiCha = true; CauHoiCurent.DoKho = IdMucDoNhanThuc; #endregion #region Update câu hỏi con và đáp án List <EX_CauHoi> lstCauHoi = new List <EX_CauHoi>(); List <EX_CauTraLoi> lstCauTraLoi = new List <EX_CauTraLoi>(); foreach (var tblPanelCauHoi in _lstTablePanelCauHoi) { SimpleButton btnXoa = tblPanelCauHoi.Controls[_nameButtonXoa] as SimpleButton; EditorControl txtCauHoi = tblPanelCauHoi.Controls[_nameTextNoiDungCauHoi] as EditorControl; CheckBox chkKhongDaoCH = tblPanelCauHoi.Controls[_nameCheckBox] as CheckBox; EX_CauHoi cauHoi = new EX_CauHoi(); cauHoi.IDCauHoiCha = CauHoiCurent.Id; cauHoi.IDEx = Convert.ToInt32(btnXoa.Tag); cauHoi.NoiDung = txtCauHoi.Rtf; cauHoi.IsKhongDao = chkKhongDaoCH.Checked; cauHoi.DoKho = IdMucDoNhanThuc; cauHoi.IDLoaiCauHoi = IdLoaiCauHoi; cauHoi.IDChuong = IdDanhMuc; lstCauHoi.Add(cauHoi); foreach (var tblPanelDapAn in _lstTablePanelCauTraLoi) { EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl; CheckBox chkKhongDaoCTL = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox; if (Convert.ToInt32(txtDapAn.Tag) == Convert.ToInt32(btnXoa.Tag)) { EX_CauTraLoi cauTraLoi = new EX_CauTraLoi(); cauTraLoi.IDCauHoi = cauHoi.IDEx; cauTraLoi.IdEx = cauHoi.IDEx; cauTraLoi.NoiDung = txtDapAn.Rtf; cauTraLoi.IsDung = true; cauTraLoi.IsKhongDao = chkKhongDaoCTL.Checked; lstCauTraLoi.Add(cauTraLoi); } } } // Cập nhật câu trả lời foreach (var exCauHoi in lstCauHoi) { var cauHoi = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.Id == exCauHoi.IDEx); if (cauHoi == null) { cauHoi = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.IDEx == exCauHoi.IDEx); } if (cauHoi != null) { cauHoi.DoKho = exCauHoi.DoKho; cauHoi.NoiDung = exCauHoi.NoiDung; cauHoi.IDChuong = exCauHoi.IDChuong; cauHoi.IsKhongDao = exCauHoi.IsKhongDao; cauHoi.IDCauHoiCha = exCauHoi.IDCauHoiCha; cauHoi.IDLoaiCauHoi = exCauHoi.IDLoaiCauHoi; foreach (var exCauTraLoi in lstCauTraLoi) { if (exCauTraLoi.IdEx == exCauHoi.IDEx) { var cauTraLoi = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.IDCauHoi == exCauTraLoi.IdEx); if (cauTraLoi == null) { cauTraLoi = cauHoi.ListCauTraLoi.FirstOrDefault(m => m.IdEx == exCauTraLoi.IdEx); } if (cauTraLoi != null) { cauTraLoi.NoiDung = exCauTraLoi.NoiDung; cauTraLoi.IsDung = exCauTraLoi.IsDung; cauTraLoi.IsKhongDao = exCauTraLoi.IsKhongDao; } } } } } // Xoa cau hoi foreach (int idCauHoiBiXoa in ListIdCauHoiBiXoa) { var cauHoiDel = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.Id == idCauHoiBiXoa); if (cauHoiDel != null) { cauHoiDel.IsDeleted = true; var cauTraLoiDel = cauHoiDel.ListCauTraLoi.FirstOrDefault(); if (cauTraLoiDel != null) { cauTraLoiDel.IsDeleted = true; } } } #endregion IsChanged = false; } catch (Exception) { return(0); } return(_cauHoiBll.UpdateCauHoi(CauHoiCurent.Id, CauHoiCurent)); }
private void ThemCauTraLoiGayNhieu(EX_CauTraLoi cauTraLoi = null) { //add more 2 new rows tblPanelMain2.RowCount += 2; int rowIndex = tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 63F)); tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 0)); // Đáp án gây nhiễu sẽ tính từ a,b,c,d Label lblCauHoi = new Label() { Width = 40, Dock = DockStyle.Right, Name = _nameLabelDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleCenter }; //Tag = 1 = true, Tag = 0 = false lblCauHoi.Text = Convert.ToChar(65 + _lstTablePanelGayNhieu.Count).ToString(); // Xóa câu trả lời var btnXoa = new DevExpress.XtraEditors.SimpleButton(); btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete; btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter; btnXoa.Dock = System.Windows.Forms.DockStyle.Left; btnXoa.Margin = new System.Windows.Forms.Padding(2); btnXoa.Name = _nameButtonXoa; btnXoa.Text = ""; btnXoa.Width = 40; btnXoa.ToolTip = "Xóa câu trả lời gây nhiễu"; btnXoa.Click += new EventHandler(XoaCauTraLoiGayNhieu); //EditorControl EditorControl txtCtrl = new EditorControl() { Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BorderStyle = BorderStyle.FixedSingle, Margin = new Padding(2) }; txtCtrl.GotFocus += TxtCtrlNoiDungCauHoi_GotFocus; // Table panel TableLayoutPanel tblPanelDapAnGayNhieu = new TableLayoutPanel(); tblPanelDapAnGayNhieu.Name = _nameTablePanelDapAn + rowIndex; tblPanelDapAnGayNhieu.ColumnCount = 3; tblPanelDapAnGayNhieu.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelDapAnGayNhieu.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelDapAnGayNhieu.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelDapAnGayNhieu.RowCount = 1; tblPanelDapAnGayNhieu.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelDapAnGayNhieu.Dock = DockStyle.Top; tblPanelDapAnGayNhieu.Controls.Add(lblCauHoi, 0, 0); tblPanelDapAnGayNhieu.Controls.Add(txtCtrl, 1, 0); tblPanelDapAnGayNhieu.Controls.Add(btnXoa, 2, 0); tblPanelMain2.Controls.Add(tblPanelDapAnGayNhieu, 0, rowIndex); //add panel to list _lstTablePanelGayNhieu.Add(tblPanelDapAnGayNhieu); if (cauTraLoi != null) { // Load noi dung dap an if (!string.IsNullOrEmpty(cauTraLoi.NoiDung)) { txtCtrl.Rtf = cauTraLoi.NoiDung; } // Gán id câu trả lời btnXoa.Tag = cauTraLoi.Id; tblPanelDapAnGayNhieu.Tag = cauTraLoi.IdEx; } CurrentControl = txtCtrl; }
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 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); }
public bool SaveUpdateCauHoi() { try { #region Update cau hoi //cap nhat noi dung cau hoi EX_CauHoi ch = _business.GetById(IdCauHoiCurent); if (ch == null) { return(false); } ch.DoKho = IdMucDoNhanThuc; ch.IDChuong = IdDanhMuc; ch.NoiDung = txtCtrlNoiDungCauHoi.Rtf; ch.IsKhongDao = ckbKhongDaoCauHoi.Checked; ch.TieuDeVeTrai = txtTieuDeVeTrai.Text.Trim(); ch.TieuDeVePhai = txtTieuDeVePhai.Text.Trim(); ch.IDLoaiCauHoi = IdLoaiCauHoi; //save lai _business.UpdateCauHoi(IdCauHoiCurent, ch); #endregion #region update dap an List <EX_CauTraLoi> lstCauTraLoi = new List <EX_CauTraLoi>(); foreach (var tblPanelDapAn in _lstTablePanelDapAnTrai) { SimpleButton btnXoa = tblPanelDapAn.Controls[_nameButtonXoa] as SimpleButton; EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl; CheckBox chkKhongDao = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox; EX_CauTraLoi cauTraLoi = new EX_CauTraLoi(); cauTraLoi.IDCauHoi = ch.Id; cauTraLoi.IdEx = Convert.ToInt32(btnXoa.Tag); cauTraLoi.NoiDung = txtDapAn.Rtf; cauTraLoi.IsDung = false; cauTraLoi.IsKhongDao = chkKhongDao.Checked; cauTraLoi.IsVeTrai = true; lstCauTraLoi.Add(cauTraLoi); } foreach (var tblPanelDapAn in _lstTablePanelDapAnPhai) { SimpleButton btnXoa = tblPanelDapAn.Controls[_nameButtonXoa] as SimpleButton; EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl; CheckBox chkKhongDao = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox; EX_CauTraLoi cauTraLoi = new EX_CauTraLoi(); cauTraLoi.IDCauHoi = ch.Id; cauTraLoi.IdEx = Convert.ToInt32(btnXoa.Tag); cauTraLoi.NoiDung = txtDapAn.Rtf; cauTraLoi.IsDung = false; cauTraLoi.IsKhongDao = chkKhongDao.Checked; cauTraLoi.IsVeTrai = false; lstCauTraLoi.Add(cauTraLoi); } // Cập nhật câu trả lời foreach (var esCauTraLoi in lstCauTraLoi) { if (esCauTraLoi.IdEx == 0) { _business.AddNewCauTraLoi(esCauTraLoi); } else { _business.UpdateCauTraLoi(esCauTraLoi.IdEx, esCauTraLoi); } } // Xoa cau tra loi foreach (int IdCauTraLoiBiXoa in ListIdCauHoiBiXoa) { _business.DeleteCauTraLoiById(IdCauTraLoiBiXoa); } #endregion IsChanged = false; } catch (Exception) { return(false); } return(true); }
public bool SaveCauHoiNew() { try { //get body string noiDungCauHoiEx = txtCtrlNoiDungCauHoi.Rtf; List <EX_CauTraLoi> lstCauTraLoi = new List <EX_CauTraLoi>(); string noiDungCauTraLoiEx = ""; 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; //get body noiDungCauTraLoiEx = txtDapAn.Rtf; lstCauTraLoi.Add(new EX_CauTraLoi() { NoiDung = noiDungCauTraLoiEx, IsDung = Convert.ToBoolean(btnDapAn.Tag), IsKhongDao = chkKhongDao.Checked }); } #region Kiểm tra trùng câu hỏi // Kiểm tra trùng đáp án if (lstCauTraLoi.GroupBy(o => o.NoiDung).ToList().Count < _lstTablePanelDapAn.Count && UICommon.ShowMsgQuestionString("Tồn tại đáp án trùng nhau. Bạn có muốn tiếp tục lưu không?") == DialogResult.No) { return(false); } #endregion #region Save new câu hỏi EX_CauHoi ch = new EX_CauHoi(); ch.IDChuong = IdDanhMuc; ch.DoKho = IdMucDoNhanThuc; ch.NoiDung = noiDungCauHoiEx; ch.IsSuDung = true; ch.IsKhongDao = ckbKhongDaoCauHoi.Checked; ch.IDLoaiCauHoi = IdLoaiCauHoi; ch.NgaySoan = DateTime.Now; _business.AddNewCauHoi(ch); // Danh sách câu trả lời foreach (var esCauTraLoi in lstCauTraLoi) { esCauTraLoi.IDCauHoi = ch.Id; _business.AddNewCauTraLoi(esCauTraLoi); } #endregion IsChanged = false; } catch (Exception ex) { return(false); } return(true); }
private void ThemCauTraLoi(EX_CauTraLoi cauTraLoi = null) { //add more 2 new rows tblPanelMain.RowCount += 2; int rowIndex = tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 63F)); tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 0)); //Câu trả lời Label lblDapAn = new Label() { Width = 90, Dock = DockStyle.Left, Name = _nameLableDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleLeft }; //Tag = 1 = true, Tag = 0 = false lblDapAn.Text = "Đáp án " + Convert.ToChar(65 + _lstTablePanelDapAn.Count).ToString(); // Đáp án đúng SimpleButton btnDapAn = new SimpleButton() { Width = 40, Dock = DockStyle.Right, Name = _nameButtonDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold) }; //Tag = 1 = true, Tag = 0 = false btnDapAn.Text = ""; btnDapAn.Image = ((System.Drawing.Image)(Properties.Resources.uncheck)); btnDapAn.Click += new EventHandler(btnDapAn_Click); // Xóa câu trả lời var btnXoa = new DevExpress.XtraEditors.SimpleButton(); btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete; btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter; btnXoa.Dock = System.Windows.Forms.DockStyle.Left; btnXoa.Margin = new System.Windows.Forms.Padding(2); btnXoa.Name = _nameButtonXoa; btnXoa.Text = ""; btnXoa.Width = 40; btnXoa.ToolTip = "Xóa câu trả lời"; btnXoa.Click += new EventHandler(XoaCauTraLoi); // Không đảo vị trí CheckBox chkKhongDao = new CheckBox() { Text = "Không đảo", Dock = DockStyle.Fill, Name = _nameCheckBox }; //EditorControl EditorControl txtCtrl = new EditorControl() { Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BorderStyle = BorderStyle.FixedSingle }; txtCtrl.Margin = new Padding(2); txtCtrl.GotFocus += txtNoiDungCauHoiCha_GotFocus; // Table panel TableLayoutPanel tblPanelDapAn = new TableLayoutPanel(); tblPanelDapAn.Name = _nameTablePanelDapAn + rowIndex; tblPanelDapAn.Tag = _lstTablePanelDapAn.Count + 1; tblPanelDapAn.ColumnCount = 5; tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 90F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 102F)); tblPanelDapAn.RowCount = 1; tblPanelDapAn.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelDapAn.Dock = DockStyle.Top; tblPanelDapAn.Controls.Add(lblDapAn, 0, 0); tblPanelDapAn.Controls.Add(txtCtrl, 1, 0); tblPanelDapAn.Controls.Add(btnDapAn, 2, 0); tblPanelDapAn.Controls.Add(btnXoa, 3, 0); tblPanelDapAn.Controls.Add(chkKhongDao, 4, 0); tblPanelMain.Controls.Add(tblPanelDapAn, 0, rowIndex); //add panel to list _lstTablePanelDapAn.Add(tblPanelDapAn); if (cauTraLoi != null) { tblPanelDapAn.Tag = cauTraLoi.IdEx; // Tô màu đáp án đúng if (cauTraLoi.IsDung ?? false) { btnDapAn.Image = ((System.Drawing.Image)(Properties.Resources.check)); btnDapAn.Tag = 1; } // Load noi dung dap an txtCtrl.Rtf = cauTraLoi.NoiDung; // Gán id câu trả lời btnXoa.Tag = cauTraLoi.Id; // Gán check không đảo chkKhongDao.Checked = cauTraLoi.IsKhongDao ?? false; } ResizeLayoutCauTraLoi(true); }
private void ThemCauTraLoi(EX_CauTraLoi cauTraLoi = null) { //add more 2 new rows tblPanelMain.RowCount += 2; int rowIndex = tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 83F)); tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 0)); // Đáp án đúng var text = Convert.ToChar(65 + _lstTablePanelDapAn.Count).ToString(); var btnDapAn = new DevExpress.XtraEditors.SimpleButton(); btnDapAn.Appearance.Font = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); btnDapAn.Appearance.Options.UseFont = true; btnDapAn.Dock = System.Windows.Forms.DockStyle.Right; btnDapAn.Margin = new System.Windows.Forms.Padding(2); btnDapAn.Name = _nameButtonDapAn; btnDapAn.Text = text; btnDapAn.Tag = 0; btnDapAn.ToolTip = "Đáp án " + text; btnDapAn.Click += new EventHandler(btnDapAn_Click); // Xóa câu trả lời var btnXoa = new DevExpress.XtraEditors.SimpleButton(); btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete; btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter; btnXoa.Dock = System.Windows.Forms.DockStyle.Left; btnXoa.Margin = new System.Windows.Forms.Padding(2); btnXoa.Name = _nameButtonXoa; btnXoa.Text = ""; btnXoa.Tag = 0; btnXoa.Width = 40; btnXoa.ToolTip = "Xóa câu trả lời"; btnXoa.Click += new EventHandler(XoaCauTraLoi); // Không đảo vị trí CheckBox chkKhongDao = new CheckBox() { Text = "Không đảo", Dock = DockStyle.Fill, Name = _nameCheckBox }; #region CauTraLoi var txtCtrl = new EditorControl(); txtCtrl.Dock = DockStyle.Fill; txtCtrl.Location = new Point(0, 0); txtCtrl.Name = _nameTextNoiDungDapAn; txtCtrl.Size = new Size(886, 127); txtCtrl.TabIndex = 0; txtCtrl.Margin = new Padding(2); txtCtrl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtCtrl.GotFocus += TxtCtrlNoiDungCauHoi_GotFocus; #endregion // Table panel TableLayoutPanel tblPanelDapAn = new TableLayoutPanel(); tblPanelDapAn.Name = _nameTablePanelDapAn + rowIndex; tblPanelDapAn.ColumnCount = 4; tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 102F)); tblPanelDapAn.RowCount = 1; tblPanelDapAn.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelDapAn.Dock = DockStyle.Top; tblPanelDapAn.Controls.Add(btnDapAn, 0, 0); tblPanelDapAn.Controls.Add(txtCtrl, 1, 0); tblPanelDapAn.Controls.Add(btnXoa, 2, 0); tblPanelDapAn.Controls.Add(chkKhongDao, 3, 0); tblPanelMain.Controls.Add(tblPanelDapAn, 0, rowIndex); //add panel to list _lstTablePanelDapAn.Add(tblPanelDapAn); if (cauTraLoi != null) { // Tô màu đáp án đúng if (cauTraLoi.IsDung ?? false) { btnDapAn.BackColor = Color.Red; btnDapAn.ForeColor = Color.Red; btnDapAn.Font = new Font(btnDapAn.Font.FontFamily, 11F, FontStyle.Bold); btnDapAn.Tag = 1; } // Load noi dung dap an txtCtrl.Rtf = cauTraLoi.NoiDung; // Gán id câu trả lời btnXoa.Tag = cauTraLoi.Id; // Gán check không đảo chkKhongDao.Checked = cauTraLoi.IsKhongDao ?? false; } ResizeLayoutCauTraLoi(true); }
public bool SaveUpdateCauHoi() { try { #region Update cau hoi //cap nhat noi dung cau hoi EX_CauHoi ch = _business.GetById(IdCauHoiCurent); if (ch == null) { return(false); } //get body ch.DoKho = IdMucDoNhanThuc; ch.IDChuong = IdDanhMuc; ch.NoiDung = txtCtrlNoiDungCauHoi.Rtf; ch.IsKhongDao = ckbKhongDaoCauHoi.Checked; ch.IDLoaiCauHoi = IdLoaiCauHoi; ch.IsSuDung = true; //save lai _business.UpdateCauHoi(IdCauHoiCurent, ch); #endregion #region update dap an List <EX_CauTraLoi> lstCauTraLoi = new List <EX_CauTraLoi>(); foreach (var tblPanelDapAn in _lstTablePanelDapAn) { SimpleButton btnXoa = tblPanelDapAn.Controls[_nameButtonXoa] as SimpleButton; EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungDapAn] as EditorControl; SimpleButton btnDapAn = tblPanelDapAn.Controls[_nameButtonDapAn] as SimpleButton; CheckBox chkKhongDao = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox; EX_CauTraLoi cauTraLoi = new EX_CauTraLoi(); cauTraLoi.IDCauHoi = ch.Id; cauTraLoi.IdEx = Convert.ToInt32(btnXoa.Tag); cauTraLoi.NoiDung = txtDapAn.Rtf; cauTraLoi.IsDung = Convert.ToBoolean(btnDapAn.Tag); cauTraLoi.IsKhongDao = chkKhongDao.Checked; lstCauTraLoi.Add(cauTraLoi); } #region Kiểm tra trùng câu hỏi // Kiểm tra trùng đáp án if (lstCauTraLoi.GroupBy(o => o.NoiDung).ToList().Count < _lstTablePanelDapAn.Count && UICommon.ShowMsgQuestionString("Tồn tại đáp án trùng nhau. Bạn có muốn tiếp tục lưu không?") == DialogResult.No) { return(false); } #endregion // Cập nhật câu trả lời foreach (var esCauTraLoi in lstCauTraLoi) { if (esCauTraLoi.IdEx == 0) { _business.AddNewCauTraLoi(esCauTraLoi); } else { _business.UpdateCauTraLoi(esCauTraLoi.IdEx, esCauTraLoi); } } // Xoa cau tra loi foreach (int IdCauTraLoiBiXoa in ListIdCauHoiBiXoa) { _business.DeleteCauTraLoiById(IdCauTraLoiBiXoa); } #endregion IsChanged = false; } catch (Exception) { return(false); } return(true); }
private void ThemCauTraLoiPhai(EX_CauTraLoi cauTraLoi = null) { //add more 2 new rows tblPanelMain2.RowCount += 2; int rowIndex = tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 63F)); tblPanelMain2.RowStyles.Add(new RowStyle(SizeType.Absolute, 0)); // Đáp án gây nhiễu sẽ tính từ a,b,c,d Label lblCauHoi = new Label() { Width = 40, Dock = DockStyle.Right, Name = _nameLableDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleLeft }; //Tag = 1 = true, Tag = 0 = false lblCauHoi.Text = (_lstTablePanelDapAnPhai.Count + 1).ToString(); // Xóa câu trả lời var btnXoa = new DevExpress.XtraEditors.SimpleButton(); btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete; btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter; btnXoa.Dock = System.Windows.Forms.DockStyle.Left; btnXoa.Margin = new System.Windows.Forms.Padding(2); btnXoa.Name = _nameButtonXoa; btnXoa.Text = ""; btnXoa.Width = 40; btnXoa.ToolTip = "Xóa câu trả lời"; btnXoa.Click += new EventHandler(XoaCauTraLoiPhai); // Không đảo vị trí CheckBox chkKhongDao = new CheckBox() { Text = "Không đảo", Dock = DockStyle.Fill, Name = _nameCheckBox }; //EditorControl EditorControl txtCtrl = new EditorControl() { Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BorderStyle = BorderStyle.FixedSingle }; txtCtrl.Margin = new Padding(2); txtCtrl.GotFocus += txtCtrlNoiDungCauHoi_GotFocus; // Table panel TableLayoutPanel tblPanelDapAnPhai = new TableLayoutPanel(); tblPanelDapAnPhai.Name = _nameTablePanelDapAn + rowIndex; tblPanelDapAnPhai.ColumnCount = 4; tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelDapAnPhai.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 102F)); tblPanelDapAnPhai.RowCount = 1; tblPanelDapAnPhai.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelDapAnPhai.Dock = DockStyle.Top; tblPanelDapAnPhai.Controls.Add(lblCauHoi, 0, 0); tblPanelDapAnPhai.Controls.Add(txtCtrl, 1, 0); tblPanelDapAnPhai.Controls.Add(btnXoa, 2, 0); tblPanelDapAnPhai.Controls.Add(chkKhongDao, 3, 0); tblPanelMain2.Controls.Add(tblPanelDapAnPhai, 0, rowIndex); //add panel to list _lstTablePanelDapAnPhai.Add(tblPanelDapAnPhai); if (cauTraLoi != null) { // Load noi dung dap an if (!string.IsNullOrEmpty(cauTraLoi.NoiDung)) { txtCtrl.Rtf = cauTraLoi.NoiDung; } // Gán id câu trả lời btnXoa.Tag = cauTraLoi.Id; // Gán check không đảo chkKhongDao.Checked = cauTraLoi.IsKhongDao ?? false; tblPanelDapAnPhai.Tag = cauTraLoi.IdEx; } ResizeLayoutCauTraLoiPhai(true); SetTextSoLuongCauHoi(); }
public int SaveUpdateCauHoi() { try { #region Update câu hỏi cha if (CauHoiCurent == null) { return(0); } //get body CauHoiCurent.IDChuong = IdDanhMuc; CauHoiCurent.NoiDung = txtCtrlNoiDungCauHoi.Rtf; CauHoiCurent.IDLoaiCauHoi = IdLoaiCauHoi; CauHoiCurent.IsCauHoiCha = true; CauHoiCurent.DoKho = IdMucDoNhanThuc; #endregion #region Update câu hỏi con List <EX_CauHoi> lstCauHoi = new List <EX_CauHoi>(); List <EX_CauTraLoi> lstCauTraLoi = new List <EX_CauTraLoi>(); foreach (var tblPanelDapAn in _lstTablePanelCauHoi) { SimpleButton btnXoa = tblPanelDapAn.Controls[_nameButtonXoa] as SimpleButton; EditorControl txtDapAn = tblPanelDapAn.Controls[_nameTextNoiDungCauHoi] as EditorControl; Label lblCauHoi = tblPanelDapAn.Controls[_nameLableCauHoi] as Label; CheckBox chkKhongDao = tblPanelDapAn.Controls[_nameCheckBox] as CheckBox; int idEX = Convert.ToInt32(btnXoa.Tag); EX_CauHoi cauHoi = new EX_CauHoi(); cauHoi.IDCauHoiCha = (int)CauHoiCurent.Id; cauHoi.IDEx = idEX; cauHoi.NoiDung = txtDapAn.Rtf; cauHoi.IsKhongDao = chkKhongDao.Checked; cauHoi.DoKho = IdMucDoNhanThuc; cauHoi.IDLoaiCauHoi = IdLoaiCauHoi; cauHoi.IDChuong = IdDanhMuc; lstCauHoi.Add(cauHoi); // Tìm câu trả lời var cauHoiTmp = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.IDEx == idEX); if (cauHoiTmp != null) { lstCauTraLoi.Add(cauHoiTmp.ListCauTraLoi.FirstOrDefault()); } } // Cập nhật câu hỏi foreach (var exCauHoi in lstCauHoi) { var cauHoi = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.Id == exCauHoi.IDEx); if (cauHoi == null) { cauHoi = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.IDEx == exCauHoi.IDEx); } if (cauHoi != null) { cauHoi.DoKho = exCauHoi.DoKho; cauHoi.NoiDung = exCauHoi.NoiDung; cauHoi.IDChuong = exCauHoi.IDChuong; cauHoi.IsKhongDao = exCauHoi.IsKhongDao; cauHoi.IDCauHoiCha = exCauHoi.IDCauHoiCha; cauHoi.IDLoaiCauHoi = exCauHoi.IDLoaiCauHoi; } } // Xoa cau hoi foreach (int IdCauHoiBiXoa in ListIdCauHoiBiXoa) { var cauHoiDel = CauHoiCurent.ListCauHoi.FirstOrDefault(m => m.Id == IdCauHoiBiXoa); if (cauHoiDel != null) { cauHoiDel.IsDeleted = true; var cauTraLoiDel = cauHoiDel.ListCauTraLoi.FirstOrDefault(); if (cauTraLoiDel != null) { cauTraLoiDel.IsDeleted = true; } } } #endregion IsChanged = false; } catch (Exception) { return(0); } return(_cauHoiBll.UpdateCauHoi(CauHoiCurent.Id, CauHoiCurent)); }
private void ThemCauTraLoi(EX_CauTraLoi cauTraLoi = null) { //add more 2 new rows tblPanelMain.RowCount += 2; int rowIndex = tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 63F)); tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 0)); // Đáp án đúng Label lblCauHoi = new Label() { Width = 40, Dock = DockStyle.Right, Name = _nameLabelDapAn, Tag = 0, Font = new Font(Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleCenter }; //Tag = 1 = true, Tag = 0 = false lblCauHoi.Text = (_isDienKhuyet ? ListCauHoi.Count : IdCauHoiCurent).ToString(); // Xóa câu trả lời var btnXoa = new DevExpress.XtraEditors.SimpleButton(); btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete; btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter; btnXoa.Dock = System.Windows.Forms.DockStyle.Left; btnXoa.Margin = new System.Windows.Forms.Padding(2); btnXoa.Name = _nameButtonXoa; btnXoa.Text = ""; btnXoa.Width = 40; btnXoa.ToolTip = "Xóa câu trả lời"; btnXoa.Click += new EventHandler(XoaCauTraLoi); //EditorControl EditorControl txtCtrl = new EditorControl() { Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BackColor = Color.White, BorderStyle = BorderStyle.FixedSingle, ReadOnly = true, Margin = new Padding(2) }; // Table panel TableLayoutPanel tblPanelDapAn = new TableLayoutPanel(); tblPanelDapAn.Name = _nameTablePanelDapAn + rowIndex; tblPanelDapAn.ColumnCount = 3; tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelDapAn.RowCount = 1; tblPanelDapAn.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelDapAn.Dock = DockStyle.Top; tblPanelDapAn.Controls.Add(lblCauHoi, 0, 0); tblPanelDapAn.Controls.Add(txtCtrl, 1, 0); tblPanelDapAn.Controls.Add(btnXoa, 2, 0); tblPanelMain.Controls.Add(tblPanelDapAn, 0, rowIndex); //add panel to list _lstTablePanelCauHoi.Add(tblPanelDapAn); if (cauTraLoi != null) { // Load noi dung dap an txtCtrl.Rtf = cauTraLoi.NoiDung; // Gán id câu trả lời btnXoa.Tag = cauTraLoi.Id; } CurrentControl = txtCtrl; CurrentControl.ReadOnly = true; }
private void ThemCauHoiCon(EX_CauHoi cauHoi = null) { //add more 2 new rows tblPanelMain.RowCount += 2; int rowIndex = tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 83F)); tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 0)); // Đáp án đúng Label lblCauHoi = new Label() { Width = 40, Dock = DockStyle.Right, Name = _nameLableCauHoi, Tag = 0, Font = new Font(this.Font.FontFamily, 11, FontStyle.Bold), TextAlign = ContentAlignment.MiddleCenter }; lblCauHoi.Text = (1 + _lstTablePanelCauHoi.Count).ToString(); // Xóa câu trả lời var btnXoa = new DevExpress.XtraEditors.SimpleButton(); btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete; btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter; btnXoa.Dock = System.Windows.Forms.DockStyle.Left; btnXoa.Margin = new System.Windows.Forms.Padding(2); btnXoa.Name = _nameButtonXoa; btnXoa.Text = ""; btnXoa.Width = 40; btnXoa.ToolTip = "Xóa câu trả lời"; btnXoa.Click += new EventHandler(XoaCauHoiCon); // Không đảo vị trí CheckBox chkKhongDao = new CheckBox() { Text = "Không đảo", Dock = DockStyle.Fill, Name = _nameCheckBox }; #region CauHoi var txtCtrl = new EditorControl(); txtCtrl.Dock = DockStyle.Fill; txtCtrl.Location = new Point(0, 0); txtCtrl.Name = _nameTextNoiDungCauHoi; txtCtrl.Size = new Size(886, 127); txtCtrl.TabIndex = 0; txtCtrl.Margin = new Padding(2); txtCtrl.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; txtCtrl.GotFocus += TxtCtrlNoiDungCauHoi_GotFocus; #endregion // Table panel TableLayoutPanel tblPanelCauHoi = new TableLayoutPanel(); tblPanelCauHoi.Name = _nameTablePanelCauHoi + rowIndex; tblPanelCauHoi.ColumnCount = 4; tblPanelCauHoi.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelCauHoi.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelCauHoi.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelCauHoi.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 102F)); tblPanelCauHoi.RowCount = 1; tblPanelCauHoi.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelCauHoi.Dock = DockStyle.Top; tblPanelCauHoi.Controls.Add(lblCauHoi, 0, 0); tblPanelCauHoi.Controls.Add(txtCtrl, 1, 0); tblPanelCauHoi.Controls.Add(btnXoa, 2, 0); tblPanelCauHoi.Controls.Add(chkKhongDao, 3, 0); tblPanelMain.Controls.Add(tblPanelCauHoi, 0, rowIndex); //add panel to list _lstTablePanelCauHoi.Add(tblPanelCauHoi); if (cauHoi != null) { // Load noi dung dap an txtCtrl.Rtf = cauHoi.NoiDung; // Gán id câu trả lời if (cauHoi.Id > 0) { btnXoa.Tag = cauHoi.Id; } else { btnXoa.Tag = cauHoi.IDEx; } // Gán check không đảo chkKhongDao.Checked = cauHoi.IsKhongDao ?? false; } ResizeLayoutCauTraLoi(true); }
private void ThemCauTraLoi(EX_CauTraLoi cauTraLoi = null) { int rowIndex = 0; if (_lstTablePanelDapAn.Count == 0 || _lstTablePanelDapAn.Count % 2 == 0) { tblPanelMain.RowCount += 2; rowIndex = tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 65F)); tblPanelMain.RowStyles.Add(new RowStyle(SizeType.Absolute, 10)); _rowInsert = rowIndex; } // Đáp án đúng var text = Convert.ToChar(65 + _lstTablePanelDapAn.Count).ToString(); var btnDapAn = new DevExpress.XtraEditors.SimpleButton(); btnDapAn.Appearance.Font = new System.Drawing.Font("Tahoma", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); btnDapAn.Appearance.Options.UseFont = true; btnDapAn.Dock = System.Windows.Forms.DockStyle.Right; btnDapAn.Margin = new System.Windows.Forms.Padding(2); btnDapAn.Name = _nameButtonDapAn; btnDapAn.Text = text; btnDapAn.Tag = 0; btnDapAn.ToolTip = "Đáp án " + text; btnDapAn.Click += new EventHandler(btnDapAn_Click); // Xóa câu trả lời var btnXoa = new DevExpress.XtraEditors.SimpleButton(); btnXoa.ImageOptions.Image = global::SimpleTest.Properties.Resources.tsbDelete; btnXoa.ImageOptions.ImageToTextAlignment = DevExpress.XtraEditors.ImageAlignToText.LeftCenter; btnXoa.Dock = System.Windows.Forms.DockStyle.Left; btnXoa.Margin = new System.Windows.Forms.Padding(2); btnXoa.Name = _nameButtonXoa; btnXoa.Text = ""; btnXoa.Width = 40; btnXoa.ToolTip = "Xóa câu trả lời"; btnXoa.Click += new EventHandler(XoaCauTraLoi); //EditorControl EditorControl txtCtrl = new EditorControl() { Dock = DockStyle.Fill, Name = _nameTextNoiDungDapAn, BorderStyle = BorderStyle.FixedSingle }; txtCtrl.ReadOnly = true; txtCtrl.BackColor = Color.White; txtCtrl.Margin = new Padding(2); txtCtrl.GotFocus += txtCtrlNoiDungCauHoi_GotFocus; // Table panel TableLayoutPanel tblPanelDapAn = new TableLayoutPanel(); tblPanelDapAn.Name = _nameTablePanelDapAn + rowIndex; tblPanelDapAn.ColumnCount = 3; tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 40F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); tblPanelDapAn.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 42F)); tblPanelDapAn.RowCount = 1; tblPanelDapAn.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); tblPanelDapAn.Dock = DockStyle.Top; tblPanelDapAn.Controls.Add(btnDapAn, 0, 0); tblPanelDapAn.Controls.Add(txtCtrl, 1, 0); tblPanelDapAn.Controls.Add(btnXoa, 2, 0); if ((_lstTablePanelDapAn.Count == 0 || _lstTablePanelDapAn.Count % 2 == 0)) { tblPanelMain.Controls.Add(tblPanelDapAn, 0, _rowInsert); } else { tblPanelMain.Controls.Add(tblPanelDapAn, 3, _rowInsert); } _rowInsert = rowIndex == 0 ? _rowInsert : rowIndex; //add panel to list _lstTablePanelDapAn.Add(tblPanelDapAn); if (cauTraLoi != null) { // Tô màu đáp án đúng if (cauTraLoi.IsDung ?? false) { btnDapAn.BackColor = Color.Red; btnDapAn.ForeColor = Color.Red; btnDapAn.Font = new Font(btnDapAn.Font.FontFamily, 11F, FontStyle.Bold); btnDapAn.Tag = 1; } // Load noi dung dap an txtCtrl.Text = UICommon.ConvertRftToText(cauTraLoi.NoiDung); } // Gán id câu trả lời txtCtrl.Tag = cauTraLoi.IdEx; btnDapAn.Tag = cauTraLoi.IdEx; btnXoa.Tag = cauTraLoi.IdEx; ResizeLayoutCauTraLoi(true); IsChanged = true; }