Ejemplo n.º 1
0
        /// <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>();

                XmlDocument doc = new XmlDocument();
                /// danasa 1-2012
                if (Propriedade.TipoAplicativo == TipoAplicativo.Nfse)
                {
                    Propriedade.Municipios = null;
                    Propriedade.Municipios = new List <Municipio>();

                    if (File.Exists(Propriedade.NomeArqXMLMunicipios))
                    {
                        doc.Load(Propriedade.NomeArqXMLMunicipios);
                        XmlNodeList estadoList = doc.GetElementsByTagName("Registro");
                        foreach (XmlNode registroNode in estadoList)
                        {
                            XmlElement registroElemento = (XmlElement)registroNode;
                            if (registroElemento.Attributes.Count > 0)
                            {
                                int    IDmunicipio = Convert.ToInt32(registroElemento.Attributes[0].Value);
                                string Nome        = registroElemento.Attributes[1].Value;
                                string Padrao      = registroElemento.Attributes[2].Value;
                                string UF          = Functions.CodigoParaUF(Convert.ToInt32(IDmunicipio.ToString().Substring(0, 2))).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, "schemas\\NFSe\\" + Padrao);
                                if (!Directory.Exists(dirSchemas))
                                {
                                    atualizaWSDL = true;
                                }
                                PadroesNFSe pdr = WebServiceNFSe.GetPadraoFromString(Padrao);

                                ///
                                /// adiciona na lista que será usada na manutencao
                                Propriedade.Municipios.Add(new Municipio(IDmunicipio, UF, Nome, pdr));

                                webServices wsItem = new webServices(IDmunicipio, Nome, UF);

                                //PreencheURLw(wsItem.URLHomologacao, "URLHomologacao", WebServiceNFSe.URLHomologacao(pdr), "");
                                //PreencheURLw(wsItem.URLProducao, "URLProducao", WebServiceNFSe.URLProducao(pdr), "");
                                PreencheURLw(wsItem.LocalHomologacao, "LocalHomologacao", WebServiceNFSe.WebServicesHomologacao(pdr, IDmunicipio), "");
                                PreencheURLw(wsItem.LocalProducao, "LocalProducao", WebServiceNFSe.WebServicesProducao(pdr, IDmunicipio), "");

                                webServicesList.Add(wsItem);
                            }
                        }
                        if (webServicesList.Count > 0)
                        {
                            ///
                            /// nao vou sair daqui pq pode ser que no "Webservice.xml" tenha algum municipio
                            /// que o usuário nao tenha incluido
                            ///
                            //return;
                        }
                    }
                }
                /// danasa 1-2012

                if (File.Exists(Propriedade.NomeArqXMLWebService))
                {
                    doc.Load(Propriedade.NomeArqXMLWebService);
                    XmlNodeList estadoList = doc.GetElementsByTagName("Estado");
                    foreach (XmlNode estadoNode in estadoList)
                    {
                        XmlElement estadoElemento = (XmlElement)estadoNode;
                        if (estadoElemento.Attributes.Count > 0)
                        {
                            if (estadoElemento.Attributes[2].Value != "XX")
                            {
                                int    ID   = Convert.ToInt32(estadoElemento.Attributes[0].Value);
                                string Nome = estadoElemento.Attributes[1].Value;
                                string UF   = estadoElemento.Attributes[2].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
                                ///
                                bool jahExiste = false;
                                foreach (webServices temp in webServicesList)
                                {
                                    if (temp.ID == ID)
                                    {
                                        jahExiste = true;
                                        break;
                                    }
                                }
                                if (jahExiste)
                                {
                                    continue;
                                }

                                webServices wsItem = new webServices(ID, Nome, UF);
                                XmlNodeList urlList;

                                #region URL´s de Homologação
                                //urlList = estadoElemento.GetElementsByTagName("URLHomologacao");
                                //if (urlList.Count > 0)
                                //    PreencheURLw(wsItem.URLHomologacao, "URLHomologacao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                #region URL´s de produção
                                //urlList = estadoElemento.GetElementsByTagName("URLProducao");
                                //if (urlList.Count > 0)
                                //    PreencheURLw(wsItem.URLProducao, "URLProducao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                #region WSDL´s locais de Homologação
                                urlList = estadoElemento.GetElementsByTagName("LocalHomologacao");
                                if (urlList.Count > 0)
                                {
                                    PreencheURLw(wsItem.LocalHomologacao, "LocalHomologacao", urlList.Item(0).OuterXml, UF);
                                }
                                #endregion

                                #region WSDL´s locais de Produção
                                urlList = estadoElemento.GetElementsByTagName("LocalProducao");
                                if (urlList.Count > 0)
                                {
                                    PreencheURLw(wsItem.LocalProducao, "LocalProducao", urlList.Item(0).OuterXml, UF);
                                }
                                #endregion

                                webServicesList.Add(wsItem);

                                // danasa 1-2012
                                if (Propriedade.TipoAplicativo == TipoAplicativo.Nfse)
                                {
                                    ///
                                    /// adiciona na lista que será usada na manutencao
                                    foreach (string p0 in WebServiceNFSe.PadroesNFSeList)
                                    {
                                        if (p0 != PadroesNFSe.NaoIdentificado.ToString())
                                        {
                                            if (wsItem.LocalHomologacao.RecepcionarLoteRps.ToLower().IndexOf(p0.ToLower()) > 0 ||
                                                wsItem.LocalProducao.RecepcionarLoteRps.ToLower().IndexOf(p0.ToLower()) > 0)
                                            {
                                                Propriedade.Municipios.Add(new Municipio(ID, UF, Nome, WebServiceNFSe.GetPadraoFromString(p0)));
                                                break;
                                            }
                                        }
                                    }
                                }
                                // danasa 1-2012
                            }
                        }
                    }
                }
            }
            return(atualizaWSDL);
        }
Ejemplo n.º 2
0
        /// <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>();

                XmlDocument doc = new XmlDocument();
                /// danasa 1-2012
                if (Propriedade.TipoAplicativo == TipoAplicativo.Nfse)
                {
                    Propriedade.Municipios = null;
                    Propriedade.Municipios = new List<Municipio>();

                    if (File.Exists(Propriedade.NomeArqXMLMunicipios))
                    {
                        doc.Load(Propriedade.NomeArqXMLMunicipios);
                        XmlNodeList estadoList = doc.GetElementsByTagName("Registro");
                        foreach (XmlNode registroNode in estadoList)
                        {
                            XmlElement registroElemento = (XmlElement)registroNode;
                            if (registroElemento.Attributes.Count > 0)
                            {
                                int IDmunicipio = Convert.ToInt32(registroElemento.Attributes[0].Value);
                                string Nome = registroElemento.Attributes[1].Value;
                                string Padrao = registroElemento.Attributes[2].Value;
                                string UF = Functions.CodigoParaUF(Convert.ToInt32(IDmunicipio.ToString().Substring(0, 2))).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, "schemas\\NFSe\\" + Padrao);
                                if (!Directory.Exists(dirSchemas))
                                {
                                    atualizaWSDL = true;
                                }
                                PadroesNFSe pdr = WebServiceNFSe.GetPadraoFromString(Padrao);

                                ///
                                /// adiciona na lista que será usada na manutencao
                                Propriedade.Municipios.Add(new Municipio(IDmunicipio, UF, Nome, pdr));

                                webServices wsItem = new webServices(IDmunicipio, Nome, UF);

                                //PreencheURLw(wsItem.URLHomologacao, "URLHomologacao", WebServiceNFSe.URLHomologacao(pdr), "");
                                //PreencheURLw(wsItem.URLProducao, "URLProducao", WebServiceNFSe.URLProducao(pdr), "");
                                PreencheURLw(wsItem.LocalHomologacao, "LocalHomologacao", WebServiceNFSe.WebServicesHomologacao(pdr, IDmunicipio), "");
                                PreencheURLw(wsItem.LocalProducao, "LocalProducao", WebServiceNFSe.WebServicesProducao(pdr, IDmunicipio), "");

                                webServicesList.Add(wsItem);
                            }
                        }
                        if (webServicesList.Count > 0)
                        {
                            ///
                            /// nao vou sair daqui pq pode ser que no "Webservice.xml" tenha algum municipio
                            /// que o usuário nao tenha incluido
                            /// 
                            //return;
                        }
                    }
                }
                /// danasa 1-2012

                if (File.Exists(Propriedade.NomeArqXMLWebService))
                {
                    doc.Load(Propriedade.NomeArqXMLWebService);
                    XmlNodeList estadoList = doc.GetElementsByTagName("Estado");
                    foreach (XmlNode estadoNode in estadoList)
                    {
                        XmlElement estadoElemento = (XmlElement)estadoNode;
                        if (estadoElemento.Attributes.Count > 0)
                        {
                            if (estadoElemento.Attributes[2].Value != "XX")
                            {
                                int ID = Convert.ToInt32(estadoElemento.Attributes[0].Value);
                                string Nome = estadoElemento.Attributes[1].Value;
                                string UF = estadoElemento.Attributes[2].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
                                ///
                                bool jahExiste = false;
                                foreach (webServices temp in webServicesList)
                                    if (temp.ID == ID)
                                    {
                                        jahExiste = true;
                                        break;
                                    }
                                if (jahExiste) continue;

                                webServices wsItem = new webServices(ID, Nome, UF);
                                XmlNodeList urlList;

                                #region URL´s de Homologação
                                //urlList = estadoElemento.GetElementsByTagName("URLHomologacao");
                                //if (urlList.Count > 0)
                                //    PreencheURLw(wsItem.URLHomologacao, "URLHomologacao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                #region URL´s de produção
                                //urlList = estadoElemento.GetElementsByTagName("URLProducao");
                                //if (urlList.Count > 0)
                                //    PreencheURLw(wsItem.URLProducao, "URLProducao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                #region WSDL´s locais de Homologação
                                urlList = estadoElemento.GetElementsByTagName("LocalHomologacao");
                                if (urlList.Count > 0)
                                    PreencheURLw(wsItem.LocalHomologacao, "LocalHomologacao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                #region WSDL´s locais de Produção
                                urlList = estadoElemento.GetElementsByTagName("LocalProducao");
                                if (urlList.Count > 0)
                                    PreencheURLw(wsItem.LocalProducao, "LocalProducao", urlList.Item(0).OuterXml, UF);
                                #endregion

                                webServicesList.Add(wsItem);

                                // danasa 1-2012
                                if (Propriedade.TipoAplicativo == TipoAplicativo.Nfse)
                                {
                                    ///
                                    /// adiciona na lista que será usada na manutencao
                                    foreach (string p0 in WebServiceNFSe.PadroesNFSeList)
                                        if (p0 != PadroesNFSe.NaoIdentificado.ToString())
                                            if (wsItem.LocalHomologacao.RecepcionarLoteRps.ToLower().IndexOf(p0.ToLower()) > 0 ||
                                                wsItem.LocalProducao.RecepcionarLoteRps.ToLower().IndexOf(p0.ToLower()) > 0)
                                            {
                                                Propriedade.Municipios.Add(new Municipio(ID, UF, Nome, WebServiceNFSe.GetPadraoFromString(p0)));
                                                break;
                                            }
                                }
                                // danasa 1-2012
                            }
                        }
                    }
                }
            }
            return atualizaWSDL;
        }