public bool SaveUpdateCauHoi()
        {
            try
            {
                var ch = new EX_CauHoi();
                ch.NoiDung      = txtNoiDungCauHoi.Rtf;
                ch.IDChuong     = IdDanhMuc;
                ch.IDLoaiCauHoi = IdLoaiCauHoi;
                ch.NgaySoan     = DateTime.Now;
                ch.DoKho        = IdMucDoNhanThuc;
                ch.IsKhongDao   = ckbKhongDaoCauHoi.Checked;
                ch.IsSuDung     = true;
                _business.UpdateCauHoi(IdCauHoiCurent, ch);

                var cauTraLoi = new EX_CauTraLoi();
                cauTraLoi.NoiDung    = txtNoiDungCauTraLoi.Rtf;
                cauTraLoi.IDCauHoi   = IdCauHoiCurent;
                cauTraLoi.IsKhongDao = true;
                cauTraLoi.NgayTao    = DateTime.Now;
                _business.UpdateCauTraLoi(IdCauTraLoi, cauTraLoi);
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
        public void CauHoiLoad()
        {
            ClearAllCauTraLoi();
            // Neu dang mode cap nhat thi tai noi dung cau hoi len form hien hanh
            if (Mode == ModeForm.CapNhat)
            {
                LoadCauHoiOld(CauHoiCurent);
                LoadCauHoiVaCauTraLoi(CauHoiCurent);
            }
            else if (Mode == ModeForm.ThemMoi)
            {
                CauHoiCurent = new EX_CauHoi();
                // Add 4 cau tra loi mac dinh
                for (int i = 1; i <= 4; i++)
                {
                    var cauHoi = new EX_CauHoi {
                        IDEx = i, NoiDung = ""
                    };
                    var cauTraLoi = new EX_CauTraLoi {
                        IdEx = i, NoiDung = "", IsKhongDao = false, IsDung = true
                    };
                    cauHoi.ListCauTraLoi.Add(cauTraLoi);
                    CauHoiCurent.ListCauHoi.Add(cauHoi);

                    ThemCauHoiCon(cauHoi);
                }
            }
        }
示例#3
0
 public void CauHoiLoad()
 {
     ClearAllCauTraLoi();
     ClearAllCauTraLoiPhai();
     // Neu dang mode cap nhat thi tai noi dung cau hoi len form hien hanh
     if (Mode == ModeForm.CapNhat)
     {
         LoadCauHoiOld(CauHoiCurent);
         LoadCauHoiVaCauTraLoi(CauHoiCurent);
     }
     else if (Mode == ModeForm.ThemMoi)
     {
         CauHoiCurent   = new EX_CauHoi();
         IdCauHoiCurent = 1;
         // Add 4 cau hỏi và câu trả lời mặc định
         for (int i = 1; i <= 4; i++)
         {
             var cauHoi = new EX_CauHoi {
                 IDEx = i, NoiDung = ""
             };
             var cauTraLoi = new EX_CauTraLoi {
                 IdEx = i, NoiDung = ""
             };
             cauHoi.ListCauTraLoi.Add(cauTraLoi);
             CauHoiCurent.ListCauHoi.Add(cauHoi);
             ThemCauHoiTrai(cauHoi);
             ThemCauTraLoiPhai(cauTraLoi);
         }
     }
 }
        private void BtnTaoSoCauHoi_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSoCauHoi.Text))
            {
                UICommon.ShowMsgInfoString("Bạn hãy nhập số câu hỏi cần tạo");
                return;
            }
            if (txtNoiDungCauHoiCha.IsEmpty)
            {
                UICommon.ShowMsgInfoString("Bạn hãy nhập nội dung câu hỏi cha");
                txtNoiDungCauHoiCha.Focus();
                return;
            }
            var soCau = Convert.ToInt32(txtSoCauHoi.Text);

            if (soCau < 1)
            {
                UICommon.ShowMsgInfoString("Số câu hỏi cần phải lớn hơn 0");
                return;
            }
            if (ListCauHoi != null && UICommon.ShowMsgQuestionString("Tạo mới danh sách câu hỏi toàn bộ dữ liệu câu hỏi bạn chưa lưu sẽ bị mất.\nBạn có muốn tiếp tục không?") != DialogResult.Yes)
            {
                return;
            }
            //Khởi tạo danh sách câu hỏi
            ListCauHoi = new List <EX_CauHoi>();
            var dataCboCauHoi = new List <DM_STT>();

            for (int i = 1; i <= soCau; i++)
            {
                EX_CauHoi cauHoi = new EX_CauHoi();
                cauHoi.IDEx       = i;
                cauHoi.NoiDung    = "";
                cauHoi.IDChuong   = IdDanhMuc;
                cauHoi.DoKho      = IdMucDoNhanThuc;
                cauHoi.IsSuDung   = true;
                cauHoi.IsKhongDao = ckbKhongDaoCauHoi.Checked;
                //Khởi tạo cau tra loi => cau hoi tu luan chi mot cau tra loi
                EX_CauTraLoi cauTraLoi = new EX_CauTraLoi();
                cauTraLoi.IdEx     = 1;
                cauTraLoi.IDCauHoi = cauHoi.Id;
                cauTraLoi.NoiDung  = "";
                cauHoi.ListCauTraLoi.Add(cauTraLoi);

                ListCauHoi.Add(cauHoi);
                dataCboCauHoi.Add(new DM_STT {
                    Id = cauHoi.IDEx, Ten = string.Format("Câu hỏi {0}", i)
                });
            }
            //Set data cauHoi vào trong cbo
            SetDataChonCauHoi(dataCboCauHoi);
            if (dataCboCauHoi.Count > 0)
            {
                IdCauHoiCurent           = 0;
                cboChonCauHoi.CategoryID = 1;
            }
            SetReadOnlyControl(false);
            btnTaoCauHoi.Enabled = false;
        }
        private void BtnTaoSoCauHoi_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSoCauHoi.Text))
            {
                UICommon.ShowMsgInfoString("Bạn hãy nhập số câu hỏi cần tạo");
                return;
            }
            if (txtNoiDungCauHoiCha.IsEmpty)
            {
                UICommon.ShowMsgInfoString("Bạn hãy nhập nội dung câu hỏi cha");
                txtNoiDungCauHoiCha.Focus();
                return;
            }
            var soCau = Convert.ToInt32(txtSoCauHoi.Text);

            if (soCau < 1)
            {
                UICommon.ShowMsgInfoString("Số câu hỏi cần phải lớn hơn 0");
                return;
            }
            //Khởi tạo danh sách câu hỏi
            ListCauHoi = new List <EX_CauHoi>();
            var dataCboCauHoi = new List <DM_STT>();

            for (int i = 1; i <= soCau; i++)
            {
                EX_CauHoi cauHoi = new EX_CauHoi();
                cauHoi.IDEx       = i;
                cauHoi.NoiDung    = "";
                cauHoi.IDChuong   = IdDanhMuc;
                cauHoi.DoKho      = IdMucDoNhanThuc;
                cauHoi.IsSuDung   = true;
                cauHoi.IsKhongDao = ckbKhongDaoCauHoi.Checked;

                //Khởi tạo danh sách câu trả lời
                for (int j = 1; j <= 4; j++)
                {
                    EX_CauTraLoi cauTraLoi = new EX_CauTraLoi();
                    cauTraLoi.IdEx     = j;
                    cauTraLoi.IDCauHoi = cauHoi.Id;
                    cauTraLoi.NoiDung  = "";
                    cauHoi.ListCauTraLoi.Add(cauTraLoi);
                }
                ListCauHoi.Add(cauHoi);
                dataCboCauHoi.Add(new DM_STT {
                    Id = cauHoi.IDEx, Ten = string.Format("Câu hỏi {0}", i)
                });
            }

            //Set data cauHoi vào trong cbo
            SetDataChonCauHoi(dataCboCauHoi);
            if (dataCboCauHoi.Count > 0)
            {
                IdCauHoiCurent           = 0;
                cboChonCauHoi.CategoryID = 1;
            }
            SetReadOnlyControl(false);
            btnTaoCauHoi.Enabled = false;
        }
示例#6
0
        private void btnThemCauHoi_Click(object sender, EventArgs e)
        {
            var maxIdEx = CauHoiCurent.ListCauHoi.Max(m => m.IDEx);
            var cauHoi  = new EX_CauHoi {
                IDEx = maxIdEx + 1, NoiDung = ""
            };
            var cauTraLoi = new EX_CauTraLoi {
                IdEx = maxIdEx + 1, NoiDung = ""
            };

            cauHoi.ListCauTraLoi.Add(cauTraLoi);
            CauHoiCurent.ListCauHoi.Add(cauHoi);

            ThemCauHoiTrai(cauHoi);
            ThemCauTraLoiPhai(cauTraLoi);
        }
        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 btnThemCauHoi_Click(object sender, EventArgs e)
        {
            var maxIdEx = CauHoiCurent.ListCauHoi.Max(m => m.IDEx);
            var cauHoi  = new EX_CauHoi {
                IDEx = maxIdEx + 1, NoiDung = ""
            };
            var cauTraLoi = new EX_CauTraLoi {
                IdEx = maxIdEx + 1, NoiDung = "", IsKhongDao = false, IsDung = true
            };

            cauHoi.ListCauTraLoi.Add(cauTraLoi);
            CauHoiCurent.ListCauHoi.Add(cauHoi);

            ThemCauHoiCon(cauHoi);

            if (Mode == ModeForm.CapNhat)
            {
                IsChanged = true;
            }
        }
示例#9
0
        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();
        }
示例#10
0
        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 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);
        }
示例#14
0
        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();
        }
示例#15
0
        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);
        }
        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;
        }