private async void Analisar(object sender, RoutedEventArgs e) { if (UF == null || string.IsNullOrEmpty(Chave)) { return; } var gerenciador = new GerenciadorGeral <ConsSitNFe, RetConsSitNFe>(UF, Operacoes.Consultar, Homologacao, isNFCe); var envio = new ConsSitNFe(Chave, Homologacao); RetConsSitNFe resultado = default(RetConsSitNFe); X509Certificate2[] certs; using (var loja = new X509Store(StoreName.My, StoreLocation.CurrentUser)) { loja.Open(OpenFlags.ReadOnly); certs = loja.Certificates.Cast <X509Certificate2>().ToArray(); } Progresso progresso = null; progresso = new Progresso(async x => { resultado = await gerenciador.EnviarAsync(envio, false, (X509Certificate2)x); await progresso.Update(5); return(true, resultado.DescricaoResposta); }, certs, "Subject", gerenciador.Etapas.Concat("Analisar resultado no banco de dados")); gerenciador.ProgressChanged += async(x, y) => await progresso.Update(y); await progresso.ShowAsync(); if (resultado.StatusResposta == 100) { NFeDI nota = null; using (var leit = new BaseGeral.Repositorio.Leitura()) { nota = leit.ObterNota($"NFe{resultado.ChaveNFe}"); } if (nota != null && nota.Status < 4) { using (var esc = new BaseGeral.Repositorio.Escrita()) { nota.Status = (int)StatusNota.Emitida; var original = XElement.Parse(nota.XML).FromXElement <NFe>(); var novo = new ProcessoNFe() { NFe = original, ProtNFe = resultado.Protocolo }; nota.XML = novo.ToXElement().ToString(); esc.SalvarItemSimples(nota, DefinicoesTemporarias.DateTimeNow); } } } }
/// <summary> /// Definir o valor de algumas das propriedades do objeto "Configuracoes" /// </summary> protected override void DefinirConfiguracao() { ConsSitNFe xml = new ConsSitNFe(); xml = xml.LerXML <ConsSitNFe>(ConteudoXML); if (!Configuracoes.Definida) { Configuracoes.Servico = Servico.NFeConsultaProtocolo; Configuracoes.CodigoUF = Convert.ToInt32(xml.ChNFe.Substring(0, 2)); Configuracoes.TipoAmbiente = xml.TpAmb; Configuracoes.Modelo = (ModeloDFe)int.Parse(xml.ChNFe.Substring(20, 2)); Configuracoes.SchemaVersao = xml.Versao; base.DefinirConfiguracao(); } }
/// <summary> /// Definir o valor de algumas das propriedades do objeto "Configuracoes" /// </summary> protected override void DefinirConfiguracao() { ConsSitNFe xml = new ConsSitNFe(); xml.Ler(ConteudoXML); if (!Configuracoes.Definida) { Configuracoes.cUF = Convert.ToInt32(xml.chNFe.Substring(0, 2)); Configuracoes.tpAmb = xml.tpAmb; Configuracoes.mod = xml.chNFe.Substring(20, 2); Configuracoes.tpEmis = xml.tpEmis; Configuracoes.SchemaVersao = xml.versao; base.DefinirConfiguracao(); } //Remover a tag tpEmis que não é padrão do XML ConteudoXML.DocumentElement.RemoveChild(ConteudoXML.GetElementsByTagName("tpEmis")[0]); }
public ConsultaProtocolo(ConsSitNFe consSitNFe, Configuracao configuracao) : this(consSitNFe.GerarXML(), configuracao) { }