public void ProcessarArquivoDeDebitoDoBancoDoBrasilCBR643(HttpPostedFile arquivoEnviado) { try { bmUsuarioPagamento = new BMUsuarioPagamento(); string linhacompleta, identificacao, datalote, convenio = null; decimal valorrecebido = 0; string liquidacao = null; string datadocredito, refTranNossoNumero = null; StringBuilder sbPagamentosNaoEncontrados = new StringBuilder(); sbPagamentosNaoEncontrados.Append("O(s) seguinte(s) Pagamento(s) não foi(oram) encontrado(s)"); sbPagamentosNaoEncontrados.AppendLine("<br />"); sbPagamentosNaoEncontrados.AppendLine("<br />"); bool arquivoVazio = true; bool temPagamentoNaoEncontrado = false; using (StreamReader sr = new StreamReader(arquivoEnviado.InputStream)) { while ((linhacompleta = sr.ReadLine()) != null) { //linhacompleta = linha; identificacao = linhacompleta.Substring(0, 1); if (int.Parse(identificacao) == 0) //registro header { datalote = linhacompleta.Substring(94, 6); } //else if (int.Parse(identificacao) == 9) //registro footer //{ // //TODO: -> Rever este ponto, pois podemos ter um arquivo começando com o valor 9. // throw new AcademicoException("Arquivo Inválido."); //} else { arquivoVazio = false; convenio = linhacompleta.Substring(31, 7); if (convenio == "3072072") { valorrecebido = decimal.Parse(linhacompleta.Substring(253, 13)); datadocredito = linhacompleta.Substring(175, 6); datadocredito = datadocredito.Substring(0, 2) + "/" + datadocredito.Substring(2, 2) + "/20" + datadocredito.Substring(4, 2); liquidacao = linhacompleta.Substring(108, 2); refTranNossoNumero = linhacompleta.Substring(63, 17); if (liquidacao == "03" || liquidacao == "13") { //TODO: Verificar esta regra no legado. //Houve problema com a liquidação - 03 = Comando recusado (Motivo indicado na posição 087/088), 13 = Abatimento Cancelado } else { if (!string.IsNullOrWhiteSpace(refTranNossoNumero)) { ManterUsuarioPagamento manterUsuarioPagamento = new ManterUsuarioPagamento(); UsuarioPagamento usuarioPagamento = manterUsuarioPagamento.ObterInformacoesDePagamentoDoUsuarioNossoNumero(refTranNossoNumero); //Se não encontrou o pagamento pelo nosso número, concatena if (usuarioPagamento == null) { sbPagamentosNaoEncontrados.AppendLine(string.Concat(refTranNossoNumero, "<br />")); temPagamentoNaoEncontrado = true; continue; } if (valorrecebido > 0) { usuarioPagamento.DataPagamento = DateTime.Parse(datadocredito); usuarioPagamento.ValorPagamento = valorrecebido / 10; usuarioPagamento.PagamentoConfirmado = true; usuarioPagamento.Auditoria = new Auditoria("Processo de retorno"); manterUsuarioPagamento.SalvarInformacoesDePagamento(usuarioPagamento); } } } } } } } //}Fim do ForEach if (arquivoVazio) { throw new AcademicoException("Arquivo Inválido."); } if (temPagamentoNaoEncontrado) { throw new AcademicoException(sbPagamentosNaoEncontrados.ToString()); } } catch (AcademicoException ex) { throw ex; } catch (Exception ex) { throw ex; } }
public void ProcessarArquivoDeDebitoDoBancoDoBrasil(HttpPostedFile arquivoEnviado) { try { bmUsuarioPagamento = new BMUsuarioPagamento(); string linhacompleta, identificacao, datalote, convenio = null; decimal valorrecebido = 0; string datadocredito, refTranNossoNumero = null; //foreach (string linha in linhas) // { StringBuilder sbPagamentosNaoEncontrados = new StringBuilder(); sbPagamentosNaoEncontrados.Append("O(s) seguinte(s) Pagamento(s) não foi(oram) encontrado(s)"); sbPagamentosNaoEncontrados.AppendLine("<br />"); sbPagamentosNaoEncontrados.AppendLine("<br />"); bool arquivoVazio = true; bool temPagamentoNaoEncontrado = false; using (StreamReader sr = new StreamReader(arquivoEnviado.InputStream)) { while ((linhacompleta = sr.ReadLine()) != null) { identificacao = linhacompleta.Substring(0, 1); if (identificacao.ToUpper().Equals("A")) //registro header { datalote = linhacompleta.Substring(65, 8); } //else if (identificacao.ToUpper().Equals("Z")) //registro footer //{ // throw new AcademicoException("Arquivo Inválido."); //} else //registro detalhe { arquivoVazio = false; convenio = linhacompleta.Substring(64, 7); if (convenio == "3072072") { valorrecebido = decimal.Parse(linhacompleta.Substring(81, 12)); datadocredito = linhacompleta.Substring(29, 8); datadocredito = datadocredito.Substring(6, 2) + "/" + datadocredito.Substring(4, 2) + "/" + datadocredito.Substring(0, 4); refTranNossoNumero = linhacompleta.Substring(64, 17); if (refTranNossoNumero.Substring(0, 7) == "3072072") { ManterUsuarioPagamento manterUsuarioPagamento = new ManterUsuarioPagamento(); UsuarioPagamento usuarioPagamento = this.ObterInformacoesDePagamentoDoUsuarioNossoNumero(refTranNossoNumero); //Se não encontrou o pagamento pelo nosso número, concatena if (usuarioPagamento == null) { sbPagamentosNaoEncontrados.AppendLine(string.Concat(refTranNossoNumero, "<br />")); temPagamentoNaoEncontrado = true; continue; } usuarioPagamento.DataPagamento = DateTime.Parse(datadocredito); usuarioPagamento.ValorPagamento = valorrecebido; usuarioPagamento.PagamentoConfirmado = true; usuarioPagamento.Auditoria = new Auditoria(); if (valorrecebido > 0) { //Inserir aqui a gravação de um registro na tabela TB_UsuarioPagamento campos IN_Pago com 1 e DT_Pagamento usuarioPagamento.DataPagamento = DateTime.Parse(datadocredito); usuarioPagamento.ValorPagamento = valorrecebido / 10; usuarioPagamento.PagamentoConfirmado = true; usuarioPagamento.Auditoria = new Auditoria("Processo de retorno"); manterUsuarioPagamento.SalvarInformacoesDePagamento(usuarioPagamento); } } } } } } //}fim foreach if (arquivoVazio) { throw new AcademicoException("Arquivo Inválido."); } if (temPagamentoNaoEncontrado) { throw new AcademicoException(sbPagamentosNaoEncontrados.ToString()); } } catch (AcademicoException ex) { throw ex; } catch (Exception ex) { throw ex; } }