コード例 #1
0
        private XmlDocument CriarLoteEAssinar(NFe nf, string idLote, bool NFCe = false)
        {
            XmlDocument lote, xmlNFe;
            EnviNFe     enviNFe = new EnviNFe();

            enviNFe.Versao  = nf.InfNFe.Versao;
            enviNFe.IndSinc = "0";

            enviNFe.IdLote = idLote;

            lote = enviNFe.ToXmlDocument();
            if (!AssinaturaDigital.Assinar(nf.ToXmlString(), "infNFe", Certificado.X509Certificado))
            {
                throw new Exception(AssinaturaDigital.Erro);
            }

            xmlNFe = AssinaturaDigital.XMLDoc;

            if (NFCe)
            {
                AdicionarQRCode(GerarQRCode(xmlNFe), WebServiceNFCe.EnderecoQRCode, xmlNFe);
            }

            XmlNode node = lote.ImportNode(xmlNFe.DocumentElement, true);

            lote.DocumentElement.AppendChild(node);
            lote.PreserveWhitespace   = true;
            xmlNFe.PreserveWhitespace = true;

            lote.Save(ObterCaminhoArquivo($"{enviNFe.IdLote}{SufixoLote}.xml"));
            xmlNFe.Save(ObterCaminhoArquivo($"{nf.InfNFe.Id.Substring(3)}{SufixoNFe}.xml"));

            return(lote);
        }