/// <summary>
        /// Metodo para ler e processar o arquivo de retorno
        /// </summary>
        /// <param name="b"><see cref="Model.Banco"/> vinculado ao arquivo</param>
        /// <param name="s">stream do arquivo a ser lido</param>
        /// <param name="tipo">informa o tipo do cnab a ser lido</param>
        /// <returns></returns>
        public bool lerArquivoRetorno(Model.Banco b, Stream s, TipoArquivo tipo)
        {
            try
            {
                IArquivoRetorno cnab  = null;
                var             banco = new BoletoNet.Banco(b.Numero);

                switch (tipo)
                {
                case TipoArquivo.CNAB400:
                    cnab = new ArquivoRetornoCNAB400();
                    cnab.LerArquivoRetorno(banco, s);
                    return(salvarArquivo400(b, (ArquivoRetornoCNAB400)cnab, s));

                    break;

                case TipoArquivo.CNAB240:
                    cnab = new ArquivoRetornoCNAB240();
                    cnab.LerArquivoRetorno(banco, s);
                    return(salvarArquivo240(b, (ArquivoRetornoCNAB240)cnab));

                    break;

                default:
                    break;
                }
                return(false);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler o arquivo de retorno.", ex.InnerException);
            }
        }
        /// <summary>
        /// Salva o arquivo no formato 240
        /// </summary>
        /// <param name="b">Banco vinculado</param>
        /// <param name="cnab">Cnab no formato 240</param>
        /// <returns></returns>
        private bool salvarArquivo240(Model.Banco b, ArquivoRetornoCNAB240 cnab)
        {
            var a = new Arquivo();

            a.DataProcessamento = DateTime.Now;
            a.Usuario           = WindowsIdentity.GetCurrent().Name.Split('\\')[1].Trim();

            dao.Inserir(a);

            return(false);
        }
예제 #3
0
        public void ArquivoSafra()
        {
            var   fileContent = string.Empty;
            var   filePath    = string.Empty;
            Banco bco         = new Banco(422);

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    ArquivoRetornoCNAB240 cnab240 = null;
                    if (openFileDialog.CheckFileExists == true)
                    {
                        cnab240 = new ArquivoRetornoCNAB240();
                        cnab240.LinhaDeArquivoLida += new EventHandler <LinhaDeArquivoLidaArgs>(cnab240_LinhaDeArquivoLida);
                        cnab240.LerArquivoRetorno(bco, openFileDialog.OpenFile());
                    }

                    if (cnab240 == null)
                    {
                        MessageBox.Show("Arquivo não processado!");
                        return;
                    }


                    dgBaixa.Rows.Clear();
                    // foreach (DataRow dr in linha)
                    // dgBaixa.Rows.Add(new object[] { dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString() })
                    foreach (DetalheRetornoCNAB240 detalhe in cnab240.ListaDetalhes)
                    {
                        ListViewItem li = new ListViewItem(detalhe.SegmentoT.NomeSacado.Trim());
                        li.Tag = detalhe;
                        dgBaixa.Rows.Add(new object[] { detalhe.SegmentoT.DataVencimento.ToString("dd/MM/yy"), detalhe.SegmentoU.DataCredito.ToString("dd/MM/yy"), detalhe.SegmentoT.ValorTitulo.ToString("###,###.00"), detalhe.SegmentoU.CodigoOcorrenciaSacado.ToString() });

                        //li.SubItems.Add(detalhe.SegmentoT.DataVencimento.ToString("dd/MM/yy"));
                        //li.SubItems.Add(detalhe.SegmentoU.DataCredito.ToString("dd/MM/yy"));
                        //li.SubItems.Add(detalhe.SegmentoT.ValorTitulo.ToString("###,###.00"));
                        //li.SubItems.Add(detalhe.SegmentoU.ValorPagoPeloSacado.ToString("###,###.00"));
                        //li.SubItems.Add(detalhe.SegmentoU.CodigoOcorrenciaSacado.ToString());
                        //li.SubItems.Add("");
                        //li.SubItems.Add(detalhe.SegmentoT.NossoNumero);
                        //dgBaixa.Items.Add(li);
                    }

                    MessageBox.Show("Arquivo aberto com sucesso!");
                }
            }
        }
 /// <summary>
 /// Metodo para processar um arquivo de retorno do tipo Cnab200
 /// </summary>
 /// <param name="banco"><see cref="Model.Banco">vinculado ao arquivo</param>
 /// <param name="stream">stram do arquivo a ser lido</param>
 /// <returns><see cref="BoletoNet.ArquivoRetornoCNAB240"></returns>
 public ArquivoRetornoCNAB240 Retorno200(Model.Banco banco, Stream stream)
 {
     try
     {
         var cnab200 = new ArquivoRetornoCNAB240();
         var bank    = new BoletoNet.Banco(banco.Numero);
         cnab200.LerArquivoRetorno(bank, stream);
         return(cnab200);
     }
     catch (Exception ex)
     {
         throw new Exception("Erro ao ler o arquivo de retorno.", ex.InnerException);
     }
 }
예제 #5
0
		private void LerRetorno(int codigo)
        {
            try
            {
                Banco bco = new Banco(codigo);

                openFileDialog.FileName = "";
                openFileDialog.Title = "Selecione um arquivo de retorno";
                openFileDialog.Filter = "Arquivos de Retorno (*.ret;*.crt)|*.ret;*.crt|Todos Arquivos (*.*)|*.*";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {

                    if (radioButtonCNAB400.Checked)
                    {
                        ArquivoRetornoCNAB400 cnab400 = null;
                        if (openFileDialog.CheckFileExists == true)
                        {
                            cnab400 = new ArquivoRetornoCNAB400();
                            cnab400.LinhaDeArquivoLida += new EventHandler<LinhaDeArquivoLidaArgs>(cnab400_LinhaDeArquivoLida);
                            cnab400.LerArquivoRetorno(bco, openFileDialog.OpenFile());
                        }

                        if (cnab400 == null)
                        {
                            MessageBox.Show("Arquivo não processado!");
                            return;
                        }

                        lstReturnFields.Items.Clear();

                        foreach (DetalheRetorno detalhe in cnab400.ListaDetalhe)
                        {
                            ListViewItem li = new ListViewItem(detalhe.NomeSacado.ToString().Trim());
                            li.Tag = detalhe;

                            li.SubItems.Add(detalhe.DataVencimento.ToString("dd/MM/yy"));
                            li.SubItems.Add(detalhe.DataCredito.ToString("dd/MM/yy"));

                            li.SubItems.Add(detalhe.ValorTitulo.ToString("###,###.00"));

                            li.SubItems.Add(detalhe.ValorPago.ToString("###,###.00"));
                            li.SubItems.Add(detalhe.CodigoOcorrencia.ToString());
                            li.SubItems.Add("");
                            li.SubItems.Add(detalhe.NossoNumeroComDV); // = detalhe.NossoNumero.ToString() + "-" + detalhe.DACNossoNumero.ToString());
                            li.SubItems.Add(detalhe.NumeroDocumento);
                            lstReturnFields.Items.Add(li);
                        }
                    }
                    else if (radioButtonCNAB240.Checked)
                    {
                        ArquivoRetornoCNAB240 cnab240 = null;
                        if (openFileDialog.CheckFileExists == true)
                        {
                            cnab240 = new ArquivoRetornoCNAB240();
                            cnab240.LinhaDeArquivoLida += new EventHandler<LinhaDeArquivoLidaArgs>(cnab240_LinhaDeArquivoLida);
                            cnab240.LerArquivoRetorno(bco, openFileDialog.OpenFile());
                        }

                        if (cnab240 == null)
                        {
                            MessageBox.Show("Arquivo não processado!");
                            return;
                        }


                        lstReturnFields.Items.Clear();

                        foreach (DetalheRetornoCNAB240 detalhe in cnab240.ListaDetalhes)
                        {
                            ListViewItem li = new ListViewItem(detalhe.SegmentoT.NomeSacado.Trim());
                            li.Tag = detalhe;

                            li.SubItems.Add(detalhe.SegmentoT.DataVencimento.ToString("dd/MM/yy"));
                            li.SubItems.Add(detalhe.SegmentoU.DataCredito.ToString("dd/MM/yy"));
                            li.SubItems.Add(detalhe.SegmentoT.ValorTitulo.ToString("###,###.00"));
                            li.SubItems.Add(detalhe.SegmentoU.ValorPagoPeloSacado.ToString("###,###.00"));
                            li.SubItems.Add(detalhe.SegmentoU.CodigoOcorrenciaSacado.ToString());
                            li.SubItems.Add("");
                            li.SubItems.Add(detalhe.SegmentoT.NossoNumero);
                            lstReturnFields.Items.Add(li);
                        }
                    }
                    //MessageBox.Show("Arquivo aberto com sucesso!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro ao abrir arquivo de retorno.");
            }
        }
예제 #6
0
        private void LerRetorno(int codigo)
        {
            try
            {
                Banco bco = new Banco(codigo);

                openFileDialog.FileName = "";
                openFileDialog.Title    = "Selecione um arquivo de retorno";
                openFileDialog.Filter   = "Arquivos de Retorno (*.ret;*.crt;*.txt)|*.ret;*.crt;*.txt|Todos Arquivos (*.*)|*.*";
                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    ArquivoRetornoCNAB240 cnab240 = null;
                    if (openFileDialog.CheckFileExists == true)
                    {
                        _arquivo = openFileDialog.FileName;
                        cnab240  = new ArquivoRetornoCNAB240();
                        cnab240.LinhaDeArquivoLida += new EventHandler <LinhaDeArquivoLidaArgs>(cnab240_LinhaDeArquivoLida);
                        cnab240.LerArquivoRetorno(bco, openFileDialog.OpenFile());
                    }

                    if (cnab240 == null)
                    {
                        MessageBox.Show("Arquivo não processado!");
                        return;
                    }


                    lstReturnFields.Items.Clear();
                    barraProgresso.Minimum = 0;
                    barraProgresso.Maximum = cnab240.ListaDetalhes.Count;

                    barraProgresso.Value = 0;

                    if (codigo == 422)
                    {
                        foreach (DetalheRetornoCNAB240 detalhe in cnab240.ListaDetalhes)
                        {
                            ListViewItem li = new ListViewItem(detalhe.SegmentoT.NomeSacado.Trim());
                            li.Tag = detalhe;

                            li.SubItems.Add(detalhe.SegmentoT.DataVencimento.ToString("dd/MM/yy"));
                            li.SubItems.Add(detalhe.SegmentoU.DataCredito.ToString("dd/MM/yy"));
                            li.SubItems.Add(detalhe.SegmentoT.ValorTitulo.ToString("###,###.00"));
                            li.SubItems.Add(detalhe.SegmentoU.ValorPagoPeloSacado.ToString("###,###.00"));
                            li.SubItems.Add(detalhe.SegmentoU.CodigoOcorrenciaSacado.ToString());
                            //li.SubItems.Add("");

                            if (detalhe.SegmentoU.ValorPagoPeloSacado > 0)
                            {
                                //li.SubItems.Add(detalhe.SegmentoT.NossoNumero);
                                li.SubItems.Add(getStatusParcela(detalhe.SegmentoT.NossoNumero.Trim()));
                            }
                            else
                            {
                                li.SubItems.Add("");
                            }
                            li.SubItems.Add(detalhe.SegmentoT.NossoNumero);
                            lstReturnFields.Items.Add(li);
                            barraProgresso.Value++;
                        }
                    }
                    if (codigo == 033)
                    {
                        foreach (DetalheRetornoCNAB240 detalhe in cnab240.ListaDetalhes)
                        {
                            //ListViewItem li = new ListViewItem(detalhe.SegmentoT.NomeSacado.Trim());
                            //li.Tag = detalhe;

                            //li.SubItems.Add(detalhe.SegmentoT.DataVencimento.ToString("dd/MM/yy"));
                            //li.SubItems.Add(detalhe.SegmentoU.DataCredito.ToString("dd/MM/yy"));
                            //li.SubItems.Add(detalhe.SegmentoT.ValorTitulo.ToString("###,###.00"));
                            //li.SubItems.Add(detalhe.SegmentoU.ValorPagoPeloSacado.ToString("###,###.00"));
                            //li.SubItems.Add(detalhe.SegmentoU.CodigoOcorrenciaSacado.ToString());
                            ////li.SubItems.Add("");

                            //if (detalhe.SegmentoU.ValorPagoPeloSacado > 0)
                            //{
                            //    //li.SubItems.Add(detalhe.SegmentoT.NossoNumero);
                            //    li.SubItems.Add(getStatusParcela(detalhe.SegmentoT.NossoNumero.Trim()));

                            //}
                            //else
                            //{
                            //    li.SubItems.Add("");
                            //}
                            //li.SubItems.Add(detalhe.SegmentoT.NossoNumero);
                            //lstReturnFields.Items.Add(li);
                            ListViewItem li = new ListViewItem(detalhe.SegmentoT.NomeSacado.Trim());
                            li.Tag = detalhe;

                            li.SubItems.Add(detalhe.SegmentoT.DataVencimento.ToString("dd/MM/yy"));
                            li.SubItems.Add(detalhe.SegmentoU.DataCredito.ToString("dd/MM/yy"));
                            li.SubItems.Add(detalhe.SegmentoT.ValorTitulo.ToString("###,###.00"));
                            li.SubItems.Add(detalhe.SegmentoU.ValorPagoPeloSacado.ToString("###,###.00"));
                            li.SubItems.Add(detalhe.SegmentoU.CodigoOcorrenciaSacado.ToString());
                            li.SubItems.Add("");
                            li.SubItems.Add(detalhe.SegmentoT.NossoNumero.Remove(detalhe.SegmentoT.NossoNumero.Length - 1));
                            lstReturnFields.Items.Add(li);
                            barraProgresso.Value++;
                        }
                    }


                    MessageBox.Show("Arquivo aberto com sucesso!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro ao abrir arquivo de retorno.");
            }
        }