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);
        }
        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;
        }
示例#3
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);
        }
        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);
        }