示例#1
0
        public override void Execute()
        {
            switch (Servico)
            {
            case Servicos.DFeEnviar:
                ExtEnvioDFe      = Propriedade.Extensao(Propriedade.TipoEnvio.EnvDFe).EnvioXML;
                ExtEnvioDFeTXT   = Propriedade.Extensao(Propriedade.TipoEnvio.EnvDFe).EnvioTXT;
                ExtRetornoDFe    = Propriedade.Extensao(Propriedade.TipoEnvio.EnvDFe).RetornoXML;
                ExtRetEnvDFe_ERR = Propriedade.ExtRetorno.retEnvDFe_ERR;
                break;

            case Servicos.CTeDistribuicaoDFe:
                ExtEnvioDFe      = Propriedade.Extensao(Propriedade.TipoEnvio.EnvDFeCTe).EnvioXML;
                ExtEnvioDFeTXT   = Propriedade.Extensao(Propriedade.TipoEnvio.EnvDFeCTe).EnvioTXT;
                ExtRetornoDFe    = Propriedade.Extensao(Propriedade.TipoEnvio.EnvDFeCTe).RetornoXML;
                ExtRetEnvDFe_ERR = Propriedade.ExtRetorno.retEnvDFeCTe_ERR;
                break;
            }

            int        emp         = Empresas.FindEmpresaByThread();
            distDFeInt _distDFeInt = new distDFeInt();

            try
            {
                if (!this.vXmlNfeDadosMsgEhXML)
                {
                    ///versao|1.00
                    ///tpAmb|1
                    ///cUFAutor|35
                    ///CNPJ|
                    /// ou
                    ///CPF|
                    ///ultNSU|123456789012345
                    /// ou
                    ///NSU|123456789012345
                    List <string> cLinhas = Functions.LerArquivo(NomeArquivoXML);
                    Functions.PopulateClasse(_distDFeInt, cLinhas);

                    string f = Path.GetFileNameWithoutExtension(NomeArquivoXML) + ".xml";

                    if (NomeArquivoXML.IndexOf(Empresas.Configuracoes[emp].PastaValidar, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        f = Path.Combine(Empresas.Configuracoes[emp].PastaValidar, f);
                    }
                    // Gerar o XML de envio de DFe a partir do TXT gerado pelo ERP
                    oGerarXML.RecepcaoDFe(f, _distDFeInt);
                }
                else
                {
                    XmlNodeList consdistDFeIntList = ConteudoXML.GetElementsByTagName("distDFeInt");

                    foreach (XmlNode consdistDFeIntNode in consdistDFeIntList)
                    {
                        XmlElement consdistDFeIntElemento = (XmlElement)consdistDFeIntNode;
                        Functions.PopulateClasse(_distDFeInt, consdistDFeIntElemento);
                    }

                    //Definir o objeto do WebService
                    WebServiceProxy wsProxy = ConfiguracaoApp.DefinirWS(Servico,
                                                                        emp,
                                                                        991,
                                                                        _distDFeInt.tpAmb, 0);

                    System.Net.SecurityProtocolType securityProtocolType = WebServiceProxy.DefinirProtocoloSeguranca(991, _distDFeInt.tpAmb, 1, Servico);

                    object oConsNFDestEvento = wsProxy.CriarObjeto(wsProxy.NomeClasseWS);

                    //Invocar o método que envia o XML para o SEFAZ
                    oInvocarObj.Invocar(wsProxy,
                                        oConsNFDestEvento,
                                        wsProxy.NomeMetodoWS[0],
                                        null,
                                        this,
                                        ExtEnvioDFe,
                                        ExtRetornoDFe,
                                        true,
                                        securityProtocolType);

                    LeRetornoDFe(emp, ConteudoXML);
                }
            }
            catch (Exception ex)
            {
                WriteLogError(ex);
            }
            finally
            {
                try
                {
                    //Deletar o arquivo de solicitação do serviço
                    Functions.DeletarArquivo(NomeArquivoXML);
                }
                catch
                {
                }
            }
        }
示例#2
0
        public override void Execute()
        {
            int        emp         = Empresas.FindEmpresaByThread();
            distDFeInt _distDFeInt = new distDFeInt();

            Servico = Servicos.DFeEnviar;
            try
            {
                if (!this.vXmlNfeDadosMsgEhXML)
                {
                    ///versao|1.00
                    ///tpAmb|1
                    ///cUFAutor|35
                    ///CNPJ|
                    /// ou
                    ///CPF|
                    ///ultNSU|123456789012345
                    /// ou
                    ///NSU|123456789012345
                    List <string> cLinhas = Functions.LerArquivo(this.NomeArquivoXML);
                    Functions.PopulateClasse(_distDFeInt, cLinhas);

                    string f = System.IO.Path.GetFileNameWithoutExtension(NomeArquivoXML) + ".xml";

                    if (NomeArquivoXML.IndexOf(Empresas.Configuracoes[emp].PastaValidar, StringComparison.InvariantCultureIgnoreCase) >= 0)
                    {
                        f = Path.Combine(Empresas.Configuracoes[emp].PastaValidar, f);
                    }
                    // Gerar o XML de envio de DFe a partir do TXT gerado pelo ERP
                    oGerarXML.RecepcaoDFe(f, _distDFeInt);
                }
                else
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(this.NomeArquivoXML);

                    XmlNodeList consdistDFeIntList = doc.GetElementsByTagName("distDFeInt");

                    foreach (XmlNode consdistDFeIntNode in consdistDFeIntList)
                    {
                        XmlElement consdistDFeIntElemento = (XmlElement)consdistDFeIntNode;
                        Functions.PopulateClasse(_distDFeInt, consdistDFeIntElemento);
                    }

                    //Definir o objeto do WebService
                    WebServiceProxy wsProxy =
                        ConfiguracaoApp.DefinirWS(Servico,
                                                  emp,
                                                  991,
                                                  _distDFeInt.tpAmb);

                    object oConsNFDestEvento = wsProxy.CriarObjeto(wsProxy.NomeClasseWS);

                    //Invocar o método que envia o XML para o SEFAZ
                    oInvocarObj.Invocar(wsProxy,
                                        oConsNFDestEvento,
                                        wsProxy.NomeMetodoWS[0],
                                        null,
                                        this,
                                        Propriedade.ExtEnvio.EnvDFe_XML.Replace(".xml", ""),
                                        Propriedade.ExtRetorno.retEnvDFe_XML.Replace(".xml", ""));

                    LeRetornoDFe(emp, doc);
                }
            }
            catch (Exception ex)
            {
                WriteLogError(ex);
            }
            finally
            {
                try
                {
                    //Deletar o arquivo de solicitação do serviço
                    Functions.DeletarArquivo(NomeArquivoXML);
                }
                catch
                {
                }
            }
        }