Пример #1
0
        public void BuscarRetorno()
        {
            daoManifesto.AlteraUltimoRetorno(objPesquisa.sequencia);
            string sRetorno = string.Empty;
            XmlNode xNodeRet = xmlConsulta.DocumentElement;
            if (Acesso.TP_AMB == 1)
            {
                HLP.GeraXml.WebService.MDFe_Producao_RetRecepcao.mdfeCabecMsg cabec = new WebService.MDFe_Producao_RetRecepcao.mdfeCabecMsg();
                HLP.GeraXml.WebService.MDFe_Producao_RetRecepcao.MDFeRetRecepcao ws = new WebService.MDFe_Producao_RetRecepcao.MDFeRetRecepcao();
                cabec.cUF = Acesso.cUF.ToString();
                cabec.versaoDados = Acesso.versaoMDFe;
                ws.mdfeCabecMsgValue = cabec;
                ws.ClientCertificates.Add(Acesso.cert_CTe);
                sRetorno = ws.mdfeRetRecepcao(xNodeRet).OuterXml;
            }
            else
            {
                HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.mdfeCabecMsg cabec = new WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.mdfeCabecMsg();
                HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.MDFeRetRecepcao ws = new WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.MDFeRetRecepcao();
                cabec.cUF = Acesso.cUF.ToString();
                cabec.versaoDados = Acesso.versaoMDFe;
                ws.mdfeCabecMsgValue = cabec;
                ws.ClientCertificates.Add(Acesso.cert_CTe);
                sRetorno = ws.mdfeRetRecepcao(xNodeRet).OuterXml;
            }

            if (sRetorno != "")
            {
                string sPath = Pastas.PROTOCOLOS + Convert.ToInt32(objPesquisa.numero) + "-pro-rec.xml";
                if (File.Exists(sPath))
                    File.Delete(sPath);
                xmlRetorno = new XmlDocument();
                xmlRetorno.LoadXml(sRetorno);
                xmlRetorno.Save(sPath);
                TRetConsReciMDFe recepacao = SerializeClassToXml.DeserializeClasse<TRetConsReciMDFe>(sPath);

                sMessage = string.Format("Sequencia: {0}{4}Numero: {1}{4}Motivo: {2}{4}Status: {3}{4}",
                        objPesquisa.sequencia,
                        objPesquisa.numero,
                        recepacao.protMDFe != null ? recepacao.protMDFe.infProt.xMotivo : recepacao.xMotivo,
                        recepacao.cStat,
                        Environment.NewLine);

                if (recepacao.cStat != "104")
                {

                    daoManifesto.LimpaRecibo(objPesquisa.sequencia);
                }
                else
                {
                    if (recepacao.protMDFe != null)
                    {
                        //if (recepacao.cStat == "104")
                        //{
                        //    string sRec = recepacao.protMDFe.infProt.xMotivo.Substring(recepacao.protMDFe.infProt.xMotivo.IndexOf("nRec:"), 20).Replace("nRec:", "");
                        //    daoManifesto.gravaRecibo(sRec, objPesquisa.sequencia);
                        //    daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S");
                        //    daoManifesto.AlteraUltimoRetornoNULL(objPesquisa.sequencia);
                        //    //IncluiTagInfProc();
                        //}
                        //else
                        if (recepacao.protMDFe.infProt.cStat == "100")
                        {
                            daoManifesto.gravaProtocolo(recepacao.protMDFe.infProt.nProt, objPesquisa.sequencia);
                            daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S");
                            IncluiTagInfProc();
                        }
                        else if (recepacao.protMDFe.infProt.cStat == "101") //CANCELADO.
                        {
                            daoManifesto.gravaProtocolo(recepacao.nRec, objPesquisa.sequencia);

                        }
                        else if (recepacao.protMDFe.infProt.cStat == "204") //DUPLICADO.
                        {
                            string sRec = recepacao.protMDFe.infProt.xMotivo.Substring(recepacao.protMDFe.infProt.xMotivo.IndexOf("nRec:"), 20).Replace("nRec:", "");
                            daoManifesto.gravaRecibo(sRec, objPesquisa.sequencia);
                            daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S");
                            //IncluiTagInfProc();
                            daoManifesto.AlteraUltimoRetornoNULL(objPesquisa.sequencia);
                            // BuscarRetorno();

                        }
                        else if (recepacao.protMDFe.infProt.cStat == "105") //LOTE EM PROCESSAMENTO.
                        {
                            daoManifesto.gravaProtocolo(recepacao.nRec, objPesquisa.sequencia);
                        }
                        else
                        {
                            daoManifesto.LimpaRecibo(objPesquisa.sequencia);
                        }
                    }
                    else
                    {
                        daoManifesto.LimpaRecibo(objPesquisa.sequencia);
                    }
                }
            }
        }
Пример #2
0
        public void BuscarRetorno()
        {
            daoManifesto.AlteraUltimoRetorno(objPesquisa.sequencia);
            string  sRetorno = string.Empty;
            XmlNode xNodeRet = xmlConsulta.DocumentElement;

            if (Acesso.TP_AMB == 1)
            {
                HLP.GeraXml.WebService.MDFe_Producao_RetRecepcao.mdfeCabecMsg    cabec = new WebService.MDFe_Producao_RetRecepcao.mdfeCabecMsg();
                HLP.GeraXml.WebService.MDFe_Producao_RetRecepcao.MDFeRetRecepcao ws    = new WebService.MDFe_Producao_RetRecepcao.MDFeRetRecepcao();
                cabec.cUF            = Acesso.cUF.ToString();
                cabec.versaoDados    = Acesso.versaoMDFe;
                ws.mdfeCabecMsgValue = cabec;
                ws.ClientCertificates.Add(Acesso.cert_CTe);
                sRetorno = ws.mdfeRetRecepcao(xNodeRet).OuterXml;
            }
            else
            {
                HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.mdfeCabecMsg    cabec = new WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.mdfeCabecMsg();
                HLP.GeraXml.WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.MDFeRetRecepcao ws    = new WebServiceHomologacao.MDFe_Homologacao_RetRecepcao.MDFeRetRecepcao();
                cabec.cUF            = Acesso.cUF.ToString();
                cabec.versaoDados    = Acesso.versaoMDFe;
                ws.mdfeCabecMsgValue = cabec;
                ws.ClientCertificates.Add(Acesso.cert_CTe);
                sRetorno = ws.mdfeRetRecepcao(xNodeRet).OuterXml;
            }

            if (sRetorno != "")
            {
                string sPath = Pastas.PROTOCOLOS + Convert.ToInt32(objPesquisa.numero) + "-pro-rec.xml";
                if (File.Exists(sPath))
                {
                    File.Delete(sPath);
                }
                xmlRetorno = new XmlDocument();
                xmlRetorno.LoadXml(sRetorno);
                xmlRetorno.Save(sPath);
                TRetConsReciMDFe recepacao = SerializeClassToXml.DeserializeClasse <TRetConsReciMDFe>(sPath);

                sMessage = string.Format("Sequencia: {0}{4}Numero: {1}{4}Motivo: {2}{4}Status: {3}{4}",
                                         objPesquisa.sequencia,
                                         objPesquisa.numero,
                                         recepacao.protMDFe != null ? recepacao.protMDFe.infProt.xMotivo : recepacao.xMotivo,
                                         recepacao.cStat,
                                         Environment.NewLine);

                if (recepacao.cStat != "104")
                {
                    daoManifesto.LimpaRecibo(objPesquisa.sequencia);
                }
                else
                {
                    if (recepacao.protMDFe != null)
                    {
                        //if (recepacao.cStat == "104")
                        //{
                        //    string sRec = recepacao.protMDFe.infProt.xMotivo.Substring(recepacao.protMDFe.infProt.xMotivo.IndexOf("nRec:"), 20).Replace("nRec:", "");
                        //    daoManifesto.gravaRecibo(sRec, objPesquisa.sequencia);
                        //    daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S");
                        //    daoManifesto.AlteraUltimoRetornoNULL(objPesquisa.sequencia);
                        //    //IncluiTagInfProc();
                        //}
                        //else
                        if (recepacao.protMDFe.infProt.cStat == "100")
                        {
                            daoManifesto.gravaProtocolo(recepacao.protMDFe.infProt.nProt, objPesquisa.sequencia);
                            daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S");
                            IncluiTagInfProc();
                        }
                        else if (recepacao.protMDFe.infProt.cStat == "101") //CANCELADO.
                        {
                            daoManifesto.gravaProtocolo(recepacao.nRec, objPesquisa.sequencia);
                        }
                        else if (recepacao.protMDFe.infProt.cStat == "204") //DUPLICADO.
                        {
                            string sRec = recepacao.protMDFe.infProt.xMotivo.Substring(recepacao.protMDFe.infProt.xMotivo.IndexOf("nRec:"), 20).Replace("nRec:", "");
                            daoManifesto.gravaRecibo(sRec, objPesquisa.sequencia);
                            daoManifesto.AlteraStatusMDFe(objPesquisa.sequencia, "S");
                            //IncluiTagInfProc();
                            daoManifesto.AlteraUltimoRetornoNULL(objPesquisa.sequencia);
                            // BuscarRetorno();
                        }
                        else if (recepacao.protMDFe.infProt.cStat == "105") //LOTE EM PROCESSAMENTO.
                        {
                            daoManifesto.gravaProtocolo(recepacao.nRec, objPesquisa.sequencia);
                        }
                        else
                        {
                            daoManifesto.LimpaRecibo(objPesquisa.sequencia);
                        }
                    }
                    else
                    {
                        daoManifesto.LimpaRecibo(objPesquisa.sequencia);
                    }
                }
            }
        }