示例#1
0
        /// <summary>
        /// Utilizado na Classe belGeraXML.
        /// </summary>
        /// <param name="sEmp"></param>
        /// <param name="sSeqs"></param>
        /// <param name="sNfes"></param>
        /// <param name="tp_amb"></param>
        /// <param name="cd_ufnro"></param>
        /// <param name="sRecibo"></param>
        /// <param name="xCert"></param>
        /// <param name="glob"></param>
        /// <param name="pf"></param>
        public belBusRetFazenda(string sEmp, List<string> sSeqs, List<string> sNfes, int tp_amb, string cd_ufnro,
                                string sRecibo, X509Certificate2 xCert, Globais glob, string UF_Empresa, bool bModoSCAN)
        {
            XNamespace pf = "http://www.portalfiscal.inf.br/nfe";
            this.bModoSCAN = bModoSCAN;
            _emp = sEmp;
            _seqs = sSeqs;
            _nfes = sNfes;

            string qtdeTentativas = glob.LeRegConfig("QtdeTentativas").ToString();

            bool parar = false;

            //Retorno da fazenda com Status de cada NFe do lote.
            belNfeRetRecepcao objnferetrecepcao = new belNfeRetRecepcao("1.02", tp_amb, sRecibo, "2.00", xCert, bModoSCAN);
            XmlDocument xret = new XmlDocument();

            //Variavel pra sabe se alguma nota possui erro
            XmlNodeList nodescStat;
            XmlNodeList nodesxMotivo;
            //contador de tentativas
            int countTentativas = 0;

            for (; ; )
            {

                xret = objnferetrecepcao.Retornaxml(UF_Empresa);
                nodescStat = xret.GetElementsByTagName("cStat");
                nodesxMotivo = xret.GetElementsByTagName("xMotivo");

                if (nodescStat[0].InnerText == "105")
                {

                    //Verifica o status do serviço e faz o calculo de tempo médio para a próxima tentativa do recebimento do retorno da fazenda
                    belnfeStatusServicoNF objstausserv = new belnfeStatusServicoNF("2.00", tp_amb, cd_ufnro, xCert, UF_Empresa);
                    System.Threading.Thread.Sleep((objstausserv.Tmed * 1000) + 3000);

                    

                    //Compara se a quantidade de tentativas dadas é igual ao limite estipuládo na configuração do sistema.
                    if (qtdeTentativas == countTentativas.ToString())
                    {

                        throw new Exception("Quantidade de Tentativas de Conexão com a secretaria da Fazenta Excedidas " + Environment.NewLine + 
                                            "Lote foi enviado a fazenda, porem esta em processamento" + Environment.NewLine +
                                            "Espere alguns segundos antes de tentar buscar o retorno novamente");

                    }

                    //Conta tentativa
                    countTentativas++;

                    continue;

                }
                else if (nodescStat[0].InnerText != "104")
                {
                    throw new Exception("Erro " + nodescStat[0].InnerText + " - " + nodesxMotivo[0].InnerText);
                }
                else
                {
                    for (int i = 0; i < sNfes.Count ; i++)
                    {
                        //Variavel que gera a mensagem de resposta
                        _loteres = _loteres + "Nota de número de sequência: " + sSeqs[i] + " - " + nodesxMotivo[i + 1].InnerText + " Cod. " + nodescStat[i + 1].InnerText + Environment.NewLine;

                        if (nodescStat[i + 1].InnerText == "100")
                        {
                            _nfeautorizadas.Add(sSeqs[i]);
                            XmlNode xRetUni = xret.GetElementsByTagName("infProt")[i]; // Diego OS_24777

                            //Método responsavel por gravar o nProt e chNfe no banco e gerar o xml protocolado.
                            geraProcNFe(sEmp, sSeqs[i], sNfes[i], xret.GetElementsByTagName("chNFe")[i].InnerText,
                                                xRetUni["nProt"].InnerText, xret.GetElementsByTagName("protNFe")[i], glob, pf);

                            xret.Save(glob.LeRegConfig("PastaProtocolos").ToString() + "\\" + sRecibo + "-pro-rec.xml");                           

                        }
                        else
                        {
                            if (nodescStat[i + 1].InnerText != "105")
                            {
                                LimpaCampoRecibo(_emp, sSeqs[i]);
                            }
                        }

                        parar = true;

                    }
                }
                if (parar == true)
                    break;
            }


        }
示例#2
0
        public void BusRetFazendaEnvio()
        {

            Globais glob = new Globais();
            XNamespace pf = "http://www.portalfiscal.inf.br/nfe";
            this.bModoSCAN = belStatic.bModoSCAN;
            _emp = belStatic.codEmpresaNFe;

            string qtdeTentativas = glob.LeRegConfig("QtdeTentativas").ToString();

            //Retorno da fazenda com Status de cada NFe do lote.
            belNfeRetRecepcao objnferetrecepcao = new belNfeRetRecepcao("1.02", _sRecibo, "2.00", _xCert, bModoSCAN);
            XmlDocument xret = new XmlDocument();

            //Variavel pra sabe se alguma nota possui erro
            XmlNodeList nodescStat;
            XmlNodeList nodesxMotivo;
            //contador de tentativas          

            while (!bStopRetorno)
            {
                _loteres = "";
                xret = objnferetrecepcao.Retornaxml(_UF_Empresa);
                nodescStat = xret.GetElementsByTagName("cStat");
                nodesxMotivo = xret.GetElementsByTagName("xMotivo");

                if (nodescStat[0].InnerText == "105")
                {
                    _loteres = nodescStat[0].InnerText + " - " + nodesxMotivo[0].InnerText;
                    countTentativas++;
                }
                else if (nodescStat[0].InnerText != "104")
                {
                    throw new Exception("Erro " + nodescStat[0].InnerText + " - " + nodesxMotivo[0].InnerText);
                }
                else
                {
                    for (int i = 0; i < _lnfes.Count; i++)
                    {
                        //Variavel que gera a mensagem de resposta
                        _loteres = _loteres + "Nota de número de sequência: " + _lsSeqs[i] + " - " + nodesxMotivo[i + 1].InnerText + " Cod. " + nodescStat[i + 1].InnerText + Environment.NewLine;

                        if (nodescStat[i + 1].InnerText == "100")
                        {
                            _nfeautorizadas.Add(_lsSeqs[i]);
                            XmlNode xRetUni = xret.GetElementsByTagName("infProt")[i]; // Diego OS_24777

                            //Método responsavel por gravar o nProt e chNfe no banco e gerar o xml protocolado.
                            geraProcNFe(_lsSeqs[i], _lnfes[i], xret.GetElementsByTagName("chNFe")[i].InnerText,
                                                xRetUni["nProt"].InnerText, xret.GetElementsByTagName("protNFe")[i], pf);

                            xret.Save(belStaticPastas.PROTOCOLOS + "\\" + _sRecibo + "-pro-rec.xml");
                            countTentativas++;
                        }
                        else if (nodescStat[i + 1].InnerText == "204")
                        {
                            string sRet = nodesxMotivo[i + 1].InnerText.Substring((nodesxMotivo[i + 1].InnerText.IndexOf("nRec") + 5), 15);
                            SalvaRetornoNotaDuplicada(sRet, _lsSeqs[i]);
                        }
                        else if ((nodescStat[i + 1].InnerText == "110") || (nodescStat[i + 1].InnerText == "302") || (nodescStat[i + 1].InnerText == "302"))
                        {
                            NotaDenegada(_lsSeqs[i]);
                        }
                        else if (nodescStat[i + 1].InnerText != "105") // Lote em processamento
                        {
                            LimpaCampoRecibo(_emp, _lsSeqs[i]);
                        }
                    }
                    bStopRetorno = true;
                }
                _lblQtde.Text = countTentativas.ToString() + " - " + _loteres;

            }

        }
示例#3
0
        //Fim - Danner - o.s. 24191 - 26/02/2010
        /// <summary>
        /// Utilizado no botão para buscar o retorno da fazenda
        /// </summary>
        /// <param name="sEmp"></param>
        /// <param name="sSeq"></param>
        /// <param name="sVersao"></param>
        /// <param name="sVersaoAplic"></param>
        /// <param name="sNFe"></param>
        /// <param name="sRecibo"></param>
        /// <param name="tp_amb"></param>
        /// <param name="glob"></param>
        /// <param name="?"></param>
        public belBusRetFazenda(string sEmp, string sSeq, string sVersao, string sVersaoAplic, string sNFe,
                                string sRecibo, string sChnfe, int tp_amb, Globais glob, X509Certificate2 xCert, string UF_Empresa)
            
        {
            XNamespace pf = "http://www.portalfiscal.inf.br/nfe";

            //Retorno da fazenda com Status de cada NFe do lote.
            belNfeRetRecepcao objnferetrecepcao = new belNfeRetRecepcao("1.02", tp_amb, sRecibo, "2.00", xCert, bModoSCAN);
            XmlDocument xret = new XmlDocument();
            xret = objnferetrecepcao.Retornaxml(UF_Empresa);

            //Variavel pra sabe se alguma nota possui erro
            XmlNodeList nodeschNFe = xret.GetElementsByTagName("chNFe");
            XmlNodeList nodecStat = xret.GetElementsByTagName("cStat");
            XmlNodeList nodesxMotivo = xret.GetElementsByTagName("xMotivo");

            try
            {
                if (nodecStat[0].InnerText != "104")
                {
                    throw new Exception("Cód. do Status: " + nodecStat[0].InnerText + " " +
                                                  "Status: " + nodesxMotivo[0].InnerText);
                }
                else
                {
                    for (int i = 0; i < nodeschNFe.Count; i++)
                    {
                        if (nodeschNFe[i].InnerText == sChnfe)
                        {
                            //Monta a mensagem de resposta
                            _loteres = _loteres + "Cód. do Status: " + nodecStat[i + 1].InnerText + " " +
                                                  "Status: " + nodesxMotivo[i + 1].InnerText;

                            if (nodecStat[i + 1].InnerText == "100")
                            {
                                _nfeunicaAut = sSeq;
                             
                                geraProcNFe(sEmp, sSeq, sNFe, xret.GetElementsByTagName("chNFe")[i].InnerText,
                                    xret.GetElementsByTagName("nProt")[i].InnerText, xret.GetElementsByTagName("protNFe")[i], glob, pf); //Claudinei - o.s. 24126 - 11/02/2010
                              
                                xret.Save(glob.LeRegConfig("PastaProtocolos").ToString() + "\\" + sRecibo + "-pro-rec.xml");                        
                            }//Diego - OS_24610
                            else if (nodecStat[i + 1].InnerText == "101")
                            {
                                _nfeunicaAut = sSeq;

                                geraProcNFe(sEmp, sSeq, sNFe, xret.GetElementsByTagName("chNFe")[i].InnerText,
                                            xret.GetElementsByTagName("nProt")[i].InnerText, xret.GetElementsByTagName("protNFe")[i], glob, pf);
                                DirectoryInfo dinfo = new DirectoryInfo(glob.LeRegConfig("PastaXmlEnviado") + "\\" + xret.GetElementsByTagName("chNFe")[i].InnerText.Substring(2,4));
                                string path = "";
                                string nome = "";
                                FileInfo[] finfo = dinfo.GetFiles();
                                foreach (var item in finfo)
                                {
                                    if (item.Name.Contains(sChnfe))
                                    {
                                        path = item.FullName;
                                        nome = item.Name;
                                        break;
                                    }
                                }
                                File.Move(path, glob.LeRegConfig("PastaXmlCancelados").ToString() + "\\" + nome.Replace("nfe", "can"));//+ ".xml");
                            }//Diego - OS_24610 - FIM
                        }
                    }
                }
            }
            catch (Exception x)
            {
                throw new Exception("Erro na BuscaRetFazenda, contrutor para o botão - " + x.Message);
            }

            

        }
示例#4
0
        public void BusRetFazendaRetorno()
        {
            try
            {
                XNamespace pf = "http://www.portalfiscal.inf.br/nfe";
                //Retorno da fazenda com Status de cada NFe do lote.
                belNfeRetRecepcao objnferetrecepcao = new belNfeRetRecepcao("1.02", _sRecibo, "2.00", _xCert, bModoSCAN);
                XmlDocument xret = new XmlDocument();

                while (!bStopRetorno)
                {
                    xret = objnferetrecepcao.Retornaxml(_UF_Empresa);
                    _loteres = "";
                    //Variavel pra sabe se alguma nota possui erro
                    XmlNodeList nodeschNFe = xret.GetElementsByTagName("chNFe");
                    XmlNodeList nodecStat = xret.GetElementsByTagName("cStat");
                    XmlNodeList nodesxMotivo = xret.GetElementsByTagName("xMotivo");

                    if (nodecStat[0].InnerText == "105")
                    {
                        _loteres = nodecStat[0].InnerText + " - " + nodesxMotivo[0].InnerText;
                        countTentativas++;
                    }
                    else if (nodecStat[0].InnerText != "104")
                    {
                        throw new Exception("Cód. do Status: " + nodecStat[0].InnerText + " " +
                                                      "Status: " + nodesxMotivo[0].InnerText);
                    }
                    else
                    {
                        for (int i = 0; i < nodeschNFe.Count; i++)
                        {
                            if (nodeschNFe[i].InnerText == _sChnfe)
                            {
                                //Monta a mensagem de resposta
                                _loteres = _loteres + "Cód. do Status: " + nodecStat[i + 1].InnerText + " " +
                                                      "Status: " + nodesxMotivo[i + 1].InnerText;

                                if (nodecStat[i + 1].InnerText == "100")
                                {
                                    _nfeunicaAut = _sSeq;

                                    geraProcNFe(_sSeq, _sNFe, xret.GetElementsByTagName("chNFe")[i].InnerText,
                                        xret.GetElementsByTagName("nProt")[i].InnerText, xret.GetElementsByTagName("protNFe")[i], pf); //Claudinei - o.s. 24126 - 11/02/2010

                                    xret.Save(belStaticPastas.PROTOCOLOS + "\\" + _sRecibo + "-pro-rec.xml");
                                    bStopRetorno = true;
                                }//Diego - OS_24610
                                else if (nodecStat[i + 1].InnerText == "101")
                                {
                                    _nfeunicaAut = _sSeq;

                                    geraProcNFe(_sSeq, _sNFe, xret.GetElementsByTagName("chNFe")[i].InnerText,
                                                xret.GetElementsByTagName("nProt")[i].InnerText, xret.GetElementsByTagName("protNFe")[i], pf);
                                    DirectoryInfo dinfo = new DirectoryInfo(belStaticPastas.ENVIADOS + "\\" + xret.GetElementsByTagName("chNFe")[i].InnerText.Substring(2, 4));
                                    string path = "";
                                    string nome = "";
                                    FileInfo[] finfo = dinfo.GetFiles();
                                    foreach (var item in finfo)
                                    {
                                        if (item.Name.Contains(_sChnfe))
                                        {
                                            path = item.FullName;
                                            nome = item.Name;
                                            break;
                                        }
                                    }
                                    File.Move(path, belStaticPastas.CANCELADOS + "\\" + nome.Replace("nfe", "can"));//+ ".xml");
                                    bStopRetorno = true;
                                }//Diego - OS_24610 - FIM
                                else if ((nodecStat[i + 1].InnerText == "110") || (nodecStat[i + 1].InnerText == "302") || (nodecStat[i + 1].InnerText == "302"))
                                {
                                    NotaDenegada(_lsSeqs[i]);
                                }
                            }
                        }
                    }
                    _lblQtde.Text = countTentativas.ToString() + " - " + _loteres;
                    // _txtMsg.Text = _loteres;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }