Esempio n. 1
0
        public static void MoveArquivoParaPastaCancelada(belPesquisaNotas objPesquisa)
        {
            DirectoryInfo dinfo = new DirectoryInfo(Pastas.ENVIADOS + "\\" + objPesquisa.sCHAVENFE.Substring(2, 4));
            FileInfo      f;

            try
            {
                FileInfo[] finfo = dinfo.GetFiles();

                if (finfo.Where(c => c.Name.Contains(objPesquisa.sCHAVENFE)).Count() > 0)
                {
                    f = finfo.FirstOrDefault(c => c.Name.Contains(objPesquisa.sCHAVENFE));
                    DirectoryInfo dinfoPasta = new DirectoryInfo(Pastas.CANCELADOS + "\\" + objPesquisa.dDT_EMI.Date.ToString("yyMM"));
                    if (!dinfoPasta.Exists)
                    {
                        dinfoPasta.Create();
                    }
                    File.Move(f.FullName, dinfoPasta.FullName + "\\" + f.Name.Replace("nfe", "can") + ".xml");
                    File.Delete(f.FullName);
                }
            }
            catch (Exception x)
            {
                throw new Exception("Erro ao tentar mover o arquivo - " + x.Message);
            }
        }
Esempio n. 2
0
 public frmCancelamentoNFe(belPesquisaNotas _objPesquisa)
 {
     InitializeComponent();
     this.objbelPesquisa = _objPesquisa;
     txtJust.txt.ScrollBars = ScrollBars.Vertical;
     txtJust.txt.CharacterCasing = CharacterCasing.Upper;
     txtJust.txt.KeyPress += new KeyPressEventHandler(txt_KeyPress);
 }
Esempio n. 3
0
        private void IncluiTagInfProc(belPesquisaNotas nota, XmlNode xret, XNamespace pf)
        {
            //Geração do Xml da nfe Autorizado, incluindo a TAG infProc onde consta as informaçoes de retorno da nfe.

            string      sCodificacao = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
            string      sRetProc     = "<nfeProc versao=\"2.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">";
            XmlDocument xmldocteste  = new XmlDocument();

            xmldocteste.Load(Util.BuscaCaminhoArquivoXml(nota.sCHAVENFE, 1));
            Util.BuscaDiretorioArquivoXml(nota.sCHAVENFE, 1);

            StreamWriter sw = new StreamWriter(Util.BuscaCaminhoArquivoXml(nota.sCHAVENFE, 2));

            if (@xmldocteste.FirstChild.Name.Equals("xml"))
            {
                sw.Write(@sRetProc + @xmldocteste.OuterXml.Remove(0, 38) + @xret.OuterXml.ToString() + @"</nfeProc>");
            }
            else
            {
                sw.Write(@sCodificacao + @sRetProc + @xmldocteste.OuterXml + @xret.OuterXml.ToString() + @"</nfeProc>");
            }
            sw.Close();
        }
Esempio n. 4
0
        public void PesquisaNotas()
        {
            belPesquisaNotas.status st;
            if (cboStatus.cbx.Text.Equals("Enviados"))
            {
                st = belPesquisaNotas.status.Enviados;
            }
            else if (cboStatus.cbx.Text.Equals("Não Enviados"))
            {
                st = belPesquisaNotas.status.NaoEnviados;
            }
            else
            {
                st = belPesquisaNotas.status.Ambos;
            }
            //Por Data
            //Por Sequência
            //Por Cliente
            //NF
            //NFS-e
            string sValor1 = string.Empty;
            string sValor2 = string.Empty;
            belPesquisaNotas.Filtro filtro = belPesquisaNotas.Filtro.Data;
            if (cboFiltro.cbx.SelectedIndex == 0)
            {
                filtro = belPesquisaNotas.Filtro.Data;
                sValor1 = dtpIni.Value.ToString();
                sValor2 = dtpFim.Value.ToString();
            }
            else if (cboFiltro.cbx.SelectedIndex == 1)
            {
                filtro = belPesquisaNotas.Filtro.Sequencia;
                sValor1 = txtNfIni.Text;
                sValor2 = txtNfFim.Text;
            }
            else if (cboFiltro.cbx.SelectedIndex == 2)
            {
                filtro = belPesquisaNotas.Filtro.Cliente;
                sValor1 = txtCliente.Text;
            }
            else if (cboFiltro.cbx.SelectedIndex == 3)
            {
                filtro = belPesquisaNotas.Filtro.NF;
                sValor1 = txtNfIni.Text;
                sValor2 = txtNfFim.Text;
            }
            else if (cboFiltro.cbx.SelectedIndex == 4)
            {
                filtro = belPesquisaNotas.Filtro.NFSe;
                sValor1 = txtNfIni.Text;
                sValor2 = txtNfFim.Text;
            }



            belPesq = new belPesquisaNotas(st,
                                                           filtro,
                                                           sValor1,
                                                           sValor2, true);
            bsNotas.DataSource = belPesq.lResultPesquisa;

            ColoriGrid();
            lblTotalRegistros.Text = belPesq.lResultPesquisa.Count + " Registro(s) encontrado(s)";
        }
Esempio n. 5
0
 public belConsultaStatusCliente(belPesquisaNotas _objPesquisa)
 {
     this.objPesquisa = _objPesquisa;
 }
Esempio n. 6
0
        private void IncluiTagInfProc(belPesquisaNotas nota, XmlNode xret, XNamespace pf)
        {
            //Geração do Xml da nfe Autorizado, incluindo a TAG infProc onde consta as informaçoes de retorno da nfe.

            string sCodificacao = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
            string sRetProc = "<nfeProc versao=\"2.00\" xmlns=\"http://www.portalfiscal.inf.br/nfe\">";
            XmlDocument xmldocteste = new XmlDocument();
            xmldocteste.Load(Util.BuscaCaminhoArquivoXml(nota.sCHAVENFE, 1));
            Util.BuscaDiretorioArquivoXml(nota.sCHAVENFE, 1);

            StreamWriter sw = new StreamWriter(Util.BuscaCaminhoArquivoXml(nota.sCHAVENFE, 2));

            if (@xmldocteste.FirstChild.Name.Equals("xml"))
            {
                sw.Write(@sRetProc + @xmldocteste.OuterXml.Remove(0, 38) + @xret.OuterXml.ToString() + @"</nfeProc>");
            }
            else
            {
                sw.Write(@sCodificacao + @sRetProc + @xmldocteste.OuterXml + @xret.OuterXml.ToString() + @"</nfeProc>");
            }
            sw.Close();
        }
Esempio n. 7
0
        public void EfetuaCancelamento(belPesquisaNotas _objPesquisa, string sJust, int iNumEvento)
        {
            this.objPesquisa = _objPesquisa;
            string      sDados = NFeDadosMsg2(_objPesquisa, sJust, iNumEvento);
            XmlDocument xRet   = new XmlDocument();

            if (Acesso.TP_EMIS == 1)
            {
                switch (Acesso.xUFtoWS)
                {
                case "SP":
                {
                    #region Regiao_SP
                    if (Acesso.TP_AMB == 1)
                    {
                        HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_SP.RecepcaoEvento ws2   = new WebService.v2_Producao_NFeRecepcaoEvento_SP.RecepcaoEvento();
                        HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_SP.nfeCabecMsg    cabec = new WebService.v2_Producao_NFeRecepcaoEvento_SP.nfeCabecMsg();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    if (Acesso.TP_AMB == 2)
                    {
                        HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.nfeCabecMsg    cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.nfeCabecMsg();
                        HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.RecepcaoEvento ws2   = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.RecepcaoEvento();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    #endregion
                }
                break;

                case "RS":
                {
                    #region Regiao_RS
                    if (Acesso.TP_AMB == 1)
                    {
                        HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_RS.RecepcaoEvento ws2   = new WebService.v2_Producao_NFeRecepcaoEvento_RS.RecepcaoEvento();
                        HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_RS.nfeCabecMsg    cabec = new WebService.v2_Producao_NFeRecepcaoEvento_RS.nfeCabecMsg();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    if (Acesso.TP_AMB == 2)
                    {
                        HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.nfeCabecMsg    cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.nfeCabecMsg();
                        HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.RecepcaoEvento ws2   = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.RecepcaoEvento();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    #endregion
                }
                break;

                case "MS":
                {
                    #region Regiao_SP
                    if (Acesso.TP_AMB == 1)
                    {
                        HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.nfeCabecMsg    cabec = new HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.nfeCabecMsg();
                        HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.RecepcaoEvento ws2   = new HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.RecepcaoEvento();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    if (Acesso.TP_AMB == 2)
                    {
                        throw new Exception("Não implementado");
                    }
                    #endregion
                }
                break;

                case "SVRS":
                {
                    #region Regiao_SP
                    if (Acesso.TP_AMB == 1)
                    {
                        HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.nfeCabecMsg    cabec = new HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.nfeCabecMsg();
                        HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.RecepcaoEvento ws2   = new HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.RecepcaoEvento();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    if (Acesso.TP_AMB == 2)
                    {
                        throw new Exception("Não implementado para o RJ em modo de homologação.");
                    }
                    #endregion
                }
                break;

                case "MG":
                {
                    #region Regiao_MG
                    if (Acesso.TP_AMB == 1)
                    {
                        HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.nfeCabecMsg    cabec = new HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.nfeCabecMsg();
                        HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.RecepcaoEvento ws2   = new HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.RecepcaoEvento();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    if (Acesso.TP_AMB == 2)
                    {
                        HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.nfeCabecMsg    cabec = new HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.nfeCabecMsg();
                        HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.RecepcaoEvento ws2   = new HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.RecepcaoEvento();

                        cabec.versaoDados = "1.00";
                        cabec.cUF         = Acesso.cUF.ToString();
                        ws2.ClientCertificates.Add(Acesso.cert_NFe);
                        ws2.nfeCabecMsgValue = cabec;
                        XmlDocument xmlCanc = new XmlDocument();
                        xmlCanc.LoadXml(sDados);
                        XmlNode xNodeCanc = xmlCanc.DocumentElement;
                        string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                        xRet.LoadXml(sRet);
                    }
                    #endregion
                }
                break;
                }
            }
            else if (Acesso.TP_EMIS == 3)
            {
                #region SCAN
                if (Acesso.TP_AMB == 1)
                {
                    HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.NfeCancelamento2 ws2   = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.NfeCancelamento2();
                    HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.nfeCabecMsg      cabec = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.nfeCabecMsg();
                    cabec.versaoDados = Acesso.versaoNFe;
                    cabec.cUF         = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    xRet.LoadXml(ws2.nfeCancelamentoNF2(xNodeCanc).OuterXml);
                }
                if (Acesso.TP_AMB == 2)
                {
                    HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.NfeCancelamento2 ws2   = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.NfeCancelamento2();
                    HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.nfeCabecMsg      cabec = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.nfeCabecMsg();

                    cabec.versaoDados = Acesso.versaoNFe;
                    cabec.cUF         = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    xRet.LoadXml(ws2.nfeCancelamentoNF2(xNodeCanc).OuterXml);
                }
                #endregion
            }
            else if (Acesso.TP_EMIS == 6)
            {
                #region SCAN
                if (Acesso.TP_AMB == 1)
                {
                    HLP.GeraXml.WebService.v2_SVC_Producao_RecepcaoEvento.RecepcaoEvento ws2   = new WebService.v2_SVC_Producao_RecepcaoEvento.RecepcaoEvento();
                    HLP.GeraXml.WebService.v2_SVC_Producao_RecepcaoEvento.nfeCabecMsg    cabec = new WebService.v2_SVC_Producao_RecepcaoEvento.nfeCabecMsg();

                    cabec.versaoDados = "1.00";
                    cabec.cUF         = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                    xRet.LoadXml(sRet);
                }
                if (Acesso.TP_AMB == 2)
                {
                    HLP.GeraXml.WebService.v2_SVC_Homologacao_RecepcaoEvento.RecepcaoEvento ws2   = new WebService.v2_SVC_Homologacao_RecepcaoEvento.RecepcaoEvento();
                    HLP.GeraXml.WebService.v2_SVC_Homologacao_RecepcaoEvento.nfeCabecMsg    cabec = new WebService.v2_SVC_Homologacao_RecepcaoEvento.nfeCabecMsg();

                    cabec.versaoDados = "1.00";
                    cabec.cUF         = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    string  sRet      = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                    xRet.LoadXml(sRet);
                }
                #endregion
            }


            string sPath = Pastas.PROTOCOLOS + "\\" + objPesquisa.sCD_NFSEQ + "_Ret_Pedcan" + DateTime.Now.ToString("ddMMyyHHmmss") + ".xml";
            xRet.Save(sPath);

            belRetEventoCancelamento objRet = SerializeClassToXml.DeserializeClasse <belRetEventoCancelamento>(sPath);

            if (objRet.retEvento.infEvento.cStat == "573")
            {
                objRetorno = new DadosRetorno();
                iNumEvento = iNumEvento + 1;
                EfetuaCancelamento(_objPesquisa, sJust, iNumEvento);
            }
            else
            {
                objRetorno = CarregaDadosRetorno(objRet);
            }
        }
Esempio n. 8
0
        private string NFeDadosMsg2(belPesquisaNotas nota, string sJust, int iNumEvento)
        {
            string           sVersao = "1.00";
            belCancelamento2 objcanc = new belCancelamento2();

            objcanc.idLote = nota.sCD_NFSEQ.PadLeft(15, '0');
            objcanc.versao = sVersao;
            Evento evento = new Evento();

            evento.versao    = sVersao;
            evento.infEvento = new eventoInfEvento();

            evento.infEvento.nSeqEvento           = iNumEvento.ToString(); // numero de evento
            evento.infEvento.Id                   = "ID" + evento.infEvento.tpEvento + nota.sCHAVENFE + evento.infEvento.nSeqEvento.PadLeft(2, '0');
            evento.infEvento.cOrgao               = Convert.ToByte(Acesso.cUF);
            evento.infEvento.tpAmb                = Convert.ToByte(Acesso.TP_AMB);
            evento.infEvento.CNPJ                 = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
            evento.infEvento.chNFe                = nota.sCHAVENFE;
            evento.infEvento.dhEvento             = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss" + Acesso.FUSO);
            evento.infEvento.verEvento            = sVersao;
            evento.infEvento.detEvento            = new eventoInfEventoDetEvento();
            evento.infEvento.detEvento.versao     = sVersao;
            evento.infEvento.detEvento.descEvento = "Cancelamento";
            evento.infEvento.detEvento.nProt      = nota.cd_nprotnfe;
            evento.infEvento.detEvento.xJust      = sJust;

            string sEvento = "";

            XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();

            nameSpaces.Add("", "");
            nameSpaces.Add("", "http://www.portalfiscal.inf.br/nfe");


            XmlSerializer xs      = new XmlSerializer(typeof(Evento));
            MemoryStream  memory  = new MemoryStream();
            XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);

            xs.Serialize(xmltext, evento, nameSpaces);
            UTF8Encoding encoding = new UTF8Encoding();

            sEvento = encoding.GetString(memory.ToArray());
            sEvento = sEvento.Substring(1);



            belAssinaXml Assinatura = new belAssinaXml();

            sEvento = Assinatura.ConfigurarArquivo(sEvento, "infEvento", Acesso.cert_NFe);

            string sXMLfinal = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.00\"><idLote>" + nota.sCD_NFSEQ.PadLeft(15, '0')
                               + "</idLote>" + sEvento.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "") + "</envEvento>";

            XmlDocument xDoc = new XmlDocument();

            xDoc.LoadXml(sXMLfinal);
            string sPath = Pastas.PROTOCOLOS + "\\" + objPesquisa.sCD_NFSEQ + "_ped-can.xml";

            if (File.Exists(sPath))
            {
                File.Delete(sPath);
            }
            xDoc.Save(sPath);
            try
            {
                belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/nfe", Pastas.SCHEMA_CANC + "\\envEventoCancNFe_v1.00.xsd", sPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(sXMLfinal);
        }
Esempio n. 9
0
        public void EfetuaCancelamento(belPesquisaNotas _objPesquisa, string sJust, int iNumEvento)
        {
            this.objPesquisa = _objPesquisa;
            string sDados = NFeDadosMsg2(_objPesquisa, sJust, iNumEvento);
            XmlDocument xRet = new XmlDocument();

            if (Acesso.TP_EMIS == 1)
            {
                switch (Acesso.xUFtoWS)
                {
                    case "SP":
                        {
                            #region Regiao_SP
                            if (Acesso.TP_AMB == 1)
                            {
                                HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_SP.RecepcaoEvento ws2 = new WebService.v2_Producao_NFeRecepcaoEvento_SP.RecepcaoEvento();
                                HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_SP.nfeCabecMsg cabec = new WebService.v2_Producao_NFeRecepcaoEvento_SP.nfeCabecMsg();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);

                            }
                            if (Acesso.TP_AMB == 2)
                            {
                                HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.nfeCabecMsg();
                                HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_SP.RecepcaoEvento();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);

                            }
                            #endregion
                        }
                        break;
                    case "RS":
                        {
                            #region Regiao_RS
                            if (Acesso.TP_AMB == 1)
                            {
                                HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_RS.RecepcaoEvento ws2 = new WebService.v2_Producao_NFeRecepcaoEvento_RS.RecepcaoEvento();
                                HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_RS.nfeCabecMsg cabec = new WebService.v2_Producao_NFeRecepcaoEvento_RS.nfeCabecMsg();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);

                            }
                            if (Acesso.TP_AMB == 2)
                            {
                                HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.nfeCabecMsg();
                                HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Homologacao_NFeRecepcaoEvento_RS.RecepcaoEvento();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);

                            }
                            #endregion
                        }
                        break;
                    case "MS":
                        {
                            #region Regiao_SP
                            if (Acesso.TP_AMB == 1)
                            {
                                HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.nfeCabecMsg();
                                HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Producao_NFeRecepcaoEvento_MS.RecepcaoEvento();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);

                            }
                            if (Acesso.TP_AMB == 2)
                            {
                                throw new Exception("Não implementado");

                            }
                            #endregion
                        }
                        break;
                    case "SVRS":
                        {
                            #region Regiao_SP
                            if (Acesso.TP_AMB == 1)
                            {
                                HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.nfeCabecMsg cabec = new HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.nfeCabecMsg();
                                HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.V2_Producao_RecepcaoEvento_SVRS.RecepcaoEvento();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);
                            }
                            if (Acesso.TP_AMB == 2)
                            {                                
                                throw new Exception("Não implementado para o RJ em modo de homologação.");
                            }
                            #endregion
                        }
                        break;
                    case "MG":
                        {
                            #region Regiao_MG
                            if (Acesso.TP_AMB == 1)
                            {
                                HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.nfeCabecMsg();
                                HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Producao_RecepcaoEvento_MG.RecepcaoEvento();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);

                            }
                            if (Acesso.TP_AMB == 2)
                            {
                                HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.nfeCabecMsg();
                                HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.RecepcaoEvento ws2 = new HLP.GeraXml.WebService.v2_Homologacao_RecepcaoEvento_MG.RecepcaoEvento();

                                cabec.versaoDados = "1.00";
                                cabec.cUF = Acesso.cUF.ToString();
                                ws2.ClientCertificates.Add(Acesso.cert_NFe);
                                ws2.nfeCabecMsgValue = cabec;
                                XmlDocument xmlCanc = new XmlDocument();
                                xmlCanc.LoadXml(sDados);
                                XmlNode xNodeCanc = xmlCanc.DocumentElement;
                                string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                                xRet.LoadXml(sRet);

                            }
                            #endregion
                        }
                        break;
                }
            }
            else if (Acesso.TP_EMIS == 3)
            {
                #region SCAN
                if (Acesso.TP_AMB == 1)
                {
                    HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.NfeCancelamento2 ws2 = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.NfeCancelamento2();
                    HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SCAN_Producao_NFeCancelamento.nfeCabecMsg();
                    cabec.versaoDados = Acesso.versaoNFe;
                    cabec.cUF = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    xRet.LoadXml(ws2.nfeCancelamentoNF2(xNodeCanc).OuterXml);

                }
                if (Acesso.TP_AMB == 2)
                {

                    HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.NfeCancelamento2 ws2 = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.NfeCancelamento2();
                    HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.nfeCabecMsg cabec = new HLP.GeraXml.WebService.v2_SCAN_Homologacao_NFeCancelamento.nfeCabecMsg();

                    cabec.versaoDados = Acesso.versaoNFe;
                    cabec.cUF = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    xRet.LoadXml(ws2.nfeCancelamentoNF2(xNodeCanc).OuterXml);

                }
                #endregion
            }
            else if (Acesso.TP_EMIS == 6)
            {
                #region SCAN
                if (Acesso.TP_AMB == 1)
                {
                    HLP.GeraXml.WebService.v2_SVC_Producao_RecepcaoEvento.RecepcaoEvento ws2 = new WebService.v2_SVC_Producao_RecepcaoEvento.RecepcaoEvento();
                    HLP.GeraXml.WebService.v2_SVC_Producao_RecepcaoEvento.nfeCabecMsg cabec = new WebService.v2_SVC_Producao_RecepcaoEvento.nfeCabecMsg();

                    cabec.versaoDados = "1.00";
                    cabec.cUF = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                    xRet.LoadXml(sRet);

                }
                if (Acesso.TP_AMB == 2)
                {
                    HLP.GeraXml.WebService.v2_SVC_Homologacao_RecepcaoEvento.RecepcaoEvento ws2 = new WebService.v2_SVC_Homologacao_RecepcaoEvento.RecepcaoEvento();
                    HLP.GeraXml.WebService.v2_SVC_Homologacao_RecepcaoEvento.nfeCabecMsg cabec = new WebService.v2_SVC_Homologacao_RecepcaoEvento.nfeCabecMsg();

                    cabec.versaoDados = "1.00";
                    cabec.cUF = Acesso.cUF.ToString();
                    ws2.ClientCertificates.Add(Acesso.cert_NFe);
                    ws2.nfeCabecMsgValue = cabec;
                    XmlDocument xmlCanc = new XmlDocument();
                    xmlCanc.LoadXml(sDados);
                    XmlNode xNodeCanc = xmlCanc.DocumentElement;
                    string sRet = ws2.nfeRecepcaoEvento(xNodeCanc).OuterXml;
                    xRet.LoadXml(sRet);
                }
                #endregion
            }


            string sPath = Pastas.PROTOCOLOS + "\\" + objPesquisa.sCD_NFSEQ + "_Ret_Pedcan" + DateTime.Now.ToString("ddMMyyHHmmss") + ".xml";
            xRet.Save(sPath);

            belRetEventoCancelamento objRet = SerializeClassToXml.DeserializeClasse<belRetEventoCancelamento>(sPath);

            if (objRet.retEvento.infEvento.cStat == "573")
            {
                objRetorno = new DadosRetorno();
                iNumEvento = iNumEvento + 1;
                EfetuaCancelamento(_objPesquisa, sJust, iNumEvento);
            }
            else
            {
              objRetorno =  CarregaDadosRetorno(objRet);
            }            
        }
Esempio n. 10
0
 public belConsultaStatusNota(belPesquisaNotas objPesquisa)
 {
     this.objPesquisa = objPesquisa;
 }
 public belConsultaStatusNota(belPesquisaNotas objPesquisa)
 {
     this.objPesquisa = objPesquisa;
 }
Esempio n. 12
0
 public belNFesSusesu(belPesquisaNotas objBelPesquisaNota)
 {
     this.CD_NFSEQ = objBelPesquisaNota.sCD_NFSEQ;
     BuscaDadosGerais(objBelPesquisaNota.sCD_NFSEQ);
 }
Esempio n. 13
0
        public void PesquisaNotas()
        {
            belPesquisaNotas.status st;
            if (cboStatus.cbx.Text.Equals("Enviados"))
            {
                st = belPesquisaNotas.status.Enviados;
            }
            else if (cboStatus.cbx.Text.Equals("Não Enviados"))
            {
                st = belPesquisaNotas.status.NaoEnviados;
            }
            else
            {
                st = belPesquisaNotas.status.Ambos;
            }
            belPesquisaNotas.Filtro filtro = new belPesquisaNotas.Filtro();
            string sValor1 = string.Empty;
            string sValor2 = string.Empty;

            if (cboFiltro.cbx.SelectedIndex == 0)
            {
                filtro = belPesquisaNotas.Filtro.Data;
                sValor1 = dtpIni.Value.ToString();
                sValor2 = dtpFim.Value.ToString();
            }
            else if (cboFiltro.cbx.SelectedIndex == 1)
            {
                filtro = belPesquisaNotas.Filtro.Sequencia;
                sValor1 = txtNfIni.Text;
                sValor2 = txtNfFim.Text;
            }
            else if (cboFiltro.cbx.SelectedIndex == 2)
            {
                filtro = belPesquisaNotas.Filtro.Cliente;
                sValor1 = txtCliente.Text;
            }
            else if (cboFiltro.cbx.SelectedIndex == 3)
            {
                filtro = belPesquisaNotas.Filtro.NF;
                sValor1 = txtNfIni.Text;
                sValor2 = txtNfFim.Text;
            }

            belPesq = new belPesquisaNotas(st,
                                                           filtro,
                                                           sValor1,
                                                           sValor2);

            bsNotas.DataSource = belPesq.lResultPesquisa;



            ColoriGrid();
        }
Esempio n. 14
0
        public static void MoveArquivoParaPastaCancelada(belPesquisaNotas objPesquisa)
        {
            DirectoryInfo dinfo = new DirectoryInfo(Pastas.ENVIADOS + "\\" + objPesquisa.sCHAVENFE.Substring(2, 4));
            FileInfo f;
            
            try
            {
                FileInfo[] finfo = dinfo.GetFiles();

                if (finfo.Where(c => c.Name.Contains(objPesquisa.sCHAVENFE)).Count() > 0)
                {
                    f = finfo.FirstOrDefault(c => c.Name.Contains(objPesquisa.sCHAVENFE));
                    DirectoryInfo dinfoPasta = new DirectoryInfo(Pastas.CANCELADOS + "\\" + objPesquisa.dDT_EMI.Date.ToString("yyMM"));
                    if (!dinfoPasta.Exists) { dinfoPasta.Create(); }
                    File.Move(f.FullName, dinfoPasta.FullName + "\\" + f.Name.Replace("nfe", "can") + ".xml");
                    File.Delete(f.FullName);
                }
            }
            catch (Exception x)
            {
                throw new Exception("Erro ao tentar mover o arquivo - " + x.Message);
            }
        }
Esempio n. 15
0
        private string NFeDadosMsg2(belPesquisaNotas nota, string sJust, int iNumEvento)
        {
            string sVersao = "1.00";
            belCancelamento2 objcanc = new belCancelamento2();
            objcanc.idLote = nota.sCD_NFSEQ.PadLeft(15, '0');
            objcanc.versao = sVersao;
            Evento evento = new Evento();
            evento.versao = sVersao;
            evento.infEvento = new eventoInfEvento();

            evento.infEvento.nSeqEvento = iNumEvento.ToString(); // numero de evento
            evento.infEvento.Id = "ID" + evento.infEvento.tpEvento + nota.sCHAVENFE + evento.infEvento.nSeqEvento.PadLeft(2, '0');
            evento.infEvento.cOrgao = Convert.ToByte(Acesso.cUF);
            evento.infEvento.tpAmb = Convert.ToByte(Acesso.TP_AMB);
            evento.infEvento.CNPJ = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
            evento.infEvento.chNFe = nota.sCHAVENFE;
            evento.infEvento.dhEvento = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss" + Acesso.FUSO);
            evento.infEvento.verEvento = sVersao;
            evento.infEvento.detEvento = new eventoInfEventoDetEvento();
            evento.infEvento.detEvento.versao = sVersao;
            evento.infEvento.detEvento.descEvento = "Cancelamento";
            evento.infEvento.detEvento.nProt = nota.cd_nprotnfe;
            evento.infEvento.detEvento.xJust = sJust;

            string sEvento = "";

            XmlSerializerNamespaces nameSpaces = new XmlSerializerNamespaces();
            nameSpaces.Add("", "");
            nameSpaces.Add("", "http://www.portalfiscal.inf.br/nfe");


            XmlSerializer xs = new XmlSerializer(typeof(Evento));
            MemoryStream memory = new MemoryStream();
            XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);
            xs.Serialize(xmltext, evento, nameSpaces);
            UTF8Encoding encoding = new UTF8Encoding();
            sEvento = encoding.GetString(memory.ToArray());
            sEvento = sEvento.Substring(1);

            

            belAssinaXml Assinatura = new belAssinaXml();
            sEvento = Assinatura.ConfigurarArquivo(sEvento, "infEvento", Acesso.cert_NFe);

            string sXMLfinal = "<?xml version=\"1.0\" encoding=\"utf-8\"?><envEvento xmlns=\"http://www.portalfiscal.inf.br/nfe\" versao=\"1.00\"><idLote>" + nota.sCD_NFSEQ.PadLeft(15, '0')
                                + "</idLote>" + sEvento.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "") + "</envEvento>";

            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(sXMLfinal);
            string sPath = Pastas.PROTOCOLOS + "\\" + objPesquisa.sCD_NFSEQ + "_ped-can.xml";
            if (File.Exists(sPath))
            {
                File.Delete(sPath);
            }
            xDoc.Save(sPath);
            try
            {
                belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/nfe", Pastas.SCHEMA_CANC + "\\envEventoCancNFe_v1.00.xsd", sPath);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return sXMLfinal;
        }
Esempio n. 16
0
        private void btnBuscaRetorno_Click(object sender, EventArgs e)
        {
            frmStatusEnvioNfs objfrmStatus = null;
            try
            {
                if (belPesq.lResultPesquisa != null)
                {
                    List<belPesquisaNotas> objSelecionadas = belPesq.lResultPesquisa.Where(c => c.bSeleciona).ToList<belPesquisaNotas>();
                    List<belPesquisaNotas> objSelect = objSelecionadas.Where(c =>
                                                                       c.bDenegada == false &&
                                                                       c.bCancelado == false).ToList<belPesquisaNotas>();

                    if (objSelect.Count() == 0)
                    {
                        KryptonMessageBox.Show("Nenhuma nota Válida foi Selecionada", Mensagens.MSG_Aviso, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    if (objSelect.Count == 1)
                    {
                        if (Acesso.tipoWsNfse == Acesso.TP_WS_NFSE.DSF)
                        {
                            belPesquisaNotas objPesquisa = new belPesquisaNotas(objSelect.FirstOrDefault().sRECIBO_NF);
                            bsNotas.DataSource = objPesquisa.lResultPesquisa;
                            belCarregaDadosRPS objCarregarNotasLote = new belCarregaDadosRPS(objPesquisa.lResultPesquisa, objPesquisa.lResultPesquisa.FirstOrDefault().sRECIBO_NF);
                            belEnviarNFSeWS objEnvio = new belEnviarNFSeWS(objCarregarNotasLote);
                            string sNumeroLote = objCarregarNotasLote.objLoteEnvio.cabec.NumeroLote.ToString();
                            KryptonMessageBox.Show(objEnvio.BuscaRetorno(sNumeroLote), Mensagens.MSG_Aviso, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            PesquisaNotas();
                        }
                        else
                        {
                            belPrestador objbelPrestador = new belPrestador();
                            belRecepcao objBelRecepcao = new belRecepcao();
                            objBelRecepcao.Protocolo = objBelRecepcao.BuscaNumProtocolo(objSelect[0].sCD_NFSEQ);

                            objfrmStatus = new frmStatusEnvioNfs();
                            objfrmStatus.Show();
                            objfrmStatus.Refresh();

                            string sMsgErro = objBelRecepcao.BuscaRetorno(objbelPrestador.RettcIdentificacaoPrestador(objSelect[0].sCD_NFSEQ), objfrmStatus.lblMsg, objfrmStatus.progressBarStatus);

                            if (objBelRecepcao.sCodigoRetorno.Equals("E4"))
                            {
                                objfrmStatus.Close();
                                KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine + Environment.NewLine + "IMPORTANTE: Tente Buscar Retorno da NFs-e, pois o serviço do WebService está demorando para responder. ", Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (objBelRecepcao.objListaNfseRetorno.Count > 0)
                            {
                                objfrmStatus.lblMsg.Text = "Alterando Status da Nota...";
                                objfrmStatus.lblMsg.Refresh();
                                objBelRecepcao.AlteraStatusDaNota(objBelRecepcao.objListaNfseRetorno);
                                objfrmStatus.Close();
                                objBelRecepcao.VerificaNotasParaCancelar(objBelRecepcao.objListaNfseRetorno);

                                KryptonMessageBox.Show(null, objBelRecepcao.MontaMsgDeRetornoParaCliente(), Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);
                                //EnviaEmail(objBelRecepcao.objListaNfseRetorno);
                            }
                            else
                            {
                                objBelRecepcao.LimpaRecibo();
                                objfrmStatus.Close();
                                KryptonMessageBox.Show(null, sMsgErro + Environment.NewLine, Mensagens.CHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);

                            }


                            PesquisaNotas();
                            VerificaGeneratorLote();
                        }
                    }
                    else
                    {
                        KryptonMessageBox.Show("Selecione apenas uma Nota para consultar o lote", Mensagens.MSG_Aviso, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        PesquisaNotas();
                    }
                }
            }
            catch (Exception ex)
            {
                if (objfrmStatus != null)
                {
                    objfrmStatus.Close();
                }
                VerificaGeneratorLote();
                new HLPexception(ex);
            }
        }
 public belConsultaStatusCliente(belPesquisaNotas _objPesquisa)
 {
     this.objPesquisa = _objPesquisa;
 }
Esempio n. 18
0
        public void BuscaRetorno()
        {
            try
            {
                XNamespace  pf          = "http://www.portalfiscal.inf.br/nfe";
                XmlDocument xret        = new XmlDocument();
                string      sCodRetorno = string.Empty;
                xret = Exec_Cosulta(lnotas.FirstOrDefault().sRECIBO_NF);

                while (!bStopRetorno)
                {
                    sCodRetorno = "";
                    XmlNodeList  nodeschNFe   = xret.GetElementsByTagName("chNFe");
                    XmlNodeList  nodecStat    = xret.GetElementsByTagName("cStat");
                    XmlNodeList  nodesxMotivo = xret.GetElementsByTagName("xMotivo");
                    DadosRetorno ret          = new DadosRetorno();

                    if (nodecStat[0].InnerText == "105") // Em processamento
                    {
                        int iCount = 0;
                        //while (iCount < 2)
                        //{
                        Thread.Sleep(4000);

                        ret  = new DadosRetorno();
                        xret = Exec_Cosulta(lnotas.FirstOrDefault().sRECIBO_NF);

                        nodeschNFe   = xret.GetElementsByTagName("chNFe");
                        nodecStat    = xret.GetElementsByTagName("cStat");
                        nodesxMotivo = xret.GetElementsByTagName("xMotivo");

                        ret.cStat   = nodecStat[0].InnerText;
                        ret.xMotivo = nodesxMotivo[0].InnerText;

                        if (nodecStat[0].InnerText != "105")
                        {
                            iCount = 2;
                        }
                        iCount++;
                        //}
                        //lDadosRetorno.Add(ret);
                    }
                    if (nodecStat[0].InnerText != "104" && nodecStat[0].InnerText != "656")
                    {
                        ret.cStat    = nodecStat[0].InnerText;
                        ret.xMotivo  = nodesxMotivo[0].InnerText;
                        bStopRetorno = true;
                        LimpaCampoRecibo();
                        lDadosRetorno.Add(ret);
                    }
                    else if (nodecStat[0].InnerText == "656")
                    {
                        ret.cStat    = nodecStat[0].InnerText;
                        ret.xMotivo  = nodesxMotivo[0].InnerText;
                        bStopRetorno = true;
                        lDadosRetorno.Add(ret);
                    }
                    else
                    {
                        int iCountNProt = 0;
                        for (int i = 0; (i < nodeschNFe.Count) && !bStopRetorno; i++)
                        {
                            if (lnotas.Where(c => c.sCHAVENFE == nodeschNFe[i].InnerText).Count() > 0)
                            {
                                belPesquisaNotas nota = lnotas.FirstOrDefault(c => c.sCHAVENFE == nodeschNFe[i].InnerText);
                                ret         = new DadosRetorno();
                                ret.cStat   = nodecStat[i + 1].InnerText;
                                ret.xMotivo = nodesxMotivo[i + 1].InnerText;
                                ret.seqNota = nota.sCD_NFSEQ;
                                ret.nNota   = nota.sCD_NOTAFIS;

                                if (nodecStat[i + 1].InnerText == "100") // 100 - Enviada com sucesso
                                {
                                    SalvaProtocoloNFe(nota.sCD_NFSEQ, nota.sCHAVENFE, xret.GetElementsByTagName("nProt")[iCountNProt].InnerText);
                                    IncluiTagInfProc(nota, xret.GetElementsByTagName("protNFe")[iCountNProt], pf);
                                    xret.Save(Pastas.PROTOCOLOS + "\\" + nota.sRECIBO_NF + "-pro-rec.xml");
                                    iCountNProt++;
                                }
                                else if (nodecStat[i + 1].InnerText == "101") // 101 - Nota Cancelada.
                                {
                                    SalvaProtocoloNFe(nota.sCD_NFSEQ, nota.sCHAVENFE, xret.GetElementsByTagName("nProt")[i].InnerText);
                                    IncluiTagInfProc(nota, xret.GetElementsByTagName("protNFe")[i], pf);
                                    DirectoryInfo dinfo = Util.BuscaDiretorioArquivoXml(nota.sCHAVENFE, 2);
                                    File.Move(Util.BuscaCaminhoArquivoXml(nota.sCHAVENFE, 2), Pastas.CANCELADOS + "\\" + nota.sCHAVENFE + "can.xml");
                                }
                                else if (nodecStat[i + 1].InnerText == "204") // Rejeição: Duplicidade de NF-e
                                {
                                    int    icount = nodesxMotivo[i + 1].InnerText.Count() - (nodesxMotivo[i + 1].InnerText.IndexOf("nRec") + 6);
                                    string sRet   = nodesxMotivo[i + 1].InnerText.Substring((nodesxMotivo[i + 1].InnerText.IndexOf("nRec") + 5), icount);

                                    if (sRet.Count() != 15)
                                    {
                                        AlteraStatusNotaDuplicada(nota.sCD_NFSEQ);
                                        string sPathEnvio    = Util.BuscaCaminhoArquivoXml(nota.sCHAVENFE, 1);
                                        string sPathEnviados = Util.BuscaCaminhoArquivoXml(nota.sCHAVENFE, 2);
                                        if (!File.Exists(sPathEnviados))
                                        {
                                            File.Copy(sPathEnvio, sPathEnviados);
                                        }
                                    }
                                    else
                                    {
                                        SalvaRetornoNotaDuplicada(sRet, nota.sCD_NFSEQ);
                                    }
                                }
                                else if ((nodecStat[i + 1].InnerText == "110") || (nodecStat[i + 1].InnerText == "302") || (nodecStat[i + 1].InnerText == "302"))
                                {
                                    NotaDenegada(nota.sCD_NFSEQ);
                                }
                                else if (nodecStat[i + 1].InnerText != "105") // Lote em processamento
                                {
                                    LimpaCampoRecibo();
                                }
                            }
                            if (ret.cStat != null)
                            {
                                lDadosRetorno.Add(ret);
                            }
                        }
                        bStopRetorno = true;
                        foreach (DadosRetorno nota in lDadosRetorno)
                        {
                            if (nota.cStat.Equals("100"))
                            {
                                AlteraStatusNotaParaEnviada(nota.seqNota);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }