Пример #1
0
        private void btnWork_Click(object sender, EventArgs e)
        {
            if (txtDest.Text == "" || txtSrc.Text == "")
            {
                Core.Utility.Msg("Nguồn dữ liệu và nơi lưu kết quả cần chọn trước" + Environment.NewLine +
                                 "Nhấn nút duyệt thư mục để chọn.");
                return;
            }
            UseWaitCursor = true;
            Cursor        = Cursors.WaitCursor;
            // Hiện group Log
            groupLog.Location       = groupIllustrate.Location;
            groupIllustrate.Visible = false;
            groupLog.Visible        = true;
            // Lấy danh sách các tệp cần xử lý.
            Core.Automate automate = new Core.Automate();
            automate.CoreMsg += new Core.CoreMsgEventHandler(automate_CoreMsg);
            automate.Folder(txtSrc.Text);
            Core.Prepare.Clip[] c_types = new Core.Prepare.Clip[]
            {
                Core.Prepare.Clip.None,
                Core.Prepare.Clip.Horizon,
                Core.Prepare.Clip.Vertical
            };
            Core.Prepare.Clip clip    = c_types[cropBox.SelectedIndex];
            RotateFlipType[]  r_types = new RotateFlipType[] {
                RotateFlipType.RotateNoneFlipNone,
                RotateFlipType.Rotate90FlipNone,
                RotateFlipType.Rotate180FlipNone,
                RotateFlipType.Rotate270FlipNone
            };
            RotateFlipType rotate = r_types[rotateBox.SelectedIndex];

            if (automate.FileList == null)
            {
                Core.Utility.Error("Không có tệp ảnh quét nào được tìm thấy trong thư mục: \n"
                                   + txtSrc.Text);
                return;
            }
            for (int i = 0; i < automate.FileList.Length; i++)
            {
                Core.Prepare prepare = new Core.Prepare(automate.FileList[i], new Core.CoreMsgEventHandler(automate_CoreMsg));
                prepare.Perform(rotate, clip, txtDest.Text, automate.FileList[i]);
                automate.Inform(this, automate.FileList[i] + " xong" + Environment.NewLine);
                progressBar.Value = (int)Math.Ceiling((i + 1) * 100.0 / automate.FileList.Length);
            }
            UseWaitCursor = false;
            Cursor        = Cursors.Default;
            System.Diagnostics.Process.Start(txtDest.Text);
            this.Close();
        }
Пример #2
0
        private void toolBtnRecognize_Click(object sender, EventArgs e)
        {
            if (_isRecognized)
            {
                return;
            }
            if (Core.Ref.UniSuite.ActiveSuiteIndex == -1)
            {
                Core.Utility.Msg("Chưa có bộ đáp án nào được chọn");
                return;
            }
            _keys = Core.Ref.UniSuite.ActiveSuite;
            // Tạm dừng hoạt động, tránh người sử dụng bấm lung tung -> hỏng việc
            // : )

            toolBtnRecognize.Enabled = false;
            #region Xác định nguồn dữ liệu quuét
            Hashtable tag = (Hashtable)this.Tag;
            _automate          = new Core.Automate();
            _automate.CoreMsg += new Core.CoreMsgEventHandler(CoreMsg_Handler);
            switch ((Core.Automate.Source)tag[TagKeys.AutomateSource])
            {
            case Core.Automate.Source.Files:
                _files = (string[])tag[TagKeys.Files];
                break;

            case Core.Automate.Source.Folder:
                _automate.Folder((string)tag[TagKeys.Path]);
                _files = _automate.FileList;
                break;
            }
            if (_files == null)
            {
                _automate.Inform(_automate, "Không có tệp nào.");
                return;
            }
            UseWaitCursor = true;
            #endregion
            #region Kiểu cũ: dựa vào dropDown
            //if (tag[TagKeys.KeySuite] != null && Core.Ref.UniSuite[(int)tag[TagKeys.KeySuite]] != null)
            //    // Lấy thẳng từ tag của form trỏ đến Unisuite
            //    _keys = Core.Ref.UniSuite[(int)tag[TagKeys.KeySuite]] as Core.KeySuite;
            //else
            //{
            //    // Tìm nguồn suite thay thế
            //    DialogResult doAction = MessageBox.Show(string.Format(
            //        "Chưa có bộ đáp án nào được chuyển đến để chấm điểm.{0}" +
            //        "\tChọn Yes nếu muốn *tạo mới* một bộ đáp án.{0}" +
            //        "\tChọn No nếu muốn *mở hay nạp* một bộ đáp án có sẵn.{0}" +
            //        "\tChọn Cancel để nhận dạng bài làm thuần tuý Trong lúc đó bạn sẽ nhập bộ đáp án {0}" +
            //        "\tvà việc lên điểm diễn ra sau cùng.", Environment.NewLine),
            //        UI.Properties.Settings.Default.WindowCaption, MessageBoxButtons.YesNoCancel,
            //        MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            //    switch (doAction)
            //    {
            //        case DialogResult.Yes:
            //            #region Tạo mới một bộ đáp án và chuyển luôn vào của sổ hiện tại

            //                FormNewsuite fns = new FormNewsuite();
            //                fns.MdiParent = this.MdiParent;
            //                this.Enabled = false;
            //                fns.Show();
            //                fns.FormClosing += new FormClosingEventHandler(fns_FormClosing);
            //                return;


            //            #endregion
            //        case DialogResult.No:
            //            #region Mở một bộ đáp án có sẵn

            //            ToolStripMenuItem mnuFile = (this.ParentForm.MainMenuStrip.Items["mnuFile"]) as ToolStripMenuItem;
            //            ToolStripMenuItem mnuFileOpen = mnuFile.DropDownItems["mnuFileOpen"] as ToolStripMenuItem;
            //            if (mnuFileOpen == null)
            //            {
            //                Core.Utility.Error("Develop: Không tìm thấy chức năng Open trong menu File");
            //                return;
            //            }
            //            mnuFileOpen.PerformClick();
            //            if (mnuFileOpen.Tag == null)
            //            {
            //                Core.Utility.Msg("Quá trình chấm điểm dừng do không có tệp nào *được chọn*.");
            //            }
            //            else
            //            {
            //                _keys = Core.Ref.UniSuite[(int)mnuFileOpen.Tag] as Core.KeySuite;
            //            }
            //            break;
            //            #endregion
            //        case DialogResult.Cancel:
            //            #region Quét ngầm, tạo mới đáp án, lên điểm sau cùng.
            //            return;

            #endregion
            #region Chấm
            gridMark.Hide();
            _numberBlurSources = 0;
            UseWaitCursor      = true;
            int ri;// result index in Discovers
            for (int i = 0; i < _files.Length; i++)
            {
                txtLog.AppendText(string.Format("{1}#{0}{1}", i, Environment.NewLine));
                Core.Discover result = _automate.OneFileG2(_files[i], ref _keys);
                #region Chuyển kết quả vào grid và cập nhật trạng thái
                if (result != null)
                {
                    result.date = DateTime.Now;
                    ri          = this.Result.AddItem(result);
                    gridMark_Populate(result, ri, _files[i]);
                }
                progressBar.Value = (int)((i + 1) * 100.0f / _files.Length);
                #endregion
            }
            #endregion
            UseWaitCursor = false;
            Cursor        = Cursors.WaitCursor;
            System.Media.SystemSounds.Beep.Play();
            if (_numberBlurSources != 0)
            {
                Core.Utility.Error(string.Format("Có   {0}*   bài không nhận dạng được do:{1}" +
                                                 "1. Giấy bị mờ chặc bẩn (đặc biệt ở bốn góc) {1}" +
                                                 "2. Khi quét nghiêng quá mức, quăn mép; dữ liệu không đúng chuẩn. {1}" +
                                                 "3. Học sinh tô không đủ đậm, cần nhắc nhở. {1}" +
                                                 "4. Mã đề trong đáp án không đúng với mã đề trong bài làm.{1}{1}" +
                                                 "Những bài chắc chắn có lỗi được tô đỏ, hãy dùng nút 'Bài gốc' để xem lại{1}" +
                                                 "và hiệu chỉnh cho đúng. Nhấn vào tiêu đề cột điểm sẽ liệt kê chúng.",
                                                 _numberBlurSources,
                                                 Environment.NewLine));
            }
            UseWaitCursor            = false;
            Cursor                   = Cursors.Default;
            toolBtnRecognize.Enabled = true;
            toolBtnRecognize.Text    = "Chấm lại";
            _isRecognized            = true;
            toolBtnRecognize.Click  += new EventHandler(toolBtnRecaculate_Click);
            gridMark.Show();
        }