Пример #1
0
        public bool LerRetorno(int formatoArquivo, string nomeArquivo, ref string mensagemErro)
        {
            try
            {
                if (boletos.Banco == null)
                {
                    mensagemErro = "Banco não definido.";
                    return(false);
                }
                if (formatoArquivo != 0 & formatoArquivo != 1)
                {
                    // Formato do Arquivo - CNAB240 = 0 / CNAB400 = 1
                    mensagemErro = "Tipo do arquivo inválido: 0-CNAB240, 1-CNAB400";
                    return(false);
                }
                boletos.Clear();

                var arquivoRetorno = new ArquivoRetorno(boletos.Banco, (TipoArquivo)formatoArquivo);
                using (var fileStream = new FileStream(nomeArquivo, FileMode.Open))
                {
                    boletos = arquivoRetorno.LerArquivoRetorno(fileStream);
                }

                return(true);
            }
            catch (Exception ex)
            {
                while (ex != null)
                {
                    mensagemErro += ex.Message + Environment.NewLine;
                    ex            = ex.InnerException;
                }
                return(false);
            }
        }
Пример #2
0
        public void LerHeaderRetornoCNAB240(ArquivoRetorno arquivoRetorno, string registro)
        {
            //LAYOUT V 2.8 Fevereiro/2017


            arquivoRetorno.Banco.Cedente = new Cedente();
            //017 - 017 Tipo de inscrição da empresa N 001 1 = CPF, 2 = CNPJ
            //018 - 032 Nº de inscrição da empresa N 015
            arquivoRetorno.Banco.Cedente.CPFCNPJ = registro.Substring(16, 1) == "1" ? registro.Substring(21, 11) : registro.Substring(18, 14);
            //053 - 061 Código do Beneficiário N 009
            arquivoRetorno.Banco.Cedente.Codigo = registro.Substring(54, 7);
            //073 - 102 Nome da empresa A 030
            arquivoRetorno.Banco.Cedente.Nome = registro.Substring(72, 30).Trim();


            ////103 - 132 Nome do Banco A 030
            //arquivoRetorno.Banco.Nome = registro.Substring(102, 30);

            arquivoRetorno.Banco.Cedente.ContaBancaria = new ContaBancaria();
            //033 - 036 Agência do Beneficiário N 004 3
            arquivoRetorno.Banco.Cedente.ContaBancaria.Agencia = registro.Substring(32, 4);
            //037 - 037 Dígito da Agência do Beneficiário N 001 3
            arquivoRetorno.Banco.Cedente.ContaBancaria.DigitoAgencia = registro.Substring(36, 1);
            //038 - 046 Número da conta corrente N 009 3
            arquivoRetorno.Banco.Cedente.ContaBancaria.Conta = registro.Substring(37, 9);
            //047 - 047 Dígito verificador da conta N 001 3
            arquivoRetorno.Banco.Cedente.ContaBancaria.DigitoConta = registro.Substring(46, 1);


            //144 - 151 Data de geração do arquivo N 008 DDMMAAAA
            arquivoRetorno.DataGeracao = Utils.ToDateTime(Utils.ToInt32(registro.Substring(143, 8)).ToString("##-##-####"));
            //158 - 163 Nº seqüencial do arquivo N 006
            arquivoRetorno.NumeroSequencial = Utils.ToInt32(registro.Substring(157, 6));
        }
Пример #3
0
        public void LerHeaderRetornoCNAB400(ArquivoRetorno arquivoRetorno, string registro)
        {
            try
            {
                if (registro.Substring(0, 9) != "02RETORNO")
                {
                    throw new Exception("O arquivo não é do tipo \"02RETORNO\"");
                }

                arquivoRetorno.DataGeracao = Utils.ToDateTime(Utils.ToInt32(registro.Substring(94, 6)).ToString("##-##-##"));
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler HEADER do arquivo de RETORNO / CNAB 400.", ex);
            }
        }
Пример #4
0
        public void LerHeaderRetornoCNAB400(ArquivoRetorno arquivoRetorno, string registro)
        {
            try
            {
                if (registro.Substring(0, 19) != "02RETORNO01COBRANCA")
                {
                    throw new Exception("O arquivo não é do tipo \"02RETORNO01COBRANCA\"");
                }
                if (registro.Substring(76, 11) != "041BANRISUL")
                {
                    throw new Exception("O arquivo não é do tipo \"041BANRISUL\"");
                }

                //095 100 DATA DA GRAVAÇÃO DO ARQUIVO
                arquivoRetorno.DataGeracao = Utils.ToDateTime(Utils.ToInt32(registro.Substring(94, 6)).ToString("##-##-##"));
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler HEADER do arquivo de RETORNO / CNAB 400.", ex);
            }
        }
Пример #5
0
        public void LerHeaderRetornoCNAB400(ArquivoRetorno arquivoRetorno, string registro)
        {
            try
            {
                if (registro.Substring(0, 9) != "02RETORNO")
                {
                    throw new Exception("O arquivo não é do tipo \"02RETORNO\"");
                }

                var dataStr = Utils.ToInt32(registro.Substring(94, 8)).ToString("####-##-##").Split('-');
                var ano     = Utils.ToInt32(dataStr[0]);
                var mes     = Utils.ToInt32(dataStr[1]);
                var dia     = Utils.ToInt32(dataStr[2]);

                //095 a 102 008 Data de gravação do arquivo AAAAMMDD
                arquivoRetorno.DataGeracao = new DateTime(ano, mes, dia);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao ler HEADER do arquivo de RETORNO / CNAB 400.", ex);
            }
        }
Пример #6
0
 public void LerHeaderRetornoCNAB240(ArquivoRetorno arquivoRetorno, string registro)
 {
     throw new NotImplementedException();
 }