Ejemplo n.º 1
0
 public KhungLamBaiLuyenTuVaCau()
 {
     InitializeComponent();
     LoaiBai     = 0;
     tTuDuocChon = new NhomTuLTVC();
     //blnDuocDrop = false;
 }
Ejemplo n.º 2
0
 public KhungLamBaiLuyenTuVaCau(IContainer container)
 {
     container.Add(this);
     LoaiBai                = 0;
     tTuDuocChon            = new NhomTuLTVC();
     tTuDuocChon.DaDuocChon = false;
     MyCaret                = TinhTrangCaret.Show;
     InitializeComponent();
 }
Ejemplo n.º 3
0
        // Đọc nội dung trong file và phân tách
        public void DocDe(string strPath)
        {
            try
            {
                if (this.LoaiBai != (byte)LoaiBaiTap.GhiNho)
                {
                    RichTextBox rtfTam = new RichTextBox();
                    rtfTam.LoadFile(strPath);
                    int i = 0;
                    //if ((intLoaiBai & (byte)LoaiBaiTap.PhanLoaiTu) != 0)      // Phép AND bit
                    //{
                    //intLoaiBai = (byte)LoaiBaiTap.PhanLoaiTu;
                    rtfTam.SelectionLength = 1;
                    lstDanhSachTu          = new List <Tu>();
                    lstDanhSachCauHoi      = new List <CauHoi>();

                    i = 0;
                    while (i < rtfTam.Text.Length)
                    {
                        rtfTam.SelectionStart = i;
                        if (rtfTam.SelectionFont.Italic && rtfTam.SelectedText != " " &&
                            (intLoaiBai & (byte)LoaiBaiTap.PhanLoaiTu) != 0)
                        {
                            NhomTuLTVC ntTu = new NhomTuLTVC();
                            ntTu.ViTri = i;

                            do
                            {
                                ntTu.NoiDung += rtfTam.SelectedText;
                                rtfTam.SelectionStart++;
                            } while (rtfTam.SelectionFont.Italic && rtfTam.SelectedText != "," &&
                                     rtfTam.SelectedText != ".");

                            i += ntTu.NoiDung.Length;
                            lstDanhSachTu.Add(ntTu);
                        }
                        else if (rtfTam.SelectedText == "." && i < rtfTam.Text.Length - 5)
                        {
                            string strTam = rtfTam.Text.Substring(i, 4);
                            if (strTam == "....")
                            {
                                KhoangTrongLTVC ktKhoangTrong = new KhoangTrongLTVC();
                                ktKhoangTrong.ViTri = i;
                                //if ((this.LoaiBai & (byte)LoaiBaiTap.ThanhPhanCau) != 0)
                                //{
                                //    ktKhoangTrong.ViTri -= DanhSachCauHoi[0].ViTri;
                                //}

                                do
                                {
                                    ktKhoangTrong.NoiDung += rtfTam.SelectedText;
                                    rtfTam.SelectionStart++;
                                } while (rtfTam.SelectionStart < rtfTam.Text.Length && rtfTam.SelectedText == ".");

                                i += ktKhoangTrong.NoiDung.Length;
                                lstDanhSachTu.Add(ktKhoangTrong);
                            }
                        }
                        //else if (rtfTam.SelectedText == "<" && (this.LoaiBai & (byte)LoaiBaiTap.ThanhPhanCau) != 0)
                        //{
                        //    Cau cCau = new Cau();
                        //    cCau.ViTri = i;
                        //    string strSoThuTu = string.Empty;
                        //    int j = i + 1;
                        //    do
                        //    {
                        //        strSoThuTu += rtfTam.Text[j];
                        //        j++;
                        //    } while (rtfTam.Text[j] != '>');
                        //    cCau.SoThuTu = int.Parse(strSoThuTu);

                        //    do
                        //    {
                        //        cCau.NoiDung += rtfTam.SelectedText;
                        //        rtfTam.SelectionStart++;
                        //    } while (rtfTam.SelectedText != ".");

                        //    cCau.NoiDung += ".";
                        //    i += cCau.NoiDung.Length;
                        //    lstDanhSachTu.Add(cCau);
                        //}
                        //// Phần này dành cho việc chọn câu và phân tách chủ ngữ vị ngữ
                        //// Tuy nhiên chưa làm xong
                        //else if (rtfTam.SelectedText == "@" && (this.LoaiBai & (byte)LoaiBaiTap.ThanhPhanCau) != 0)
                        //{
                        //    CauHoi chCauHoi = new CauHoi();

                        //    chCauHoi.ViTri = i;
                        //    string strChuoiDinhDang = string.Empty;

                        //    // Xóa ký tự @
                        //    rtfTam.SelectedText = string.Empty;
                        //    rtfTam.SelectionLength = 1;
                        //    while (rtfTam.SelectedText != "#")
                        //    {
                        //        strChuoiDinhDang += rtfTam.SelectedText;
                        //        rtfTam.SelectedText = string.Empty;
                        //        rtfTam.SelectionLength = 1;
                        //    }
                        //    // Xóa nốt ký tự #
                        //    rtfTam.SelectedText = string.Empty;
                        //    rtfTam.SelectionLength = 1;

                        //    int intLoaiCauHoi = int.Parse(strChuoiDinhDang);
                        //    switch(intLoaiCauHoi)
                        //    {
                        //        case 1:
                        //            chCauHoi.Loai = LoaiCauHoi.TimCau;
                        //            break;
                        //        case 4:
                        //            chCauHoi.Loai = LoaiCauHoi.TracNghiem;
                        //            break;
                        //        case 3:
                        //            chCauHoi.Loai = LoaiCauHoi.TraLoiViet;
                        //            break;
                        //        case 2:
                        //            chCauHoi.Loai = LoaiCauHoi.XacDinhThanhPhan;
                        //            break;
                        //        default:
                        //            throw new Exception("Đề bài nhập liệu không đúng quy định");
                        //    }

                        //    while (rtfTam.SelectedText != "@" && rtfTam.SelectionStart < rtfTam.Text.Length)
                        //    {
                        //        if ((intLoaiCauHoi == 3 || intLoaiCauHoi == 4) && rtfTam.SelectedText == ".")
                        //        {
                        //            if (rtfTam.Text.Substring(rtfTam.SelectionStart, 4) == "....")
                        //            {
                        //                break;
                        //            }
                        //        }
                        //        chCauHoi.NoiDung += rtfTam.SelectedText;
                        //        rtfTam.SelectionStart++;
                        //    }
                        //    //chCauHoi.NoiDung += '\n';
                        //    chCauHoi.ViTriDuLieu = chCauHoi.NoiDung.Length;
                        //    i += chCauHoi.NoiDung.Length - 1;
                        //    DanhSachCauHoi.Add(chCauHoi);
                        //}

                        i++;
                    }

                    // Nếu là dạng bài thành phần câu thì xóa bỏ phần câu hỏi
                    // để chuyển sang text box đáp án
                    //if ((this.LoaiBai & (byte)LoaiBaiTap.ThanhPhanCau) != 0)
                    //{
                    //    if (DanhSachCauHoi.Count > 0)
                    //    {
                    //        rtfTam.SelectionStart = DanhSachCauHoi[0].ViTri;
                    //        rtfTam.SelectionLength = rtfTam.Text.Length - (DanhSachCauHoi[0].ViTri);
                    //        rtfTam.SelectedText = string.Empty;
                    //    }
                    //}
                    this.Rtf = rtfTam.Rtf;
                }
                else
                {
                    this.LoadFile(strPath);
                }
                if ((this.LoaiBai & ((byte)LoaiBaiTap.GhiNho
                                     | (byte)LoaiBaiTap.PhanLoaiTu)) != 0)
                {
                    MyCaret = TinhTrangCaret.Hide;
                }

                ttTinhTrangLamBai = TinhTrang.DangLamBai;
                //this.Invalidate();
            }
            catch (Exception Ex)
            {
                //DialogResult Result = MessageBox.Show("Đường dẫn đến tập tin " + strPath + " không đúng\r\nBạn có muốn tìm tập tin này?", "Thong bao", MessageBoxButtons.OKCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                //if (Result == DialogResult.OK)
                //{
                //    OpenFileDialog dlgOpenFile = new OpenFileDialog();
                //    dlgOpenFile.InitialDirectory = strPath;
                //    dlgOpenFile.Filter = "Tập tin bài giảng|*.rtf";
                //    DialogResult OpenResult = dlgOpenFile.ShowDialog();
                //    if (OpenResult == DialogResult.OK)
                //    {
                //        DocDe(dlgOpenFile.FileName);
                //    }
                //}
                MessageBox.Show(Ex.Message);
            }
        }