Пример #1
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);
        }
Пример #2
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;
        }