public bool Arquivo_Retorno_Banco(string sFile_Retorno, IBanco banco) { bool bRetorno = true; FileStream fs = new FileStream(sFile_Retorno, FileMode.Open); //-- Carrega e alimenta o arquivo. ArquivoRetornoCNAB400 file = new ArquivoRetornoCNAB400(); file.LerArquivoRetorno(banco, fs); foreach (DetalheRetorno dr in file.ListaDetalhe) { try { StringBuilder sb = new StringBuilder(300); sb.AppendLine("update Boletos_Gerados set "); sb.AppendLine(" Boleto_pago = 1"); sb.AppendFormat(" , Data_pagamento = '{0}'\r\n", dr.DataCredito.ToString("yyyyMMdd")); sb.AppendFormat(" , Valor_Pago = {0}\r\n", dr.ValorPago.ToString("n2").Replace(',', '.')); sb.AppendFormat(" where Nota_Fiscal_Duplicata = {0}", dr.NossoNumero); SQL.Execute(sb.ToString()); } catch { bRetorno = false; break; } } return(bRetorno); }
/// <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); } }
public void TestInitialize() { arquivoRetorno = new ArquivoRetornoCrb643(); using (new MemoryStream(Encoding.UTF8.GetBytes(ARQUIVO_RETORNO))) arquivoRetorno.LerArquivoRetorno(new Banco(001), new MemoryStream(Encoding.UTF8.GetBytes(ARQUIVO_RETORNO))); arquivoRetornoCNAB400 = new ArquivoRetornoCNAB400(); using (new MemoryStream(Encoding.UTF8.GetBytes(ARQUIVO_RETORNO))) arquivoRetornoCNAB400.LerArquivoRetorno(new Banco(001), new MemoryStream(Encoding.UTF8.GetBytes(ARQUIVO_RETORNO))); }
public void BancoSicredi_Ler_Retorno() { var banco = new Banco(748); var retorno = new ArquivoRetornoCNAB400(); using (FileStream fs = File.Open(arquivoRetorno, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { retorno.LerArquivoRetorno(banco, fs); } }
/// <summary> /// Metodo para processar um arquivo de retorno do tipo Cnab400 /// </summary> /// <param name="banco"><see cref="Model.Banco">vinculado ao arquivo</param> /// <param name="stream">stream do arquivo a ser lido</param> /// <returns><see cref="BoletoNet.ArquivoRetornoCNAB400"></returns> public ArquivoRetornoCNAB400 Retorno400(Model.Banco banco, Stream stream) { try { var cnab400 = new ArquivoRetornoCNAB400(); var bank = new BoletoNet.Banco(banco.Numero); cnab400.LerArquivoRetorno(bank, stream); return(cnab400); } catch (Exception ex) { throw new Exception("Erro ao ler o arquivo de retorno.", ex.InnerException); } }
public ArquivoRetornoCNAB400 LerArquivoCnab400(Stream arquivo, Model.Banco bank) { BoletoNet.Banco banco = new BoletoNet.Banco(bank.Codigo); ArquivoRetornoCNAB400 arquivoRetorno = new ArquivoRetornoCNAB400(); try { arquivoRetorno.LerArquivoRetorno(banco, arquivo); return(arquivoRetorno); } catch (Exception) { throw; } }
public void Bradesco_Carteira_09_ArquivoRetorno400() { ArquivoRetornoCNAB400 ret = new ArquivoRetornoCNAB400(); var arquivo = string.Empty; //@"C:\Temp\2017-Julho-CB180701_009_CB_09_433920_20170718041844_00152068-7.RET"; if (arquivo != string.Empty) { using (FileStream fs = new FileStream(arquivo, FileMode.Open, FileAccess.Read)) { ret.LerArquivoRetorno(new Banco(237), fs); } foreach (var item in ret.ListaDetalhe) { Console.WriteLine(item.ToString()); } } }
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."); } }