public bool FecharBoleto(ref string mensagemErro)
 {
     mensagemErro = "";
     try
     {
         if (!setupOk)
         {
             mensagemErro = "Realize o setup da cobrança antes de executar este método.";
             return(false);
         }
         boleto.ValidarDados();
         boletos.Add(boleto);
         return(true);
     }
     catch (Exception ex)
     {
         while (ex != null)
         {
             mensagemErro += ex.Message + Environment.NewLine;
             ex            = ex.InnerException;
         }
         return(false);
     }
 }
示例#2
0
        private void LerLinhaDoArquivoRetornoCNAB400(string registro)
        {
            // Identifica o tipo do registro (primeira posição da linha)
            var tipoRegistro = registro.Substring(0, 1);

            // Registro HEADER
            if (tipoRegistro == "0")
            {
                Banco.LerHeaderRetornoCNAB400(registro);
                return;
            }

            // Registro TRAILER
            if (tipoRegistro == "9")
            {
                Banco.LerTrailerRetornoCNAB400(registro);
                return;
            }

            // Se o registro não estiver na lista a ser processada pelo banco selecionado, ignora o registro
            if (!Banco.IdsRetornoCnab400RegistroDetalhe.Contains(tipoRegistro))
            {
                return;
            }

            // O primeiro ID da lista, identifica um novo boleto.
            bool novoBoleto = false;

            if (tipoRegistro == Banco.IdsRetornoCnab400RegistroDetalhe.First())
            {
                novoBoleto = true;
            }


            // Se for um novo boleto, cria um novo objeto, caso contrário, seleciona o último boleto
            // Estamos considerando que, quando houver mais de um registro para o mesmo boleto, no arquivo retorno, os registros serão apresentados na sequencia.
            Boleto boleto;

            if (novoBoleto)
            {
                boleto = new Boleto(this.Banco, _ignorarCarteiraBoleto);
            }
            else
            {
                boleto = Boletos.Last();
                // Se não encontrou um boleto válido, ocorreu algum problema, pois deveria ter criado um novo objeto no registro que foi analisado anteriormente.
                if (boleto == null)
                {
                    throw new Exception("Objeto boleto não identificado");
                }
            }


            // Identifica o tipo de registro que deve ser analisado pelo Banco.
            switch (tipoRegistro)
            {
            case "1":
                Banco.LerDetalheRetornoCNAB400Segmento1(ref boleto, registro);
                break;

            case "7":
                Banco.LerDetalheRetornoCNAB400Segmento7(ref boleto, registro);
                break;

            default:
                break;
            }

            // Se for um novo boleto, adiciona na lista de boletos.
            if (novoBoleto)
            {
                Boletos.Add(boleto);
            }
        }