Пример #1
0
        public TRetEvento GerarXmlCancelamento(belCancelaCte objCancelaCte)
        {
            try
            {
                //Serialização Cancelamento
                XNamespace pf = "http://www.portalfiscal.inf.br/cte";


                XContainer envCTe = new XElement(pf + "evCancCTe",
                     new XElement(pf + "descEvento", "Cancelamento"),
                     new XElement(pf + "nProt", objCancelaCte.nProt),
                     new XElement(pf + "xJust", objCancelaCte.xJust));


                XmlDocument xmlCanc = new XmlDocument();
                xmlCanc.LoadXml(envCTe.ToString());

                // Serialização Evento
                string sVersao = Acesso.versaoCTe; // "1.00";

                TEvento evento = new TEvento();
                evento.versao = sVersao;
                evento.infEvento = new TEventoInfEvento();
                evento.infEvento.tpEvento = "110111";
                evento.infEvento.nSeqEvento = "1"; // numero de evento
                evento.infEvento.Id = "ID" + evento.infEvento.tpEvento + objCancelaCte.chCTe + evento.infEvento.nSeqEvento.PadLeft(2, '0');
                evento.infEvento.cOrgao = Convert.ToByte(Acesso.cUF);
                evento.infEvento.tpAmb = Acesso.TP_AMB == 1 ? TAmb.Item1 : TAmb.Item2;
                evento.infEvento.CNPJ = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
                evento.infEvento.chCTe = objCancelaCte.chCTe;
                evento.infEvento.dhEvento = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss");
                evento.infEvento.detEvento = new TEventoInfEventoDetEvento();
                evento.infEvento.detEvento.versaoEvento = sVersao;
                evento.infEvento.detEvento.Any = (System.Xml.XmlElement)xmlCanc.DocumentElement;

                string sEvento = "";

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


                //SerializeClassToXml.SerializeClasse(TEvento,)



                XmlSerializer xs = new XmlSerializer(typeof(TEvento));
                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_CTe);

                //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(sEvento);
                string sPath = Pastas.PROTOCOLOS + "\\" + objCancelaCte.chCTe + "_ped-can.xml";
                if (File.Exists(sPath))
                {
                    File.Delete(sPath);
                }
                xDoc.Save(sPath);
                try
                {
                    belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/cte", Pastas.SCHEMA_CTE + "\\eventoCTe_v2.00.xsd", sPath);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                #region Cancelar Cte


                XmlDocument doc = new XmlDocument();
                doc.Load(sPath);

                string sRetorno = CancelarCte(doc);

                XDocument xRet = XDocument.Parse(sRetorno);
                xRet.Save(sPath);
                HLP.GeraXml.bel.CTe.Evento.TRetEvento retorno = SerializeClassToXml.DeserializeClasse<HLP.GeraXml.bel.CTe.Evento.TRetEvento>(sPath);

                //List<belStatusCte> ListaStatus = TrataDadosRetorno(sRetorno);

                //foreach (belStatusCte cte in ListaStatus)
                //{
                if (retorno.infEvento.cStat != "135")
                {
                    File.Delete(sPath);
                }
                //}

                #endregion

                return retorno;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        private void CarregaItensEventoCartaCorrecao(belPesquisaCCe objbelPesquisa)
        {
            try
            {
                if (Acesso.NM_RAMO != Acesso.BancoDados.TRANSPORTE)
                {
                    objEnvEvento = new belEnvEvento();
                    objEnvEvento.versao = this._VERSAO;
                    objEnvEvento.id = objbelPesquisa.CD_NRLANC;
                    belEvento objEvento = new belEvento();
                    objEvento.versao = _VERSAO;
                    objEvento.infEvento = new _infEvento();
                    objEvento.infEvento.CNPJ = objbelPesquisa.CNPJ;
                    objEvento.infEvento.CPF = objbelPesquisa.CPF;
                    objEvento.infEvento.dhEvento = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss" + Acesso.FUSO);
                    objEvento.infEvento.verEvento = _VERSAO;
                    objEvento.infEvento.tpAmb = Acesso.TP_AMB;
                    objEvento.infEvento.chNFe = objbelPesquisa.CHNFE;
                    objEvento.infEvento.cOrgao = Acesso.cUF.ToString();
                    objEvento.infEvento.detEvento = new _detEvento
                    {
                        versao = _VERSAO
                    };
                    objEvento.infEvento.detEvento.xCorrecao = BuscaCorrecoes(objbelPesquisa.CD_NRLANC);
                    objEvento.infEvento.nSeqEvento = objbelPesquisa.QT_ENVIO + 1;
                    objEvento.idLote = "ID" + objEvento.infEvento.tpEvento + objEvento.infEvento.chNFe + objEvento.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    objEnvEvento.evento.Add(objEvento);
                }
                else
                {

                    objEvCCeCTe = new TEvento();

                    objEvCCeCTe.versao = Acesso.versaoCTe;
                    objEvCCeCTe.infEvento = new  TEventoInfEvento();
                    objEvCCeCTe.infEvento.tpEvento = "110110";
                    objEvCCeCTe.infEvento.nSeqEvento = (objbelPesquisa.QT_ENVIO + 1).ToString();// numero de evento
                    objEvCCeCTe.infEvento.Id = "ID" + objEvCCeCTe.infEvento.tpEvento + objlItensPesquisa.FirstOrDefault().CHNFE + objEvCCeCTe.infEvento.nSeqEvento.ToString().PadLeft(2, '0');
                    //objEvCCeCTe.infEvento.Id = "ID" + objlItensPesquisa.FirstOrDefault().CHNFE;                   
                    objEvCCeCTe.infEvento.cOrgao = Convert.ToByte(Acesso.cUF);
                    objEvCCeCTe.infEvento.tpAmb = Acesso.TP_AMB == 1 ? TAmb.Item1 : TAmb.Item2;
                    objEvCCeCTe.infEvento.CNPJ = Util.RetiraCaracterCNPJ(Acesso.CNPJ_EMPRESA);
                    objEvCCeCTe.infEvento.chCTe = objbelPesquisa.CHNFE;
                    objEvCCeCTe.infEvento.dhEvento = daoUtil.GetDateServidor().ToString("yyyy-MM-ddTHH:mm:ss");
                    objEvCCeCTe.infEvento.detEvento = new TEventoInfEventoDetEvento();
                    objEvCCeCTe.infEvento.detEvento.versaoEvento = Acesso.versaoCTe;

                    evCCeCTe objEvCanc = new evCCeCTe();
                    objEvCanc.descEvento = evCCeCTeDescEvento.CartadeCorrecao;
                    objEvCanc.infCorrecao = new List<evCCeCTeInfCorrecao>();
                    objEvCanc.CD_NRLANC = objbelPesquisa.CD_NRLANC;
                    foreach (DataRow item in BuscaCorrecoesCTe(objbelPesquisa.CD_NRLANC).Rows)
                    {
                        objEvCanc.infCorrecao.Add(new evCCeCTeInfCorrecao
                        {
                            grupoAlterado = item["grupoAlterado"].ToString(),
                            campoAlterado = item["campoAlterado"].ToString(),
                            valorAlterado = item["valorAlterado"].ToString(),
                            nroItemAlterado = item["nroItemAlterado"].ToString(),
                        });
                    }
                    objEvCanc.xCondUso = evCCeCTeXCondUso.ACartadeCorreçãoédisciplinadapeloArt58BdoCONVÊNIOSINIEF0689FicapermitidaautilizaçãodecartadecorreçãopararegularizaçãodeerroocorridonaemissãodedocumentosfiscaisrelativosàprestaçãodeserviçodetransportedesdequeoerronãoestejarelacionadocomIasvariáveisquedeterminamovalordoimpostotaiscomobasedecálculoalíquotadiferençadepreçoquantidadevalordaprestaçãoIIacorreçãodedadoscadastraisqueimpliquemudançadoemitentetomadorremetenteoudodestinatárioIIIadatadeemissãooudesaída;
                    string xFile = Pastas.CCe + "\\" + objEvCanc.CD_NRLANC + "_prevalida.xml";
                    SerializeClassToXml.SerializeClasse<evCCeCTe>(objEvCanc, xFile);
                    XmlDocument xml = new XmlDocument();
                    xml.Load(xFile);
                    objEvCCeCTe.infEvento.detEvento.Any = (System.Xml.XmlElement)xml.DocumentElement;


                    XmlSerializer xs = new XmlSerializer(typeof(TEvento));
                    MemoryStream memory = new MemoryStream();
                    XmlTextWriter xmltext = new XmlTextWriter(memory, Encoding.UTF8);
                    xs.Serialize(xmltext, objEvCCeCTe);
                    UTF8Encoding encoding = new UTF8Encoding();
                    this.sXMLfinal = encoding.GetString(memory.ToArray());
                    this.sXMLfinal = this.sXMLfinal.Substring(1);

                    belAssinaXml Assinatura = new belAssinaXml();
                    this.sXMLfinal = Assinatura.ConfigurarArquivo(this.sXMLfinal, "infEvento", Acesso.cert_CTe);

                    xml = new XmlDocument();
                    xml.LoadXml(this.sXMLfinal);
                    string sPath = Pastas.PROTOCOLOS + "\\" + objbelPesquisa.CHNFE + "_ped-cce.xml";
                    if (File.Exists(sPath))
                    {
                        File.Delete(sPath);
                    }
                    xml.Save(sPath);
                    try
                    {
                        belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/cte", Pastas.SCHEMA_CTE + "\\eventoCTe_v2.00.xsd", sPath);
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }