private static string getURLs(string local, ref PadroesNFSe padrao, int idMunicipio) { /* * tenta ler as URL's do 'WebService.xml' * não encontrando, assume o ID='padrao' e UF='XX' e padrao='padrao' */ if (System.IO.File.Exists(Propriedade.NomeArqXMLWebService_NFSe)) { XElement axml = XElement.Load(Propriedade.NomeArqXMLWebService_NFSe); /// /// primeiro, pesquisa pelo ID /// var s = (from p in axml.Descendants(NFe.Components.NFeStrConstants.Estado) where //(string)p.Attribute(NFe.Components.NFeStrConstants.Padrao) == padrao.ToString() && (string)p.Attribute(NFe.Components.TpcnResources.ID.ToString()) == idMunicipio.ToString() select p); foreach (var item in s) { if (item.Element(local) != null) { /// /// pega o padrao definido no WebService.xml descartando o que constar no UninMunic.xml /// padrao = WebServiceNFSe.GetPadraoFromString(item.Attribute(NFe.Components.NFeStrConstants.Padrao).Value); return(local.Equals(NFe.Components.NFeStrConstants.LocalHomologacao) ? item.FirstNode.ToString() : item.LastNode.ToString()); } } /// /// não encontrei, assume o ID='padrao' e UF='XX' e padrao='padrao' /// PadroesNFSe pdr = padrao; var xs = (from p in axml.Descendants(NFe.Components.NFeStrConstants.Estado) where (string)p.Attribute(NFe.Components.NFeStrConstants.Padrao) == pdr.ToString() && (string)p.Attribute(TpcnResources.UF.ToString()) == "XX" && (string)p.Attribute(NFe.Components.TpcnResources.ID.ToString()) == pdr.ToString() select p); foreach (var item in xs) { if (item.Element(local) != null) { return(local.Equals(NFe.Components.NFeStrConstants.LocalHomologacao) ? item.FirstNode.ToString() : item.LastNode.ToString()); } } } return(""); }
private static bool LoadArqXMLWebService(string filenameWS, string subfolder) { bool salvaXmlLocal = false; if (File.Exists(filenameWS)) { XmlDocument doc = new XmlDocument(); doc.Load(filenameWS); XmlNodeList estadoList = doc.GetElementsByTagName(NFeStrConstants.Estado); foreach (XmlNode estadoNode in estadoList) { XmlElement estadoElemento = (XmlElement)estadoNode; if (estadoElemento.Attributes.Count > 0) { if (estadoElemento.Attributes[TpcnResources.UF.ToString()].Value != "XX") { int ID = Convert.ToInt32("0" + Functions.OnlyNumbers(estadoElemento.Attributes[TpcnResources.ID.ToString()].Value)); if (ID == 0) { continue; } string Nome = estadoElemento.Attributes[NFeStrConstants.Nome].Value; string UF = estadoElemento.Attributes[TpcnResources.UF.ToString()].Value; /// danasa 1-2012 /// /// verifica se o ID já está na lista /// isto previne que no xml de configuracao tenha duplicidade e evita derrubar o programa /// var ci = (from i in webServicesList where i.ID == ID select i).FirstOrDefault(); if (ci == null) { webServices wsItem = new webServices(ID, Nome, UF); XmlNodeList urlList; urlList = estadoElemento.GetElementsByTagName(NFe.Components.NFeStrConstants.LocalHomologacao); if (urlList.Count > 0) { PreencheURLw(wsItem.LocalHomologacao, NFe.Components.NFeStrConstants.LocalHomologacao, urlList.Item(0).OuterXml, UF, subfolder); } urlList = estadoElemento.GetElementsByTagName(NFe.Components.NFeStrConstants.LocalProducao); if (urlList.Count > 0) { PreencheURLw(wsItem.LocalProducao, NFe.Components.NFeStrConstants.LocalProducao, urlList.Item(0).OuterXml, UF, subfolder); } webServicesList.Add(wsItem); } // danasa 1-2012 if (estadoElemento.HasAttribute(NFeStrConstants.Padrao)) { try { string padrao = estadoElemento.Attributes[NFeStrConstants.Padrao].Value; if (!padrao.Equals(PadroesNFSe.NaoIdentificado.ToString(), StringComparison.InvariantCultureIgnoreCase)) { var cc = (from i in Propriedade.Municipios where i.CodigoMunicipio == ID select i).FirstOrDefault(); if (cc == null) { Propriedade.Municipios.Add(new Municipio(ID, UF, Nome, WebServiceNFSe.GetPadraoFromString(padrao))); salvaXmlLocal = true; } else { if (!cc.PadraoStr.Equals(padrao) || !cc.UF.Equals(UF) || !cc.Nome.Equals(Nome, StringComparison.InvariantCultureIgnoreCase)) { cc.Padrao = WebServiceNFSe.GetPadraoFromString(padrao); cc.Nome = Nome; cc.UF = UF; salvaXmlLocal = true; } } } } catch { } } // danasa 1-2012 } } } } return(salvaXmlLocal); }
/// <summary> /// Carrega a lista de webservices definidos no arquivo WebService.XML /// </summary> public static bool CarregaWebServicesList() { bool atualizaWSDL = false; if (webServicesList == null) { webServicesList = new List <webServices>(); Propriedade.Municipios = null; Propriedade.Municipios = new List <Municipio>(); XmlDocument doc = new XmlDocument(); /// danasa 1-2012 if (File.Exists(Propriedade.NomeArqXMLMunicipios)) { doc.Load(Propriedade.NomeArqXMLMunicipios); XmlNodeList estadoList = doc.GetElementsByTagName(NFe.Components.NFeStrConstants.Registro); foreach (XmlNode registroNode in estadoList) { XmlElement registroElemento = (XmlElement)registroNode; if (registroElemento.Attributes.Count > 0) { int IDmunicipio = Convert.ToInt32("0" + Functions.OnlyNumbers(registroElemento.Attributes[TpcnResources.ID.ToString()].Value)); string Nome = registroElemento.Attributes[NFeStrConstants.Nome].Value; string Padrao = registroElemento.Attributes[NFeStrConstants.Padrao].Value; string UF = Functions.CodigoParaUF(Convert.ToInt32(IDmunicipio.ToString().Substring(0, 2))); /// /// danasa 9-2013 /// verifica se o 'novo' padrao existe, nao existindo retorna para atualizar os wsdl's dele string dirSchemas = Path.Combine(Propriedade.PastaExecutavel, "NFse\\schemas\\NFSe\\" + Padrao); if (!Directory.Exists(dirSchemas)) { atualizaWSDL = true; } PadroesNFSe pdr = WebServiceNFSe.GetPadraoFromString(Padrao); string urlsH = WebServiceNFSe.WebServicesHomologacao(ref pdr, IDmunicipio); string urlsP = WebServiceNFSe.WebServicesProducao(ref pdr, IDmunicipio); if (!string.IsNullOrEmpty(urlsH) || !string.IsNullOrEmpty(urlsP)) { var ci = (from i in webServicesList where i.ID == IDmunicipio select i).FirstOrDefault(); if (ci == null) { webServices wsItem = new webServices(IDmunicipio, Nome, UF); PreencheURLw(wsItem.LocalHomologacao, NFe.Components.NFeStrConstants.LocalHomologacao, urlsH, "", "NFse\\"); PreencheURLw(wsItem.LocalProducao, NFe.Components.NFeStrConstants.LocalProducao, urlsP, "", "NFse\\"); webServicesList.Add(wsItem); } } /// /// adiciona na lista que será usada na manutencao /// Propriedade.Municipios.Add(new Municipio(IDmunicipio, UF, Nome, pdr)); } } } /// danasa 1-2012 bool salvaXmlLocal = false; LoadArqXMLWebService(Propriedade.NomeArqXMLWebService_NFe, "NFe\\"); salvaXmlLocal = LoadArqXMLWebService(Propriedade.NomeArqXMLWebService_NFSe, "NFse\\"); if (salvaXmlLocal) { WebServiceNFSe.SalvarXMLMunicipios(null, null, 0, null, false); } } return(atualizaWSDL); }
private static string getURLs(string local, ref PadroesNFSe padrao, int idMunicipio) { /* * tenta ler as URL's do 'WebService.xml' * não encontrando, assume o ID='padrao' e UF='XX' e padrao='padrao' */ if (System.IO.File.Exists(Propriedade.NomeArqXMLWebService_NFSe)) { XElement axml = null; try { axml = XElement.Load(Propriedade.NomeArqXMLWebService_NFSe); } catch (Exception ex) { Functions.WriteLog("Ocorreu um erro na tentativa de carregamento do arquivo " + Propriedade.NomeArqXMLWebService_NFSe + ".\r\n" + "Acesse novamente o sistema para que se recupere automaticamente do erro.\r\n\r\n" + "Erro:\r\n\r\n" + ex.Message, true, true, ""); if (System.IO.File.Exists(Propriedade.XMLVersaoWSDLXSD)) { System.IO.File.Delete(Propriedade.XMLVersaoWSDLXSD); } Environment.Exit(0); } /// /// primeiro, pesquisa pelo ID /// var s = (from p in axml.Descendants(NFeStrConstants.Estado) where //(string)p.Attribute(NFe.Components.NFeStrConstants.Padrao) == padrao.ToString() && (string)p.Attribute(TpcnResources.ID.ToString()) == idMunicipio.ToString() select p); foreach (var item in s) { if (item.Element(local) != null) { /// /// pega o padrao definido no WebService.xml descartando o que constar no UninMunic.xml /// padrao = WebServiceNFSe.GetPadraoFromString(item.Attribute(NFeStrConstants.Padrao).Value); return(local.Equals(NFeStrConstants.LocalHomologacao) ? item.FirstNode.ToString() : item.LastNode.ToString()); } } /// /// não encontrei, assume o ID='padrao' e UF='XX' e padrao='padrao' /// PadroesNFSe pdr = padrao; var xs = (from p in axml.Descendants(NFeStrConstants.Estado) where (string)p.Attribute(NFeStrConstants.Padrao) == pdr.ToString() && (string)p.Attribute(TpcnResources.UF.ToString()) == "XX" && (string)p.Attribute(TpcnResources.ID.ToString()) == pdr.ToString() select p); foreach (var item in xs) { if (item.Element(local) != null) { return(local.Equals(NFeStrConstants.LocalHomologacao) ? item.FirstNode.ToString() : item.LastNode.ToString()); } } } else { Functions.WriteLog("Ocorreu um erro na tentativa de carregamento do arquivo " + Propriedade.NomeArqXMLWebService_NFSe + ".\r\n" + "Acesse novamente o sistema para que se recupere automaticamente do erro.", true, true, ""); if (System.IO.File.Exists(Propriedade.XMLVersaoWSDLXSD)) { System.IO.File.Delete(Propriedade.XMLVersaoWSDLXSD); } Environment.Exit(0); } return(""); }