Пример #1
0
        private void btnScan_Click(object sender, EventArgs e)
        {
            try
            {
                if (TempData.isFirstScan == 0)
                {
                    TempData.isFirstScan = 1;
                    tw.Select();
                }
                if (!msgfilter)
                {
                    msgfilter = true;
                    Application.AddMessageFilter(this);
                }
                if (!tw.Acquire())
                {
                    MessageBox.Show("Операция отменена, \nлибо необходимо проверить \nподключение сканера", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Error);


                    //if (tw.getSRCT()== 0)
                    //{
                    //    MessageBox.Show("Не найдено подключенных сканеров", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //}
                    //this.Close();
                }
                //this.Activate();
            }
            catch
            {
                MessageBox.Show("Сканер недоступен");
                tw.CloseSrc();
                EndingScan();
            }
        }
Пример #2
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Not)
            {
                return(false);
            }
            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();
                picnumber++;
                for (int i = 0; i < pics.Count; i++)
                {
                    IntPtr img = (IntPtr)pics[i];
                    bmpptr = GlobalLock(img);
                    pixptr = GetPixelInfo(bmpptr);
                    tw.SaveDIBAs(bmpptr, pixptr, i + 1);
                }
                scannedcount          = 0;
                scannedcount          = this.NoofScannedfileCount();
                this.HeaderLabel.Text = scannedcount + " page scanned.";
                break;
            }
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Filtros del formulario para detectar los cambios de estado del escaneo
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                this.setImageFromScanner();
                break;
            }

            default:
                return(false);
            }
            return(true);
        }
Пример #4
0
        public bool PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();

                int picCount = pics.Count;
                if (picCount > 0)
                {
                    string fileName = "";
                    for (int i = 0; i < picCount; i++)
                    {
                        IntPtr      img = (IntPtr)pics[i];
                        GetGraphics get = new GetGraphics(img);
                        Bitmap      b   = get.GetImage();

                        StringBuilder sb = new StringBuilder();
                        sb.Append("IMG");
                        sb.Append((i + 1).ToString("0000"));
                        sb.Append(DateTime.UtcNow.ToString("_yyyyMMddHHmmss"));
                        fileName = string.Format(SavePath, sb);

                        b.Save(fileName);
                        listPicture.Items.Add(fileName);

                        if (i == picCount - 1)
                        {
                            pictureBox1.Image = b;
                        }
                    }
                }
                break;
            }
            }

            return(true);
        }
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            IntPtr                  img;
            TwainCommand            cmd;
            bool                    ReturnValue = false;
            string                  TempDirPdf  = string.Empty;
            BODigitalizarDocumentos objBoDigitalizarDocumentos = null;

            try
            {
                cmd = objTwain.PassMessage(ref m);

                if (cmd == TwainCommand.Null)
                {
                    MessageBox.Show("Talvez o Scanner esteja DESLIGADO, DESPLUGADO ou DESCONECTADO, por favor verifique !!!", Global.CODAPP + " - " + Global.DESCRICAOAPP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Cursor.Current         = Cursors.Default;
                    btnDigitalizar.Enabled = true;
                    EndingScan();
                    objTwain.CloseSrc();
                    return(false);
                }

                if (cmd == TwainCommand.Not)
                {
                    return(false);
                }

                switch (cmd)
                {
                case TwainCommand.CloseRequest:
                {
                    EndingScan();
                    objTwain.CloseSrc();
                    break;
                }

                case TwainCommand.CloseOk:
                {
                    EndingScan();
                    objTwain.CloseSrc();
                    break;
                }

                case TwainCommand.DeviceEvent:
                {
                    break;
                }

                case TwainCommand.TransferReady:
                {
                    ArrayList pics         = objTwain.TransferPictures();
                    string    FileNameTemp = string.Empty;
                    string    DirTemp      = string.Empty;
                    EndingScan();
                    objTwain.CloseSrc();

                    for (int i = 0; i < lstDocumentosDigitalisados.SelectedItems.Count; i++)
                    {
                        FileNameTemp = lstDocumentosDigitalisados.SelectedItems[i].SubItems[1].Text;
                        DirTemp      = lstDocumentosDigitalisados.SelectedItems[i].SubItems[2].Text;
                    }

                    for (int i = 0; i < pics.Count; i++)
                    {
                        img = (IntPtr)pics[i];
                        RImageScan.GdiPlusLib.Gdip.SaveImage(i.ToString() +
                                                             System.Configuration.ConfigurationSettings.AppSettings["EXTIMG"].ToString().ToLower(),
                                                             GlobalLock(img), GetPixelInfo(GlobalLock(img)), FileNameTemp);
                        GdipDisposeImage(img);
                        GlobalFree(img);
                    }
                    //Generate the PDF file

                    if (pics.Count != 0)
                    {
                        if (MessageBox.Show("Você deseja realmente [ SALVAR ] o arquivo digitalizado?", "SALVAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        {
                            RImageScan.RImageToPdf objPDF = new RImageScan.RImageToPdf();
                            objPDF.ExportToPDF(FileNameTemp, false);

                            //Save file to System DataBase.
                            AtualizarDigitralizacao();
                            btnDigitalizar.Enabled = true;
                        }
                        else
                        {
                            MessageBox.Show("Documento não foi gravado!!!", Global.CODAPP + " - " + Global.DESCRICAOAPP, MessageBoxButtons.OK, MessageBoxIcon.Information);

                            btnDigitalizar.Enabled = true;
                        }
                    }
                    break;
                }
                }
                ReturnValue    = true;
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {
                Cursor.Current         = Cursors.Default;
                btnDigitalizar.Enabled = true;
                EndingScan();
                MessageBox.Show("ERROR : " + ex.ToString());
            }

            return(ReturnValue);
        }
Пример #6
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            IntPtr       img;
            TwainCommand cmd;
            bool         ReturnValue = false;
            string       TempDirPdf  = string.Empty;

            gObjLog.Inserir("Lendo eventos de Imessage Filter --> " + m.ToString(), TipoLog.AVISO);
            try
            {
                Cursor = Cursors.WaitCursor;
                cmd    = objTwain.PassMessage(ref m);

                if (cmd == TwainCommand.Null)
                {
                    MessageBox.Show("Talvez o Scanner esteja DESLIGADO, DESPLUGADO ou DESCONECTADO, por favor verifique !!!", Global.CODAPP + " - " + Global.DESCRICAOAPP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Cursor.Current         = Cursors.Default;
                    btnDigitalizar.Enabled = true;
                    EndingScan();
                    objTwain.CloseSrc();
                    return(false);
                }

                if (cmd == TwainCommand.Not)
                {
                    return(false);
                }

                switch (cmd)
                {
                case TwainCommand.CloseRequest:
                {
                    EndingScan();
                    objTwain.CloseSrc();
                    break;
                }

                case TwainCommand.CloseOk:
                {
                    EndingScan();
                    objTwain.CloseSrc();
                    break;
                }

                case TwainCommand.DeviceEvent:
                {
                    break;
                }

                case TwainCommand.TransferReady:
                {
                    TempDirPdf = System.Configuration.ConfigurationSettings.AppSettings["DIRPDF"].ToString();
                    ArrayList pics = objTwain.TransferPictures();

                    EndingScan();
                    objTwain.CloseSrc();

                    for (int i = 0; i < pics.Count; i++)
                    {
                        img = (IntPtr)pics[i];
                        RImageScan.GdiPlusLib.Gdip.SaveImage(i.ToString() +
                                                             System.Configuration.ConfigurationSettings.AppSettings["EXTIMG"].ToString().ToLower(),
                                                             GlobalLock(img), GetPixelInfo(GlobalLock(img)), lblNomeArquivo.Text);
                        GdipDisposeImage(img);
                        GlobalFree(img);
                    }
                    //Generate the PDF file
                    gObjLog.Inserir("Escaneou as imagens para o diretório temporario ", TipoLog.AVISO);

                    if (pics.Count != 0)
                    {
                        if (MessageBox.Show("Você deseja realmente [ SALVAR ] o arquivo digitalizado?",
                                            "SALVAR", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                        {
                            string diretorioTemporario = TempDirPdf + lblNomeArquivo.Text;
                            string pathDiretorio       = lblPathDiretorio.Text;
                            string nomearquivo         = lblNomeArquivo.Text;
                            double id_documento        = (double)cmbDocumento.SelectedValue;
                            double id_processo         = objCliente.ObjProcesso[0].IdProcesso;
                            double id_cliente          = objCliente.IdCliente;


                            RImageScan.RImageToPdf objPDF = new RImageScan.RImageToPdf();
                            objPDF.ExportToPDF(lblNomeArquivo.Text, chkVisualizacao.Checked);
                            gObjLog.Inserir("Escaneou as imagens para o diretório temporario ", TipoLog.AVISO);

                            //Save file to System DataBase.

                            //objBoDigitalizarDocumentos = new BODigitalizarDocumentos();

                            gObjLog.Inserir("Salvando os Informações no banco de dados.", TipoLog.AVISO);

                            // Se for dados cadastrais salvo as informações do documento digitalizado na tabela de dados cadastrais
                            // Se o documento digitalizado for de processos salvo na tabela de documentos_digitais.


                            String nomePastaDadosCadastraisemParametros =
                                System.Configuration.ConfigurationManager.AppSettings["NOMEPASTADADOSCADASTRAIS"].ToString();

                            if (nomePastaDadosCadastraisemParametros.Equals(cmbTipoDocumento.Text) &&
                                cmbDocumento.SelectedItem != null)
                            {
                                digitalizarDocumentosDeDadosCadastrais(diretorioTemporario,
                                                                       pathDiretorio,
                                                                       nomearquivo,
                                                                       id_documento,
                                                                       id_cliente);
                            }
                            else if (!nomePastaDadosCadastraisemParametros.Equals(cmbTipoDocumento.Text) && cmbDocumento.Text != "")
                            {
                                digitalizarDocumentosDeProcessos(diretorioTemporario,
                                                                 pathDiretorio,
                                                                 nomearquivo,
                                                                 id_documento,
                                                                 id_processo);
                            }

                            MessageBox.Show("Documento Digitalizado com SUCESSO!!!",
                                            Global.CODAPP + " - " + Global.DESCRICAOAPP,
                                            MessageBoxButtons.OK, MessageBoxIcon.Information);

                            btnDigitalizar.Enabled = true;
                            gObjLog.Inserir("Documento foi digitalizado com sucesso!!!.", TipoLog.AVISO);
                        }
                        else
                        {
                            MessageBox.Show("Documento não foi gravado!!!", Global.CODAPP + " - " + Global.DESCRICAOAPP, MessageBoxButtons.OK, MessageBoxIcon.Information);

                            btnDigitalizar.Enabled = true;
                        }
                    }
                    break;
                }
                }
                ReturnValue    = true;
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {
                gObjLog.Inserir("ERROR: " + ex.ToString(), TipoLog.ERRO);
                Cursor.Current         = Cursors.Default;
                btnDigitalizar.Enabled = true;
                EndingScan();
                MessageBox.Show("ERROR : " + ex.ToString());
            }
            finally {
                Cursor = Cursors.Default;
            }

            return(ReturnValue);
        }
Пример #7
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Null)
            {
                EndingScan();
                tw.CloseSrc();
                return(false);
            }
            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();
                picnumber++;
                if (pics.Count > 0)
                {
                }
                for (int i = 0; i < pics.Count; i++)
                {
                    IntPtr img = (IntPtr)pics[i];


                    dibhand = img;
                    bmpptr  = GlobalLock(dibhand);
                    pixptr  = GetPixelInfo(bmpptr);
                    //Bitmap map = new Bitmap(130, 170);
                    Bitmap   map = new Bitmap(bmprect.Width, bmprect.Height);
                    Graphics scannedImageGraphics = Graphics.FromImage(map);

                    IntPtr hdc = scannedImageGraphics.GetHdc();
                    // IntPtr hdc = map.GetHbitmap();
                    SetDIBitsToDevice(hdc, 0, 0, bmprect.Width, bmprect.Height,
                                      0, 0, 0, bmprect.Height, pixptr, bmpptr, 0);
                    scannedImageGraphics.ReleaseHdc(hdc);

                    // map.Save("c:\\tempgetimageformdevice.bmp");
                    // this.pictureBox1.Image = map;
                    if (set.CapWidth == set.DevWidth && set.CapHeight == set.DevHeight)
                    {
                        this.picPic.Image = map;
                        this.SavePic();
                    }
                    else
                    {
                        CaptureImage form = new CaptureImage(map, this.picPic, set);
                        form.ShowDialog();
                        this.SavePic();
                    }



                    /*
                     * //333,266
                     * Rectangle cltrect = ClientRectangle;
                     * Point loc = this.pictureBox1.Location;
                     * //100 128
                     * Size size=this.pictureBox1.Size;
                     * //Point scrol = AutoScrollPosition;
                     *
                     * // Rectangle realrect = this.pictureBox1.Location;
                     * // realrect.X -= scrol.X;
                     * //  realrect.Y -= scrol.Y;
                     *
                     * //240
                     * int bot = bmprect.Height;
                     *
                     *
                     * dibhand = img;
                     * bmpptr = GlobalLock(dibhand);
                     * pixptr = GetPixelInfo(bmpptr);
                     * IntPtr hdc = this.pictureBox1.CreateGraphics().GetHdc();
                     * SetDIBitsToDevice(hdc, 0, 0, bmprect.Width, bmprect.Height,
                     *      0, 0, 0, bmprect.Height, pixptr, bmpptr, 0);
                     * //this.pictureBox1.CreateGraphics().ReleaseHdc(hdc);
                     * // Image img = (Image)pics[i];
                     * // PicForm newpic = new PicForm(img);
                     * // newpic.MdiParent = this;
                     * //this.pictureBox1.Image = img;
                     * int picnum = i + 1;
                     *
                     *
                     * // newpic.Text = "ScanPass" + picnumber.ToString() + "_Pic" + picnum.ToString();
                     * //  newpic.Show();
                     */
                }
                break;
            }
            }

            return(true);
        }
Пример #8
0
 //============================================================================
 // NOMBRE: CerrarConexion
 //
 // DESCRIPCIÓN: Cierra la conexión con el escáner (al terminar una transacción).
 //
 // ARGUMENTOS: -
 //
 // SALIDA: -
 //============================================================================
 public void CerrarConexion()
 {
     escaner.CloseSrc();
 }
Пример #9
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                logger.Error("BaseScan.(DeviceEvent)裝置錯誤");
                //Console.WriteLine("DeviceEvent");
                break;
            }

            case TwainCommand.Null:
            {
                //logger.Error("BaseScan.(null) 正常等待");

                break;
            }

            case TwainCommand.Failure:
            {
                MessageBox.Show("設置錯誤");
                logger.Error("BaseScan.設置錯誤");
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.TransferReady:
            {
                #region 立即存檔
                logger.Info("BaseScan.1.已取得圖檔,存入指定路徑");
                DJScanCompletList = tw.TransferePicturesSaveImmediate(DJScanPath, DJScanTitle);
                EndingScan();
                tw.CloseSrc();
                #endregion

                switch (DJImageFormat)
                {
                case "jpg":
                    logger.Info("BaseScan.2.jpg 轉換");
                    DJScanCompletList = DJImageProcess.TransBmpToJpg(DJScanCompletList, DJJpgEncodeLevel, DJImgEncrypt);
                    logger.Info("BaseScan.2.jpg 轉換 ok");
                    break;

                default:
                    break;
                }

                logger.Info("BaseScan.3.21.送出完成委派");
                OnScanComplete(this);
                logger.Info("BaseScan.3.3.送完完成委派");
                break;
            }

            default:
                Console.WriteLine(cmd.ToString());
                break;
            }

            return(true);
        }
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            IntPtr                  img;
            TwainCommand            cmd;
            bool                    ReturnValue = false;
            string                  TempDirPdf  = string.Empty;
            BODigitalizarDocumentos objBoDigitalizarDocumentos = null;

            gObjLog.Inserir("Lendo eventos de Imessage Filter --> " + m.ToString(), TipoLog.AVISO);
            try
            {
                cmd = objTwain.PassMessage(ref m);

                if (cmd == TwainCommand.Null)
                {
                    MessageBox.Show("Talvez o Scanner esteja DESLIGADO, DESPLUGADO ou DESCONECTADO, por favor verifique !!!", Global.CODAPP + " - " + Global.DESCRICAOAPP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Cursor.Current         = Cursors.Default;
                    btnDigitalizar.Enabled = true;
                    EndingScan();
                    objTwain.CloseSrc();
                    return(false);
                }

                if (cmd == TwainCommand.Not)
                {
                    return(false);
                }

                switch (cmd)
                {
                case TwainCommand.CloseRequest:
                {
                    EndingScan();
                    objTwain.CloseSrc();
                    break;
                }

                case TwainCommand.CloseOk:
                {
                    EndingScan();
                    objTwain.CloseSrc();
                    break;
                }

                case TwainCommand.DeviceEvent:
                {
                    break;
                }

                case TwainCommand.TransferReady:
                {
                    TempDirPdf = System.Configuration.ConfigurationSettings.AppSettings["DIRPDF"].ToString();
                    ArrayList pics = objTwain.TransferPictures();

                    EndingScan();
                    objTwain.CloseSrc();

                    for (int i = 0; i < pics.Count; i++)
                    {
                        img = (IntPtr)pics[i];
                        //RImageScan.GdiPlusLib.Gdip.SaveImage(i.ToString() +
                        //                    System.Configuration.ConfigurationSettings.AppSettings["EXTIMG"].ToString().ToLower(),
                        //                    GlobalLock(img), GetPixelInfo(GlobalLock(img)),lblNomeArquivo.Text);
                        GdipDisposeImage(img);
                        GlobalFree(img);
                    }
                    //Generate the PDF file
                    gObjLog.Inserir("Escaneou as imagens para o diretório temporario ", TipoLog.AVISO);

                    if (pics.Count != 0)
                    {
                        RImageScan.RImageToPdf objPDF = new RImageScan.RImageToPdf();
                        objPDF.ExportToPDF(lblNomeArquivo.Text, chkVisualizacao.Checked);
                        gObjLog.Inserir("Escaneou as imagens para o diretório temporario ", TipoLog.AVISO);

                        //Save file to System DataBase.

                        objBoDigitalizarDocumentos = new BODigitalizarDocumentos();

                        gObjLog.Inserir("Salvando os Informações no banco de dados.", TipoLog.AVISO);

                        if (objBoDigitalizarDocumentos.boDigitalizarDocumentos(TempDirPdf + lblNomeArquivo.Text,
                                                                               lblPathDiretorio.Text,
                                                                               lblNomeArquivo.Text,
                                                                               (double)cmbDocumento.SelectedValue,
                                                                               objCliente.ObjProcesso[0].IdProcesso))
                        {
                            MessageBox.Show("Documento Digitalizado com SUCESSO!!!", Global.CODAPP + " - " + Global.DESCRICAOAPP, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            btnDigitalizar.Enabled = true;
                            gObjLog.Inserir("Documento foi digitalizado com sucesso!!!.", TipoLog.AVISO);
                        }
                    }
                    break;
                }
                }
                ReturnValue    = true;
                Cursor.Current = Cursors.Default;
            }
            catch (Exception ex)
            {
                gObjLog.Inserir("ERROR: " + ex.ToString(), TipoLog.ERRO);
                Cursor.Current         = Cursors.Default;
                btnDigitalizar.Enabled = true;
                EndingScan();
                MessageBox.Show("ERROR : " + ex.ToString());
            }

            return(ReturnValue);
        }