private void LoadNoiDungCauHoiCha(int idCauHoiCha)
        {
            //Chuyen id cau hoi va idcau tra li ve dang IDEx từ 1 đến... để xủ lý chung
            if (base.IdCauHoiCha > 0)
            {
                var cauHoiCha = _bus.GetById(base.IdCauHoiCha);
                if (cauHoiCha != null)
                {
                    txtNoiDungCauHoiCha.Rtf = cauHoiCha.NoiDung;
                    //Đổ dữ liệu cau hoi để xử lý
                    ListCauHoi = new List <EX_CauHoi>();
                    ListCauHoi = _bus.Context.EX_CauHoi.Where(mbox => mbox.IDCauHoiCha == cauHoiCha.Id).ToList();
                    var lstDataCbo = new List <DM_STT>();
                    int i          = 1;
                    foreach (var item in ListCauHoi)
                    {
                        var lstCauTL = _bus.GetCauTraLoi(item.Id);
                        int j        = 1;
                        foreach (var ctl in lstCauTL)
                        {
                            ctl.IdEx = j; j++;
                        }
                        item.ListCauTraLoi = lstCauTL;
                        item.IDEx          = i;
                        lstDataCbo.Add(new DM_STT {
                            Id = i, Ten = string.Format("Câu hỏi {0}", i)
                        });
                        i++;
                    }
                    cboChonCauHoi.EditValueChanged -= CboChonCauHoi_EditValueChanged;
                    SetDataChonCauHoi(lstDataCbo);

                    var cauHoiFirst = new EX_CauHoi();
                    if (IdCauHoiCurent > 0)
                    {
                        cauHoiFirst = ListCauHoi.FirstOrDefault(m => m.Id == IdCauHoiCurent);
                    }
                    else
                    {
                        cauHoiFirst = ListCauHoi.FirstOrDefault();
                    }

                    CauHoiCurent             = cauHoiFirst;
                    IdCauHoiCurent           = cauHoiFirst.IDEx;
                    cboChonCauHoi.CategoryID = IdCauHoiCurent;

                    txtSoCauHoi.Text                = ListCauHoi.Count.ToString();
                    txtSoCauHoi.Enabled             = false;
                    btnTaoCauHoi.Enabled            = false;
                    cboChonCauHoi.EditValueChanged += CboChonCauHoi_EditValueChanged;
                }
            }
        }
        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;

                //save lai
                _business.UpdateCauHoi(IdCauHoiCurent, ch);

                #endregion

                // Cập nhật câu trả lời
                foreach (var esCauTraLoi in CauHoiCurent.ListCauTraLoi)
                {
                    if (esCauTraLoi.Id == 0)
                    {
                        esCauTraLoi.IDCauHoi = CauHoiCurent.Id;
                        _business.AddNewCauTraLoi(esCauTraLoi);
                    }
                    else
                    {
                        _business.UpdateCauTraLoi(esCauTraLoi.Id, esCauTraLoi);
                    }
                }

                // Xoa cau tra loi
                foreach (int IdCauTraLoiBiXoa in ListIdCauHoiBiXoa)
                {
                    _business.DeleteCauTraLoiById(IdCauTraLoiBiXoa);
                }

                IsChanged = false;
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
 public void CauHoiLoad()
 {
     //Phan nay ap dung khi upadate
     if (Mode == ModeForm.CapNhat)
     {
         var cauHoi = _business.GetById(IdCauHoiCurent);
         if (cauHoi != null)
         {
             ckbKhongDaoCauHoi.Checked = cauHoi.IsKhongDao ?? false;
             txtNoiDungCauHoi.Rtf      = cauHoi.NoiDung;
             //Load cau tra loi => loai cau hoi tu luan chỉ có một câu trả lời
             var lstCauTraLoi = _business.GetCauTraLoi(cauHoi.Id);
             if (lstCauTraLoi.Count > 0)
             {
                 var cauTraLoi = lstCauTraLoi.FirstOrDefault();
                 //Set lai id len bien toan cuc
                 IdCauTraLoi             = cauTraLoi.Id;
                 txtNoiDungCauTraLoi.Rtf = cauTraLoi.NoiDung;
             }
         }
     }
 }
        private void LoadNoiDungCauHoiCha(long idCauHoiCha)
        {
            //Chuyen id cau hoi va idcau tra li ve dang IDEx từ 1 đến... để xủ lý chung
            if (IdCauHoiCha > 0)
            {
                var cauHoiCha = _business.GetById(IdCauHoiCha);
                if (cauHoiCha != null)
                {
                    txtCtrlNoiDungCauHoi.Rtf = cauHoiCha.NoiDung;
                    //Đổ dữ liệu cau hoi để xử lý
                    ListCauHoi = new List <EX_CauHoi>();
                    ListCauHoi = _business.Context.EX_CauHoi.Where(mbox => mbox.IDCauHoiCha == cauHoiCha.Id).ToList();
                    var lstDataCbo = new List <DM_STT>();
                    int i          = 1;
                    foreach (var item in ListCauHoi)
                    {
                        var lstCauTL = _business.GetCauTraLoi(item.Id);
                        int j        = 1;
                        foreach (var ctl in lstCauTL)
                        {
                            ctl.IdEx = j;
                            j++;
                        }
                        item.ListCauTraLoi = lstCauTL;
                        item.IDEx          = i;
                        lstDataCbo.Add(new DM_STT {
                            Id = i, Ten = string.Format("Câu hỏi {0}", i)
                        });
                        i++;
                    }
                    cboCauHoi.EditValueChanged -= CboCauHoi_EditValueChanged;

                    var lstItem = new List <LookUpEditItem>();
                    lstItem.Add(new LookUpEditItem {
                        ColumnName = "Id", ColumnCaption = "Id"
                    });
                    lstItem.Add(new LookUpEditItem {
                        ColumnName = "Ten", ColumnCaption = "Tên"
                    });
                    cboCauHoi.SetData(lstDataCbo, lstItem, "Ten", "Id");

                    var cauHoiFirst = new EX_CauHoi();
                    if (IdCauHoiCurent > 0)
                    {
                        cauHoiFirst = ListCauHoi.FirstOrDefault(m => m.Id == IdCauHoiCurent);
                    }
                    else
                    {
                        cauHoiFirst = ListCauHoi.FirstOrDefault();
                    }

                    CauHoiCurent         = cauHoiFirst;
                    IdCauHoiCurent       = cauHoiFirst.IDEx;
                    cboCauHoi.CategoryID = IdCauHoiCurent;

                    txtSoCauHoi.Text            = ListCauHoi.Count.ToString();
                    cboCauHoi.EditValueChanged += CboCauHoi_EditValueChanged;
                    //Day vao list match
                    _mathCollection = _parsing.ParseDienKhuyet2(txtCtrlNoiDungCauHoi.Text);
                }
            }
        }
        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);
        }
Beispiel #6
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);
        }