Skip to content

Commit

Permalink
Adicionado Eventos Antes do envio do CT-e e MDF-e
Browse files Browse the repository at this point in the history
  • Loading branch information
robertorp committed Apr 9, 2017
1 parent 72883cd commit 4f7a375
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 0 deletions.
Binary file modified .vs/Zeus NFe/v15/.suo
Binary file not shown.
12 changes: 12 additions & 0 deletions CTe.AppTeste/CTeTesteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,10 @@ public void CriarEnviarCTe2e3()
var numeroLote = InputBoxTuche("Número Lote");

var servicoRecepcao = new ServicoCTeRecepcao();

// Evento executado antes do envio do CT-e para o WebService
// servicoRecepcao.AntesDeEnviar += AntesEnviarLoteCte;

var retornoEnvio = servicoRecepcao.CTeRecepcao(int.Parse(numeroLote), new List<CteEletronico> { cteEletronico });

OnSucessoSync(new RetornoEEnvio(retornoEnvio));
Expand All @@ -1039,6 +1043,14 @@ public void CriarEnviarCTe2e3()
new ConfiguracaoDao().SalvarConfiguracao(config);
}

private void AntesEnviarLoteCte(object sender, AntesEnviarRecepcao e)
{
e.enviCTe.CTe.ForEach(cte =>
{
MessageBoxTuche(cte.Chave());
});
}


private static int GetRandom()
{
Expand Down
1 change: 1 addition & 0 deletions CTe.Servicos/CTe.Servicos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="Factory\WsdlFactory.cs" />
<Compile Include="Inutilizacao\InutilizacaoServico.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Recepcao\AntesEnviarRecepcao.cs" />
<Compile Include="Recepcao\ServicoCTeRecepcao.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
20 changes: 20 additions & 0 deletions CTe.Servicos/Recepcao/AntesEnviarRecepcao.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using CTe.Classes.Servicos.Recepcao;

namespace CTe.Servicos.Recepcao
{
public class AntesEnviarRecepcao : EventArgs
{
private readonly enviCTe _enviCTe;

public AntesEnviarRecepcao(enviCTe enviCTe)
{
_enviCTe = enviCTe;
}

public enviCTe enviCTe
{
get { return _enviCTe; }
}
}
}
12 changes: 12 additions & 0 deletions CTe.Servicos/Recepcao/ServicoCTeRecepcao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
/* Rua Comendador Francisco josé da Cunha, 111 - Itabaiana - SE - 49500-000 */
/********************************************************************************/

using System;
using System.Collections.Generic;
using CTe.Classes;
using CTe.Classes.Servicos.Recepcao;
Expand All @@ -44,6 +45,8 @@ namespace CTe.Servicos.Recepcao
{
public class ServicoCTeRecepcao
{
public event EventHandler<AntesEnviarRecepcao> AntesDeEnviar;

public retEnviCte CTeRecepcao(int lote, List<CTeEletronico> cteEletronicosList)
{
var instanciaConfiguracao = ConfiguracaoServico.Instancia;
Expand Down Expand Up @@ -73,12 +76,21 @@ public retEnviCte CTeRecepcao(int lote, List<CTeEletronico> cteEletronicosList)
enviCte.SalvarXmlEmDisco();

var webService = WsdlFactory.CriaWsdlCteRecepcao();

OnAntesDeEnviar(enviCte);

var retornoXml = webService.cteRecepcaoLote(enviCte.CriaRequestWs());

var retorno = retEnviCte.LoadXml(retornoXml.OuterXml, enviCte);
retorno.SalvarXmlEmDisco();

return retorno;
}

protected virtual void OnAntesDeEnviar(enviCTe enviCTe)
{
var handler = AntesDeEnviar;
if (handler != null) handler(this, new AntesEnviarRecepcao(enviCTe));
}
}
}
10 changes: 10 additions & 0 deletions MDFe.AppTeste/MDFeTesteModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
/* Esta biblioteca é distribuída na expectativa de que seja útil, porém, SEM */
/* NENHUMA GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU */
/* ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral Menor*/
/* ADEQUAÇÃO A UMA FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral Menor*/
/* do GNU para mais detalhes. (Arquivo LICENÇA.TXT ou LICENSE.TXT) */
/* */
/* Você deve ter recebido uma cópia da Licença Pública Geral Menor do GNU junto*/
Expand Down Expand Up @@ -778,6 +779,10 @@ public void CriarEnviar()
#endregion

var servicoRecepcao = new ServicoMDFeRecepcao();

// Evento executado antes do envio da mdf-e para a sefaz
//servicoRecepcao.AntesDeEnviar += AntesEnviar;

var retornoEnvio = servicoRecepcao.MDFeRecepcao(1, mdfe);

OnSucessoSync(new RetornoEEnvio(retornoEnvio));
Expand All @@ -786,6 +791,11 @@ public void CriarEnviar()
new ConfiguracaoDao().SalvarConfiguracao(config);
}

private void AntesEnviar(object sender, AntesDeEnviar e)
{
MessageBoxTuche(e.enviMdFe.MDFe.Chave());
}

private static int GetRandom()
{
var rand = new Random();
Expand Down
1 change: 1 addition & 0 deletions MDFe.Servicos/MDFe.Servicos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
<Compile Include="Factory\ClassesFactory.cs" />
<Compile Include="Factory\WsdlFactory.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RecepcaoMDFe\AntesDeEnviar.cs" />
<Compile Include="RecepcaoMDFe\ServicoMDFeRecepcao.cs" />
<Compile Include="RetRecepcaoMDFe\ServicoMDFeRetRecepcao.cs" />
<Compile Include="StatusServicoMDFe\ServicoMDFeStatusServico.cs" />
Expand Down
21 changes: 21 additions & 0 deletions MDFe.Servicos/RecepcaoMDFe/AntesDeEnviar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using MDFe.Classes.Servicos.Autorizacao;

namespace MDFe.Servicos.RecepcaoMDFe
{
public class AntesDeEnviar : EventArgs
{
private MDFeEnviMDFe _enviMdFe;

public AntesDeEnviar(MDFeEnviMDFe enviMdfe)
{
_enviMdFe = enviMdfe;
}

public MDFeEnviMDFe enviMdFe
{
get { return _enviMdFe; }
set { _enviMdFe = value; }
}
}
}
13 changes: 13 additions & 0 deletions MDFe.Servicos/RecepcaoMDFe/ServicoMDFeRecepcao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
/* Rua Comendador Francisco josé da Cunha, 111 - Itabaiana - SE - 49500-000 */
/********************************************************************************/

using System;
using MDFe.Classes.Extencoes;
using MDFe.Classes.Flags;
using MDFe.Classes.Retorno.MDFeRecepcao;
using MDFe.Classes.Servicos.Autorizacao;
using MDFe.Servicos.Factory;
using MDFe.Utils.Configuracoes;
using MDFe.Utils.Flags;
Expand All @@ -43,6 +45,8 @@ namespace MDFe.Servicos.RecepcaoMDFe
{
public class ServicoMDFeRecepcao
{
public event EventHandler<AntesDeEnviar> AntesDeEnviar;

public MDFeRetEnviMDFe MDFeRecepcao(long lote, MDFeEletronico mdfe)
{
var enviMDFe = ClassesFactory.CriaEnviMDFe(lote, mdfe);
Expand All @@ -62,12 +66,21 @@ public MDFeRetEnviMDFe MDFeRecepcao(long lote, MDFeEletronico mdfe)
enviMDFe.SalvarXmlEmDisco();

var webService = WsdlFactory.CriaWsdlMDFeRecepcao();

OnAntesDeEnviar(enviMDFe);

var retornoXml = webService.mdfeRecepcaoLote(enviMDFe.CriaXmlRequestWs());

var retorno = MDFeRetEnviMDFe.LoadXml(retornoXml.OuterXml, enviMDFe);
retorno.SalvarXmlEmDisco();

return retorno;
}

protected virtual void OnAntesDeEnviar(MDFeEnviMDFe enviMdfe)
{
var handler = AntesDeEnviar;
if (handler != null) handler(this, new AntesDeEnviar(enviMdfe));
}
}
}

0 comments on commit 4f7a375

Please sign in to comment.