public void EditarDanfe()
        {
            var arq_ret   = new StringBuilder();
            var objReader = new StreamReader(SpdNFeX.DiretorioXmlDestinatario + Nota.ChaveNota + "-nfe.xml");
            var sLine     = String.Empty;

            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                {
                    arq_ret.Append(sLine);
                }
            }
            objReader.Close();

            if (Nota.Empresa.ComponenteDfe == 0)
            {
                SpdNFeX.EditarModeloDanfe("0000001", arq_ret.ToString(), "");
            }
            else
            {
                NFeFacade facade = new NFeFacade();
                facade.EditarDanfe(arq_ret.ToString());
            }
        }
 //Falta Implementar Zeus
 public void ImprimirDANFE(Dictionary <string, string> pDictChaveXmlNotas)
 {
     foreach (string chave in pDictChaveXmlNotas.Keys)
     {
         SpdNFeX.ImprimirDanfe("1", pDictChaveXmlNotas[chave], "", GetDefaultPrinter());
     }
 }
        //Falta Implementar Zeus
        public string ImprimirEpec()
        {
            string aXmlNota     = Nota.XmlLogEnvNFe;
            string dataHoraEpec = PegaDataHoraEPEC();

            return(SpdNFeX.ImprimirEPEC(aXmlNota, Nota.NumeroProtocolo, dataHoraEpec, "Templates\\vm50a\\Danfe\\Retrato.rtm", GetDefaultPrinter()));
        }
        public override IDictionary <string, string> CancelarNFe(string _motivo, string _usuario)
        {
            string aXmlNota = SpdNFeX.CancelarNF(Nota.ChaveNota, Nota.NumeroProtocolo, _motivo);

            if (aXmlNota == null || aXmlNota == "")
            {
                throw new SemRespostaDoServidorException(null);
            }

            XDocument documentoXml = XDocument.Load(new StreamReader(new MemoryStream(ASCIIEncoding.UTF8.GetBytes(aXmlNota))));

            XElement nohInfCanc = (from c in documentoXml.Root.Elements() where c.Name.LocalName == "infCanc" select c).Single();
            string   valorCStat = (from c in nohInfCanc.Elements() where c.Name.LocalName == "cStat" select c.Value).Single();

            if (valorCStat == "101" || valorCStat == "218")
            {
                Nota.CancDt            = DateTime.Today;
                Nota.CancMotivo        = _motivo;
                Nota.CancUsuario       = _usuario;
                Nota.UltimoXmlRecebido = aXmlNota;

                Nota.Status = "3";
            }
            else
            {
                throw new NFeException(aXmlNota.DesmembrarXml(), "Houve erro no cancelamento da nota.");
            }

            return(documentoXml.DesmembrarXml());
        }
        //Falta Implementar ZEUS
        public void ExportarEPEC()
        {
            string aXmlNota     = Nota.XmlLogEnvNFe;
            string dataHoraEpec = PegaDataHoraEPEC();

            SpdNFeX.ExportarEPEC(aXmlNota, Nota.NumeroProtocolo, dataHoraEpec, "", 1, DiretorioPadrao + "\\pdf\\" + Nota.ChaveNota + ".pdf");
        }
        //Falta Implementar ZEUS
        public void VisualizarEPEC()
        {
            string aXmlNota     = Nota.XmlLogEnvNFe;
            string dataHoraEpec = PegaDataHoraEPEC();

            SpdNFeX.VisualizarEPEC(aXmlNota, Nota.NumeroProtocolo, dataHoraEpec, "Templates\\vm50a\\Danfe\\Retrato.rtm");
            ExportarEPEC();
        }
        public void EnviarDanfeEmail(string _emailDestinatario, string _assunto, string _mensagem)
        {
            if (Nota.Empresa.ComponenteDfe == 0) //0 = Tecnospeed / 1 = Zeus Automação
            {
                string arquivo = "";

                SpdNFeX.EmailServidor     = Empresa.ServidorSMTP;
                SpdNFeX.EmailPorta        = Empresa.PortaSMTP;
                SpdNFeX.EmailRemetente    = Empresa.EmailUsuario;
                SpdNFeX.EmailUsuario      = Empresa.EmailUsuario;
                SpdNFeX.EmailSenha        = Empresa.EmailSenha;
                SpdNFeX.EmailDestinatario = _emailDestinatario;
                SpdNFeX.EmailAssunto      = _assunto;
                SpdNFeX.EmailMensagem     = _mensagem;

                if (Empresa.GMailAutenticacao)
                {
                    SpdNFeX.EmailAutenticacao = Empresa.GMailAutenticacao;
                }

                try
                {
                    arquivo = SpdNFeX.EnviarNotaDestinatario(Nota.ChaveNota, DiretorioPadrao + "\\LOG\\" + Nota.LogEnvio, DiretorioPadrao + "\\LOG\\" + Nota.LogRecibo);
                }
                catch
                {
                    arquivo = SpdNFeX.EnviarNotaDestinatario(Nota.ChaveNota, DiretorioPadrao + "\\LogHom\\" + Nota.LogEnvio, DiretorioPadrao + "\\LogHom\\" + Nota.LogRecibo);
                }
            }
            else
            {
                NFe.Utils.Email.ConfiguracaoEmail ConfigEmail = new NFe.Utils.Email.ConfiguracaoEmail(
                    Empresa.EmailUsuario,
                    Empresa.EmailSenha,
                    _assunto,
                    _mensagem,
                    Empresa.ServidorSMTP,
                    Empresa.PortaSMTP,
                    false,
                    true);
                // Nome da Empresa
                ConfigEmail.Nome = Empresa.Fantasia;

                if (Empresa.GMailAutenticacao)
                {
                    ConfigEmail.Ssl = true;
                }

                var emailBuilder = new EmailBuilder(ConfigEmail)
                                   .AdicionarDestinatario(_emailDestinatario)
                                   .AdicionarAnexo(DiretorioXML + "\\" + Nota.ChaveNota + "-nfe.xml")
                                   .AdicionarAnexo(DiretorioPadrao + "\\pdf\\" + Nota.ChaveNota + "-nfe.pdf");

                //emailBuilder.ErroAoEnviarEmail += erro => MessageBox.Show(erro.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);

                emailBuilder.Enviar();
            }
        }
        public override IDictionary <string, string> GerarNFe()
        {
            IDictionary <string, string> retorno = new Dictionary <string, string>();
            string aXmlNota = "";

            Nota.Status = "-1";

            if ((retorno = ValidaDadosNFe()).Count > 0)
            {
                throw new Exception("Nota não é validada");
            }

            aXmlNota = SpdNFeX.StatusDoServico();
            if ((retorno = VerificaStatusServico(aXmlNota)) != null)
            {
                throw new ServidorOfflineException(null, "O servidor do serviço está offline.");
            }

            this.SpdNFeDataSetX.DicionarioXML = @"Templates\vm30\Conversor\NFeDataSets.xml";
            this.SpdNFeDataSetX.Incluir();

            this.DadosNFe();
            this.DadosEmitente();
            this.DadosDestinatario();

            int seq = 0;

            foreach (INotaItem objNotaItem in Nota.NotaItems)
            {
                seq += 1;
                this.SpdNFeDataSetX.IncluirItem();
                this.DadosItem(objNotaItem);
                this.SpdNFeDataSetX.SalvarItem();
            }

            DadosCobranca();
            DadosTotalizadores();
            DadosTransporte();

            SpdNFeDataSetX.Salvar();

            aXmlNota       = SpdNFeDataSetX.LoteNFe;
            Nota.ChaveNota = aXmlNota.Substring(aXmlNota.IndexOf("infNFe Id") + 14, 44);

            aXmlNota = SpdNFeX.AssinarNota(aXmlNota);

            aXmlNota = SpdNFeX.EnviarNF(Nota.Numero.ToString(), aXmlNota, false);
            string envioDaNota = aXmlNota;

            Nota.NumeroRecibo = TrataRetornoEnvioNumeroRecibo(aXmlNota);
            Nota.LogEnvio     = FormataUltimoLog(1, SpdNFeX.UltimoLogEnvio);

            return(envioDaNota.DesmembrarXml());
        }
 public void ExportarDanfe(string pXmlNota, string pChaveNota)
 {
     if (Nota.Empresa.ComponenteDfe == 0)
     {
         SpdNFeX.ExportarDanfe("1", pXmlNota, "", 1, DiretorioPadrao + "\\pdf\\" + pChaveNota + ".pdf");
     }
     else
     {
         NFeFacade facade = new NFeFacade();
         facade.ExportarDanfe(pXmlNota, DiretorioPadrao + "\\pdf\\" + pChaveNota + ".pdf");
     }
 }
        public override IDictionary <string, string> ConsultarRecibo()
        {
            List <string> retorno  = new List <string>();
            string        aXmlNota = "";

            aXmlNota = SpdNFeX.ConsultarRecibo(Nota.NumeroRecibo);

            if (aXmlNota == null || aXmlNota == "")
            {
                throw new SemRespostaDoServidorException(null, "Não houve resposta do servidor no recebimento do recibo.");
            }
            return(AtribuiRetornoRecibo(aXmlNota));
        }
        public override IDictionary <string, string> ConsultarNFe()
        {
            List <string> retorno  = new List <string>();
            string        aXmlNota = "";

            aXmlNota = SpdNFeX.ConsultarNF(Nota.ChaveNota);

            if (aXmlNota == null || aXmlNota == "")
            {
                throw new SemRespostaDoServidorException(null, "Não houve resposta do servidor na requisição de consulta.");
            }
            Nota.UltimoXmlRecebido = aXmlNota;
            return(aXmlNota.DesmembrarXml());
        }
        public override string InutilizarNFe(string _ano, string _serie, string _numeroInicio, string _numeroFim, string _justificativa, string _cnpj = null)
        {
            List <string> retorno  = new List <string>();
            string        aXmlNota = "";

            aXmlNota = SpdNFeX.InutilizarNF("", _ano, Funcoes.LimpaStr(Empresa.Cnpj), "55", _serie, _numeroInicio, _numeroFim, _justificativa);

            XDocument documentoXml = XDocument.Load(new StreamReader(new MemoryStream(ASCIIEncoding.UTF8.GetBytes(aXmlNota))));
            var       noh          = (from c in documentoXml.Root.Elements() where c.Name.LocalName == "infInut" select c).Single <XElement>();

            string valorRetorno = (from c in noh.Elements() where c.Name.LocalName == "cStat" select c).Single <XElement>().Value;

            if (valorRetorno == "102")
            {
                return("");
            }
            else
            {
                string motivoErro = (from c in noh.Elements() where c.Name.LocalName == "xMotivo" select c).Single <XElement>().Value;
                return(motivoErro);
            }
        }
        public void VisualizarDANFE()
        {
            if (Nota.Empresa.ComponenteDfe == 0)
            {
                string aXmlNota = Funcoes.AbrirArquivo(SpdNFeX.DiretorioXmlDestinatario + Nota.ChaveNota + "-nfe.xml");
                SpdNFeX.VisualizarDanfe("0000", aXmlNota, "Templates\\vm50a\\Danfe\\Retrato.rtm");
                ExportarDanfe(aXmlNota, Nota.ChaveNota);
            }
            else
            {
                NFeFacade facade = new NFeFacade();

                if (Nota.ModeloDocto == 65)
                {
                    string aXmlNota = Funcoes.AbrirArquivo(DiretorioXML + "\\" + Nota.ChaveNota + "-nfe.xml");
                    facade.VisualizarDanfeNFCe(aXmlNota, _configuracoes.ConfiguracaoDanfeNfce, _configuracoes.ConfiguracaoCsc.CIdToken, _configuracoes.ConfiguracaoCsc.Csc);
                }
                else
                {
                    string aXmlNota = Funcoes.AbrirArquivo(DiretorioXML + "\\" + Nota.ChaveNota + "-nfe.xml");
                    facade.VisualizarDanfe(aXmlNota);
                }
            }
        }