/// <summary> /// Consulta a situação cadastral, com base na UF/Documento /// <para>O documento pode ser: CPF ou CNPJ. O serviço avaliará o tamanho da string passada e determinará se a coonsulta será por CPF ou por CNPJ</para> /// </summary> /// <param name="uf">Sigla da UF consultada, informar 'SU' para SUFRAMA.</param> /// <param name="tipoDocumento">Tipo do documento</param> /// <param name="documento">CPF ou CNPJ</param> /// <returns>Retorna um objeto da classe RetornoNfeConsultaCadastro com o retorno do serviço NfeConsultaCadastro</returns> public RetornoNfeConsultaCadastro ConsultaCadastro(string uf, ConsultaCadastroTipoDocumento tipoDocumento, string documento) { var servicoNFe = new ServicosNFe(ConfiguracaoServico.Instancia); return(servicoNFe.NfeConsultaCadastro(uf, tipoDocumento, documento)); }
private void BtnConsultaCadastro_Click(object sender, RoutedEventArgs e) { try { #region Consulta Cadastro var uf = Funcoes.InpuBox(this, "Consultar Cadastro", "UF do Documento a ser Consultado:"); if (String.IsNullOrEmpty(uf)) { throw new Exception("A UF deve ser informada!"); } if (uf.Length != 2) { throw new Exception("UF deve conter 2 caracteres!"); } var documento = Funcoes.InpuBox(this, "Consultar Cadastro", "Documento(CPF/CNPJ):"); if (String.IsNullOrEmpty(documento)) { throw new Exception("O Documento(CPF/CNPJ) deve ser informado!"); } if (documento.Length != 11 & documento.Length != 14) { throw new Exception("O Documento(CPF/CNPJ) deve conter 11 ou 14 caracteres!"); } var servicoNFe = new ServicosNFe(_configuracoes.CfgServico); var retornoConsulta = servicoNFe.NfeConsultaCadastro(uf, documento); TrataRetorno(retornoConsulta); #endregion } catch (Exception ex) { if (!String.IsNullOrEmpty(ex.Message)) { Funcoes.Mensagem(ex.Message, "Erro", MessageBoxButton.OK); } } }
private static async Task FuncaoConsultaCadastroContribuinte() { try { #region Consulta Cadastro Console.Clear(); Console.WriteLine("UF do Documento a ser Consultado:"); string uf = Console.ReadLine(); if (string.IsNullOrEmpty(uf)) { throw new Exception("A UF deve ser informada!"); } if (uf.Length != 2) { throw new Exception("UF deve conter 2 caracteres!"); } Console.Clear(); Console.WriteLine("Tipo de documento a ser consultado: (0 - IE; 1 - CNPJ; 2 - CPF):"); string tipoDocumento = Console.ReadLine(); if (string.IsNullOrEmpty(tipoDocumento)) { throw new Exception("O Tipo de documento deve ser informado!"); } if (tipoDocumento.Length != 1) { throw new Exception("O Tipo de documento deve conter um apenas um número!"); } if (!tipoDocumento.All(char.IsDigit)) { throw new Exception("O Tipo de documento deve ser um número inteiro"); } int intTipoDocumento = int.Parse(tipoDocumento); if (!(intTipoDocumento >= 0 && intTipoDocumento <= 2)) { throw new Exception("Tipos válidos: (0 - IE; 1 - CNPJ; 2 - CPF)"); } Console.Clear(); Console.WriteLine("Documento(IE/CNPJ/CPF):"); string documento = Console.ReadLine(); if (string.IsNullOrEmpty(documento)) { throw new Exception("O Documento(IE/CNPJ/CPF) deve ser informado!"); } //efetua req de consulta ServicosNFe servicoNFe = new ServicosNFe(_configuracoes.CfgServico); var retornoConsulta = servicoNFe.NfeConsultaCadastro(uf, (ConsultaCadastroTipoDocumento)intTipoDocumento, documento); OnSucessoSync(retornoConsulta); #endregion } catch (ComunicacaoException ex) { throw ex; } catch (ValidacaoSchemaException ex) { throw ex; } catch (Exception ex) { throw ex; } }
public void ConsultaCadastro(Pedido ped) { int NumOfRetries = 10; int trysExCom = 0; int trysExOthers = 0; var recRet = new Model.retConsCad(); Task.Run(() => { TryAgain: try { var servicoNFe = new ServicosNFe(Configuracoes.CfgServico); //var cert = DFe.Utils.Assinatura.CertificadoDigital.ListareObterDoRepositorio(); //Configuracoes.CfgServico.Certificado.Serial = cert.SerialNumber; //Configuracoes.CfgServico.Certificado.Serial = "00D424AA"; var retornoConsulta = servicoNFe.NfeConsultaCadastro("MG", (ConsultaCadastroTipoDocumento)1, ped.Cliente.CNPJ.Replace(".", "").Replace("/", "").Replace("-", "")); recRet = FuncoesXml.XmlStringParaClasse <Model.retConsCad>(retornoConsulta.RetornoCompletoStr); //ped.Cliente.RetConsultaCadastro = recRet; using (var context = new ColinfoContext()) { var vnd = context.Arquivos .Include(vd => vd.Pedidos) .ThenInclude(cli => cli.Cliente) .ThenInclude(cons => cons.RetConsultaCadastro) .ThenInclude(inf => inf.infCons) .ThenInclude(cad => cad.infCad) .FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID); var oldPed = vnd.Pedidos.FirstOrDefault(pd => pd.PedidoID == ped.PedidoID); var ctxPed = Arquivos.FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID).Pedidos.FirstOrDefault(p => p.PedidoID == ped.PedidoID); var ctxVnd = Arquivos.FirstOrDefault(v => v.ArquivoID == ped.Arquivo.ArquivoID); oldPed.Cliente.RetConsultaCadastro = recRet; oldPed.Cliente.Situacao = SituacaoCadastro(oldPed); context.Entry(oldPed).State = EntityState.Modified; context.SaveChanges(); ctxPed.Cliente.RetConsultaCadastro = recRet; Arquivo = ctxVnd; NotifyOfPropertyChange(() => ctxVnd.Pedidos); NotifyOfPropertyChange(() => Arquivo.Pedidos); Arquivo.ForcePropertyChanged("Pedidos"); ctxPed.Cliente.ForcePropertyChanged("RetConsultaCadastro"); } } catch (ComunicacaoException ex) { if (trysExCom < NumOfRetries) { trysExCom += 1; goto TryAgain; } var consulta = new Model.retConsCad() { ErrorCode = "err_dives", ErrorMessage = ex.Message }; EditarPedido(ped, consulta); } catch (ValidacaoSchemaException ex) { var consulta = new Model.retConsCad() { ErrorCode = "err_dives", ErrorMessage = ex.Message }; EditarPedido(ped, consulta); } catch (DbUpdateException) { throw; } catch (Exception ex) { if (trysExOthers < NumOfRetries) { trysExOthers += 1; goto TryAgain; } var consulta = new Model.retConsCad() { ErrorCode = "err_dives", ErrorMessage = ex.Message }; EditarPedido(ped, consulta); } }); }