Пример #1
0
        /// <summary>
        /// CopiaPastaDaEmpresa
        /// </summary>
        /// <param name="origemCNPJ"></param>
        /// <param name="origemPasta"></param>
        /// <param name="oEmpresa"></param>
        /// <returns></returns>
        private string CopiaPastaDeEmpresa(string origemCNPJ, string origemPasta, Empresa oEmpresa)
        {
            if (string.IsNullOrEmpty(origemPasta))
            {
                return("");
            }

            ///
            /// o usuario pode ter colocado o CNPJ como parte do nome da pasta
            ///
            /// origemPasta: C:\uninfe\CNPJ_antigo\envio
            /// origemCNPJ:  CNPJ_novo
            /// newPasta:    C:\uninfe\CNPJ_novo\envio
            ///
            string newPasta = origemPasta.Replace(origemCNPJ.Trim(), oEmpresa.CNPJ.Trim());

            if (origemPasta.ToLower() == newPasta.ToLower())
            {
                ///
                /// o cnpj nao foi informado como parte da pasta
                ///
                int lastBackSlash = ConfiguracaoApp.RemoveEndSlash(origemPasta).LastIndexOf("\\");
                newPasta = origemPasta.Insert(lastBackSlash, "\\" + oEmpresa.CNPJ);
            }
            return(newPasta);
        }
Пример #2
0
        /// <summary>
        /// Localiza a empresa da qual o arquivo faz parte para processar com as configurações corretas
        /// </summary>
        /// <param name="fullPath">Nome do arquivo completo (com pasta e tudo)</param>
        /// <returns>Index da empresa dentro da lista de configurações</returns>
        /// <remarks>
        /// Autor: Wandrey Mundin Ferreira
        /// Data: 26/04/2011
        /// </remarks>
        private int LocalizaEmpresa(FileInfo fi)
        {
            int empresa = -1;

            try
            {
                ///
                ///danasa 3/11/2011
                string fullName = ConfiguracaoApp.RemoveEndSlash(fi.Directory.FullName.ToLower());
                ///
                /// "EndsWith" é para pegar apenas se terminar com, já que nas empresas pode ter um nome 'temp' no meio das definicoes das pastas
                if (fullName.EndsWith("\\temp"))
                {
                    /// exclui o 'arquivo' temp.
                    fullName = Path.GetDirectoryName(fullName);
                }

                for (int i = 0; i < Empresas.Configuracoes.Count; i++)
                {
                    if (fullName == Empresas.Configuracoes[i].PastaXmlEnvio.ToLower() ||
                        fullName == Empresas.Configuracoes[i].PastaXmlEmLote.ToLower() ||
                        fullName == Empresas.Configuracoes[i].PastaValidar.ToLower() ||
                        fullName == Empresas.Configuracoes[i].PastaContingencia.ToLower())
                    {
                        empresa = i;
                        break;
                    }
                }
            }
            catch
            {
            }

            return(empresa);
        }
Пример #3
0
        /// <summary>
        /// CopiaPastaDeEmpresa
        /// </summary>
        /// <param name="empresa"></param>
        /// <param name="oempresa"></param>
        private void CopiaPastaDeEmpresa(Empresa empresa, Empresa oempresa)
        {
            oempresa.PastaXmlEnvio   = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaXmlEnvio, oempresa);
            oempresa.PastaXmlRetorno = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaXmlRetorno, oempresa);
            oempresa.PastaXmlErro    = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaXmlErro, oempresa);
            oempresa.PastaValidar    = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaValidar, oempresa);
            if (oempresa.Servico != TipoAplicativo.Nfse)
            {
                if (empresa.Servico != TipoAplicativo.Nfse)
                {
                    oempresa.PastaXmlEmLote       = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaXmlEmLote, oempresa);
                    oempresa.PastaXmlEnviado      = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaXmlEnviado, oempresa);
                    oempresa.PastaBackup          = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaBackup, oempresa);
                    oempresa.PastaDownloadNFeDest = CopiaPastaDeEmpresa(empresa.CNPJ, empresa.PastaDownloadNFeDest, oempresa);
                }
                else
                {
                    string folder = Path.GetDirectoryName(ConfiguracaoApp.RemoveEndSlash(oempresa.PastaXmlEnvio));

                    oempresa.PastaXmlEnviado      = Path.Combine(folder, "Enviado");
                    oempresa.PastaXmlEmLote       = Path.Combine(folder, "EnvioEmLote");
                    oempresa.PastaDownloadNFeDest = Path.Combine(folder, "DownloadNFe");
                    oempresa.PastaBackup          = Path.Combine(folder, "Backup");
                }
            }
            oempresa.ConfiguracaoDanfe   = empresa.ConfiguracaoDanfe;
            oempresa.ConfiguracaoCCe     = empresa.ConfiguracaoCCe;
            oempresa.PastaConfigUniDanfe = empresa.PastaConfigUniDanfe;
            oempresa.PastaExeUniDanfe    = empresa.PastaExeUniDanfe;
            oempresa.PastaDanfeMon       = empresa.PastaDanfeMon;
            oempresa.XMLDanfeMonNFe      = empresa.XMLDanfeMonNFe;
            oempresa.XMLDanfeMonProcNFe  = empresa.XMLDanfeMonProcNFe;

            oempresa.GravarRetornoTXTNFe                         = empresa.GravarRetornoTXTNFe;
            oempresa.GravarEventosNaPastaEnviadosNFe             = empresa.GravarEventosNaPastaEnviadosNFe;
            oempresa.GravarEventosCancelamentoNaPastaEnviadosNFe = empresa.GravarEventosCancelamentoNaPastaEnviadosNFe;
            oempresa.GravarEventosDeTerceiros                    = empresa.GravarEventosDeTerceiros;
            oempresa.CompactarNfe = empresa.CompactarNfe;
            oempresa.IndSinc      = empresa.IndSinc;

            oempresa.CodigoAtivacaoSAT   = empresa.CodigoAtivacaoSAT;
            oempresa.MarcaSAT            = empresa.MarcaSAT;
            oempresa.UtilizaConversaoCFe = empresa.UtilizaConversaoCFe;
            oempresa.CNPJSoftwareHouse   = empresa.CNPJSoftwareHouse;
            oempresa.SignACSAT           = empresa.SignACSAT;
            oempresa.NumeroCaixa         = empresa.NumeroCaixa;
            oempresa.IndRatISSQNSAT      = empresa.IndRatISSQNSAT;
            oempresa.RegTribISSQNSAT     = empresa.RegTribISSQNSAT;

            oempresa.CriaPastasAutomaticamente = true;
        }
Пример #4
0
 /// <summary>
 /// RemoveEndSlash
 /// </summary>
 public void RemoveEndSlash()
 {
     PastaXmlEnvio        = ConfiguracaoApp.RemoveEndSlash(PastaXmlEnvio);
     PastaXmlErro         = ConfiguracaoApp.RemoveEndSlash(PastaXmlErro);
     PastaXmlRetorno      = ConfiguracaoApp.RemoveEndSlash(PastaXmlRetorno);
     PastaValidar         = ConfiguracaoApp.RemoveEndSlash(PastaValidar);
     PastaXmlEnviado      = this.Servico == TipoAplicativo.Nfse ? "" : ConfiguracaoApp.RemoveEndSlash(PastaXmlEnviado);
     PastaBackup          = this.Servico == TipoAplicativo.Nfse ? "" : ConfiguracaoApp.RemoveEndSlash(PastaBackup);
     PastaXmlEmLote       = this.Servico == TipoAplicativo.Nfse ? "" : ConfiguracaoApp.RemoveEndSlash(PastaXmlEmLote);
     PastaDownloadNFeDest = this.Servico == TipoAplicativo.Nfse ? "" : ConfiguracaoApp.RemoveEndSlash(PastaDownloadNFeDest);
     PastaDanfeMon        = this.Servico == TipoAplicativo.Nfse ? "" : ConfiguracaoApp.RemoveEndSlash(PastaDanfeMon);
     PastaExeUniDanfe     = this.Servico == TipoAplicativo.Nfse ? "" : ConfiguracaoApp.RemoveEndSlash(PastaExeUniDanfe);
     PastaConfigUniDanfe  = this.Servico == TipoAplicativo.Nfse ? "" : ConfiguracaoApp.RemoveEndSlash(PastaConfigUniDanfe);
 }
Пример #5
0
        /// <summary>
        /// CopiaPastaDaEmpresa
        /// </summary>
        /// <param name="origemCNPJ"></param>
        /// <param name="origemPasta"></param>
        /// <param name="oEmpresa"></param>
        /// <returns></returns>
        private string CopiaPastaDeEmpresa(string origemCNPJ, string origemPasta, Empresa destino)
        {
            if (string.IsNullOrEmpty(origemPasta))
            {
                return("");
            }

            ///
            /// o usuario pode ter colocado o CNPJ como parte do nome da pasta
            ///
            /// origemPasta: C:\uninfe\CNPJ_antigo\envio
            /// origemCNPJ:  CNPJ_novo
            /// newPasta:    C:\uninfe\CNPJ_novo\envio
            ///
            string newPasta = origemPasta.Replace(origemCNPJ.Trim(), destino.CNPJ.Trim());

            if (origemPasta.Equals(newPasta, StringComparison.InvariantCultureIgnoreCase))
            {
                foreach (string sp in new string[] { "\\nfse\\", "\\nfce\\", "\\cte\\", "\\mdfe\\", "\\" })
                {
                    origemPasta = origemPasta.Replace(destino.CNPJ + sp, "");
                }

                int lastBackSlash = ConfiguracaoApp.RemoveEndSlash(origemPasta).LastIndexOf("\\");

                string subpasta = destino.CNPJ;
                switch (destino.Servico)
                {
                case TipoAplicativo.Todos:
                case TipoAplicativo.Nfe:
                    break;

                default:
                    subpasta += "\\" + destino.Servico.ToString().ToLower();
                    break;
                }
                newPasta = origemPasta.Insert(lastBackSlash, "\\" + subpasta);
            }
            return(newPasta);
        }
Пример #6
0
        /// <summary>
        /// Definir o tipo do servico a ser executado a partir da extensão do arquivo
        /// </summary>
        /// <param name="fullPath">Nome do arquivo completo do qual é para definir o tipo de serviço a ser executado</param>
        /// <returns>Retorna o tipo do serviço que deve ser executado</returns>
        /// <remarks>
        /// Autor: Wandrey Mundin Ferreira
        /// Data: 27/04/2011
        /// </remarks>
#if movido_para_processar_cs
        public static Servicos xDefinirTipoServico(int empresa, string fullPath)
        {
            Servicos tipoServico = Servicos.Nulo;

            try
            {
                string arq = fullPath.ToLower().Trim();

                if (arq.IndexOf(Empresa.Configuracoes[empresa].PastaValidar.ToLower()) >= 0)
                {
                    tipoServico = Servicos.AssinarValidar;
                }
                else
                {
                    if (arq.IndexOf(Propriedade.ExtEnvio.PedSit_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.PedSit_TXT) >= 0)
                    {
                        tipoServico = Servicos.PedidoConsultaSituacaoNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedSta_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.PedSta_TXT) >= 0)
                    {
                        tipoServico = Servicos.PedidoConsultaStatusServicoNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.ConsCad_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.ConsCad_TXT) >= 0)
                    {
                        tipoServico = Servicos.ConsultaCadastroContribuinte;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedCan_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.PedCan_TXT) >= 0)
                    {
                        tipoServico = Servicos.CancelarNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedInu_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.PedInu_TXT) >= 0)
                    {
                        tipoServico = Servicos.InutilizarNumerosNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedRec_XML) >= 0)
                    {
                        tipoServico = Servicos.PedidoSituacaoLoteNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.Nfe) >= 0)
                    {
                        FileInfo infArq     = new FileInfo(arq);
                        string   pastaArq   = ConfiguracaoApp.RemoveEndSlash(infArq.DirectoryName).ToLower().Trim();
                        string   pastaLote  = ConfiguracaoApp.RemoveEndSlash(Empresa.Configuracoes[empresa].PastaEnvioEmLote).ToLower().Trim();
                        string   pastaEnvio = ConfiguracaoApp.RemoveEndSlash(Empresa.Configuracoes[empresa].PastaEnvio).ToLower().Trim();

                        //Remover a subpasta temp
                        if (pastaArq.EndsWith("\\temp"))
                        {
                            pastaArq = Path.GetDirectoryName(pastaArq);
                        }

                        //Definir o serviço
                        if (pastaArq == pastaLote)
                        {
                            tipoServico = Servicos.AssinarValidarNFe;
                        }
                        else if (pastaArq == pastaEnvio)
                        {
                            tipoServico = Servicos.MontarLoteUmaNFe;
                        }
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.Nfe_TXT) >= 0)
                    {
                        tipoServico = Servicos.ConverterTXTparaXML;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvLot) >= 0)
                    {
                        tipoServico = Servicos.EnviarLoteNfe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.GerarChaveNFe_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.GerarChaveNFe_TXT) >= 0)
                    {
                        tipoServico = Servicos.GerarChaveNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvWSExiste_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvWSExiste_TXT) >= 0)
                    {
                        tipoServico = Servicos.WSExiste;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvDPEC_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvDPEC_TXT) >= 0)
                    {
                        tipoServico = Servicos.EnviarDPEC;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.ConsDPEC_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.ConsDPEC_TXT) >= 0)
                    {
                        tipoServico = Servicos.ConsultarDPEC;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.AltCon_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.AltCon_TXT) >= 0)
                    {
                        tipoServico = Servicos.AlterarConfiguracoesUniNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.ConsInf_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.ConsInf_TXT) >= 0)
                    {
                        tipoServico = Servicos.ConsultaInformacoesUniNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvCCe_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvCCe_TXT) >= 0)
                    {
                        tipoServico = Servicos.EnviarCCe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvCancelamento_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvCancelamento_TXT) >= 0)
                    {
                        tipoServico = Servicos.EnviarEventoCancelamento;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvManifestacao_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvManifestacao_TXT) >= 0)
                    {
                        tipoServico = Servicos.EnviarManifestacao;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.ConsNFeDest_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.ConsNFeDest_TXT) >= 0)
                    {
                        tipoServico = Servicos.ConsultaNFDest;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvDownload_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvDownload_TXT) >= 0)
                    {
                        tipoServico = Servicos.DownloadNFe;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvRegistroDeSaida_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvRegistroDeSaida_TXT) >= 0)
                    {
                        tipoServico = Servicos.RegistroDeSaida;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvCancRegistroDeSaida_XML) >= 0 || arq.IndexOf(Propriedade.ExtEnvio.EnvCancRegistroDeSaida_TXT) >= 0)
                    {
                        tipoServico = Servicos.RegistroDeSaidaCancelamento;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.MontarLote) >= 0)
                    {
                        if (arq.IndexOf(Empresa.Configuracoes[empresa].PastaEnvioEmLote.ToLower().Trim()) >= 0)
                        {
                            tipoServico = Servicos.MontarLoteVariasNFe;
                        }
                    }
                    #region NFS-e
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedLoteRps) >= 0)
                    {
                        tipoServico = Servicos.ConsultarLoteRps;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedCanNfse) >= 0)
                    {
                        tipoServico = Servicos.CancelarNfse;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedSitLoteRps) >= 0)
                    {
                        tipoServico = Servicos.ConsultarSituacaoLoteRps;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.EnvLoteRps) >= 0)
                    {
                        tipoServico = Servicos.RecepcionarLoteRps;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedSitNfse) >= 0)
                    {
                        tipoServico = Servicos.ConsultarNfse;
                    }
                    else if (arq.IndexOf(Propriedade.ExtEnvio.PedSitNfseRps) >= 0)
                    {
                        tipoServico = Servicos.ConsultarNfsePorRps;
                    }
                    #endregion
                }
            }
            catch
            {
            }

            return(tipoServico);
        }