コード例 #1
0
 public tcIdentificacaoPrestador RettcIdentificacaoPrestador(string sNota)
 {
     try
     {
         tcIdentificacaoPrestador objtcIdentificacaoPrestador = new tcIdentificacaoPrestador();
         DataTable dt = BuscaDadosPrestador();
         foreach (DataRow dr in dt.Rows)
         {
             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();
             }
         }
         return(objtcIdentificacaoPrestador);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #2
0
ファイル: belPrestador.cs プロジェクト: dramosti/GeraXml_3.0
        public tcIdentificacaoPrestador RettcIdentificacaoPrestador(string sNota)
        {
            try
            {
                tcIdentificacaoPrestador objtcIdentificacaoPrestador = new tcIdentificacaoPrestador();
                DataTable dt = BuscaDadosPrestador();
                foreach (DataRow dr in dt.Rows)
                {

                    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();
                    }
                }
                return objtcIdentificacaoPrestador;
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }
コード例 #3
0
ファイル: belRecepcao.cs プロジェクト: brozuni9/GIT
        private string MontaXmlConsultaLote2(tcIdentificacaoPrestador objPrestador)
        {
            try
            {
                XNamespace pf           = "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd";
                XContainer conPrestador = null;
                XContainer conProtocolo = null;

                XContainer conConsultarLoteRpsEnvio = (new XElement(pf + "ConsultarLoteRpsEnvio", new XAttribute("xmlns", "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd")));

                conPrestador = (new XElement(pf + "Prestador",
                                             new XElement(pf + "Cnpj", objPrestador.Cnpj),
                                             ((objPrestador.InscricaoMunicipal != "") ? new XElement(pf + "InscricaoMunicipal", objPrestador.InscricaoMunicipal) : null)));
                conProtocolo = new XElement(pf + "Protocolo", Protocolo);


                conConsultarLoteRpsEnvio.Add(conPrestador);
                conConsultarLoteRpsEnvio.Add(conProtocolo);
                string       sPathLote = Pastas.PROTOCOLOS + "\\Servicos\\" + "Prot_ConsultaLote_Serv_" + Protocolo + ".xml";
                StreamWriter sw        = new StreamWriter(sPathLote);
                sw.Write(conConsultarLoteRpsEnvio.ToString());
                sw.Close();

                try
                {
                    belValidaXml.ValidarXml("http://www.nfe.com.br/WSNacional/XSD/1/nfse_municipal_v01.xsd", Pastas.SCHEMA_NFSE + "\\TIPLAN\\nfse_municipal_v01.xsd", sPathLote);
                }
                catch (XmlException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                catch (XmlSchemaException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }

                //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", Pastas.SCHEMA_NFSE + "\\servico_consultar_lote_rps_envio_v03.xsd");

                //reader.ValidationType = ValidationType.Schema;

                //reader.Schemas.Add(myschema);

                //while (reader.Read())
                //{ }


                return(conConsultarLoteRpsEnvio.ToString());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #4
0
ファイル: belRecepcao.cs プロジェクト: brozuni9/GIT
        private string MontaXmlConsultarSituacaoLoteRps(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_situacao_lote_rps_envio_v03.xsd";
                XContainer conPrestador = null;
                XContainer conProtocolo = null;

                XContainer conConsultarLoteRpsEnvio = (new XElement(pf + "ConsultarSituacaoLoteRpsEnvio", new XAttribute("xmlns", "http://www.ginfes.com.br/servico_consultar_situacao_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);
                belAssinaXml Assinatura = new belAssinaXml();
                string       sArquivo   = Assinatura.ConfigurarArquivo(conConsultarLoteRpsEnvio.ToString(), "Protocolo", Acesso.cert_NFs);



                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                reader = new XmlValidatingReader(sArquivo, XmlNodeType.Element, context);

                myschema.Add("http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_envio_v03.xsd", Pastas.SCHEMA_NFSE + "\\servico_consultar_situacao_lote_rps_envio_v03.xsd");

                reader.ValidationType = ValidationType.Schema;

                reader.Schemas.Add(myschema);

                while (reader.Read())
                {
                }


                return(sArquivo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #5
0
ファイル: belRecepcao.cs プロジェクト: brozuni9/GIT
        private string BuscaRetornoWebService(tcIdentificacaoPrestador Prestador)
        {
            try
            {
                if (Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES)
                {
                    string sVerificacao = Pastas.GINFES + this.Protocolo + ".txt";

                    bool bValida = false;

                    if (File.Exists(sVerificacao))
                    {
                        StreamReader sr  = new StreamReader(sVerificacao);
                        string       sdt = sr.ReadToEnd();
                        sr.Close();

                        DateTime dtEnvio = Convert.ToDateTime(sdt).AddMinutes(6);
                        DateTime dtAtual = DateTime.Now;

                        if (dtEnvio > dtAtual)
                        {
                            throw new Exception("Aguarde mais alguns minutos para o buscar o retorno da Nota. Aproximadamente 6 minutos após o envio.");
                        }
                        else
                        {
                            bValida = true;
                        }
                    }
                    else
                    {
                        bValida = true;
                    }

                    string sretorno = "";
                    if (bValida)
                    {
                        if (Acesso.TP_AMB_SERV == 2)
                        {
                            WebService.Itu_servicos_Homologacao.ServiceGinfesImplService teste = new WebService.Itu_servicos_Homologacao.ServiceGinfesImplService();
                            teste.ClientCertificates.Add(Acesso.cert_NFs);
                            teste.Timeout = 60000;
                            string sret = teste.ConsultarSituacaoLoteRpsV3(NfeCabecMsg(), MontaXmlConsultarSituacaoLoteRps(Prestador));

                            WebService.Itu_servicos_Homologacao.ServiceGinfesImplService objtrans = new WebService.Itu_servicos_Homologacao.ServiceGinfesImplService();
                            objtrans.ClientCertificates.Add(Acesso.cert_NFs);
                            objtrans.Timeout = 60000;
                            return(objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador)));
                        }
                        else if (Acesso.TP_AMB_SERV == 1)
                        {
                            ConsultarSituacaoLoteRpsResposta objResposta;
                            try
                            {
                                WebService.Itu_servicos_Producao.ServiceGinfesImplService teste = new WebService.Itu_servicos_Producao.ServiceGinfesImplService();
                                teste.ClientCertificates.Add(Acesso.cert_NFs);
                                teste.Timeout = 60000;
                                string      sret = teste.ConsultarSituacaoLoteRpsV3(NfeCabecMsg(), MontaXmlConsultarSituacaoLoteRps(Prestador));
                                XmlDocument doc  = new XmlDocument();
                                doc.LoadXml(sret);
                                string sNmFile = Pastas.PROTOCOLOS + "//ConsultaSitLoteRps_" + this.Protocolo + ".xml";
                                if (File.Exists(sNmFile))
                                {
                                    File.Delete(sNmFile);
                                }
                                doc.Save(sNmFile);
                                objResposta = SerializeClassToXml.DeserializeClasse <ConsultarSituacaoLoteRpsResposta>(sNmFile);
                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }

                            if (objResposta != null)
                            {
                                if ((objResposta.Situacao == 4) || (objResposta.Situacao == 3))
                                {
                                    WebService.Itu_servicos_Producao.ServiceGinfesImplService objtrans = new WebService.Itu_servicos_Producao.ServiceGinfesImplService();
                                    objtrans.ClientCertificates.Add(Acesso.cert_NFs);
                                    objtrans.Timeout = 60000;
                                    sretorno         = objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador));
                                }
                                else
                                {
                                    if (objResposta.Situacao == 1)
                                    {
                                        throw new Exception("Lote ainda não recebido.");
                                    }
                                    else if (objResposta.Situacao == 2)
                                    {
                                        throw new Exception("Lote ainda não processado.");
                                    }
                                }
                            }
                        }

                        return(sretorno);
                    }
                    else
                    {
                        throw new Exception("Cadastro de Empresa não configurado para enviar NFe-serviço");
                    }
                }
                else
                {
                    WebService.riodasostras_Producao.Nfse nfse = new WebService.riodasostras_Producao.Nfse();
                    nfse.ClientCertificates.Add(Acesso.cert_NFs);
                    nfse.Timeout = 60000;
                    return(nfse.ConsultarLoteRps(MontaXmlConsultaLote2(Prestador)));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
ファイル: belRecepcao.cs プロジェクト: brozuni9/GIT
        public string BuscaRetorno(tcIdentificacaoPrestador Prestador, KryptonLabel lblStatus, ProgressBar ProgresStatus)
        {
            bool   parar          = false;
            string sMensagemErro  = "";
            int    iCountBuscaRet = 1;

            ProgresStatus.Step    = 1;
            ProgresStatus.Minimum = 0;
            ProgresStatus.Maximum = 20;
            ProgresStatus.MarqueeAnimationSpeed = 20;
            ProgresStatus.Value = 0;

            try
            {
                for (; ;)
                {
                    ProgresStatus.PerformStep();
                    ProgresStatus.Refresh();
                    lblStatus.Text = "O Sistema está tentando buscar Retorno..." + Environment.NewLine + "Tentativa " + iCountBuscaRet.ToString() + " de 21";
                    lblStatus.Refresh();
                    string      sRetConsulta = BuscaRetornoWebService(Prestador);
                    XmlDocument xmlRet       = new XmlDocument();
                    xmlRet.LoadXml(sRetConsulta);

                    XmlNodeList xNodeList = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "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[(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Codigo"].InnerText;

                            if (sCodigoRetorno.Equals("E4") && iCountBuscaRet <= 20)
                            {
                                iCountBuscaRet++;
                            }
                            else
                            {
                                sMensagemErro = string.Format(sMensagemErro, node[(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Codigo"].InnerText,
                                                              "Esse RPS ainda não se encontra em nossa base de dados.",
                                                              node[(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Correcao"].InnerText, Environment.NewLine);
                                parar = true;
                            }
                        }
                    }
                    else if (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns3:" : "") + "CompNfse").Count > 0)
                    {
                        this.sCodigoRetorno = "";
                        sMensagemErro       = "";
                        bool bAlteraDupl = Convert.ToBoolean(Acesso.GRAVA_NUM_NF_DUPL);


                        for (int i = 0; i < xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns3:" : "") + "CompNfse").Count; i++)
                        {
                            #region Salva Arquivo por arquivo
                            string sPasta = Convert.ToDateTime(xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "DataEmissao"].InnerText).ToString("MM/yy").Replace("/", "");
                            //Numero da nota no sefaz + numero da sequencia no sistema
                            string sNomeArquivo = sPasta + (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText.PadLeft(6, '0'))
                                                  + (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "IdentificacaoRps")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText.PadLeft(6, '0'));

                            XmlDocument xmlSaveNfes = new XmlDocument();
                            xmlSaveNfes.LoadXml(xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Nfse")[i].InnerXml);
                            DirectoryInfo dPastaData = new DirectoryInfo(Pastas.ENVIADOS + "\\Servicos\\" + sPasta);
                            if (!dPastaData.Exists)
                            {
                                dPastaData.Create();
                            }
                            xmlSaveNfes.Save(Pastas.ENVIADOS + "\\Servicos\\" + sPasta + "\\" + sNomeArquivo + "-nfes.xml");
                            #endregion

                            objNfseRetorno                   = new TcInfNfse();
                            objNfseRetorno.Numero            = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText;
                            objNfseRetorno.CodigoVerificacao = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "CodigoVerificacao"].InnerText;

                            tcIdentificacaoRps objIdentRps = BuscatcIdentificacaoRps(xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "IdentificacaoRps")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText.PadLeft(6, '0'));

                            string sNotaFis = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText;
                            if (Acesso.NM_EMPRESA.Equals("LORENZON"))
                            {
                                AlteraDuplicataNumNFse(objIdentRps, sNotaFis);
                            }

                            if (Acesso.NM_EMPRESA.Equals("FORMINGP"))
                            {
                                daoDuplicata objdaodup = new daoDuplicata();
                                objdaodup.BuscaVencto(objIdentRps.Nfseq, sNotaFis, objIdentRps.Numero);
                            }

                            if (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "SubstituicaoNfse")[i] != null)
                            {
                                objNfseRetorno.NfseSubstituida = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "SubstituicaoNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "NfseSubstituidora"].InnerText;
                            }
                            objNfseRetorno.IdentificacaoRps = objIdentRps;
                            objListaNfseRetorno.Add(objNfseRetorno);
                        }
                        parar = true;
                    }

                    if (parar)
                    {
                        break;
                    }
                }
                return(sMensagemErro);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #7
0
ファイル: belRecepcao.cs プロジェクト: dramosti/GeraXml_3.0
        private string MontaXmlConsultaLote2(tcIdentificacaoPrestador objPrestador)
        {
            try
            {
                XNamespace pf = "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd";
                XContainer conPrestador = null;
                XContainer conProtocolo = null;

                XContainer conConsultarLoteRpsEnvio = (new XElement(pf + "ConsultarLoteRpsEnvio", new XAttribute("xmlns", "http://www.abrasf.org.br/ABRASF/arquivos/nfse.xsd")));

                conPrestador = (new XElement(pf + "Prestador",
                    new XElement(pf + "Cnpj", objPrestador.Cnpj),
                                                                     ((objPrestador.InscricaoMunicipal != "") ? new XElement(pf + "InscricaoMunicipal", objPrestador.InscricaoMunicipal) : null)));
                conProtocolo = new XElement(pf + "Protocolo", Protocolo);


                conConsultarLoteRpsEnvio.Add(conPrestador);
                conConsultarLoteRpsEnvio.Add(conProtocolo);
                string sPathLote = Pastas.PROTOCOLOS + "\\Servicos\\" + "Prot_ConsultaLote_Serv_" + Protocolo + ".xml";
                StreamWriter sw = new StreamWriter(sPathLote);
                sw.Write(conConsultarLoteRpsEnvio.ToString());
                sw.Close();

                try
                {
                    belValidaXml.ValidarXml("http://www.nfe.com.br/WSNacional/XSD/1/nfse_municipal_v01.xsd", Pastas.SCHEMA_NFSE + "\\TIPLAN\\nfse_municipal_v01.xsd", sPathLote);
                }
                catch (XmlException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }
                catch (XmlSchemaException x)
                {
                    File.Delete(sPathLote);
                    throw new Exception(x.Message);
                }

                //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", Pastas.SCHEMA_NFSE + "\\servico_consultar_lote_rps_envio_v03.xsd");

                //reader.ValidationType = ValidationType.Schema;

                //reader.Schemas.Add(myschema);

                //while (reader.Read())
                //{ }


                return conConsultarLoteRpsEnvio.ToString();

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #8
0
ファイル: belRecepcao.cs プロジェクト: dramosti/GeraXml_3.0
        private string MontaXmlConsultarSituacaoLoteRps(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_situacao_lote_rps_envio_v03.xsd";
                XContainer conPrestador = null;
                XContainer conProtocolo = null;

                XContainer conConsultarLoteRpsEnvio = (new XElement(pf + "ConsultarSituacaoLoteRpsEnvio", new XAttribute("xmlns", "http://www.ginfes.com.br/servico_consultar_situacao_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);
                belAssinaXml Assinatura = new belAssinaXml();
                string sArquivo = Assinatura.ConfigurarArquivo(conConsultarLoteRpsEnvio.ToString(), "Protocolo", Acesso.cert_NFs);



                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                reader = new XmlValidatingReader(sArquivo, XmlNodeType.Element, context);

                myschema.Add("http://www.ginfes.com.br/servico_consultar_situacao_lote_rps_envio_v03.xsd", Pastas.SCHEMA_NFSE + "\\servico_consultar_situacao_lote_rps_envio_v03.xsd");

                reader.ValidationType = ValidationType.Schema;

                reader.Schemas.Add(myschema);

                while (reader.Read())
                { }


                return sArquivo;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #9
0
ファイル: belRecepcao.cs プロジェクト: dramosti/GeraXml_3.0
        private string BuscaRetornoWebService(tcIdentificacaoPrestador Prestador)
        {
            try
            {

                if (Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES)
                {
                    string sVerificacao = Pastas.GINFES + this.Protocolo + ".txt";

                    bool bValida = false;

                    if (File.Exists(sVerificacao))
                    {
                        StreamReader sr = new StreamReader(sVerificacao);
                        string sdt = sr.ReadToEnd();
                        sr.Close();

                        DateTime dtEnvio = Convert.ToDateTime(sdt).AddMinutes(6);
                        DateTime dtAtual = DateTime.Now;

                        if (dtEnvio > dtAtual)
                        {
                            throw new Exception("Aguarde mais alguns minutos para o buscar o retorno da Nota. Aproximadamente 6 minutos após o envio.");
                        }
                        else
                        {
                            bValida = true;
                        }
                    }
                    else
                    {
                        bValida = true;
                    }

                    string sretorno = "";
                    if (bValida)
                    {
                        if (Acesso.TP_AMB_SERV == 2)
                        {
                            WebService.Itu_servicos_Homologacao.ServiceGinfesImplService teste = new WebService.Itu_servicos_Homologacao.ServiceGinfesImplService();
                            teste.ClientCertificates.Add(Acesso.cert_NFs);
                            teste.Timeout = 60000;
                            string sret = teste.ConsultarSituacaoLoteRpsV3(NfeCabecMsg(), MontaXmlConsultarSituacaoLoteRps(Prestador));

                            WebService.Itu_servicos_Homologacao.ServiceGinfesImplService objtrans = new WebService.Itu_servicos_Homologacao.ServiceGinfesImplService();
                            objtrans.ClientCertificates.Add(Acesso.cert_NFs);
                            objtrans.Timeout = 60000;
                            return objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador));

                        }
                        else if (Acesso.TP_AMB_SERV == 1)
                        {
                            ConsultarSituacaoLoteRpsResposta objResposta;
                            try
                            {

                                WebService.Itu_servicos_Producao.ServiceGinfesImplService teste = new WebService.Itu_servicos_Producao.ServiceGinfesImplService();
                                teste.ClientCertificates.Add(Acesso.cert_NFs);
                                teste.Timeout = 60000;
                                string sret = teste.ConsultarSituacaoLoteRpsV3(NfeCabecMsg(), MontaXmlConsultarSituacaoLoteRps(Prestador));
                                XmlDocument doc = new XmlDocument();
                                doc.LoadXml(sret);
                                string sNmFile = Pastas.PROTOCOLOS + "//ConsultaSitLoteRps_" + this.Protocolo + ".xml";
                                if (File.Exists(sNmFile))
                                    File.Delete(sNmFile);
                                doc.Save(sNmFile);
                                objResposta = SerializeClassToXml.DeserializeClasse<ConsultarSituacaoLoteRpsResposta>(sNmFile);

                            }
                            catch (Exception ex)
                            {
                                throw ex;
                            }

                            if (objResposta != null)
                            {

                                if ((objResposta.Situacao == 4) || (objResposta.Situacao == 3))
                                {
                                    WebService.Itu_servicos_Producao.ServiceGinfesImplService objtrans = new WebService.Itu_servicos_Producao.ServiceGinfesImplService();
                                    objtrans.ClientCertificates.Add(Acesso.cert_NFs);
                                    objtrans.Timeout = 60000;
                                    sretorno = objtrans.ConsultarLoteRpsV3(NfeCabecMsg(), MontaXmlConsultaLote(Prestador));
                                }
                                else
                                {
                                    if (objResposta.Situacao == 1)
                                    {
                                        throw new Exception("Lote ainda não recebido.");
                                    }
                                    else if (objResposta.Situacao == 2)
                                    {
                                        throw new Exception("Lote ainda não processado.");
                                    }
                                }
                            }
                        }

                        return sretorno;
                    }
                    else
                    {
                        throw new Exception("Cadastro de Empresa não configurado para enviar NFe-serviço");
                    }
                }
                else
                {
                    WebService.riodasostras_Producao.Nfse nfse = new WebService.riodasostras_Producao.Nfse();
                    nfse.ClientCertificates.Add(Acesso.cert_NFs);
                    nfse.Timeout = 60000;
                    return nfse.ConsultarLoteRps(MontaXmlConsultaLote2(Prestador));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #10
0
ファイル: belRecepcao.cs プロジェクト: dramosti/GeraXml_3.0
        public string BuscaRetorno(tcIdentificacaoPrestador Prestador, KryptonLabel lblStatus, ProgressBar ProgresStatus)
        {

            bool parar = false;
            string sMensagemErro = "";
            int iCountBuscaRet = 1;

            ProgresStatus.Step = 1;
            ProgresStatus.Minimum = 0;
            ProgresStatus.Maximum = 20;
            ProgresStatus.MarqueeAnimationSpeed = 20;
            ProgresStatus.Value = 0;

            try
            {
                for (; ; )
                {
                    ProgresStatus.PerformStep();
                    ProgresStatus.Refresh();
                    lblStatus.Text = "O Sistema está tentando buscar Retorno..." + Environment.NewLine + "Tentativa " + iCountBuscaRet.ToString() + " de 21";
                    lblStatus.Refresh();
                    string sRetConsulta = BuscaRetornoWebService(Prestador);
                    XmlDocument xmlRet = new XmlDocument();
                    xmlRet.LoadXml(sRetConsulta);

                    XmlNodeList xNodeList = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "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[(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Codigo"].InnerText;

                            if (sCodigoRetorno.Equals("E4") && iCountBuscaRet <= 20)
                            {
                                iCountBuscaRet++;
                            }
                            else
                            {
                                sMensagemErro = string.Format(sMensagemErro, node[(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Codigo"].InnerText,
                                                      "Esse RPS ainda não se encontra em nossa base de dados.",
                                                      node[(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Correcao"].InnerText, Environment.NewLine);
                                parar = true;
                            }
                        }
                    }
                    else if (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns3:" : "") + "CompNfse").Count > 0)
                    {
                        this.sCodigoRetorno = "";
                        sMensagemErro = "";
                        bool bAlteraDupl = Convert.ToBoolean(Acesso.GRAVA_NUM_NF_DUPL);


                        for (int i = 0; i < xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns3:" : "") + "CompNfse").Count; i++)
                        {
                            #region Salva Arquivo por arquivo
                            string sPasta = Convert.ToDateTime(xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "DataEmissao"].InnerText).ToString("MM/yy").Replace("/", "");
                            //Numero da nota no sefaz + numero da sequencia no sistema
                            string sNomeArquivo = sPasta + (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText.PadLeft(6, '0'))
                                                 + (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "IdentificacaoRps")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText.PadLeft(6, '0'));

                            XmlDocument xmlSaveNfes = new XmlDocument();
                            xmlSaveNfes.LoadXml(xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Nfse")[i].InnerXml);
                            DirectoryInfo dPastaData = new DirectoryInfo(Pastas.ENVIADOS + "\\Servicos\\" + sPasta);
                            if (!dPastaData.Exists) { dPastaData.Create(); }
                            xmlSaveNfes.Save(Pastas.ENVIADOS + "\\Servicos\\" + sPasta + "\\" + sNomeArquivo + "-nfes.xml");
                            #endregion

                            objNfseRetorno = new TcInfNfse();
                            objNfseRetorno.Numero = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText;
                            objNfseRetorno.CodigoVerificacao = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "CodigoVerificacao"].InnerText;

                            tcIdentificacaoRps objIdentRps = BuscatcIdentificacaoRps(xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "IdentificacaoRps")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText.PadLeft(6, '0'));

                            string sNotaFis = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "InfNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "Numero"].InnerText;
                            if (Acesso.NM_EMPRESA.Equals("LORENZON"))
                            {
                                AlteraDuplicataNumNFse(objIdentRps, sNotaFis);
                            }

                            if (Acesso.NM_EMPRESA.Equals("FORMINGP"))
                            {
                                daoDuplicata objdaodup = new daoDuplicata();
                                objdaodup.BuscaVencto(objIdentRps.Nfseq, sNotaFis, objIdentRps.Numero);
                            }

                            if (xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "SubstituicaoNfse")[i] != null)
                            {
                                objNfseRetorno.NfseSubstituida = xmlRet.GetElementsByTagName((Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "SubstituicaoNfse")[i][(Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.GINFES ? "ns4:" : "") + "NfseSubstituidora"].InnerText;
                            }
                            objNfseRetorno.IdentificacaoRps = objIdentRps;
                            objListaNfseRetorno.Add(objNfseRetorno);

                        }
                        parar = true;
                    }

                    if (parar) break;
                }
                return sMensagemErro;

            }
            catch (Exception ex)
            {
                throw ex;
            }
        }