Beispiel #1
0
        public ParametroProdutoProjetoProperties parametroProdutoProjeto(ProjetoProperties projetoObj)
        {
            DataTable dt = new DataTable();
            ParametroProdutoProjetoProperties parametroProdutoProjetoProperties = new ParametroProdutoProjetoProperties();


            try
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("declare @idParametro int, @idProduto  int, @idProjeto int");
                sb.AppendLine("set @idParametro = " + Constantes.CAMINHO_IMAGEM);
                sb.AppendLine("set @idProduto = 3");
                sb.AppendLine("set @idProjeto = " + projetoObj.idProjeto);
                sb.AppendLine("select IdProduto,IdProjeto, nmValorParametro,IdParametro from tb_parametro_produto_projeto with(nolock)");
                sb.AppendLine("where idparametro = @idParametro");
                sb.AppendLine("and idproduto = @idProduto");
                sb.AppendLine("and idProjeto = @idProjeto");
                dt = Database.Instance.ExecuteQuery(sb.ToString(), dt);


                foreach (DataRow objetoParametroProdutoProjeto in dt.Rows)
                {
                    parametroProdutoProjetoProperties.IdProduto        = (int)objetoParametroProdutoProjeto["IdProduto"];
                    parametroProdutoProjetoProperties.IdProjeto        = (int)objetoParametroProdutoProjeto["IdProjeto"];
                    parametroProdutoProjetoProperties.NmValorParametro = (string)objetoParametroProdutoProjeto["nmValorParametro"];
                    parametroProdutoProjetoProperties.IdParametro      = (int)objetoParametroProdutoProjeto["IdParametro"];
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro Parametro Produto Projeto Properties: " + ex.Message + "\n" + ex.ToString());
            }
            return(parametroProdutoProjetoProperties);
        }
        public ParametroProdutoProjetoProperties getParametroProdutoProjeto(ProjetoProperties projetoObj, ConfiguracaoProperties configApp)
        {
            ParametroProdutoProjetoProperties parametroProdutoProjetoProperties = dao.parametroProdutoProjeto(projetoObj);

            log.escreveLog(string.Concat(new object[] { "Parametro produto projeto ", parametroProdutoProjetoProperties.NmValorParametro, "para o id projeto", projetoObj.idProjeto }), configApp);

            return(parametroProdutoProjetoProperties);
        }
        public ProjetoProperties getProjeto(ConfiguracaoProperties configApp)
        {
            SqlConnection     con     = ConnectionFactory.ConnectionFactory.getConnection();
            ProjetoProperties projeto = new ProjetoProperties();

            try
            {
                String strSql = "select idProjeto,NmProjeto,NmProjetoCompleto,Ativo,TemCapturaDistribuida,QtHoraExpurgo,DtAtualizacao,QtDiaExpurgoBaseLocal,MsRelPCP  from tb_projeto with(nolock) where idProjeto = " + configApp.idProjeto;

                con.Open();
                SqlCommand cmd = new SqlCommand(strSql, con);
                cmd.CommandType    = CommandType.Text;
                cmd.CommandTimeout = 120;
                IDataReader reader = cmd.ExecuteReader();


                while (reader.Read())
                {
                    projeto.idProjeto             = reader.GetInt32(reader.GetOrdinal("IdProjeto"));
                    projeto.nmProjeto             = reader.GetString(reader.GetOrdinal("NmProjeto"));
                    projeto.nmProjetoCompleto     = reader.GetString(reader.GetOrdinal("NmProjetoCompleto"));
                    projeto.ativo                 = reader.GetBoolean(reader.GetOrdinal("Ativo"));
                    projeto.temCaptureDistribuida = reader.GetBoolean(reader.GetOrdinal("TemCapturaDistribuida"));
                    projeto.QHoraExpurgo          = reader.GetInt32(reader.GetOrdinal("QtHoraExpurgo"));
                    projeto.dtAtualizacao         = reader.GetDateTime(reader.GetOrdinal("DtAtualizacao"));
                    projeto.qtDiaExpurgoBaseLocal = reader.GetInt32(reader.GetOrdinal("QtDiaExpurgoBaseLocal"));
                    projeto.msRefPCP              = reader.GetString(reader.GetOrdinal("MsRelPCP"));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro getProjeto: " + ex.Message + "\n" + ex.ToString());
            }
            finally
            {
                ConnectionFactory.ConnectionFactory.fechaConexão(con);
            }

            return(projeto);
        }
Beispiel #4
0
        public DirectoryInfo trataCaixa(CaixaProperties caixa, ConfiguracaoProperties configApp, ReleaseJucecProperties releaseJucec, string path, ProjetoProperties projetoObj, DocumentosProperties documento)
        {
            String        subStringCaixa = string.Empty;
            String        destino        = string.Empty;
            DirectoryInfo dirDestino;

            if (caixa.DsCaixa.Length >= 9)
            {
                subStringCaixa = caixa.DsCaixa.Substring(caixa.DsCaixa.Length - 9);
            }

            subStringCaixa = subStringCaixa.Replace(".", "");

            DateTime dataAtual = DateTime.Now;

            string dataAtualFormatada = dataAtual.ToString("yyyyMMdd");

            string pathDestino = string.Concat(new string[] { configApp.pastaPrincipal, "TCIReleaseJucec_2017\\", "Data_" + dataAtualFormatada, "\\", "Caixa_" + subStringCaixa, "\\", "Protocolo_" + Util.Util.ajustaDiretorio(releaseJucec.numProtocolo), "\\", "Processo_" + documento.idProcesso.ToString(), "\\", "Documento_" + documento.idDocumento.ToString() });

            if (path.Contains(";") && projetoObj.nmProjeto.ToUpper() != "JUCEC - CADASTRO SINCRONIZADO")
            {
                pathDestino = pathDestino.Replace("NUMERO_PROTOCOLO\\", "NIRE_ARQUIVAMENTO\\");
            }

            dirDestino = new DirectoryInfo(pathDestino);

            return(dirDestino);
        }
        public ReleaseJucecProperties getIndexerProcesso(DocumentosProperties documento, ProjetoProperties projetoObj, ProtocoloProperties protocolo, ConfiguracaoProperties configApp)
        {
            try
            {
                List <ValorIndiceProcessoProperties> listaIndexerProcesso = dao.indexerProcesso(documento);

                if (listaIndexerProcesso.Count > 0)
                {
                    releaseJucec = new ReleaseJucecProperties();

                    foreach (ValorIndiceProcessoProperties indexerProcesso in listaIndexerProcesso)
                    {
                        // siarco consulta para carregar os indices

                        if (indexerProcesso.indiceObject.NmIndiceSistema != null)
                        {
                            if (!(indexerProcesso.indiceObject.NmIndiceSistema == "NUMERO_PROTOCOLO"))
                            {
                                if (!(indexerProcesso.indiceObject.NmIndiceSistema == "NIRE"))
                                {
                                    if (!(indexerProcesso.indiceObject.NmIndiceSistema == "CNPJ"))
                                    {
                                        if (!(indexerProcesso.indiceObject.NmIndiceSistema == "NOME_EMPRESARIAL"))
                                        {
                                            if (!(indexerProcesso.indiceObject.NmIndiceSistema == "ATO"))
                                            {
                                                if (!(indexerProcesso.indiceObject.NmIndiceSistema == "EVENTO"))
                                                {
                                                    if (!(indexerProcesso.indiceObject.NmIndiceSistema == "DESCRICAO"))
                                                    {
                                                        if (!(indexerProcesso.indiceObject.NmIndiceSistema == "MUNICIPIO"))
                                                        {
                                                            if (indexerProcesso.indiceObject.NmIndiceSistema == "NUMERO_ARQUIVAMENTO")
                                                            {
                                                                if (!string.IsNullOrEmpty(indexerProcesso.NmValorIndiceProcesso.ToString().Trim()))
                                                                {
                                                                    releaseJucec.numArquivamento = indexerProcesso.NmValorIndiceProcesso;
                                                                }
                                                                else
                                                                {
                                                                    releaseJucec.numArquivamento = "000000";
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            releaseJucec.municipio = indexerProcesso.NmValorIndiceProcesso.ToString();
                                                        }
                                                    }
                                                    else
                                                    {
                                                        releaseJucec.descricao = indexerProcesso.NmValorIndiceProcesso.ToString();
                                                    }
                                                }
                                                else
                                                {
                                                    releaseJucec.evento = indexerProcesso.NmValorIndiceProcesso.ToString();
                                                }
                                            }
                                            else
                                            {
                                                releaseJucec.ato = indexerProcesso.NmValorIndiceProcesso.ToString();
                                            }
                                        }
                                        else
                                        {
                                            releaseJucec.nomeempresarial = indexerProcesso.NmValorIndiceProcesso.ToString();
                                        }
                                    }
                                    else
                                    {
                                        releaseJucec.cnpj = indexerProcesso.NmValorIndiceProcesso.ToString();
                                    }
                                }
                                else if (!string.IsNullOrEmpty(indexerProcesso.NmValorIndiceProcesso.ToString().Trim()))
                                {
                                    releaseJucec.nire = indexerProcesso.NmValorIndiceProcesso.ToString();
                                }
                            }
                            else
                            {
                                releaseJucec.numProtocolo = indexerProcesso.NmValorIndiceProcesso.ToString();
                            }
                        }
                    }
                }

                if (projetoObj.nmProjeto.ToUpper() != "JUCEC - CADASTRO SINCRONIZADO")
                {
                    if (projetoObj.nmProjeto != string.Empty)
                    {
                        releaseJucec.nireConcatnumArquivamento = releaseJucec.nireConcatnumArquivamento + "\\" + protocolo.dsProtocolo;
                    }
                    else if (releaseJucec.nire != string.Empty && releaseJucec.numArquivamento != string.Empty)
                    {
                        string concat = releaseJucec.nireConcatnumArquivamento;
                        releaseJucec.nireConcatnumArquivamento = string.Concat(new string[] { concat, "\\", releaseJucec.nire, "\";\"", releaseJucec.numArquivamento });
                    }
                    else
                    {
                        releaseJucec.nireConcatnumArquivamento += "\\000\";\"000000";
                    }
                }
                else
                {
                    string text3 = releaseJucec.nireConcatnumArquivamento;
                    releaseJucec.nireConcatnumArquivamento = string.Concat(new string[] { text3, "\\", releaseJucec.nire, "\";\"", releaseJucec.numArquivamento });
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Quantidade de Indices"))
                {
                    log.escreveLog(ex.Message + Environment.NewLine + ex.StackTrace, configApp);

                    return(null);
                }
                throw new Exception("Erro em obterNumProtocolo:" + ex.Message + "\n" + ex.StackTrace);
            }

            releaseJucec.nireConcatnumArquivamento = releaseJucec.nireConcatnumArquivamento.Replace("\\", "").Replace("/", "").Replace("-", "").Replace("_", "");

            return(releaseJucec);
        }
        public string concatNire_NunArquivamento(ReleaseJucecProperties releaseJucec, ProjetoProperties projeto)
        {
            string NireNunArquivamento = string.Empty;

            if (projeto.nmProjeto.ToUpper() != "JUCEC - CADASTRO SINCRONIZADO")
            {
                if (releaseJucec.numProtocolo != string.Empty)
                {
                    NireNunArquivamento = NireNunArquivamento + "\\" + releaseJucec.numProtocolo;
                }
                else if (releaseJucec.nire != string.Empty && releaseJucec.numArquivamento != string.Empty)
                {
                    string text2 = NireNunArquivamento;

                    NireNunArquivamento = string.Concat(new string[] { text2, "\\", releaseJucec.nire, "\";\"", releaseJucec.numArquivamento });
                }
                else
                {
                    NireNunArquivamento += "\\000\";\"000000";
                }
            }
            else
            {
                string text3 = NireNunArquivamento;
                NireNunArquivamento = string.Concat(new string[] { text3, "\\", releaseJucec.nire, "\";\"", releaseJucec.numProtocolo });
            }

            return(NireNunArquivamento);
        }
        public ReleaseJucecProperties getImagem(DocumentosProperties documento, ReleaseJucecProperties releaseJucec, ConfiguracaoProperties configApp, ParametroProdutoProjetoProperties parametroProdutoProjetoPropertie, DirectoryInfo pathDestino, ProjetoProperties projetoObj)
        {
            ImagemDao dao = new ImagemDaoImpl();

            try
            {
                List <ImagemProperties> listaImagems = dao.ImagemProcessa(documento);

                log.escreveLog("Quantidade de imagem para o documento " + documento.idDocumento.ToString() + listaImagems.Count.ToString(), configApp);

                if (listaImagems.Count > 0)
                {
                    //releaseJucec.penultimaImg = listaImagems[listaImagems.Count - 2].NmImagem;

                    //log.escreveLog("PenultimaImg " + releaseJucec.penultimaImg, configApp);

                    releaseJucec.flagSemImagem = true;
                }
                else
                {
                    //releaseJucec.penultimaImg = string.Empty;

                    //log.escreveLog("PenultimaImg " + releaseJucec.penultimaImg, configApp);

                    releaseJucec.flagSemImagem = true;
                }
                if (releaseJucec.flagSemImagem)
                {
                    releaseJucec.ultimaImg = listaImagems[listaImagems.Count - 1].NmImagem;

                    log.escreveLog("UltimaImg " + releaseJucec.ultimaImg, configApp);

                    FileInfo fileDestinoPdf = null;

                    foreach (ImagemProperties imagem in listaImagems)
                    {
                        log.escreveLog("lendo a imagem  id " + imagem.IdImagem + " Nome imagem " + imagem.NmImagem, configApp);

                        log.escreveLog("Caminho da imagem no banco " + imagem.NmCaminhoImagem, configApp);

                        FileInfo fileOrigem = new FileInfo(parametroProdutoProjetoPropertie.NmValorParametro + imagem.NmCaminhoImagem);

                        log.escreveLog("Origem da imagem .Tiff " + fileOrigem.FullName.ToString(), configApp);

                        log.escreveLog("Destino do .CSV, .PDF sem assinatura, .PDF assinado " + pathDestino.FullName, configApp);

                        fileDestinoPdf = new FileInfo(pathDestino.FullName + "\\");

                        log.escreveLog("Destino com PDF " + fileDestinoPdf.FullName.ToString(), configApp);

                        if (!fileDestinoPdf.Directory.Exists)
                        {
                            fileDestinoPdf.Directory.Create();
                        }
                        if (new FileInfo(fileOrigem.FullName).Exists)
                        {
                            if (projetoObj.nmProjeto.ToUpper() != Constantes.DESCRICSO_PROJETO)
                            {
                                fileOrigem.CopyTo(fileDestinoPdf.FullName, true);
                            }
                            else
                            {
                                fileDestinoPdf = new FileInfo(string.Concat(new object[] { fileDestinoPdf.FullName, "\\", releaseJucec.numProtocolo, "_.pdf" }));

                                this.processaImagem(fileOrigem, fileDestinoPdf, listaImagems.Count, configApp);

                                dao.logImagem(imagem, Constantes.ENVIADO_FTP);
                            }

                            log.escreveLog("A Imagem [" + fileOrigem.FullName + "] copiada para o diretorio " + fileDestinoPdf.FullName, configApp);
                        }
                        else
                        {
                            log.escreveLog("A Imagem [" + fileOrigem.FullName + "] não existe no diretorio", configApp);
                        }
                    }
                }

                // processo
                //dao.atualizaStatus(imagem, Constantes.PDF_GERADO);

                releaseJucec.flag = true;
            }
            catch (Exception ex)
            {
                log.escreveLog("Erro ao tentar processaImagem:" + ex.Message + "\n" + ex.StackTrace, configApp);
                throw new Exception(ex.Message + "\n" + ex.StackTrace);
            }

            return(releaseJucec);
        }
        public void processamento()
        {
            log.escreveLog("Inicio ", configApp);

            while (!Constantes.THREAD_PARADA_SOLICITADO)
            {
                try
                {
                    RegrasProjeto regraProjeto = new RegrasProjeto();

                    RegrasProtocolo regraProtocolo = new RegrasProtocolo();

                    // carrega as informaçoes do projeto
                    projetoObj = regraProjeto.getProjeto(configApp);

                    // Busca protocolo liberados
                    List <ProtocoloProperties> listaProtocolosLiberado = regraProtocolo.getProtocoloProtocolosLiberado(configApp);

                    log.escreveLog("Quantidade de protocolo disponível " + listaProtocolosLiberado.Count, configApp);

                    foreach (ProtocoloProperties protocolo in listaProtocolosLiberado)
                    {
                        RegrasDocumentos regrasDocumentos = new RegrasDocumentos();

                        // lista de documentos liberados
                        List <DocumentosProperties> listaDocumentosLiberados = regrasDocumentos.getDocumentosLiberado(protocolo);

                        log.escreveLog("Quantidade de documentos disponível " + listaProtocolosLiberado.Count, configApp);

                        foreach (DocumentosProperties documento in listaDocumentosLiberados)
                        {
                            log.escreveLog("Lendo o documento " + documento.idDocumento, configApp);

                            RegrasIndexer regrasIndexer = new RegrasIndexer();

                            // Recupera os indices e valorIndice
                            ReleaseJucecProperties releaseJucec = regrasIndexer.getIndexerProcesso(documento, projetoObj, protocolo, configApp);

                            //Concatena Nire e NumeroArquivamento
                            NireNunArquivamento = regrasIndexer.concatNire_NunArquivamento(releaseJucec, projetoObj);

                            if (NireNunArquivamento != null)
                            {
                                RegrasCaixa  regrasCaixa  = new RegrasCaixa();
                                RegrasImagem regrasImagem = new RegrasImagem();
                                RegrasParametroProdutoProjeto regrasParametroProdutoProjeto = new RegrasParametroProdutoProjeto();
                                Servicos servicos = new Servicos();

                                // Busca caixa com base no numero arquivamento
                                CaixaProperties caixa = regrasCaixa.getCaixaProcesso(documento);
                                log.escreveLog("Pegou a caixa " + caixa.IdCaixa, configApp);

                                // caminho onde será depositado os arquivos .pdf
                                DirectoryInfo pathDestino = regrasCaixa.trataCaixa(caixa, configApp, releaseJucec, NireNunArquivamento, projetoObj, documento);

                                // retorna um projeto produto
                                ParametroProdutoProjetoProperties parametroProdutoProjetoProperties = regrasParametroProdutoProjeto.getParametroProdutoProjeto(projetoObj, configApp);

                                // pega todas as imagens referente ao  idDocumento passado como parametro e diferente de excluida.
                                // busca a origem do arquivo .tiff
                                // cria o _.pdf no destino passado como parametro
                                releaseJucec = regrasImagem.getImagem(documento, releaseJucec, configApp, parametroProdutoProjetoProperties, pathDestino, projetoObj);

                                documentoSemTiff = releaseJucec.flagSemImagem;

                                if (documentoSemTiff)
                                {
                                    if (releaseJucec.flag)
                                    {
                                        // Gera o arquivo csv no mesmo diretorio do PDF
                                        log.escreveLog("Gerando arquivo .CSV ", configApp);
                                        servicos.geraArqvuivoCSV(pathDestino.ToString() + "\\" + documento.idProcesso.ToString() + ".csv", releaseJucec, pathDestino, caixa);

                                        log.escreveLog("Gerando arquivo .CSV para o carga generica ", configApp);
                                        // Enviando cvs para o sistema carga Generica
                                        servicos.geraArqvuivoCSV(ConfigurationSettings.AppSettings["diretorioCsvContentProcessar"].ToString() + "\\" + documento.idProcesso.ToString() + ".csv", releaseJucec, pathDestino, caixa);
                                    }
                                    else
                                    {
                                        log.escreveLog("Quantidade de Indices [0] no Processo [" + documento.idProcesso + "] não é o mesmo na estrutura do arquivo", configApp);
                                    }

                                    log.escreveLog("Pesquisando as imagens no diretorio para assinatura do Protocolo [" + protocolo.dsProtocolo + "] na estrutura do arquivo", configApp);

                                    // retorna uma lista de pdf que termine com _.pdf
                                    FileInfo[] filesPdf = servicos.getPdfs(configApp, caixa, pathDestino);

                                    log.escreveLog("Foram encontrados .Pdf's com _.PDF [" + filesPdf.Length + "]", configApp);

                                    // move os pdfs sem assinatura para o diretorio informado  na tag do app.config  <caminhoPdfSemAssinatura>
                                    servicos.moverPdfSemAssinaturaSRM(filesPdf[0], releaseJucec, documento, configApp);

                                    // serviço que assina os pdfs de acordo com a certificado da maquina
                                    pdfisOk = servicos.arquivoParaAssinar(filesPdf[0], releaseJucec, configApp);
                                }
                                if (documentoSemTiff)
                                {
                                    // documento log e status
                                    regrasDocumentos = new RegrasDocumentos();
                                    regrasDocumentos.LogDocumento(documento, Constantes.ENVIADO_FTP);
                                    regrasDocumentos.atualizaSatusDocumento(documento, Constantes.ENVIADO_FTP);
                                }
                                else
                                {
                                    // documento log e status
                                    regrasDocumentos = new RegrasDocumentos();
                                    regrasDocumentos.LogDocumento(documento, Constantes.DOCUMENTO_SEM_TIFF);
                                    regrasDocumentos.atualizaSatusDocumento(documento, Constantes.DOCUMENTO_SEM_TIFF);
                                }
                            }
                        }
                        // processo e status
                        regrasProtocolo = new RegrasProtocolo();
                        regrasProtocolo.atualizaProcesso(protocolo, Constantes.ENVIADO_FTP);
                        regrasProtocolo.logProcesso(protocolo, Constantes.ENVIADO_FTP);
                    }
                }
                catch (Exception ex)
                {
                    log.escreveLog("\n Erro: " + ex.Message + "\n" + ex.ToString() + "\n", configApp);

                    // MessageBox.Show(ex.StackTrace);
                }
            }
        }