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 BtnDienKhuyet_Click(object sender, EventArgs e) { txtCtrlNoiDungCauHoi.Focus(); //Them vao cau tra loi if (txtCtrlNoiDungCauHoi.SelectionLength == 0) { UICommon.ShowMsgWarningString("Bạn chưa chọn nội dung cần điền khuyết"); return; } var textStart = txtCtrlNoiDungCauHoi.SelectionStart; //Kiem tra vi tri dien khuyet if (_mathCollection != null) { for (int i = 0; i < _mathCollection.Count; i++) { var viTriNext = _mathCollection[i].Index + _mathCollection[i].Length; if (textStart >= _mathCollection[i].Index && textStart <= viTriNext) { UICommon.ShowMsgWarningString("Vị trí điền khuyết không hợp lệ!"); if (txtCtrlNoiDungCauHoi.SelectionLength == 0) { txtCtrlNoiDungCauHoi.Undo(); } return; } } } var tmp = txtCtrlNoiDungCauHoi.SelectedRtf; //Buoc 2: Add cau tra loi dau tien cho cau hoi hien tai => vi trí diền khuyết if (txtCtrlNoiDungCauHoi.SelectionLength != 0) { //Gan du lieu toan cuc và cboCauHoi CauHoiCurent = new EX_CauHoi { IDEx = ListCauHoi.Count + 1, DoKho = IdMucDoNhanThuc }; //Buoc 1 ListCauHoi.Add(CauHoiCurent); CauHoiCurent.ListCauTraLoi.Add(new EX_CauTraLoi { IdEx = 1, NoiDung = txtCtrlNoiDungCauHoi.SelectedRtf, IndexEx = textStart }); var textStt = string.Format("({0})_____", ListCauHoi.Count); PasteClipboard: { try { Clipboard.SetText(textStt); } catch (Exception) { goto PasteClipboard; } } txtCtrlNoiDungCauHoi.Paste(); } else { UICommon.ShowMsgWarningString("Nội dung chọn không hợp lệ"); if (txtCtrlNoiDungCauHoi.SelectionLength == 0) { txtCtrlNoiDungCauHoi.Undo(); } return; } //Buoc 3: do du lieu len cbo if (ListCauHoi.Count > 0) { SetDataToCboCauHoi(); } //Buoc 4 => changCategoryID _isDienKhuyet = true; cboCauHoi.CategoryID = ListCauHoi.Count; IdCauHoiCurent = (int)cboCauHoi.CategoryID; //Ve lai cau hoi => phan ben trai ClearAllCauTraLoi(); ClearAllCauTraLoiGayNhieu(); ThemCauTraLoi(); CurrentControl.Focus(); CurrentControl.Rtf = tmp; CurrentControl.ReadOnly = true; // Nhận dạng lại vị trí _mathCollection = _parsing.ParseDienKhuyet2(txtCtrlNoiDungCauHoi.Text); }