Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Melhorias - Interceptar linha atual no processo de leitura e escrita #122

Merged
merged 4 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/FiscalBr.Common/Sped/ArquivoSped.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ namespace FiscalBr.Common.Sped
{
public abstract class ArquivoSped
{
public event EventHandler<SpedEventArgs> AoProcessarLinha;
protected void AoProcessarLinhaRaise(object sender, SpedEventArgs e)
public event EventHandler<SpedEventArgs> AoLerLinha;
protected void AoLerLinhaRaise(object sender, SpedEventArgs e)
{
if (AoProcessarLinha != null)
AoProcessarLinha.Invoke(sender, e);
if (AoLerLinha != null)
AoLerLinha.Invoke(sender, e);
}

public event EventHandler<SpedEventArgs> AntesEscreverLinha;
protected void AntesEscreverLinhaRaise(object sender, SpedEventArgs e)
{
if (AntesEscreverLinha != null)
AntesEscreverLinha.Invoke(sender, e);
}

public List<string> Linhas { get; private set; }
Expand Down Expand Up @@ -130,7 +137,7 @@ private int ObterPrimeiraVersaoLayout()
public virtual void CalcularBloco9(bool totalizarblocos = true)
{
if (Linhas == null || !Linhas.Any())
throw new Exception("Não é possível calcular o bloco 9 sem as linhas. Execute a função \"GerarLinhas()\", gere as linhas manualemnte ou leia um arquivo para preencher as linhas.");
throw new Exception("Não é possível calcular o bloco 9 sem as linhas. Execute a função \"GerarLinhas()\", gere as linhas manualmente ou leia um arquivo para preencher as linhas.");
}

/// <summary>
Expand Down Expand Up @@ -161,7 +168,15 @@ protected void EscreverLinha(RegistroSped registro)
if (!string.IsNullOrEmpty(erro))
Erros.Add(erro);

Linhas.Add(texto);
//permite interceptar a linha que será escrita e alterar o texto da linha
var args = new SpedEventArgs
{
Linha = texto,
Registro = registro
};
AntesEscreverLinhaRaise(this, args);

Linhas.Add(args.Linha);
}

protected virtual void GerarComFilhos(object registro)
Expand Down
2 changes: 1 addition & 1 deletion src/FiscalBr.EFDContribuicoes/ArquivoEFDContribuicoes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Ler(string path, Encoding encoding = null, int codVersaoLay
Linha = linha,
Registro = registro
};
AoProcessarLinhaRaise(this, args);
AoLerLinhaRaise(this, args);

if (linha.StartsWith("|0"))
LerBloco0(registro);
Expand Down
4 changes: 2 additions & 2 deletions src/FiscalBr.EFDFiscal/ArquivoEFDFiscal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void Ler(string[] source)
Linha = linha,
Registro = registro
};
AoProcessarLinhaRaise(this, args);
AoLerLinhaRaise(this, args);

if (linha.StartsWith("|0"))
LerBloco0(registro);
Expand Down Expand Up @@ -98,7 +98,7 @@ public override void Ler(string path, Encoding encoding = null, int codVersaoLay
Linha = linha,
Registro = registro
};
AoProcessarLinhaRaise(this, args);
AoLerLinhaRaise(this, args);

if (linha.StartsWith("|0"))
LerBloco0(registro);
Expand Down
Loading