예제 #1
0
 private void VerNFe(object sender, RoutedEventArgs e)
 {
     using (var repo = new BaseGeral.Repositorio.Leitura())
     {
         var item  = repo.ObterNota(ItemBanco.NotaFiscalRelacionada);
         var acoes = new AcoesNFe(item);
         BasicMainPage.Current.Navegar <Fiscal.Visualizacao>(acoes);
     }
 }
예제 #2
0
        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);
                    }
                }
            }
        }