예제 #1
0
 public void Assinar(ref TNfeProc nota)
 {
     if (Certificado == null)
     {
         throw new Exception("O Certificado Digital não está Configurado.");
     }
     nota.NFe = AssinarNFE(nota.NFe, "infNFe");
 }
예제 #2
0
 /// <summary>
 /// Deserializes workflow markup into an TNfeProc object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output TNfeProc object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out TNfeProc obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(TNfeProc);
     try
     {
         obj = Deserialize(xml);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
예제 #3
0
 /// <summary>
 /// Deserializes xml markup from file into an TNfeProc object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output TNfeProc object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out TNfeProc obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(TNfeProc);
     try
     {
         obj = LoadFromFile(fileName, encoding);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
예제 #4
0
 public static bool Deserialize(string xml, out TNfeProc obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }
예제 #5
0
 public void SalvarNFe(ref TNfeProc nota)
 {
     nota.NFe.NomeArquivo = GetFileNameNFe(nota.NFe.infNFe);
     nota.NFe.ArquivoXML  = SaveXml(nota.Serialize(), nota.NFe.NomeArquivo);
 }
예제 #6
0
        private void EnviaMensagemEmailCartaCorrecao(TNfeProc nota, CartaCorrecao.TProcEvento evento, string destinatario, string bcc, string cc, string assunto, string corpo)
        {
            if (string.IsNullOrEmpty(Configuracao.ConfiguracaoMail.SMTPServer))
            {
                throw new Exception("É necessário preencher a propriedade ConfiguracaoEmail para enviar email");
                //return;
            }

            var mMailMessage = new MailMessage {
                From = new MailAddress(Configuracao.ConfiguracaoMail.Remetente)
            };

            var arrDestinatarios = destinatario.Split(';');

            foreach (var email in arrDestinatarios.Where(email => !String.IsNullOrEmpty(email)))
            {
                mMailMessage.To.Add(new MailAddress(email.Trim()));
            }

            if ((bcc != null) & bcc != string.Empty)
            {
                mMailMessage.Bcc.Add(new MailAddress(bcc));
            }

            if ((cc != null) & cc != string.Empty)
            {
                mMailMessage.CC.Add(new MailAddress(cc));
            }

            mMailMessage.Subject    = assunto;
            mMailMessage.Body       = corpo;
            mMailMessage.IsBodyHtml = Configuracao.ConfiguracaoMail.CorpoHtml;
            mMailMessage.Priority   = MailPriority.Normal;

            var servidorSMTP = Configuracao.ConfiguracaoMail.SMTPServer;
            var mSmtpClient  = new SmtpClient(servidorSMTP)
            {
                Port      = Configuracao.ConfiguracaoMail.Port,
                EnableSsl = Configuracao.ConfiguracaoMail.HabilitaSSL
            };

            //Configurar a conta de envio
            var usuario = Configuracao.ConfiguracaoMail.Usuario;
            var senha   = Configuracao.ConfiguracaoMail.Senha;

            mSmtpClient.Credentials = new System.Net.NetworkCredential(usuario, senha);
            //mSmtpClient.UseDefaultCredentials = True
            mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

            //Anexa o XML
            var anexo = new Attachment(evento.NomeArquivo);

            mMailMessage.Attachments.Add(anexo);

            //Anexa o PDF
            var arquivoPDF = NfeConvert.ToPDFCartaCorrecao(nota, evento, Configuracao);
            var anexoPDF   = new Attachment(arquivoPDF);

            mMailMessage.Attachments.Add(anexoPDF);

            //Enviar email
            try
            {
                mSmtpClient.Send(mMailMessage);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao enviar o email do evento: " + evento.retEvento.infEvento.chNFe + " para: " + destinatario + ". Motivo: " + ex.Message);
            }

            //File.Delete(arquivoPDF);
        }
 public static bool Deserialize(string xml, out TNfeProc obj)
 {
     System.Exception exception = null;
     return Deserialize(xml, out obj, out exception);
 }
예제 #8
0
 public void SalvarNFe(ref TNfeProc nota)
 {
     nota.NFe.NomeArquivo = GetFileNameNFe(nota.NFe.infNFe);
     nota.NFe.ArquivoXML = SaveXml(nota.Serialize(), nota.NFe.NomeArquivo);
 }
예제 #9
0
        public Cancelamento.TRetEnvEvento CancelaNFe(TNfeProc nota, string Justificativa, X509Certificate2 pCertificado, int numLote, int nSequencia, TAmb ambiente, out ACBr.Net.NFe.Cancelamento.TProcEvento procEvento)
        {
            XmlElement strRetorno = null;

            string arqPedCanc = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-ped-evento.xml";
            string retPedCanc = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-eve.xml";
            C_WebService.ListaUrl listaURL = default(C_WebService.ListaUrl);
            listaURL = WsUrls.BuscaURL(nota.NFe.infNFe.ide.cUF, ambiente);

            #region evento
            Cancelamento.TEvento evento = new Cancelamento.TEvento();
            evento.versao = "1.00";

            #region infEvento
            Cancelamento.TEventoInfEvento infEvento = new Cancelamento.TEventoInfEvento();
            infEvento.tpAmb = ambiente;
            infEvento.chNFe = nota.NFe.infNFe.Id.Substring(3);
            infEvento.cOrgao = nota.NFe.infNFe.ide.cUF;
            infEvento.dhEvento = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzzz");// +"-00:00";
            infEvento.Id = "ID" + "110111" + nota.NFe.infNFe.Id.Substring(3) + nSequencia.ToString("D2");
            infEvento.ItemElementName = Cancelamento.TipoDocumentoCanc.CNPJ;
            infEvento.Item = nota.NFe.infNFe.emit.Item;
            infEvento.nSeqEvento = nSequencia.ToString();
            infEvento.verEvento = Cancelamento.TEventoInfEventoVerEvento.Item100;
            infEvento.tpEvento = Cancelamento.TEventoInfEventoTpEvento.Cancelamento;

            #region detEvento
            Cancelamento.TEventoInfEventoDetEvento detEvento = new Cancelamento.TEventoInfEventoDetEvento();
            detEvento.descEvento = Cancelamento.TEventoInfEventoDetEventoDescEvento.Cancelamento;
            detEvento.nProt = nota.protNFe.infProt.nProt;
            detEvento.versao = Cancelamento.TEventoInfEventoDetEventoVersao.Item100;
            detEvento.xJust = Justificativa;
            #endregion detEvento

            infEvento.detEvento = detEvento;
            #endregion infEvento

            evento.infEvento = infEvento;

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(Funcoes.RemoveNameSpaceFromXml(evento.Serialize()));
            xmldoc = CertificadoDigital.Assinar(xmldoc, "infEvento", pCertificado);
            xmldoc.Save(arqPedCanc);

            #endregion evento

            dynamic envEvento = GeraLoteEvento(arqPedCanc, numLote);

            try
            {
                RecepcaoEvento.nfeCabecMsg cab = new RecepcaoEvento.nfeCabecMsg();
                RecepcaoEvento.RecepcaoEvento wsMsg = default(RecepcaoEvento.RecepcaoEvento);

                // UF E VERSÃO DO CABEÇALHO
                cab.cUF = PegarCodigoUF(nota.NFe.infNFe.ide.cUF);
                cab.versaoDados = "1.00";

                //CABEÇALHO USADA PARA ENVIO DE LOTE
                wsMsg = new RecepcaoEvento.RecepcaoEvento(listaURL.UrlRecepcaoEvento);
                wsMsg.nfeCabecMsgValue = cab;
                wsMsg.Timeout = 100000;
                wsMsg.ClientCertificates.Add(pCertificado);
                wsMsg.SoapVersion = SoapProtocolVersion.Soap12;

                //RETORNO DA SEFAZ
                strRetorno = wsMsg.nfeRecepcaoEvento(envEvento);

                XmlDocument xmlRetorno = new XmlDocument();
                xmlRetorno.LoadXml(strRetorno.OuterXml);
                xmlRetorno.Save(retPedCanc);

                ACBr.Net.NFe.Cancelamento.TRetEnvEvento retCancNFe = ACBr.Net.NFe.Cancelamento.TRetEnvEvento.LoadFromFile(retPedCanc);

                //saída
                procEvento = new Cancelamento.TProcEvento();
                procEvento.evento = ACBr.Net.NFe.Cancelamento.TEvento.Deserialize(xmldoc.OuterXml);
                procEvento.retEvento = retCancNFe.retEvento[0];
                procEvento.versao = "1.00";

                return retCancNFe;
            }
            catch (Exception ex)
            {
                throw new System.InvalidOperationException("Erro ao cancelar NFe. Erro: " + ex.Message);
            }
        }
예제 #10
0
        private void EnviaMensagemEmailCartaCorrecao(TNfeProc nota, CartaCorrecao.TProcEvento evento, string destinatario, string bcc, string cc, string assunto, string corpo)
        {
            if (string.IsNullOrEmpty(Configuracao.ConfiguracaoMail.SMTPServer))
            {
                throw new Exception("É necessário preencher a propriedade ConfiguracaoEmail para enviar email");
                //return;
            }

            var mMailMessage = new MailMessage { From = new MailAddress(Configuracao.ConfiguracaoMail.Remetente) };

            var arrDestinatarios = destinatario.Split(';');

            foreach (var email in arrDestinatarios.Where(email => !String.IsNullOrEmpty(email)))
            {
                mMailMessage.To.Add(new MailAddress(email.Trim()));
            }

            if ((bcc != null) & bcc != string.Empty)
            {
                mMailMessage.Bcc.Add(new MailAddress(bcc));
            }

            if ((cc != null) & cc != string.Empty)
            {
                mMailMessage.CC.Add(new MailAddress(cc));
            }

            mMailMessage.Subject = assunto;
            mMailMessage.Body = corpo;
            mMailMessage.IsBodyHtml = Configuracao.ConfiguracaoMail.CorpoHtml;
            mMailMessage.Priority = MailPriority.Normal;

            var servidorSMTP = Configuracao.ConfiguracaoMail.SMTPServer;
            var mSmtpClient = new SmtpClient(servidorSMTP)
            {
                Port = Configuracao.ConfiguracaoMail.Port,
                EnableSsl = Configuracao.ConfiguracaoMail.HabilitaSSL
            };

            //Configurar a conta de envio
            var usuario = Configuracao.ConfiguracaoMail.Usuario;
            var senha = Configuracao.ConfiguracaoMail.Senha;
            mSmtpClient.Credentials = new System.Net.NetworkCredential(usuario, senha);
            //mSmtpClient.UseDefaultCredentials = True
            mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnSuccess;

            //Anexa o XML
            var anexo = new Attachment(evento.NomeArquivo);
            mMailMessage.Attachments.Add(anexo);

            //Anexa o PDF
            var arquivoPDF = NfeConvert.ToPDFCartaCorrecao(nota, evento, Configuracao);
            var anexoPDF = new Attachment(arquivoPDF);
            mMailMessage.Attachments.Add(anexoPDF);

            //Enviar email
            try
            {
                mSmtpClient.Send(mMailMessage);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao enviar o email do evento: " + evento.retEvento.infEvento.chNFe + " para: " + destinatario + ". Motivo: " + ex.Message);
            }

            //File.Delete(arquivoPDF);
        }
예제 #11
0
 public void Assinar(ref TNfeProc nota)
 {
     if (Certificado == null)
     {
         throw new Exception("O Certificado Digital não está Configurado.");
     }
     nota.NFe = AssinarNFE(nota.NFe, "infNFe");
 }
 public static bool LoadFromFile(string fileName, out TNfeProc obj)
 {
     System.Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 public static bool LoadFromFile(string fileName, out TNfeProc obj, out System.Exception exception)
 {
     return LoadFromFile(fileName, Encoding.UTF8, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an TNfeProc object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output TNfeProc object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out TNfeProc obj, out System.Exception exception)
 {
     exception = null;
     obj = default(TNfeProc);
     try
     {
         obj = LoadFromFile(fileName, encoding);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }
예제 #15
0
 public static bool LoadFromFile(string fileName, out TNfeProc obj, out System.Exception exception)
 {
     return(LoadFromFile(fileName, Encoding.UTF8, out obj, out exception));
 }
예제 #16
0
        public CartaCorrecao.TRetEnvEvento CartaCorrecao(TNfeProc nota, string Correcao, X509Certificate2 pCertificado, int numLote, int nSequencia, TAmb ambiente, out ACBr.Net.NFe.CartaCorrecao.TProcEvento procEvento)
        {
            string arqPedCorecao = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-ped-evento.xml";//-ped-cce.xml ???
            string retPedCorrecao = _PastaLog + nota.NFe.infNFe.Id.Substring(3) + "-eve.xml";
            C_WebService.ListaUrl listaURL = default(C_WebService.ListaUrl);
            listaURL = WsUrls.BuscaURL(nota.NFe.infNFe.ide.cUF, ambiente);

            #region evento
            CartaCorrecao.TEvento evento = new CartaCorrecao.TEvento();
            evento.versao = "1.00";

            #region infEvento
            CartaCorrecao.TEventoInfEvento infEvento = new CartaCorrecao.TEventoInfEvento();
            infEvento.tpAmb = ambiente;
            infEvento.chNFe = nota.NFe.infNFe.Id.Substring(3);
            infEvento.cOrgao = PegarCodigoOrgaoUF(nota.NFe.infNFe.ide.cUF);
            infEvento.dhEvento = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzzz");
            infEvento.Id = "ID" + "110110" + nota.NFe.infNFe.Id.Substring(3) + nSequencia.ToString("D2");
            infEvento.ItemElementName = ACBr.Net.NFe.CartaCorrecao.ItemChoiceTypeCC.CNPJ;
            infEvento.Item = nota.NFe.infNFe.emit.Item;
            infEvento.nSeqEvento = nSequencia.ToString();
            infEvento.verEvento = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoVerEvento.Item100;
            infEvento.tpEvento = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoTpEvento.Item110110;

            #region detEvento
            CartaCorrecao.TEventoInfEventoDetEvento detEvento = new CartaCorrecao.TEventoInfEventoDetEvento();
            detEvento.descEvento = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoDetEventoDescEvento.CartadeCorrecao;
            detEvento.versao = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoDetEventoVersao.Item100;
            detEvento.xCondUso = ACBr.Net.NFe.CartaCorrecao.TEventoInfEventoDetEventoXCondUso.ACartadeCorrecaoedisciplinadapeloparagrafo1oAdoart7odoConvenioSNde15dedezembrode1970epodeserutilizadapararegularizacaodeerroocorridonaemissaodedocumentofiscaldesdequeoerronaoestejarelacionadocomIasvariaveisquedeterminamovalordoimpostotaiscomobasedecalculoaliquotadiferencadeprecoquantidadevalordaoperacaooudaprestacaoIIacorrecaodedadoscadastraisqueimpliquemudancadoremetenteoudodestinatarioIIIadatadeemissaooudesaida;
            detEvento.xCorrecao = Correcao;
            #endregion detEvento

            infEvento.detEvento = detEvento;
            #endregion infEvento

            evento.infEvento = infEvento;

            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(Funcoes.RemoveNameSpaceFromXml(evento.Serialize()));
            xmldoc = CertificadoDigital.Assinar(xmldoc, "infEvento", pCertificado);
            xmldoc.Save(arqPedCorecao);

            #endregion evento

            dynamic envEvento = GeraLoteEvento(arqPedCorecao, numLote);

            try
            {
                RecepcaoEvento.nfeCabecMsg cab = new RecepcaoEvento.nfeCabecMsg();
                RecepcaoEvento.RecepcaoEvento wsMsg = default(RecepcaoEvento.RecepcaoEvento);

                // UF E VERSÃO DO CABEÇALHO
                cab.cUF = PegarCodigoUF(nota.NFe.infNFe.ide.cUF);
                cab.versaoDados = "1.00";

                //CABEÇALHO USADA PARA ENVIO DE LOTE
                wsMsg = new RecepcaoEvento.RecepcaoEvento(listaURL.UrlRecepcaoEvento);
                wsMsg.nfeCabecMsgValue = cab;
                wsMsg.Timeout = 100000;
                wsMsg.ClientCertificates.Add(pCertificado);
                wsMsg.SoapVersion = SoapProtocolVersion.Soap12;

                //RETORNO DA SEFAZ
                XmlElement strRetorno = wsMsg.nfeRecepcaoEvento(envEvento);
                XmlDocument xmlRetorno = new XmlDocument();
                xmlRetorno.LoadXml(strRetorno.OuterXml);
                xmlRetorno.Save(retPedCorrecao);

                ACBr.Net.NFe.CartaCorrecao.TRetEnvEvento retCorrecaoNFe = ACBr.Net.NFe.CartaCorrecao.TRetEnvEvento.LoadFromFile(retPedCorrecao);

                //saída
                procEvento = new CartaCorrecao.TProcEvento();
                procEvento.evento = ACBr.Net.NFe.CartaCorrecao.TEvento.Deserialize(xmldoc.OuterXml);
                procEvento.retEvento = retCorrecaoNFe.retEvento[0];
                procEvento.versao = "1.00";

                return retCorrecaoNFe;
            }
            catch (Exception ex)
            {
                throw new System.InvalidOperationException("Erro ao corrigir NFe. Erro: " + ex.Message);
            }
        }
예제 #17
0
 public static bool LoadFromFile(string fileName, out TNfeProc obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
 /// <summary>
 /// Deserializes workflow markup into an TNfeProc object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output TNfeProc object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out TNfeProc obj, out System.Exception exception)
 {
     exception = null;
     obj = default(TNfeProc);
     try
     {
         obj = Deserialize(xml);
         return true;
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return false;
     }
 }