public string NomeArquivo => Banco?.FormatarNomeArquivoRemessa(NumeroArquivoRemessaNoDia ?? NumeroArquivoRemessa); // public ArquivoRemessa(IBanco banco, TipoArquivo tipoArquivo, int numeroArquivoRemessa, int?numeroArquivoRemessaNoDia = null) { Banco = banco; TipoArquivo = tipoArquivo; NumeroArquivoRemessa = numeroArquivoRemessa; NumeroArquivoRemessaNoDia = numeroArquivoRemessaNoDia; }
public void GeraArquivoCNAB400(IBanco banco, Cedente cedente, Boletos boletos) { try { saveFileDialog.Filter = "Arquivos de Retorno (*.rem)|*.rem|Todos Arquivos (*.*)|*.*"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ArquivoRemessa arquivo = new ArquivoRemessa(TipoArquivo.CNAB400); //Valida a Remessa Correspondentes antes de Gerar a mesma... string vMsgRetorno = string.Empty; bool vValouOK = arquivo.ValidarArquivoRemessa(cedente.Convenio.ToString(), banco, cedente, boletos, 1, out vMsgRetorno); if (!vValouOK) { MessageBox.Show(String.Concat("Foram localizados inconsistências na validação da remessa!", Environment.NewLine, vMsgRetorno), "Teste", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { arquivo.GerarArquivoRemessa("0", banco, cedente, boletos, saveFileDialog.OpenFile(), 1); MessageBox.Show("Arquivo gerado com sucesso!", "Teste", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 2; string strline; StreamWriter incluiLinha = new StreamWriter(arquivo); strline = banco.GerarHeaderRemessa("0", cedente, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); numeroRegistro++; } strline = banco.GerarTrailerRemessa(numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); incluiLinha.Close(); } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }
/// <summary> /// Método que fará a verificação se a classe está devidamente implementada para a geração da Remessa /// </summary> public override bool ValidarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { try { bool vRetorno = true; string vMsg = string.Empty; if (boletos != null && boletos.Count > 0) { Boleto boleto = boletos[0]; string vMsgBol = string.Empty; bool vRetBol = boleto.Banco.ValidarRemessa(this.TipoArquivo, numeroConvenio, banco, cedente, boletos, numeroArquivoRemessa, out vMsgBol); if (!vRetBol && !String.IsNullOrEmpty(vMsgBol)) { vMsg += vMsgBol; vRetorno = vRetBol; } } mensagem = vMsg; return(vRetorno); } catch (Exception ex) { throw ex; } }
public Banco(int codigoBanco) { try { switch (codigoBanco) { case 001: _IBanco = new Banco_Brasil(); break; case 104: _IBanco = new Banco_Caixa(); break; case 237: _IBanco = new Banco_Bradesco(); break; case 756: _IBanco = new Banco_Sicoob(); break; default: throw new Exception("Banco não implementando: " + codigoBanco); } } catch (Exception ex) { throw new Exception("Erro ao instanciar objeto.", ex); } }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { this.Banco = banco; try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; // Lendo o arquivo linha = stream.ReadLine(); // Próxima linha (DETALHE) linha = stream.ReadLine(); while (DetalheRetorno.PrimeiroCaracter(linha) == "1") { DetalheRetorno detalhe = banco.LerDetalheRetornoCNAB400(linha); ListaDetalhe.Add(detalhe); OnLinhaLida(detalhe, linha); linha = stream.ReadLine(); } stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
public Socorro(SocorroVeicular socorroVeicular, IVeiculo veiculo, IOperacoesGuincho OperacoesGuincho, IBanco Banco) { _veiculo = socorroVeicular.CriarVeiculo(veiculo.Modelo, veiculo.Placa, veiculo.AroPneu); _guincho = socorroVeicular.SelecionarGuincho(); this.OperacoesGuincho = OperacoesGuincho; this.Banco = Banco; }
public override bool ValidarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { try { bool vRetorno = true; string vMsg = string.Empty; // foreach (Boleto boleto in boletos) { string vMsgBol = string.Empty; bool vRetBol = boleto.Banco.ValidarRemessa(this.TipoArquivo, numeroConvenio, banco, cedente, boletos, numeroArquivoRemessa, out vMsgBol); if (!vRetBol && !String.IsNullOrEmpty(vMsgBol)) { vMsg += vMsgBol; vRetorno = vRetBol; } } // mensagem = vMsg; return vRetorno; } catch (Exception ex) { throw ex; } }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 2; string strline; decimal vltitulostotal = 0; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 StreamWriter incluiLinha = new StreamWriter(arquivo); strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB400, numeroArquivoRemessa); incluiLinha.WriteLine(strline); foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); vltitulostotal += boleto.ValorBoleto; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 numeroRegistro++; } strline = banco.GerarTrailerRemessa(numeroRegistro, TipoArquivo.CNAB400, vltitulostotal); incluiLinha.WriteLine(strline); incluiLinha.Close(); incluiLinha.Dispose(); // Incluido por Luiz Ponce 07/07/2012. incluiLinha = null; // Incluido por Luiz Ponce 07/07/2012. } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }
public MenusPOO(IBanco banco, ITelespectador telespectador, IIndividuo individuo, IPoo poo) { _banco = banco; _telespectador = telespectador; _individuo = individuo; _poo = poo; }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 2; string strline; decimal vltitulostotal = 0; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 StreamWriter incluiLinha = new StreamWriter(arquivo, Encoding.GetEncoding("ISO-8859-1")); strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB400, numeroArquivoRemessa); incluiLinha.WriteLine(strline); foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); vltitulostotal += boleto.ValorBoleto; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 numeroRegistro++; } strline = banco.GerarTrailerRemessa(numeroRegistro, TipoArquivo.CNAB400, cedente, vltitulostotal); incluiLinha.WriteLine(strline); incluiLinha.Close(); incluiLinha.Dispose(); // Incluido por Luiz Ponce 07/07/2012. incluiLinha = null; // Incluido por Luiz Ponce 07/07/2012. } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }
public IBanco CriarBanco(string tipoBanco) { IBanco retorno = null; try { switch (tipoBanco) { case "SQLServer": retorno = new SQLserver(); break; case "SQLite": retorno = new SQLite(); break; default: break; } return(retorno); } catch (Exception ex) { throw ex; } }
public void GeraArquivoCNAB400(IBanco banco, Cedente cedente, Boletos boletos, string numeroConvenio = null) { try { saveFileDialog.Filter = "Arquivos de Retorno (*.rem)|*.rem|Todos Arquivos (*.*)|*.*"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ArquivoRemessa arquivo = new ArquivoRemessa(TipoArquivo.CNAB400); //Valida a Remessa Correspondentes antes de Gerar a mesma... string vMsgRetorno = string.Empty; bool vValouOK = arquivo.ValidarArquivoRemessa(cedente.Convenio.ToString(), banco, cedente, boletos, 1, out vMsgRetorno); if (!vValouOK) { MessageBox.Show(String.Concat("Foram localizados inconsistências na validação da remessa!", Environment.NewLine, vMsgRetorno), "Teste", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { arquivo.GerarArquivoRemessa(numeroConvenio != null ? numeroConvenio : "0", banco, cedente, boletos, saveFileDialog.OpenFile(), 1); MessageBox.Show("Arquivo gerado com sucesso!", "Teste", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
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> /// Gera o arquivo de remessa para o banco /// </summary> /// <param name="ilBB">Dictionary com os boletos bancários.</param> /// <param name="sFolderRemessa">Pasta de geração do arquivo.</param> /// <returns>true/false indicando se o arquivo foi gerado com sucesso.</returns> public bool Gerar_Arquivo_Remessa(Dictionary <int, BoletoBancario> ilBB, string sFolderRemessa, ref int iNumeroLote) { bool bRetorno = false; try { Boletos boletos = new Boletos(); //-- Gera a list de Boletos para gerar o arquivo de remessa foreach (BoletoBancario bb in ilBB.Values) { boletos.Add(bb.Boleto); } if (boletos.Count > 0) { Cedente c = boletos[0].Cedente; IBanco b = boletos[0].Banco; //-- Carrega o contador CompSoft.compFrameWork.Funcoes func = new Funcoes(); iNumeroLote = Convert.ToInt32(func.Contador("NumeroContadorCNAB", false)); //-- Pega o número do contador. if (!sFolderRemessa.EndsWith(@"\")) { sFolderRemessa += @"\"; } string sFileRemessa = sFolderRemessa + "B" + b.Codigo.ToString().PadLeft(3, '0') + iNumeroLote.ToString().PadLeft(4, '0') + ".REM"; FileInfo fi = new FileInfo(sFileRemessa); //-- Processo o arquivo de remessa ArquivoRemessa ar = new ArquivoRemessa(TipoArquivo.CNAB400); ar.GerarArquivoRemessa(c.Codigo.ToString() //-- Codigo Cedente , b //-- Interface do Banco , c //-- Classe do Cedente , boletos //-- Classe com lista dos boletos , fi.OpenWrite() //-- Arquivos texto , iNumeroLote); //-- Contador func.Contador("NumeroContadorCNAB", true); //-- Atualiza contador. bRetorno = true; } } catch (Exception ex) { MsgBox.Show("ERRO AO GARAR ARQUIVO DE REMESSA\r\n\r\n" + ex.Message , "Arquivo de Remessa" , System.Windows.Forms.MessageBoxButtons.OK , System.Windows.Forms.MessageBoxIcon.Error); } return(bRetorno); }
public Boleto(IBanco banco) { Banco = banco; Carteira = banco.Cedente.ContaBancaria.CarteiraPadrao; VariacaoCarteira = banco.Cedente.ContaBancaria.VariacaoCarteiraPadrao; TipoCarteira = banco.Cedente.ContaBancaria.TipoCarteiraPadrao; }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; // Lendo o arquivo linha = stream.ReadLine(); // Próxima linha (DETALHE) linha = stream.ReadLine(); while (DetalheRetorno.PrimeiroCaracter(linha) == "1") { DetalheRetorno detalhe = banco.LerDetalheRetornoCNAB400(linha); ListaDetalhe.Add(detalhe); OnLinhaLida(detalhe, linha); linha = stream.ReadLine(); } stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
/// <summary> /// Construtor da Classe Boleto /// </summary> /// <param name="banco"></param> public Boleto(IBanco banco) { Banco = banco; Carteira = banco.Beneficiario.ContaBancaria.CarteiraPadrao; CarteiraImpressaoBoleto = banco.Beneficiario.ContaBancaria.CarteiraPadrao; VariacaoCarteira = banco.Beneficiario.ContaBancaria.VariacaoCarteiraPadrao; TipoCarteira = banco.Beneficiario.ContaBancaria.TipoCarteiraPadrao; }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); // Identificação do registro detalhe List <string> IdsRegistroDetalhe = new List <string>(); // Lendo o arquivo string linha = stream.ReadLine(); this.HeaderRetorno = banco.LerHeaderRetornoCNAB400(linha); // Próxima linha (DETALHE) linha = stream.ReadLine(); //tem arquivo de retorno que possui somente cabeçalho if (linha != null) { switch (banco.Codigo) { // 85 - CECRED - Código de registro detalhe 7 para CECRED case (int)Bancos.CECRED: IdsRegistroDetalhe.Add("7"); break; // 1 - Banco do Brasil- Código de registro detalhe 7 para convênios com 7 posições, e detalhe 1 para convênios com 6 posições(colocado as duas, pois não interferem em cada tipo de arquivo) case (int)Bancos.BancoBrasil: IdsRegistroDetalhe.Add("1"); //Para convênios de 6 posições IdsRegistroDetalhe.Add("7"); //Para convênios de 7 posições break; default: IdsRegistroDetalhe.Add("1"); break; } while (linha != null) { if (IdsRegistroDetalhe.Contains(DetalheRetorno.PrimeiroCaracter(linha))) { DetalheRetorno detalhe = banco.LerDetalheRetornoCNAB400(linha); ListaDetalhe.Add(detalhe); OnLinhaLida(detalhe, linha); } linha = stream.ReadLine(); } } //TODO: Tratar Triller. stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo, bool closeStream = true) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; // Lendo o arquivo //linha = stream.ReadLine(); //// Próxima linha (DETALHE) //linha = stream.ReadLine(); //while (DetalheRetorno.PrimeiroCaracter(linha) == "1") //{ // DetalheRetorno detalhe = banco.LerDetalheRetornoCNAB400(linha); // ListaDetalhe.Add(detalhe); // OnLinhaLida(detalhe, linha); // linha = stream.ReadLine(); //} while ((linha = stream.ReadLine()) != null) { if (!String.IsNullOrEmpty(linha)) { //DetalheRetorno detalheRetorno = new DetalheRetorno(); switch (DetalheRetorno.PrimeiroCaracter(linha)) { case "0": //Header de arquivo OnLinhaLida(null, linha); HeaderArquivo400 = banco.LerHeaderArquivoRetornoCNAB400(linha); break; case "1": //Detalhe DetalheRetorno detalhe = banco.LerDetalheRetornoCNAB400(linha); ListaDetalhe.Add(detalhe); OnLinhaLida(detalhe, linha); break; //case "9": //Trailler de arquivo // OnLinhaLida(null, linha, EnumTipodeLinhaLida.TraillerDeArquivo); // break; } } } if (closeStream) { stream.Close(); } } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
internal void InitBanco(short?codBanco, string carteira) { this._carteira = carteira; if (codBanco.HasValue) { this._banco = new Banco(codBanco.Value); this.BancoCarteira = BancoCarteiraFactory.Fabrica(this.Carteira, codBanco.Value); } }
/// <summary> /// Gera o arquivo de remessa /// </summary> /// <param name="numeroConvenio">Número do Convênio</param> /// <param name="banco">Banco</param> /// <param name="cedente">Dados do Cedente</param> /// <param name="boletos">Lista com Boletos para geração da remessa</param> /// <param name="arquivo">Arquivo (Stream / File)</param> /// <param name="numeroArquivoRemessa">Número do arquivo da remessa</param> public virtual void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { this.Banco = banco; this.Cedente = cedente; this.Boletos = boletos; this.NumeroConvenio = numeroConvenio; this.NumeroArquivoRemessa = numeroArquivoRemessa; _arquivoRemessa.GerarArquivoRemessa(numeroConvenio, banco, cedente, boletos, arquivo, numeroArquivoRemessa); }
public BancoBrasilCarteira17019Tests() { //Código de cedente com 4 dígitos var contaBancariaCed4Digitos = new ContaBancaria { Agencia = "1234", DigitoAgencia = "X", Conta = "123456", DigitoConta = "X", CarteiraPadrao = "17", VariacaoCarteiraPadrao = "019", TipoCarteiraPadrao = TipoCarteira.CarteiraCobrancaSimples, TipoFormaCadastramento = TipoFormaCadastramento.ComRegistro, TipoImpressaoBoleto = TipoImpressaoBoleto.Empresa }; _banco = Banco.Instancia(Bancos.BancoDoBrasil); _banco.Cedente = Utils.GerarCedente("1234", "", "", contaBancariaCed4Digitos); _banco.FormataCedente(); //Código de cedente com 6 dígitos var contaBancariaCed6Digitos = new ContaBancaria { Agencia = "1234", DigitoAgencia = "X", Conta = "123456", DigitoConta = "X", CarteiraPadrao = "17", VariacaoCarteiraPadrao = "019", TipoCarteiraPadrao = TipoCarteira.CarteiraCobrancaSimples, TipoFormaCadastramento = TipoFormaCadastramento.ComRegistro, TipoImpressaoBoleto = TipoImpressaoBoleto.Empresa }; _banco = Banco.Instancia(Bancos.BancoDoBrasil); _banco.Cedente = Utils.GerarCedente("123456", "", "", contaBancariaCed6Digitos); _banco.FormataCedente(); //Código de cedente com 7 dígitos var contaBancariaCed7Digitos = new ContaBancaria { Agencia = "1234", DigitoAgencia = "X", Conta = "123456", DigitoConta = "X", CarteiraPadrao = "17", VariacaoCarteiraPadrao = "019", TipoCarteiraPadrao = TipoCarteira.CarteiraCobrancaSimples, TipoFormaCadastramento = TipoFormaCadastramento.ComRegistro, TipoImpressaoBoleto = TipoImpressaoBoleto.Empresa }; _banco = Banco.Instancia(Bancos.BancoDoBrasil); _banco.Cedente = Utils.GerarCedente("1234567", "", "", contaBancariaCed7Digitos); _banco.FormataCedente(); }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; while ((linha = stream.ReadLine()) != null) { DetalheRetornoCNAB240 detalheRetorno = new DetalheRetornoCNAB240(); switch (linha.Substring(7, 1)) { case "0": //Header de arquivo OnLinhaLida(null, linha, EnumTipodeLinhaLida.HeaderDeArquivo); break; case "1": //Header de lote OnLinhaLida(null, linha, EnumTipodeLinhaLida.HeaderDeLote); break; case "3": //Detalhe if (linha.Substring(13, 1) == "W") { OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoW); detalheRetorno.SegmentoW.LerDetalheSegmentoWRetornoCNAB240(linha); } else { OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoT); detalheRetorno.SegmentoT.LerDetalheSegmentoTRetornoCNAB240(linha); linha = stream.ReadLine(); OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoU); detalheRetorno.SegmentoU.LerDetalheSegmentoURetornoCNAB240(linha); } ListaDetalhes.Add(detalheRetorno); break; case "5": //Trailler de lote OnLinhaLida(null, linha, EnumTipodeLinhaLida.TraillerDeLote); break; case "9": //Trailler de arquivo OnLinhaLida(null, linha, EnumTipodeLinhaLida.TraillerDeArquivo); break; } } stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 2; string strline; decimal vltitulostotal = 0; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 StreamWriter incluiLinha = new StreamWriter(arquivo, Encoding.GetEncoding("ISO-8859-1")); cedente.Carteira = boletos[0].Carteira; strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB400, numeroArquivoRemessa); incluiLinha.WriteLine(strline); foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); vltitulostotal += boleto.ValorBoleto; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 numeroRegistro++; // 85 - CECRED if (banco.Codigo == 85) { if (boleto.PercMulta > 0 || boleto.ValorMulta > 0) { Banco_Cecred _banco = new Banco_Cecred(); string linhaCECREDRegistroDetalhe5 = _banco.GerarRegistroDetalhe5(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(linhaCECREDRegistroDetalhe5); numeroRegistro++; } } if ((boleto.Instrucoes != null && boleto.Instrucoes.Count > 0) || (boleto.Sacado.Instrucoes != null && boleto.Sacado.Instrucoes.Count > 0)) { strline = boleto.Banco.GerarMensagemVariavelRemessa(boleto, ref numeroRegistro, TipoArquivo.CNAB400); if (!string.IsNullOrEmpty(strline) && !string.IsNullOrWhiteSpace(strline)) { incluiLinha.WriteLine(strline); } } } strline = banco.GerarTrailerRemessa(numeroRegistro, TipoArquivo.CNAB400, cedente, vltitulostotal); incluiLinha.WriteLine(strline); incluiLinha.Close(); incluiLinha.Dispose(); // Incluido por Luiz Ponce 07/07/2012. incluiLinha = null; // Incluido por Luiz Ponce 07/07/2012. } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }
/// <summary> /// Método que fará a verificação se a classe está devidamente implementada para a geração da Remessa /// </summary> /// <param name="numeroConvenio">Número do Convênio</param> /// <param name="banco">Banco</param> /// <param name="cedente">Dados do Cedente</param> /// <param name="boletos">Lista com Boletos para geração da remessa</param> /// <param name="numeroArquivoRemessa">Número do arquivo da remessa</param> /// <param name="mensagem">Mensagem</param> /// <returns></returns> public virtual bool ValidarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { try { return(_arquivoRemessa.ValidarArquivoRemessa(numeroConvenio, banco, cedente, boletos, numeroArquivoRemessa, out mensagem)); } catch (Exception ex) { throw ex; } }
private byte[] ObterLogoBanco(IBanco banco) { var embeddedProvider = new EmbeddedFileProvider(Assembly.GetExecutingAssembly()); using (var reader = embeddedProvider.GetFileInfo($"logos/{banco.Codigo.ToString("000")}.bmp").CreateReadStream()) { var logo = new byte[reader.Length]; reader.Read(logo, 0, (int)reader.Length); return(logo); } }
public bool ValidarRemessa(TipoArquivo tipoArquivo, string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { try { return(_IBanco.ValidarRemessa(tipoArquivo, numeroConvenio, _IBanco, cedente, boletos, numeroArquivoRemessa, out mensagem)); } catch (Exception ex) { throw new Exception("Erro durante a validação do arquivo de REMESSA.", ex); } }
public Boleto(IBanco banco) { Banco = banco; //alteração evita erro ao processar retorno sem dados da carteira, e somente informando o banco (múltiplas carteiras no arquivo de retorno) if (banco.Cedente != null) { Carteira = banco.Cedente.ContaBancaria.CarteiraPadrao; VariacaoCarteira = banco.Cedente.ContaBancaria.VariacaoCarteiraPadrao; TipoCarteira = banco.Cedente.ContaBancaria.TipoCarteiraPadrao; } }
/// <summary> /// Construtor da Classe Boleto com parâmetro para viabilizar várias carteiras /// </summary> /// <param name="banco"></param> /// <param name="ignorarCarteira"></param> public Boleto(IBanco banco, Boolean ignorarCarteira) { Banco = banco; //se o arquivo de retorno for criado par multiplas carteiras, ignora a carteira (para compatibilidade) if (!ignorarCarteira && banco.Beneficiario != null) { Carteira = banco.Beneficiario.ContaBancaria.CarteiraPadrao; VariacaoCarteira = banco.Beneficiario.ContaBancaria.VariacaoCarteiraPadrao; TipoCarteira = banco.Beneficiario.ContaBancaria.TipoCarteiraPadrao; } }
public Boleto(IBanco banco, Boolean ignorarCarteira) { Banco = banco; //se o arquivo de retorno for criado par multiplas carteiras, ignora a carteira (para compatibilidade) if (!ignorarCarteira) { Carteira = banco.Cedente.ContaBancaria.CarteiraPadrao; CarteiraImpressaoBoleto = banco.Cedente.ContaBancaria.CarteiraPadrao; VariacaoCarteira = banco.Cedente.ContaBancaria.VariacaoCarteiraPadrao; TipoCarteira = banco.Cedente.ContaBancaria.TipoCarteiraPadrao; } }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 2; string strline; decimal vltitulostotal = 0; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 bool PassarInformacoesBoleto = false; if (banco.Codigo == 104) { PassarInformacoesBoleto = true; } //StreamWriter incluiLinha = new StreamWriter(arquivo, Encoding.GetEncoding("ISO-8859-1")); //StreamWriter incluiLinha = new StreamWriter(arquivo, Encoding.GetEncoding(1252)); //StreamWriter incluiLinha = new StreamWriter(arquivo, Encoding.Default); //StreamWriter incluiLinha = new StreamWriter(arquivo, Encoding.ASCII); StreamWriter incluiLinha = new StreamWriter(arquivo); if (PassarInformacoesBoleto) { strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB400, numeroArquivoRemessa, boletos[0]); } else { strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB400, numeroArquivoRemessa); } incluiLinha.WriteLine(strline); foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); vltitulostotal += boleto.ValorBoleto; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 numeroRegistro++; } strline = banco.GerarTrailerRemessa(numeroRegistro, TipoArquivo.CNAB400, cedente, vltitulostotal); incluiLinha.WriteLine(strline); incluiLinha.Close(); incluiLinha.Dispose(); // Incluido por Luiz Ponce 07/07/2012. incluiLinha = null; // Incluido por Luiz Ponce 07/07/2012. } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader Linha = new StreamReader(arquivo); string strline = ""; int _codigoBanco; // Lendo o arquivo strline = Linha.ReadLine(); _codigoBanco = 341; // Convert.ToInt16(strline.Substring(76, 3)); switch (_codigoBanco) { case 341: // Próxima linha (DETALHE) strline = Linha.ReadLine(); DetalheRetorno detalhex = new DetalheRetorno(); // gamb while (DetalheRetorno.PrimeiroCaracter(strline) == "1") { DetalheRetorno detalhe = new DetalheRetorno(); detalhe.LerDetalheRetornoCNAB400(strline); this.ListaDetalhe.Add(detalhe); //detalhe.ListaDetalhe.Add(detalhe); strline = Linha.ReadLine(); } break; default: // Próxima linha (DETALHE) strline = Linha.ReadLine(); while (DetalheRetorno.PrimeiroCaracter(strline) == "1") { DetalheRetorno detalhe = new DetalheRetorno(); detalhe.LerDetalheRetornoCNAB400(strline); detalhe.ListaDetalhe.Add(detalhe); strline = Linha.ReadLine(); } break; } Linha.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
internal static void RenderizaBoletos(IBanco banco, TipoArquivo tipoArquivo, string nomeCarteira, int quantidadeBoletos, string aceite, string NossoNumero) { var boletos = GerarBoletos(banco, quantidadeBoletos, aceite, NossoNumero); try { var html = new StringBuilder(); var contador = 1; foreach (var boletoTmp in boletos) { using (var boletoParaImpressao = new BoletoBancario { Boleto = boletoTmp, OcultarInstrucoes = true, MostrarComprovanteEntrega = false, MostrarEnderecoCedente = false, ExibirDemonstrativo = false, OcultarEnderecoSacado = false, MostrarCodigoCarteira = true }) { var nomeArquivo = Path.Combine(Path.GetTempPath(), "Boleto2Net", $"{nomeCarteira}_{tipoArquivo}_{contador}.html"); if (File.Exists(nomeArquivo)) { File.Delete(nomeArquivo); if (File.Exists(nomeArquivo)) { Console.WriteLine("Arquivo Boletos (PDF) não foi excluído: " + nomeArquivo); } } html.Append("<div style=\"page-break-after: always;\">"); html.Append(boletoParaImpressao.MontaHtmlEmbedded()); html.Append("</div>"); using (StreamWriter sw = new StreamWriter(nomeArquivo)) { sw.Write(html); } html.Clear(); contador++; } } } catch (Exception e) { Console.WriteLine(e.InnerException.ToString()); } }
public void GeraArquivoCNAB240(IBanco banco, Cedente cedente, Boletos boletos) { saveFileDialog.Filter = "Arquivos de Retorno (*.rem)|*.rem|Todos Arquivos (*.*)|*.*"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { ArquivoRemessa arquivo = new ArquivoRemessa(TipoArquivo.CNAB240); arquivo.GerarArquivoRemessa("1200303001417053", banco, cedente, boletos, saveFileDialog.OpenFile(), 1); MessageBox.Show("Arquivo gerado com sucesso!", "Teste", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 2; string strline; decimal vltitulostotal = 0; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 StreamWriter incluiLinha = new StreamWriter(arquivo, Encoding.GetEncoding("ISO-8859-1")); cedente.Carteira = boletos[0].Carteira; strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB400, numeroArquivoRemessa); incluiLinha.WriteLine(strline); foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(strline); vltitulostotal += boleto.ValorBoleto; //Uso apenas no registro TRAILER do banco Santander - jsoda em 09/05/2012 - Add no registro TRAILER do banco Banrisul - sidneiklein em 08/08/2013 numeroRegistro++; // 85 - CECRED if (banco.Codigo == 85) { if (boleto.PercMulta > 0 || boleto.ValorMulta > 0) { Banco_Cecred _banco = new Banco_Cecred(); string linhaCECREDRegistroDetalhe5 = _banco.GerarRegistroDetalhe5(boleto, numeroRegistro, TipoArquivo.CNAB400); incluiLinha.WriteLine(linhaCECREDRegistroDetalhe5); numeroRegistro++; } } if ((boleto.Instrucoes != null && boleto.Instrucoes.Count > 0) || (boleto.Sacado.Instrucoes != null && boleto.Sacado.Instrucoes.Count > 0)) { strline = boleto.Banco.GerarMensagemVariavelRemessa(boleto, ref numeroRegistro, TipoArquivo.CNAB400); if (!string.IsNullOrEmpty(strline) && !string.IsNullOrWhiteSpace(strline)) incluiLinha.WriteLine(strline); } } strline = banco.GerarTrailerRemessa(numeroRegistro, TipoArquivo.CNAB400, cedente, vltitulostotal); incluiLinha.WriteLine(strline); incluiLinha.Close(); incluiLinha.Dispose(); // Incluido por Luiz Ponce 07/07/2012. incluiLinha = null; // Incluido por Luiz Ponce 07/07/2012. } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; DetalheRetornoCNAB240 detalheRetorno = new DetalheRetornoCNAB240(); // Lendo o arquivo linha = stream.ReadLine(); OnLinhaLida(null, linha, EnumTipodeLinhaLida.HeaderDeArquivo); detalheRetorno.HeaderArquivo.LerHeaderDeArquivoCNAB240(linha); // Próxima linha (DETALHE) linha = stream.ReadLine(); OnLinhaLida(null, linha, EnumTipodeLinhaLida.HeaderDeLote); linha = stream.ReadLine(); while (linha.Substring(7, 1) == "3") { if (linha.Substring(13, 1) == "W") { OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoW); detalheRetorno.SegmentoW.LerDetalheSegmentoWRetornoCNAB240(linha); } else { OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoT); detalheRetorno.SegmentoT.LerDetalheSegmentoTRetornoCNAB240(linha); linha = stream.ReadLine(); OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoU); detalheRetorno.SegmentoU.LerDetalheSegmentoURetornoCNAB240(linha); } ListaDetalhes.Add(detalheRetorno); linha = stream.ReadLine(); } OnLinhaLida(null, linha, EnumTipodeLinhaLida.TraillerDeLote); linha = stream.ReadLine(); OnLinhaLida(null, linha, EnumTipodeLinhaLida.TraillerDeArquivo); stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; // Identificação do registro detalhe List<string> IdsRegistroDetalhe = new List<string>(); // Lendo o arquivo linha = stream.ReadLine(); // Próxima linha (DETALHE) linha = stream.ReadLine(); // 85 - CECRED - Código de registro detalhe 7 para CECRED // 1 - Banco do Brasil- Código de registro detalhe 7 para convênios com 7 posições, e detalhe 1 para convênios com 6 posições(colocado as duas, pois não interferem em cada tipo de arquivo) if (banco.Codigo == 85) { IdsRegistroDetalhe.Add("7"); } else if (banco.Codigo == 1) { IdsRegistroDetalhe.Add("1");//Para convênios de 6 posições IdsRegistroDetalhe.Add("7");//Para convênios de 7 posições } else { IdsRegistroDetalhe.Add("1"); } while (IdsRegistroDetalhe.Contains(DetalheRetorno.PrimeiroCaracter(linha))) { DetalheRetorno detalhe = banco.LerDetalheRetornoCNAB400(linha); ListaDetalhe.Add(detalhe); OnLinhaLida(detalhe, linha); linha = stream.ReadLine(); } stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; // Identificação do registro detalhe string IdRegistroDetalhe = string.Empty; // Lendo o arquivo linha = stream.ReadLine(); // Próxima linha (DETALHE) linha = stream.ReadLine(); // 85 - CECRED - Código de registro detalhe 7 para CECRED if (banco.Codigo == 85) { IdRegistroDetalhe = "7"; } else { IdRegistroDetalhe = "1"; } while (DetalheRetorno.PrimeiroCaracter(linha) == IdRegistroDetalhe) { DetalheRetorno detalhe = banco.LerDetalheRetornoCNAB400(linha); ListaDetalhe.Add(detalhe); OnLinhaLida(detalhe, linha); linha = stream.ReadLine(); } stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
public bool ValidarRemessaCNAB240(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; // #region Pré Validações if (banco == null) { vMsg += String.Concat("Remessa: O Banco é Obrigatório!", Environment.NewLine); vRetorno = false; } if (cedente == null) { vMsg += String.Concat("Remessa: O Cedente/Beneficiário é Obrigatório!", Environment.NewLine); vRetorno = false; } if (boletos == null || boletos.Count.Equals(0)) { vMsg += String.Concat("Remessa: Deverá existir ao menos 1 boleto para geração da remessa!", Environment.NewLine); vRetorno = false; } #endregion // //validação de cada boleto foreach (Boleto boleto in boletos) { #region Validação de cada boleto if (boleto.Remessa == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe as diretrizes de remessa!", Environment.NewLine); vRetorno = false; } else if (boleto.Remessa.TipoDocumento.Equals("1") && String.IsNullOrEmpty(boleto.Sacado.Endereco.CEP)) //1 - SICGB - Com registro { //Para o "Remessa.TipoDocumento = "1", o CEP é Obrigatório! vMsg += String.Concat("Para o Tipo Documento [1 - SIGCB - COM REGISTRO], o CEP do SACADO é Obrigatório!", Environment.NewLine); vRetorno = false; } if (boleto.NossoNumero.Length > 15) boleto.NossoNumero = boleto.NossoNumero.Substring(0, 15); //if (!boleto.Remessa.TipoDocumento.Equals("2")) //2 - SIGCB - SEM REGISTRO //{ // //Para o "Remessa.TipoDocumento = "2", não poderá ter NossoNumero Gerado! // vMsg += String.Concat("Tipo Documento de boleto não Implementado!", Environment.NewLine); // vRetorno = false; //} #endregion } // mensagem = vMsg; return vRetorno; }
public bool ValidarRemessaCNAB400(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; // #region Pré Validações if (banco == null) { vMsg += String.Concat("Remessa: O Banco é Obrigatório!", Environment.NewLine); vRetorno = false; } if (cedente == null) { vMsg += String.Concat("Remessa: O Cedente/Beneficiário é Obrigatório!", Environment.NewLine); vRetorno = false; } if (boletos == null || boletos.Count.Equals(0)) { vMsg += String.Concat("Remessa: Deverá existir ao menos 1 boleto para geração da remessa!", Environment.NewLine); vRetorno = false; } #endregion // foreach (Boleto boleto in boletos) { #region Validação de cada boleto if (boleto.Remessa == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe as diretrizes de remessa!", Environment.NewLine); vRetorno = false; } if (boleto.Sacado == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Sacado: Informe os dados do sacado!", Environment.NewLine); vRetorno = false; } else { if (boleto.Sacado.Nome == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Nome: Informe o nome do sacado!", Environment.NewLine); vRetorno = false; } if (boleto.Sacado.CPFCNPJ == null || boleto.Sacado.CPFCNPJ == "") { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; CPF/CNPJ: Informe o CPF ou CNPJ do sacado!", Environment.NewLine); vRetorno = false; } if (boleto.Sacado.Endereco == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Endereço: Informe o endereço do sacado!", Environment.NewLine); vRetorno = false; } else { if (boleto.Sacado.Endereco.End == null || boleto.Sacado.Endereco.End == "") { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Endereço: Informe o Endereço do sacado!", Environment.NewLine); vRetorno = false; } if (boleto.Sacado.Endereco.Bairro == null || boleto.Sacado.Endereco.Bairro == "") { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Endereço: Informe o Bairro do sacado!", Environment.NewLine); vRetorno = false; } if (boleto.Sacado.Endereco.CEP == null || boleto.Sacado.Endereco.CEP == "" || boleto.Sacado.Endereco.CEP == "00000000") { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Endereço: Informe o CEP do sacado!", Environment.NewLine); vRetorno = false; } if (boleto.Sacado.Endereco.Cidade == null || boleto.Sacado.Endereco.Cidade == "") { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Endereço: Informe a cidade do sacado!", Environment.NewLine); vRetorno = false; } if (boleto.Sacado.Endereco.UF == null || boleto.Sacado.Endereco.UF == "") { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Endereço: Informe a UF do sacado!", Environment.NewLine); vRetorno = false; } } } #region OLD //else //{ // //#region Validações da Remessa que deverão estar preenchidas quando CAIXA // //if (String.IsNullOrEmpty(boleto.Remessa.Ambiente)) // //{ // // vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe o Tipo Documento!", Environment.NewLine); // // vRetorno = false; // //} // //#endregion //} #endregion OLD #endregion } // mensagem = vMsg; return vRetorno; }
public virtual bool ValidarRemessa(TipoArquivo tipoArquivo, string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { throw new NotImplementedException("Função não implementada na classe filha. Implemente na classe que está sendo criada."); }
public bool ValidarRemessaCNAB400(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; // #region Pré Validações if (banco == null) { vMsg += String.Concat("Remessa: O Banco é Obrigatório!", Environment.NewLine); vRetorno = false; } if (cedente == null) { vMsg += String.Concat("Remessa: O Cedente/Beneficiário é Obrigatório!", Environment.NewLine); vRetorno = false; } if (boletos == null || boletos.Count.Equals(0)) { vMsg += String.Concat("Remessa: Deverá existir ao menos 1 boleto para geração da remessa!", Environment.NewLine); vRetorno = false; } #endregion // foreach (Boleto boleto in boletos) { #region Validação de cada boleto if (boleto.Remessa == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe as diretrizes de remessa!", Environment.NewLine); vRetorno = false; } else { #region Validações da Remessa que deverão estar preenchidas quando BANCO DO BRASIL if (String.IsNullOrEmpty(boleto.Remessa.TipoDocumento)) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe o Tipo Documento!", Environment.NewLine); vRetorno = false; } #endregion } #endregion } // mensagem = vMsg; return vRetorno; }
public void LerArquivoRetorno(IBanco banco) { LerArquivoRetorno(banco, StreamArquivo); }
/// <summary> /// Efetua as Validações dentro da classe Boleto, para garantir a geração da remessa /// </summary> public override bool ValidarRemessa(TipoArquivo tipoArquivo, string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; // switch (tipoArquivo) { case TipoArquivo.CNAB240: //vRetorno = ValidarRemessaCNAB240(numeroConvenio, banco, cedente, boletos, numeroArquivoRemessa, out vMsg); break; case TipoArquivo.CNAB400: vRetorno = ValidarRemessaCNAB400(numeroConvenio, banco, cedente, boletos, numeroArquivoRemessa, out vMsg); break; case TipoArquivo.Outro: throw new Exception("Tipo de arquivo inexistente."); } // mensagem = vMsg; return vRetorno; }
public bool ValidarRemessaCNAB400(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; // #region Pré Validações if (banco == null) { vMsg += String.Concat("Remessa: O Banco é Obrigatório!", Environment.NewLine); vRetorno = false; } if (cedente == null) { vMsg += String.Concat("Remessa: O Cedente/Beneficiário é Obrigatório!", Environment.NewLine); vRetorno = false; } if (boletos == null || boletos.Count.Equals(0)) { vMsg += String.Concat("Remessa: Deverá existir ao menos 1 boleto para geração da remessa!", Environment.NewLine); vRetorno = false; } #endregion mensagem = vMsg; return vRetorno; }
public bool ValidarRemessaCNAB400(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; // #region Pré Validações if (banco == null) { vMsg += String.Concat("Remessa: O Banco é Obrigatório!", Environment.NewLine); vRetorno = false; } if (cedente == null) { vMsg += String.Concat("Remessa: O Cedente/Beneficiário é Obrigatório!", Environment.NewLine); vRetorno = false; } if (boletos == null || boletos.Count.Equals(0)) { vMsg += String.Concat("Remessa: Deverá existir ao menos 1 boleto para geração da remessa!", Environment.NewLine); vRetorno = false; } #endregion // foreach (Boleto boleto in boletos) { #region Validação de cada boleto if (boleto.Remessa == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe as diretrizes de remessa!", Environment.NewLine); vRetorno = false; } else { #region Validações da Remessa que deverão estar preenchidas quando BANRISUL //Comentado porque ainda está fixado em 01 //if (String.IsNullOrEmpty(boleto.Remessa.CodigoOcorrencia)) //{ // vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe o Código de Ocorrência!", Environment.NewLine); // vRetorno = false; //} if (String.IsNullOrEmpty(boleto.Remessa.TipoDocumento)) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe o Tipo Documento!", Environment.NewLine); vRetorno = false; } else if (boleto.Remessa.TipoDocumento.Equals("06") && !String.IsNullOrEmpty(boleto.NossoNumero)) { //Para o "Remessa.TipoDocumento = "06", não poderá ter NossoNumero Gerado! vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Não pode existir NossoNumero para o Tipo Documento '06 - cobrança escritural'!", Environment.NewLine); vRetorno = false; } //Para o Tipo #endregion } #endregion } // mensagem = vMsg; return vRetorno; }
/// <summary> /// Gera o arquivo de remessa /// </summary> public virtual void LerArquivoRetorno(IBanco banco, Stream arquivo) { _banco = banco; _arquivoRetorno.LerArquivoRetorno(banco, arquivo); }
private void InstanciaBanco(int codigoBanco) { try { switch (codigoBanco) { //104 - Caixa case 104: _IBanco = new Banco_Caixa(); break; //341 - Itaú case 341: _IBanco = new Banco_Itau(); break; //356 - Real case 275: case 356: _IBanco = new Banco_Real(); break; //422 - Safra case 422: _IBanco = new Banco_Safra(); break; //237 - Bradesco case 237: _IBanco = new Banco_Bradesco(); break; //347 - Sudameris case 347: _IBanco = new Banco_Sudameris(); break; //353 - Santander case 353: _IBanco = new Banco_Santander(); break; //070 - BRB case 70: _IBanco = new Banco_BRB(); break; //479 - BankBoston case 479: _IBanco = new Banco_BankBoston(); break; //001 - Banco do Brasil case 1: _IBanco = new Banco_Brasil(); break; //399 - HSBC case 399: _IBanco = new Banco_HSBC(); break; //003 - HSBC case 3: _IBanco = new Banco_Basa(); break; //409 - Unibanco case 409: _IBanco = new Banco_Unibanco(); break; //33 - Unibanco case 33: _IBanco = new Banco_Santander(); break; //41 - Banrisul case 41: _IBanco = new Banco_Banrisul(); break; //756 - Sicoob (Bancoob) case 756: _IBanco = new Banco_Sicoob(); break; //748 - Sicredi case 748: _IBanco = new Banco_Sicredi(); break; //21 - Banestes case 21: _IBanco = new Banco_Banestes(); break; //004 - Nordeste case 4: _IBanco = new Banco_Nordeste(); break; //85 - CECRED case 85: _IBanco = new Banco_Cecred(); break; default: throw new Exception("Código do banco não implementando: " + codigoBanco); } } catch (Exception ex) { throw new Exception("Erro durante a execução da transação.", ex); } }
public override bool ValidarRemessa(TipoArquivo tipoArquivo, string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { try { return _IBanco.ValidarRemessa(tipoArquivo, numeroConvenio, _IBanco, cedente, boletos, numeroArquivoRemessa, out mensagem); } catch (Exception ex) { throw new Exception("Erro durante a validação do arquivo de REMESSA.", ex); } }
public override void LerArquivoRetorno(IBanco banco, Stream arquivo) { try { StreamReader stream = new StreamReader(arquivo, System.Text.Encoding.UTF8); string linha = ""; while ((linha = stream.ReadLine()) != null) { if (!String.IsNullOrEmpty(linha)) { DetalheRetornoCNAB240 detalheRetorno = new DetalheRetornoCNAB240(); switch (linha.Substring(7, 1)) { case "0": //Header de arquivo OnLinhaLida(null, linha, EnumTipodeLinhaLida.HeaderDeArquivo); break; case "1": //Header de lote OnLinhaLida(null, linha, EnumTipodeLinhaLida.HeaderDeLote); break; case "3": //Detalhe if (linha.Substring(13, 1) == "W") { OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoW); detalheRetorno.SegmentoW.LerDetalheSegmentoWRetornoCNAB240(linha); } else if (linha.Substring(13, 1) == "E") { OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoE); detalheRetorno.SegmentoE = new DetalheSegmentoERetornoCNAB240(); detalheRetorno.SegmentoE.LerDetalheSegmentoERetornoCNAB240(linha); } else { OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoT); //detalheRetorno.SegmentoT.LerDetalheSegmentoTRetornoCNAB240(linha); detalheRetorno.SegmentoT = banco.LerDetalheSegmentoTRetornoCNAB240(linha); linha = stream.ReadLine(); OnLinhaLida(detalheRetorno, linha, EnumTipodeLinhaLida.DetalheSegmentoU); //detalheRetorno.SegmentoU.LerDetalheSegmentoURetornoCNAB240(linha); detalheRetorno.SegmentoU = banco.LerDetalheSegmentoURetornoCNAB240(linha); } ListaDetalhes.Add(detalheRetorno); break; case "5": //Trailler de lote OnLinhaLida(null, linha, EnumTipodeLinhaLida.TraillerDeLote); break; case "9": //Trailler de arquivo OnLinhaLida(null, linha, EnumTipodeLinhaLida.TraillerDeArquivo); break; } } } stream.Close(); } catch (Exception ex) { throw new Exception("Erro ao ler arquivo.", ex); } }
/// <summary> /// Efetua as Validações dentro da classe Boleto, para garantir a geração da remessa /// </summary> public override bool ValidarRemessa(TipoArquivo tipoArquivo, string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; ////IMPLEMENTACAO PENDENTE... mensagem = vMsg; return vRetorno; }
/// <summary> /// Efetua as Validações dentro da classe Boleto, para garantir a geração da remessa /// </summary> public override bool ValidarRemessa(TipoArquivo tipoArquivo, string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; ////IMPLEMENTACAO PENDENTE... //validando endereços foreach (var boleto in boletos) { if (boleto.Sacado.Endereco != null && !string.IsNullOrEmpty(boleto.Sacado.Endereco.End) && !string.IsNullOrEmpty(boleto.Sacado.Endereco.Cidade) && !string.IsNullOrEmpty(boleto.Sacado.Endereco.UF) && !string.IsNullOrEmpty(boleto.Sacado.Endereco.CEP)) continue; vMsg = string.Format("Endereço do Pagador {0} no boleto {1} inválido", boleto.Sacado.Nome, boleto.NumeroDocumento); vRetorno = false; break; } mensagem = vMsg; return vRetorno; }
/// <summary> /// Efetua as Validações dentro da classe Boleto, para garantir a geração da remessa /// </summary> public override bool ValidarRemessa(TipoArquivo tipoArquivo, string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; ////IMPLEMENTACAO PENDENTE... cedente.ContaBancaria.DigitoConta = Mod10(cedente.ContaBancaria.Agencia + cedente.ContaBancaria.Conta).ToString(); mensagem = vMsg; return vRetorno; }
/// <summary> /// Gera o arquivo de remessa /// </summary> public virtual void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { _banco = banco; _cedente = cedente; _boletos = boletos; _numeroConvenio = numeroConvenio; _numeroArquivoRemessa = numeroArquivoRemessa; _arquivoRemessa.GerarArquivoRemessa(numeroConvenio, banco, cedente, boletos, arquivo, numeroArquivoRemessa); }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 3; int numeroRegistroDetalhe = 1; string strline; StreamWriter incluiLinha = new StreamWriter(arquivo); if (banco.Codigo == 104)//quando é caixa verifica o modelo de leiatue que é está em boletos.remssa.tipodocumento strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB240, numeroArquivoRemessa, boletos[0]); else strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB240, numeroArquivoRemessa); // incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.HeaderDeArquivo); if (banco.Codigo == 104)//quando é caixa verifica o modelo de leiatue que é está em boletos.remssa.tipodocumento strline = banco.GerarHeaderLoteRemessa(numeroConvenio, cedente, numeroArquivoRemessa, TipoArquivo.CNAB240, boletos[0]); else strline = banco.GerarHeaderLoteRemessa(numeroConvenio, cedente, numeroArquivoRemessa, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.HeaderDeLote); if (banco.Codigo == 341) { #region se Banco Itau - 341 foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; } numeroRegistro--; strline = banco.GerarTrailerLoteRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeLote); numeroRegistro++; numeroRegistro++; strline = banco.GerarTrailerArquivoRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); #endregion } else if (banco.Codigo == 104 && boletos[0].Remessa.TipoDocumento.Equals("2")) { #region se Banco Caixa - 104 e tipo de arquivo da remessa SIGCB foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheSegmentoPRemessa(boleto, numeroRegistroDetalhe, numeroConvenio, cedente); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; strline = boleto.Banco.GerarDetalheSegmentoQRemessa(boleto, numeroRegistroDetalhe, boleto.Sacado); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoQ); numeroRegistro++; numeroRegistroDetalhe++; //segmento R não implementado... //if (boleto.ValorMulta > 0) //{ // strline = boleto.Banco.GerarDetalheSegmentoRRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); // incluiLinha.WriteLine(strline); // OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoR); // numeroRegistro++; // numeroRegistroDetalhe++; //} } numeroRegistro--; strline = banco.GerarTrailerLoteRemessa(numeroRegistro, boletos[0]); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeLote); numeroRegistro++; numeroRegistro++; strline = banco.GerarTrailerArquivoRemessa(numeroRegistro, boletos[0]); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); #endregion } else //para qualquer outro banco, gera CNAB240 com segmentos abaixo { #region outros bancos foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheSegmentoPRemessa(boleto, numeroRegistroDetalhe, numeroConvenio); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; strline = boleto.Banco.GerarDetalheSegmentoQRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoQ); numeroRegistro++; numeroRegistroDetalhe++; if (boleto.ValorMulta > 0) { strline = boleto.Banco.GerarDetalheSegmentoRRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoR); numeroRegistro++; numeroRegistroDetalhe++; } } numeroRegistro--; strline = banco.GerarTrailerLoteRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeLote); numeroRegistro++; numeroRegistro++; strline = banco.GerarTrailerArquivoRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); #endregion } } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }
public bool ValidarRemessaCNAB240(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { string vMsg = string.Empty; mensagem = vMsg; return true; //throw new NotImplementedException("Função não implementada."); }
public bool ValidarRemessaCNAB400(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, int numeroArquivoRemessa, out string mensagem) { bool vRetorno = true; string vMsg = string.Empty; // #region Pré Validações if (banco == null) { vMsg += String.Concat("Remessa: O Banco é Obrigatório!", Environment.NewLine); vRetorno = false; } if (cedente == null) { vMsg += String.Concat("Remessa: O Cedente/Beneficiário é Obrigatório!", Environment.NewLine); vRetorno = false; } if (boletos == null || boletos.Count.Equals(0)) { vMsg += String.Concat("Remessa: Deverá existir ao menos 1 boleto para geração da remessa!", Environment.NewLine); vRetorno = false; } #endregion // foreach (Boleto boleto in boletos) { #region Validação de cada boleto if (boleto.Remessa == null) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe as diretrizes de remessa!", Environment.NewLine); vRetorno = false; } else { #region Validações da Remessa que deverão estar preenchidas quando SICREDI //Comentado porque ainda está fixado em 01 //if (String.IsNullOrEmpty(boleto.Remessa.CodigoOcorrencia)) //{ // vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe o Código de Ocorrência!", Environment.NewLine); // vRetorno = false; //} if (String.IsNullOrEmpty(boleto.NumeroDocumento)) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe um Número de Documento!", Environment.NewLine); vRetorno = false; } else if (String.IsNullOrEmpty(boleto.Remessa.TipoDocumento)) { // Para o Sicredi, defini o Tipo de Documento sendo: // A = 'A' - SICREDI com Registro // C1 = 'C' - SICREDI sem Registro Impressão Completa pelo Sicredi // C2 = 'C' - SICREDI sem Registro Pedido de bloquetos pré-impressos // ** Isso porque são tratados 3 leiautes de escrita diferentes para o Detail da remessa; vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe o Tipo Documento!", Environment.NewLine); vRetorno = false; } else if (!boleto.Remessa.TipoDocumento.Equals("A") && !boleto.Remessa.TipoDocumento.Equals("C1") && !boleto.Remessa.TipoDocumento.Equals("C2")) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Tipo de Documento Inválido! Deverão ser: A = SICREDI com Registro; C1 = SICREDI sem Registro Impressão Completa pelo Sicredi; C2 = SICREDI sem Registro Pedido de bloquetos pré-impressos", Environment.NewLine); vRetorno = false; } //else if (boleto.Remessa.TipoDocumento.Equals("06") && !String.IsNullOrEmpty(boleto.NossoNumero)) //{ // //Para o "Remessa.TipoDocumento = "06", não poderá ter NossoNumero Gerado! // vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Não pode existir NossoNumero para o Tipo Documento '06 - cobrança escritural'!", Environment.NewLine); // vRetorno = false; //} else if (!boleto.EspecieDocumento.Codigo.Equals("A") && //A - Duplicata Mercantil por Indicação !boleto.EspecieDocumento.Codigo.Equals("B") && //B - Duplicata Rural; !boleto.EspecieDocumento.Codigo.Equals("C") && //C - Nota Promissória; !boleto.EspecieDocumento.Codigo.Equals("D") && //D - Nota Promissória Rural; !boleto.EspecieDocumento.Codigo.Equals("E") && //E - Nota de Seguros; !boleto.EspecieDocumento.Codigo.Equals("F") && //G – Recibo; !boleto.EspecieDocumento.Codigo.Equals("H") && //H - Letra de Câmbio; !boleto.EspecieDocumento.Codigo.Equals("I") && //I - Nota de Débito; !boleto.EspecieDocumento.Codigo.Equals("J") && //J - Duplicata de Serviço por Indicação; !boleto.EspecieDocumento.Codigo.Equals("O") && //O – Boleto Proposta !boleto.EspecieDocumento.Codigo.Equals("K") //K – Outros. ) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Informe o Código da EspécieDocumento! São Aceitas:{A,B,C,D,E,F,H,I,J,O,K}", Environment.NewLine); vRetorno = false; } else if (!boleto.Sacado.CPFCNPJ.Length.Equals(11) && !boleto.Sacado.CPFCNPJ.Length.Equals(14)) { vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: Cpf/Cnpj diferente de 11/14 caracteres!", Environment.NewLine); vRetorno = false; } else if (!boleto.NossoNumero.Length.Equals(8)) { //sidnei.klein: Segundo definição recebida pelo Sicredi-RS, o Nosso Número sempre terá somente 8 caracteres sem o DV que está no boleto.DigitoNossoNumero vMsg += String.Concat("Boleto: ", boleto.NumeroDocumento, "; Remessa: O Nosso Número diferente de 8 caracteres!", Environment.NewLine); vRetorno = false; } #endregion } #endregion } // mensagem = vMsg; return vRetorno; }
public override void GerarArquivoRemessa(string numeroConvenio, IBanco banco, Cedente cedente, Boletos boletos, Stream arquivo, int numeroArquivoRemessa) { try { int numeroRegistro = 0; int numeroRegistroDetalhe = 1; string strline; StreamWriter incluiLinha = new StreamWriter(arquivo); if (banco.Codigo == 104)//quando é caixa verifica o modelo de leiatue que é está em boletos.remssa.tipodocumento strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB240, numeroArquivoRemessa, boletos[0]); else strline = banco.GerarHeaderRemessa(numeroConvenio, cedente, TipoArquivo.CNAB240, numeroArquivoRemessa); numeroRegistro++; // incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.HeaderDeArquivo); if (banco.Codigo == 104)//quando é caixa verifica o modelo de leiatue que é está em boletos.remssa.tipodocumento strline = banco.GerarHeaderLoteRemessa(numeroConvenio, cedente, numeroArquivoRemessa, TipoArquivo.CNAB240, boletos[0]); else strline = banco.GerarHeaderLoteRemessa(numeroConvenio, cedente, numeroArquivoRemessa, TipoArquivo.CNAB240); if (strline != "") { incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.HeaderDeLote); numeroRegistro++; } if (banco.Codigo == 341) { #region se Banco Itau - 341 foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; } numeroRegistro--; strline = banco.GerarTrailerLoteRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeLote); numeroRegistro++; strline = banco.GerarTrailerArquivoRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); #endregion } else if (banco.Codigo == 104) // Só validar boleto.Remessa quando o banco for Caixa porque quando o banco for diferente de 104 a propriedade "Remessa" fica null { #region se Banco Caixa - 104 e tipo de arquivo da remessa SIGCB if ((boletos[0].Remessa.TipoDocumento.Equals("2")) || boletos[0].Remessa.TipoDocumento.Equals("1")) { foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheSegmentoPRemessa(boleto, numeroRegistroDetalhe, numeroConvenio, cedente); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; strline = boleto.Banco.GerarDetalheSegmentoQRemessa(boleto, numeroRegistroDetalhe, boleto.Sacado); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoQ); numeroRegistro++; numeroRegistroDetalhe++; //segmento R não implementado... //if (boleto.ValorMulta > 0) //{ // strline = boleto.Banco.GerarDetalheSegmentoRRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); // incluiLinha.WriteLine(strline); // OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoR); // numeroRegistro++; // numeroRegistroDetalhe++; //} } numeroRegistro--; strline = banco.GerarTrailerLoteRemessa(numeroRegistro, boletos[0]); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeLote); numeroRegistro++; numeroRegistro++; strline = banco.GerarTrailerArquivoRemessa(numeroRegistro, boletos[0]); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); } #endregion } else if (banco.Codigo == 33) { #region se Banco Santander - 33 foreach (Boleto boleto in boletos) { boleto.Banco = banco; boleto.Remessa.NumeroLote = numeroArquivoRemessa; strline = boleto.Banco.GerarDetalheSegmentoPRemessa(boleto, numeroRegistroDetalhe, numeroConvenio); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; strline = boleto.Banco.GerarDetalheSegmentoQRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoQ); numeroRegistro++; numeroRegistroDetalhe++; if (boleto.ValorMulta > 0 || boleto.OutrosDescontos > 0 || boleto.PercMulta > 0) { strline = boleto.Banco.GerarDetalheSegmentoRRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoR); numeroRegistro++; numeroRegistroDetalhe++; } strline = boleto.Banco.GerarDetalheSegmentoSRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoS); numeroRegistro++; numeroRegistroDetalhe++; } numeroRegistro--; strline = banco.GerarTrailerLoteRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeLote); numeroRegistro++; numeroRegistro++; strline = banco.GerarTrailerArquivoRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); #endregion } else if (banco.Codigo == 237) // bradesco { decimal totalTitulos = 0; foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheSegmentoARemessa(boleto, numeroRegistroDetalhe); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; strline = boleto.Banco.GerarDetalheSegmentoBRemessa(boleto, numeroRegistroDetalhe); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; totalTitulos += boleto.ValorBoleto; } numeroRegistro++; strline = banco.GerarTrailerRemessaComDetalhes(numeroRegistro, boletos.Count, TipoArquivo.CNAB240, cedente, totalTitulos); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); } else //para qualquer outro banco, gera CNAB240 com segmentos abaixo { #region outros bancos foreach (Boleto boleto in boletos) { boleto.Banco = banco; strline = boleto.Banco.GerarDetalheSegmentoPRemessa(boleto, numeroRegistroDetalhe, numeroConvenio); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoP); numeroRegistro++; numeroRegistroDetalhe++; strline = boleto.Banco.GerarDetalheSegmentoQRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoQ); numeroRegistro++; numeroRegistroDetalhe++; if (boleto.PercMulta > 0 || boleto.ValorMulta > 0) { strline = boleto.Banco.GerarDetalheSegmentoRRemessa(boleto, numeroRegistroDetalhe, TipoArquivo.CNAB240); incluiLinha.WriteLine(strline); OnLinhaGerada(boleto, strline, EnumTipodeLinha.DetalheSegmentoR); numeroRegistro++; numeroRegistroDetalhe++; } } numeroRegistro--; strline = banco.GerarTrailerLoteRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeLote); numeroRegistro++; numeroRegistro++; strline = banco.GerarTrailerArquivoRemessa(numeroRegistro); incluiLinha.WriteLine(strline); OnLinhaGerada(null, strline, EnumTipodeLinha.TraillerDeArquivo); incluiLinha.Close(); #endregion } } catch (Exception ex) { throw new Exception("Erro ao gerar arquivo remessa.", ex); } }