public string RetPrestadorEmail() { belConnection cx = new belConnection(); try { string sMsgPadraoEmail = "{5}Razão Social:{1}{0}{5}E-mail: {2}{0}{5}CCM :{3}{0}{5}CNPJ:{4}{0}{0}"; StringBuilder sQuery = new StringBuilder(); sQuery.Append(" select empresa.cd_cgc, empresa.cd_inscrmu, empresa.cd_email, empresa.nm_empresa from empresa "); sQuery.Append(" where empresa.cd_empresa = '" + belStatic.codEmpresaNFe + "'"); FbCommand Comand = new FbCommand(sQuery.ToString(), cx.get_Conexao()); cx.Open_Conexao(); Comand.ExecuteNonQuery(); FbDataReader dr = Comand.ExecuteReader(); dr.Read(); objtcIdentificacaoPrestador = new tcIdentificacaoPrestador(); return string.Format(sMsgPadraoEmail, "<br>", dr["nm_empresa"].ToString(), dr["cd_email"].ToString(), dr["cd_inscrmu"].ToString(), dr["cd_cgc"].ToString(), " "); } catch (Exception ex) { throw; } finally { cx.Close_Conexao(); } }
public tcIdentificacaoPrestador RettcIdentificacaoPrestador(FbConnection Conn, string sNota) { try { StringBuilder sQuery = new StringBuilder(); sQuery.Append(" select empresa.cd_cgc, empresa.cd_inscrmu from empresa "); sQuery.Append(" where empresa.cd_empresa = '" + belStatic.codEmpresaNFe + "'"); FbCommand Comand = new FbCommand(sQuery.ToString(), Conn); if (Conn.State == System.Data.ConnectionState.Closed) { Conn.Open(); } Comand.ExecuteNonQuery(); FbDataReader dr = Comand.ExecuteReader(); dr.Read(); objtcIdentificacaoPrestador = new tcIdentificacaoPrestador(); if (dr["cd_cgc"] != null) { objtcIdentificacaoPrestador.Cnpj = dr["cd_cgc"].ToString(); } else { throw new Exception("Prestador cadastrado sem CNPJ, Item é obrigatório!"); } if (dr["cd_inscrmu"] != null) { objtcIdentificacaoPrestador.InscricaoMunicipal = dr["cd_inscrmu"].ToString(); } } catch (Exception ex) { throw; } finally { Conn.Close(); } return objtcIdentificacaoPrestador; }
private string BuscaRetornoWebService(tcIdentificacaoPrestador Prestador) { try { //Homologação if (belStatic.tpAmbNFse == 2) { HLP.WebService.Itu_servicos_Homologacao.ServiceGinfesImplService objtrans = new HLP.WebService.Itu_servicos_Homologacao.ServiceGinfesImplService(); objtrans.ClientCertificates.Add(cert); objtrans.Timeout = 60000; return objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador)); } else if (belStatic.tpAmbNFse == 1) { HLP.WebService.Itu_servicos_Producao.ServiceGinfesImplService objtrans = new HLP.WebService.Itu_servicos_Producao.ServiceGinfesImplService(); objtrans.ClientCertificates.Add(cert); objtrans.Timeout = 60000; return objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador)); } else { throw new Exception("Cadastro de Empresa não configurado para enviar NFe-serviço"); } } catch (Exception) { throw; } }
private string MontaXmlConsultaLote(tcIdentificacaoPrestador objPrestador) { XmlSchemaCollection myschema = new XmlSchemaCollection(); XmlValidatingReader reader; try { XNamespace tipos = "http://www.ginfes.com.br/tipos_v03.xsd"; XNamespace pf = "http://www.ginfes.com.br/servico_consultar_lote_rps_envio_v03.xsd"; XContainer conPrestador = null; XContainer conProtocolo = null; XContainer conConsultarLoteRpsEnvio = (new XElement(pf + "ConsultarLoteRpsEnvio", new XAttribute("xmlns", "http://www.ginfes.com.br/servico_consultar_lote_rps_envio_v03.xsd"), new XAttribute(XNamespace.Xmlns + "tipos", "http://www.ginfes.com.br/tipos_v03.xsd"))); conPrestador = (new XElement(pf + "Prestador", new XElement(tipos + "Cnpj", objPrestador.Cnpj), ((objPrestador.InscricaoMunicipal != "") ? new XElement(tipos + "InscricaoMunicipal", objPrestador.InscricaoMunicipal) : null))); conProtocolo = new XElement(pf + "Protocolo", Protocolo); conConsultarLoteRpsEnvio.Add(conPrestador); conConsultarLoteRpsEnvio.Add(conProtocolo); AssinaNFeXml Assinatura = new AssinaNFeXml(); string sArquivo = Assinatura.ConfigurarArquivo(conConsultarLoteRpsEnvio.ToString(), "Protocolo", cert); //Valida Globais getschema = new Globais(); XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None); reader = new XmlValidatingReader(sArquivo, XmlNodeType.Element, context); myschema.Add("http://www.ginfes.com.br/servico_consultar_lote_rps_envio_v03.xsd", belStaticPastas.SCHEMA_NFSE + "\\servico_consultar_lote_rps_envio_v03.xsd"); reader.ValidationType = ValidationType.Schema; reader.Schemas.Add(myschema); while (reader.Read()) { } return sArquivo; } catch (Exception ex) { throw; } }
public string BuscaRetorno(tcIdentificacaoPrestador Prestador, KryptonLabel lblStatus, ProgressBar ProgresStatus) { bool parar = false; Globais glob = new Globais(); string sMensagemErro = ""; int iCountBuscaRet = 0; ProgresStatus.Step = 1; ProgresStatus.Minimum = 0; ProgresStatus.Maximum = 20; ProgresStatus.MarqueeAnimationSpeed = 20; ProgresStatus.Value = 0; try { for (; ; ) { ProgresStatus.PerformStep(); ProgresStatus.Refresh(); lblStatus.Text = "Sistema tentando buscar retorno!!" + Environment.NewLine + "Tentativas: " + iCountBuscaRet.ToString() + " de 21"; lblStatus.Refresh(); string sRetConsulta = BuscaRetornoWebService(Prestador); XmlDocument xmlRet = new XmlDocument(); xmlRet.LoadXml(sRetConsulta); XmlNodeList xNodeList = xmlRet.GetElementsByTagName("ns4:MensagemRetorno"); if (xNodeList.Count > 0) { sMensagemErro = "{3}Lote: " + NumeroLote + "{3}{3}Código: {0}{3}{3}Mensagem: {1}{3}{3}Correção: {2}{3}{3}Protocolo: " + Protocolo; foreach (XmlNode node in xNodeList) { sCodigoRetorno = node["ns4:Codigo"].InnerText; if (sCodigoRetorno.Equals("E4") && iCountBuscaRet <= 20) { iCountBuscaRet++; } else { sMensagemErro = string.Format(sMensagemErro, node["ns4:Codigo"].InnerText, "Esse RPS ainda não se encontra em nossa base de dados.", node["ns4:Correcao"].InnerText, Environment.NewLine); parar = true; } } } else if (xmlRet.GetElementsByTagName("ns3:CompNfse").Count > 0) { this.sCodigoRetorno = ""; sMensagemErro = ""; Globais objGlobais = new Globais(); bool bAlteraDupl = Convert.ToBoolean(objGlobais.LeRegConfig("GravaNumNFseDupl")); for (int i = 0; i < xmlRet.GetElementsByTagName("ns3:CompNfse").Count; i++) { #region Salva Arquivo por arquivo string sPasta = Convert.ToDateTime(xmlRet.GetElementsByTagName("ns4:InfNfse")[i]["ns4:DataEmissao"].InnerText).ToString("MM/yy").Replace("/", ""); //Numero da nota no sefaz + numero da sequencia no sistema string sNomeArquivo = sPasta + (xmlRet.GetElementsByTagName("ns4:InfNfse")[i]["ns4:Numero"].InnerText.PadLeft(6, '0')) + (xmlRet.GetElementsByTagName("ns4:IdentificacaoRps")[i]["ns4:Numero"].InnerText.PadLeft(6, '0')); XmlDocument xmlSaveNfes = new XmlDocument(); xmlSaveNfes.LoadXml(xmlRet.GetElementsByTagName("ns4:Nfse")[i].InnerXml); DirectoryInfo dPastaData = new DirectoryInfo(belStaticPastas.ENVIADOS + "\\Servicos\\" + sPasta); if (!dPastaData.Exists) { dPastaData.Create(); } xmlSaveNfes.Save(belStaticPastas.ENVIADOS + "\\Servicos\\" + sPasta + "\\" + sNomeArquivo + "-nfes.xml"); #endregion objNfseRetorno = new TcInfNfse(); objNfseRetorno.Numero = xmlRet.GetElementsByTagName("ns4:InfNfse")[i]["ns4:Numero"].InnerText; objNfseRetorno.CodigoVerificacao = xmlRet.GetElementsByTagName("ns4:InfNfse")[i]["ns4:CodigoVerificacao"].InnerText; tcIdentificacaoRps objIdentRps = BuscatcIdentificacaoRps(xmlRet.GetElementsByTagName("ns4:IdentificacaoRps")[i]["ns4:Numero"].InnerText.PadLeft(6, '0')); belGerarXML objBelGeraXml = new belGerarXML(); if (belStatic.sNomeEmpresa == "LORENZON") { AlteraDuplicataNumNFse(objIdentRps, xmlRet.GetElementsByTagName("ns4:InfNfse")[i]["ns4:Numero"].InnerText); } if (xmlRet.GetElementsByTagName("ns4:SubstituicaoNfse")[i] != null) { objNfseRetorno.NfseSubstituida = xmlRet.GetElementsByTagName("ns4:SubstituicaoNfse")[i]["ns4:NfseSubstituidora"].InnerText; } objNfseRetorno.IdentificacaoRps = objIdentRps; objListaNfseRetorno.Add(objNfseRetorno); } parar = true; } if (parar) break; } return sMensagemErro; } catch (Exception ex) { throw ex; } }