internal int GerarId(string sequencia) { Comando comando = null; int idGerado = 0; try { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); comando = bancoDeDadosGeo.GetComandoSql("select " + sequencia + ".nextval from dual"); object retorno = bancoDeDadosGeo.ExecutarScalar(comando); if (retorno == null || !int.TryParse(retorno.ToString(), out idGerado)) { return(-1); } } finally { if (comando != null) { comando.Dispose(); } } return(idGerado); }
public static void Gerar(string log) { try { Comando comando = null; try { BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); comando = bancoDeDadosGeo.GetComandoSql(@"insert into log_servicos (id, data, source, mensagem) values (seq_log_servicos.nextval, sysdate, 'DesenhadorWs', :log)");; comando.AdicionarParametroEntrada("log", DbType.String, 4000, log); bancoDeDadosGeo.ExecutarNonQuery(comando); } finally { if (comando != null) { comando.Dispose(); } } } catch { } }
internal void TransferirAtualizarGeometria(string tabela, string rascunho, int objectid) { Comando comando = null; IDbConnection connection = null; try { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"]; BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); connection = bancoDeDadosGeo.GetConexao(); connection.Open(); comando = bancoDeDadosGeo.GetComandoSql(@"begin " + " DesenhadorWS.AtualizarGeometriaFeicao(:schema, :tabela, :objectid, :rascunho);" + " end;"); comando.AdicionarParametroEntrada("schema", schemaUsuarioGeo.ToUpper(), DbType.String); comando.AdicionarParametroEntrada("tabela", tabela.ToUpper(), DbType.String); comando.AdicionarParametroEntrada("objectid", objectid, DbType.Int32); comando.AdicionarParametroEntrada("rascunho", rascunho.ToUpper(), DbType.String); bancoDeDadosGeo.ExecutarNonQuery(comando); } finally { if (connection != null) { connection.Close(); connection.Dispose(); } } }
internal bool Excluir(int objectId, string tabela, string primaryKey) { Comando comando = null; try { if (tabela.ToUpper().Contains("DES_PATIV") || tabela.ToUpper().Contains("DES_AATIV")) { BancoDeDados banco = BancoDeDadosFactory.CriarBancoDeDados("StringConexao"); comando = banco.GetComandoSql($@"select c.id from crt_exp_florestal_exploracao c where exists (select 1 from crt_exp_florestal_geo g where g.exp_florestal_exploracao = c.id and exists (select 1 from idafgeo.{(tabela.ToUpper().Contains("DES_PATIV") ? "des_pativ" : "des_aativ")} d where d.codigo = c.identificacao and d.id = :objectid and exists(select 1 from idafgeo.{(tabela.ToUpper().Contains("DES_PATIV") ? "tmp_pativ" : "tmp_aativ")} t where t.projeto = d.projeto and id = g.{(tabela.ToUpper().Contains("DES_PATIV") ? "tmp_pativ_id" : "tmp_aativ_id")})))" ); comando.AdicionarParametroEntrada("objectId", objectId, DbType.Int32); var id = banco.ExecutarScalar(comando); comando = banco.GetComandoPlSql($@"begin delete from crt_exp_florestal_geo g where g.exp_florestal_exploracao = :id; delete from crt_exp_florestal_produto p where p.exp_florestal_exploracao = :id; delete from crt_exp_florestal_exploracao c where c.id = :id; delete from tab_titulo_exp_florestal t where exists (select 1 from crt_exploracao_florestal c where not exists (select 1 from crt_exp_florestal_exploracao ce where ce.exploracao_florestal = c.id) and c.id = t.exploracao_florestal); delete from crt_exploracao_florestal c where not exists (select 1 from crt_exp_florestal_exploracao ce where ce.exploracao_florestal = c.id); end;" ); comando.AdicionarParametroEntrada("id", id, DbType.Int32); banco.ExecutarNonQuery(comando); } string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); comando = bancoDeDados.GetComandoSql("delete from " + schemaUsuario + "." + tabela + " t where t." + primaryKey + " = :objectId"); comando.AdicionarParametroEntrada("objectId", objectId, DbType.Int32); bancoDeDados.ExecutarNonQuery(comando); } finally { if (comando != null) { comando.Dispose(); } } return(true); }
internal Navegador Buscar(int idNavegador, int idProjeto) { Comando comando = null; Comando comandoGeo = null; Navegador navegador = null; IDataReader reader = null; try { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); comandoGeo = bancoDeDadosGeo.GetComandoSql(@"select a.nome from " + schemaUsuarioGeo + @".tab_navegador a where a.id = :id "); comandoGeo.AdicionarParametroEntrada("id", idNavegador, DbType.Int32); reader = bancoDeDadosGeo.ExecutarReader(comandoGeo); if (reader.Read()) { navegador = new Navegador(); navegador.Id = idNavegador; navegador.Nome = Convert.ToString(reader["nome"]); } if (navegador != null) { List <string> projetosAssociados; navegador.Servicos = BuscarServicos(idNavegador); navegador.Cenarios = BuscarCenarios(idNavegador); navegador.Filtros = BuscarFiltrosLayerFeicao(idNavegador, idProjeto, out projetosAssociados); if (projetosAssociados != null) { navegador.ProjetosAssociados = projetosAssociados.ToArray(); } } } finally { if (comando != null) { comando.Dispose(); } if (comandoGeo != null) { comandoGeo.Dispose(); } if (reader != null) { reader.Close(); reader.Dispose(); } } return(navegador); }
internal ServicoArcGis[] BuscarServicos(int idNavegador) { string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); IDataReader reader = null; List <ServicoArcGis> lista = null; Comando comando = bancoDeDados.GetComandoSql(@"select b.id, b.nome, b.url, b.is_cacheado, a.is_principal, a.identificar, a.gera_legenda, nvl((select max(sf.id_layer) from " + schemaUsuario + @".tab_servico_feicao sf where sf.servico(+) = b.id),0) ultimo_id_layer from " + schemaUsuario + @".tab_navegador_servico a, " + schemaUsuario + @".tab_servico b where a.servico = b.id and a.navegador = :navegador order by a.ordem_exibicao "); comando.AdicionarParametroEntrada("navegador", idNavegador, DbType.Int32); try { reader = bancoDeDados.ExecutarReader(comando); lista = new List <ServicoArcGis>(); ServicoArcGis servico = null; while (reader.Read()) { servico = new ServicoArcGis(); servico.Id = Convert.ToInt32(reader["id"]); servico.Nome = Convert.ToString(reader["nome"]); servico.Url = Convert.ToString(reader["url"]); servico.IsCacheado = Convert.ToString(reader["is_cacheado"]) == "1"; servico.IsPrincipal = Convert.ToString(reader["is_principal"]) == "1"; servico.Identificar = Convert.ToString(reader["identificar"]) == "1"; servico.GeraLegenda = Convert.ToString(reader["gera_legenda"]) == "1"; servico.UltimoIdLayer = Convert.ToInt32(reader["ultimo_id_layer"]); lista.Add(servico); } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } } return(lista.ToArray()); }
public static decimal GetSrid() { BancoDeDados bd = null; bd = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); Comando comando = null; comando = bd.GetComandoSql("select c.valor SRID from tab_configuracao c where c.chave = 'SRID_BASE_REAL'"); object retorno = bd.ExecutarScalar(comando); if (retorno == null) { return(0); } return(Convert.ToDecimal(retorno)); }
public Dictionary <string, string> ObterParameters() { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); Comando com = bancoDeDadosGeo.GetComandoSql("select * from v$nls_parameters"); IDataReader reader = bancoDeDadosGeo.ExecutarReader(com); Dictionary <string, string> dic = new Dictionary <string, string>(); while (reader.Read()) { dic.Add(reader[0].ToString(), reader[1].ToString()); } reader.Close(); return(dic); }
internal bool Excluir(int objectId, string tabela, string primaryKey) { Comando comando = null; try { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); comando = bancoDeDadosGeo.GetComandoSql("delete from " + schemaUsuarioGeo + "." + tabela + " t where t." + primaryKey + " = :objectId"); comando.AdicionarParametroEntrada("objectId", objectId, DbType.Int32); bancoDeDadosGeo.ExecutarNonQuery(comando); } finally { if (comando != null) { comando.Dispose(); } } return(true); }
internal bool ValidarGeometria(int idGeometria, string tabelaRascunho, string primaryKey, int idLayerFeicao, int idProjeto, out string mensagem) { Comando comando = null; try { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); comando = bancoDeDadosGeo.GetComandoSql(@"select x.COLUMN_NAME from all_sdo_geom_metadata x where x.TABLE_NAME = :tabela and x.owner = :schema"); comando.AdicionarParametroEntrada("tabela", DbType.String, 50, tabelaRascunho); comando.AdicionarParametroEntrada("schema", DbType.String, 50, schemaUsuarioGeo); object retorno = bancoDeDadosGeo.ExecutarScalar(comando); if (retorno == null) { throw new Exception("Feição não encontrada"); } bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); comando = bancoDeDadosGeo.GetComandoPlSql(String.Format( @"declare v_geo_val mdsys.sdo_geometry; v_val varchar2(4000); v_projetoId number:= :idProjeto; v_idLayerFeicao number:= :idLayerFeicao; begin :resposta := 'TRUE'; for i in (select t.{0} geometry from {1}.{2} t where t.{3} = :id and t.projeto = v_projetoId and t.feicao = v_idLayerFeicao) loop v_val := DesenhadorWS.ValidarGeometria(i.geometry, v_projetoId); if v_val <> 'TRUE' then if :resposta = 'TRUE' then :resposta := ''; end if; :resposta := :resposta||' '||v_val; end if; end loop; end;" , retorno, schemaUsuarioGeo, tabelaRascunho, primaryKey)); comando.AdicionarParametroEntrada("id", idGeometria, DbType.Int32); comando.AdicionarParametroEntrada("idProjeto", idProjeto, DbType.Int32); comando.AdicionarParametroEntrada("idLayerFeicao", idLayerFeicao, DbType.Int32); comando.AdicionarParametroSaida("resposta", DbType.String, 4000); bancoDeDadosGeo.ExecutarNonQuery(comando); retorno = comando.ObterValorDoParametro("resposta"); if (retorno == null) { throw new Exception("Geometria não encontrada"); } mensagem = retorno.ToString(); } finally { if (comando != null) { comando.Dispose(); } } return(mensagem == "TRUE"); }
internal Retorno ImportarFeicoes(int idNavegador, int idProjeto, bool isFinalizadas) { Comando comando = null; IDataReader reader = null; Projeto projeto = new Projeto(); projeto.TipoNavegador = 1; projeto.Id = idProjeto; try { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); int fila_tipo = 0; switch (idNavegador) { case 1: //Dominialidade if (isFinalizadas) { comando = bancoDeDadosGeo.GetComandoSql(@"select count(*) quantidade from geo_atp where projeto = :projeto "); } else { comando = bancoDeDadosGeo.GetComandoSql(@"select count(*) quantidade from tmp_atp where projeto = :projeto "); } break; case 2: //Atividade if (isFinalizadas) { comando = bancoDeDadosGeo.GetComandoSql(@"select sum(quantidade) quantidade from ( select count(*) quantidade from geo_pativ where projeto = :projeto union all select count(*) quantidade from geo_aativ where projeto = :projeto union all select count(*) quantidade from geo_aiativ where projeto = :projeto union all select count(*) quantidade from geo_lativ where projeto = :projeto ) "); } else { comando = bancoDeDadosGeo.GetComandoSql(@"select sum(quantidade) quantidade from ( select count(*) quantidade from tmp_pativ where projeto = :projeto union all select count(*) quantidade from tmp_aativ where projeto = :projeto union all select count(*) quantidade from tmp_aiativ where projeto = :projeto union all select count(*) quantidade from tmp_lativ where projeto = :projeto ) "); } break; case 3: //Fiscalização comando = bancoDeDadosGeo.GetComandoSql(@"select sum(quantidade) quantidade from ( select count(*) quantidade from tmp_fiscal_area where projeto = :projeto union all select count(*) quantidade from tmp_fiscal_ponto where projeto = :projeto union all select count(*) quantidade from tmp_fiscal_linha where projeto = :projeto )"); break; } comando.AdicionarParametroEntrada("projeto", idProjeto, DbType.Int32); reader = bancoDeDadosGeo.ExecutarReader(comando); int quantidade = 0; if (reader.Read()) { quantidade = Convert.ToInt32(reader["quantidade"]); } if (quantidade == 0) { return(new Retorno(false, "Nenhum projeto geográfico encontrado.")); } if (reader != null) { reader.Close(); reader.Dispose(); } comando = bancoDeDadosGeo.GetComandoSql(@"select fila_tipo from tab_navegador a where a.id = :navegador "); comando.AdicionarParametroEntrada("navegador", idNavegador, DbType.Int32); reader = bancoDeDadosGeo.ExecutarReader(comando); if (reader.Read()) { fila_tipo = Convert.ToInt32(reader["fila_tipo"]); } if (reader != null) { reader.Close(); reader.Dispose(); } #region Importa Feições if (fila_tipo > 0) { if (isFinalizadas) { comando = bancoDeDadosGeo.GetComandoSql(@"begin " + " Operacoesprocessamentogeo.ImportarParaDesenhFinalizada(" + idProjeto + "," + fila_tipo + " ); " + " end;"); } else { comando = bancoDeDadosGeo.GetComandoSql(@"begin " + " Operacoesprocessamentogeo.ImportarParaDesenhProcessada(" + idProjeto + "," + fila_tipo + " ); " + " end;"); } bancoDeDadosGeo.ExecutarNonQuery(comando); } #endregion } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (comando != null) { comando.Dispose(); } } return(new Retorno(true)); }
internal void AtualizarAtributos(List <AtributoFeicao> atributos, string schema, string tabela, int id, string colunaPK) { Comando comando = null; IDataReader reader = null; try { BancoDeDados banco = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); string sqlQuery = @"select t.column_name coluna_nome, (case t.char_length when 0 then t.data_type else t.data_type end) tipo, nvl(t.char_length,0) tamanho from all_tab_cols t where t.owner=upper('" + schema.ToUpper() + @"') and t.table_name = upper('" + tabela + @"') and t.column_name not like '%$%' and t.data_type<>'BLOB' and t.column_name not like upper('geometry') and t.column_name not like upper('" + colunaPK + @"')"; comando = banco.GetComandoSql(sqlQuery); List <ColunaLayerFeicao> colunas = new List <ColunaLayerFeicao>(); reader = banco.ExecutarReader(comando); while (reader.Read()) { ColunaLayerFeicao coluna = new ColunaLayerFeicao(); coluna.Coluna = Convert.ToString(reader["coluna_nome"]); coluna.Tamanho = Convert.ToInt32(reader["tamanho"]); coluna.Alias = Convert.ToString(reader["tipo"]); colunas.Add(coluna); } if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } int qtdColunas = colunas.Count; string valores = string.Empty; comando = banco.GetComandoSql(" "); for (int j = 0; j < qtdColunas; j++) { for (int i = 0; i < atributos.Count; i++) { if (Convert.ToString(atributos[i].Nome).ToUpper() == colunas[j].Coluna.ToUpper() && Convert.ToString(atributos[i].Valor) != null) { valores += colunas[j].Coluna + " = :coluna" + j.ToString() + " , "; if (colunas[j].Alias.ToUpper() == "NUMBER") { comando.AdicionarParametroEntrada("coluna" + j.ToString(), atributos[i].Valor, DbType.Decimal); } else { comando.AdicionarParametroEntrada("coluna" + j.ToString(), atributos[i].Valor, DbType.String); } } } } if (valores != string.Empty) { valores = valores.Substring(0, (valores.Length - 2)); comando.DBCommand.CommandText += "update " + tabela + " set " + valores + " where " + colunaPK + " = :id"; comando.AdicionarParametroEntrada("id", id, DbType.Int32); banco.ExecutarNonQuery(comando); } } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (comando != null) { comando.Dispose(); } } }
internal bool AtualizarRascunho(FeicaoGeometria geoFeicao, int objectid, string tabelaRascunho, string primaryKey, int idLayerFeicao) { OracleConnection connection = null; OracleTransaction transaction = null; OracleCommand comando = null; FonteFeicaoOracleSpatial destino = null; try { if (geoFeicao == null) { throw new ApplicationException("Referência nula do objeto"); } string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); destino = GetConexao(bancoDeDados); destino.Abrir(); connection = destino.Conexao; if (connection != null) { transaction = connection.BeginTransaction(); } comando = new OracleCommand("delete from " + tabelaRascunho + " t where t." + primaryKey + " = :objectid and t.feicao = :feicao ", connection); comando.Parameters.Add("objectid", OracleDbType.Int32); comando.Parameters["objectid"].Value = objectid; comando.Parameters.Add("feicao", OracleDbType.Int32); comando.Parameters["feicao"].Value = idLayerFeicao; comando.ExecuteNonQuery(); ClasseFeicao classeDestino = destino.ObterClasseFeicao(tabelaRascunho); FeicaoAdapter adpt = new FeicaoAdapter(classeDestino); OperadorFeicaoOracleSpatial operador = (OperadorFeicaoOracleSpatial)destino.ObterOperadorFeicao(tabelaRascunho); TecnoGeo.Geografico.Feicao feicao = classeDestino.CriarFeicao(); decimal srid = GetSrid(); OperacaoEspacial operacao = new OperacaoEspacialTransformacao(new CampoGeometrico(), srid, srid); feicao.Geometria = geoFeicao.RetornarGeometria(); if (feicao.Geometria == null) { throw new ApplicationException("Referência nula da geometria"); } foreach (AtributoFeicao a in geoFeicao.Atributos) { if (feicao.Atributos.IndiceDe(a.Nome.ToUpper()) < 0) { continue; } switch (a.Tipo) { case AtributoFeicao.TipoAtributo.Manual: feicao.Atributos[a.Nome.ToUpper()].Valor = a.Valor; break; case AtributoFeicao.TipoAtributo.Sequencia: adpt.Adaptadores[a.Nome.ToUpper()].Origem = TipoOrigem.Sequencia; adpt.Adaptadores[a.Nome.ToUpper()].Valor = a.Valor.ToString(); break; } } feicao.Atributos["FEICAO"].Valor = idLayerFeicao; operador.Inserir(adpt.Transformar(feicao), operacao); transaction.Commit(); } catch { if (transaction != null) { transaction.Rollback(); } throw; } finally { if (transaction != null) { transaction.Dispose(); } if (destino != null) { destino.Fechar(); } if (connection != null) { connection.Close(); connection.Dispose(); } } return(true); }
internal bool Cadastrar(FeicaoGeometria geoFeicao, string tabelaRascunho, int idLayerFeicao) { BancoDeDados bancoDeDados = null; if (geoFeicao == null) { throw new ApplicationException("Referência nula do objeto"); } string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); FonteFeicaoOracleSpatial destino = GetConexao(bancoDeDados); OperadorFeicaoOracleSpatial operador = null; try { destino.Abrir(); ClasseFeicao classeDestino = destino.ObterClasseFeicao(tabelaRascunho); FeicaoAdapter adpt = new FeicaoAdapter(classeDestino); operador = (OperadorFeicaoOracleSpatial)destino.ObterOperadorFeicao(schemaUsuario + "." + tabelaRascunho); Tecnomapas.TecnoGeo.Geografico.Feicao feicao = classeDestino.CriarFeicao(); feicao.Geometria = geoFeicao.RetornarGeometria(); if (feicao.Geometria == null) { throw new ApplicationException("Referência nula da geometria"); } foreach (AtributoFeicao a in geoFeicao.Atributos) { if (feicao.Atributos.IndiceDe(a.Nome.ToUpper()) < 0) { continue; } switch (a.Tipo) { case AtributoFeicao.TipoAtributo.Manual: feicao.Atributos[a.Nome.ToUpper()].Valor = a.Valor; break; case AtributoFeicao.TipoAtributo.Sequencia: adpt.Adaptadores[a.Nome.ToUpper()].Origem = TipoOrigem.Sequencia; adpt.Adaptadores[a.Nome.ToUpper()].Valor = a.Valor.ToString(); break; } } feicao.Atributos["FEICAO"].Valor = idLayerFeicao; decimal srid = GetSrid(); OperacaoEspacial operacao = new OperacaoEspacialTransformacao(new CampoGeometrico(), srid, srid); operador.Inserir(adpt.Transformar(feicao), operacao); operador.Fechar(); } finally { destino.Fechar(); } return(true); }
public List <Item> BuscarListaDeValores(string tabela_referencia, string coluna_referencia) { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"]; BancoDeDados bancoGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); IDataReader reader = null; List <Item> itens = new List <Item>(); Comando comando = null; try { comando = bancoGeo.GetComandoSql(@"select count(*) existe from user_tables t where t.table_name = :tabela "); comando.AdicionarParametroEntrada("tabela", tabela_referencia, DbType.String); try { reader = bancoGeo.ExecutarReader(comando); if (reader == null) { return(null); } if (!reader.Read()) { return(itens); } if (reader["existe"].ToString() == "0") { return(itens); } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } } comando = bancoGeo.GetComandoSql(@"select t.chave, t.texto from " + schemaUsuarioGeo + "." + tabela_referencia + @" t order by texto "); reader = bancoGeo.ExecutarReader(comando); if (reader == null) { return(null); } Item item = null; item = new Item(); item.Chave = ""; item.Texto = "**Selecione**"; itens.Add(item); while (reader.Read()) { item = new Item(); item.Chave = Convert.ToString(reader["chave"]); item.Texto = Convert.ToString(reader["texto"]); itens.Add(item); } } finally { if (comando != null) { comando.Dispose(); } if (reader != null) { reader.Close(); reader.Dispose(); } } return(itens); }
public List <LayerFeicaoQuantidade> ListarQuantidadeFeicoes(int idNavegador, int idProjeto) { Comando comando = null; List <LayerFeicaoQuantidade> lista = new List <LayerFeicaoQuantidade>(); IDataReader reader = null; IDataReader readerQtd = null; try { string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuario"]; BancoDeDados bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexao"); string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"]; BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); string projetos_associados = string.Empty; if (idNavegador == 2) { #region Atividade comando = bancoDeDados.GetComandoSql(@"select id projeto_associado from crt_projeto_geo a where a.empreendimento = (select empreendimento from tmp_projeto_geo pg where pg.id = :projeto union select empreendimento from crt_projeto_geo pg where pg.id = :projeto )"); comando.AdicionarParametroEntrada("projeto", idProjeto, DbType.Int32); try { reader = bancoDeDados.ExecutarReader(comando); while (reader.Read()) { if (!string.IsNullOrEmpty(Convert.ToString(reader["projeto_associado"]))) { projetos_associados += " or PROJETO = " + Convert.ToString(reader["projeto_associado"]); } } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } } #endregion } if (idNavegador == 4) { #region CAR comando = bancoDeDados.GetComandoSql(@"select id projeto_associado from crt_projeto_geo a where a.empreendimento = (select empreendimento from tmp_projeto_geo pg where pg.id = :projeto union select empreendimento from crt_cad_ambiental_rural pg where pg.projeto_geo_id = :projeto )"); comando.AdicionarParametroEntrada("projeto", idProjeto, DbType.Int32); try { reader = bancoDeDados.ExecutarReader(comando); while (reader.Read()) { if (!string.IsNullOrEmpty(Convert.ToString(reader["projeto_associado"]))) { projetos_associados += " or PROJETO = " + Convert.ToString(reader["projeto_associado"]); } } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } } #endregion } comando = bancoDeDadosGeo.GetComandoSql(@"select sqlquery from ( select ' select count('||f.coluna_pk||') quantidade, '||f.id ||' layer, '||f.categoria||' categoria from '|| f.tabela ||' where '||(case when sf.is_editavel = 1 then ' PROJETO = " + idProjeto.ToString() + "' else ' ( PROJETO = " + idProjeto.ToString() + projetos_associados + @")' end) ||(case when sf.filtro is not null then ' and '||sf.filtro else ''end) ||' union' sqlQuery, f.categoria, f.id from tab_servico s, tab_servico_feicao sf, tab_feicao f, tab_navegador_servico ns where ns.servico = s.id and sf.feicao = f.id and sf.servico = s.id and ns.is_principal = 1 and ns.navegador = :navegador union select ' select count('||f.coluna_pk||') quantidade, '||f.id ||' layer, '||f.categoria||' categoria from '|| f.tabela ||(case when sf.filtro is not null then ' where '||sf.filtro else ''end) ||' union' sqlQuery, f.categoria, f.id from tab_servico s, tab_servico_feicao sf, tab_feicao f, tab_navegador_camada ns where ns.servico = s.id and sf.feicao = f.id and sf.servico = s.id and ns.navegador = :navegador and ns.servico = s.id ) order by categoria, id "); comando.AdicionarParametroEntrada("navegador", idNavegador, DbType.Int32); string sqlQuery = string.Empty; LayerFeicaoQuantidade layer = null; try { reader = bancoDeDadosGeo.ExecutarReader(comando); if (reader == null) { return(null); } while (reader.Read()) { sqlQuery += Convert.ToString(reader["sqlQuery"]); } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } } if (sqlQuery.Length > 7) { sqlQuery = sqlQuery.Substring(0, sqlQuery.Length - 6); if (!string.IsNullOrEmpty(sqlQuery.Trim())) { sqlQuery += " order by categoria, layer"; comando = bancoDeDadosGeo.GetComandoSql(sqlQuery); readerQtd = bancoDeDadosGeo.ExecutarReader(comando); while (readerQtd.Read()) { layer = new LayerFeicaoQuantidade(); layer.Categoria = Convert.ToInt32(readerQtd["categoria"]); layer.LayerFeicao = Convert.ToInt32(readerQtd["layer"]); layer.Quantidade = Convert.ToInt32(readerQtd["quantidade"]); lista.Add(layer); } } } } finally { if (comando != null) { comando.Dispose(); } if (reader != null) { reader.Close(); reader.Dispose(); } if (readerQtd != null) { readerQtd.Close(); readerQtd.Dispose(); } } return(lista); }
public LayerFeicao Buscar(Hashtable filtros) { LayerFeicao layerFeicao = null; BancoDeDados banco = null; string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); banco = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); Comando comando = banco.GetComandoSql(@"select t.id, t.nome, t.categoria, t.esquema schema, t.tabela, t.sequencia, t.tipo, t.coluna_pk from tab_feicao t where rownum > 0 "); if (filtros != null && filtros.Count > 0) { if (filtros.ContainsKey("feicao")) { comando.DBCommand.CommandText += " and upper(t.nome) = upper(:feicao) "; comando.AdicionarParametroEntrada("feicao", DbType.String, 4000, filtros["feicao"]); } if (filtros.ContainsKey("id")) { comando.DBCommand.CommandText += " and id = :id"; comando.AdicionarParametroEntrada("id", DbType.Int32, 10, filtros["id"]); } if (filtros.ContainsKey("tabela")) { comando.DBCommand.CommandText += " and upper(t.tabela) = upper(:tabela) "; comando.AdicionarParametroEntrada("tabela", DbType.String, 4000, filtros["tabela"]); } } IDataReader reader = null; try { reader = banco.ExecutarReader(comando); if (reader == null) { return(null); } if (reader.Read()) { layerFeicao = new LayerFeicao(); layerFeicao.Nome = Convert.ToString(reader["nome"]); layerFeicao.Id = Convert.ToInt32(reader["id"]); layerFeicao.Tabela = Convert.ToString(reader["tabela"]); layerFeicao.Schema = Convert.ToString(reader["schema"]); layerFeicao.Sequencia = Convert.ToString(reader["sequencia"]); layerFeicao.TipoGeometria = (TipoGeometriaFeicao)Convert.ToInt32(reader["tipo"]); layerFeicao.ColunaPK = Convert.ToString(reader["coluna_pk"]); } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); } } if (layerFeicao == null) { return(null); } if (filtros == null || !filtros.ContainsKey("SEM_COLUNAS")) { comando = banco.GetComandoSql(@"select f.feicao, f.coluna, f.tipo, f.tamanho, f.tabela_referenciada, f.coluna_referenciada, f.alias, f.is_obrigatorio, f.is_visivel, f.is_editavel from " + schemaUsuario + @".tab_feicao_colunas f where f.is_visivel = 1 and f.feicao = :id "); comando.AdicionarParametroEntrada("id", DbType.Int32, 10, layerFeicao.Id); try { reader = banco.ExecutarReader(comando); ColunaLayerFeicao coluna = null; while (reader.Read()) { coluna = new ColunaLayerFeicao(); coluna.Coluna = Convert.ToString(reader["coluna"]); coluna.Alias = Convert.ToString(reader["alias"]); if (reader["tipo"] != null && !(reader["tipo"] is DBNull)) { coluna.Tipo = Convert.ToInt32(reader["tipo"]); } else { coluna.Tipo = 0; } if (reader["tamanho"] != null && !(reader["tamanho"] is DBNull)) { coluna.Tamanho = Convert.ToDouble(reader["tamanho"]); } else { coluna.Tamanho = 0; } coluna.Tabela_Referencia = Convert.ToString(reader["tabela_referenciada"]); coluna.Coluna_Referencia = Convert.ToString(reader["coluna_referenciada"]); coluna.IsObrigatorio = Convert.ToString(reader["is_obrigatorio"]) == "1"; coluna.IsVisivel = Convert.ToString(reader["is_visivel"]) == "1"; coluna.IsEditavel = Convert.ToString(reader["is_editavel"]) == "1"; layerFeicao.Colunas.Add(coluna); } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); } } } return(layerFeicao); }
public List <CategoriaLayerFeicao> ListarCategoria(int idNavegador, int idProjeto) { Comando comando = null; IDataReader reader = null; IDbConnection connection = null; List <CategoriaLayerFeicao> lista = new List <CategoriaLayerFeicao>(); try { string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); CategoriaLayerFeicao categoria = null; LayerFeicao layerFeicao = null; IDataReader readerQtde = null; int?idCategoria = null; comando = bancoDeDados.GetComandoSql(@"select id_categoria, nome_categoria, id, descricao, feicao, tabela, esquema, sequencia, tipo, coluna_pk, is_principal, servico, url, id_layer, nome_layer, is_visivel, is_editavel, nvl(is_finalizada,0) is_finalizada, ordem_categoria, ordem_feicao from ( select c.id id_categoria, c.nome nome_categoria, f.id, f.nome feicao, f.descricao, f.tabela, f.esquema, f.sequencia, f.tipo, f.coluna_pk, n.is_principal, serv.id servico, serv.url, fei.id_layer, fei.nome_layer, fei.is_visivel, fei.is_editavel, fei.is_finalizada, c.ordem ordem_Categoria, fei.ordem ordem_feicao from tab_categoria_feicao c, tab_feicao f, tab_navegador_servico n, tab_servico serv, tab_servico_feicao fei, tab_navegador nav where c.id = f.categoria and n.servico = fei.servico and fei.feicao = f.id and n.is_principal = 1 and serv.id = n.servico and n.navegador = nav.id and nav.id = :navegador union select c.id id_categoria, c.nome nome_categoria, f.id, f.nome feicao, f.descricao, f.tabela, f.esquema, f.sequencia, f.tipo, f.coluna_pk, 0 is_principal, serv.id servico, serv.url, fei.id_layer, fei.nome_layer, fei.is_visivel, fei.is_editavel, fei.is_finalizada, c.ordem ordem_Categoria, fei.ordem ordem_feicao from tab_categoria_feicao c, tab_feicao f, tab_navegador_camada nav_cam, tab_servico serv, tab_servico_feicao fei where c.id = f.categoria and nav_cam.servico = fei.servico and fei.feicao = f.id and serv.id = nav_cam.servico and nav_cam.navegador = :navegador ) order by ordem_Categoria, ordem_feicao "); comando.AdicionarParametroEntrada("navegador", idNavegador, DbType.Int32); reader = bancoDeDados.ExecutarReader(comando); if (reader == null) { return(null); } while (reader.Read()) { if (reader["id_categoria"] is DBNull) { idCategoria = null; if (categoria == null) { categoria = new CategoriaLayerFeicao(); categoria.Id = -1; categoria.Nome = string.Empty; } } if (!(reader["id_categoria"] is DBNull) && idCategoria != Convert.ToInt32(reader["id_categoria"])) { idCategoria = Convert.ToInt32(reader["id_categoria"]); if (categoria != null) { lista.Add(categoria); } categoria = new CategoriaLayerFeicao(); categoria.Id = Convert.ToInt32(reader["id_categoria"]); categoria.Nome = Convert.ToString(reader["nome_categoria"]); } if (!categoria.LayersFeicoes.Exists(delegate(LayerFeicao f) { return(f.Id == Convert.ToInt32(reader["id"])); })) { layerFeicao = new LayerFeicao(); layerFeicao.Categoria = categoria.Id; layerFeicao.Id = Convert.ToInt32(reader["id"]); layerFeicao.Nome = Convert.ToString(reader["feicao"]); layerFeicao.Descricao = Convert.ToString(reader["descricao"]); layerFeicao.Tabela = Convert.ToString(reader["tabela"]); layerFeicao.Schema = Convert.ToString(reader["esquema"]); if (reader["tipo"] is DBNull) { layerFeicao.TipoGeometria = TipoGeometriaFeicao.NaoDefinido; } else { layerFeicao.TipoGeometria = (TipoGeometriaFeicao)Convert.ToInt32(reader["tipo"]); } layerFeicao.Sequencia = Convert.ToString(reader["sequencia"]); layerFeicao.ServicoId = Convert.ToInt32(reader["servico"]); layerFeicao.ServicoUrlMxd = Convert.ToString(reader["url"]); layerFeicao.ServicoIsPrincipal = Convert.ToString(reader["is_principal"]) != "0"; layerFeicao.Selecionavel = Convert.ToString(reader["is_editavel"]) != "0";; if (reader["id_layer"] is DBNull) { layerFeicao.IdLayer = -1; } else { layerFeicao.IdLayer = Convert.ToInt32(reader["id_layer"]); } layerFeicao.NomeLayer = Convert.ToString(reader["nome_layer"]); layerFeicao.Visivel = Convert.ToString(reader["is_visivel"]) == "1"; layerFeicao.IsFinalizada = Convert.ToString(reader["is_finalizada"]) == "1"; layerFeicao.ColunaPK = Convert.ToString(reader["coluna_pk"]); if (!string.IsNullOrEmpty(layerFeicao.Tabela.Trim())) { comando = bancoDeDados.GetComandoSql(@"select count(*) quantidade from " + layerFeicao.Tabela + " where projeto = :projeto"); comando.AdicionarParametroEntrada("projeto", idProjeto, DbType.Int32); try { readerQtde = bancoDeDados.ExecutarReader(comando); if (readerQtde.Read()) { layerFeicao.Quantidade = Convert.ToInt32(readerQtde["quantidade"]); } } finally { if (readerQtde != null) { readerQtde.Close(); readerQtde.Dispose(); readerQtde = null; } if (comando != null) { comando.Dispose(); comando = null; } } } categoria.LayersFeicoes.Add(layerFeicao); } } if (categoria != null) { lista.Add(categoria); } if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); } comando = bancoDeDados.GetComandoSql(@"select f.feicao id_feicao, f.coluna, f.tipo, f.tamanho, f.tabela_referenciada, f.coluna_referenciada, f.alias, f.is_obrigatorio, f.is_visivel, f.is_editavel, tfco.operacao, tfco.valor, tfco.coluna_obrigada from " + schemaUsuario + @".tab_feicao_colunas f, " + schemaUsuario + @".tab_feicao_col_obrigator tfco where tfco.feicao(+) = f.feicao and tfco.coluna(+) = f.coluna and f.feicao = :id "); comando.AdicionarParametroEntrada("id", DbType.Int32); ColunaLayerFeicao coluna = null; foreach (CategoriaLayerFeicao c in lista) { foreach (LayerFeicao f in c.LayersFeicoes) { comando.SetarValorDoParametro("id", f.Id); reader = bancoDeDados.ExecutarReader(comando); if (reader == null) { continue; } List <ColunaLayerFeicao> colunas = new List <ColunaLayerFeicao>(); while (reader.Read()) { coluna = new ColunaLayerFeicao(); coluna.Coluna = Convert.ToString(reader["coluna"]); coluna.Alias = Convert.ToString(reader["alias"]); if (reader["tipo"] != null && !(reader["tipo"] is DBNull)) { coluna.Tipo = Convert.ToInt32(reader["tipo"]); } else { coluna.Tipo = 0; } if (reader["tamanho"] != null && !(reader["tamanho"] is DBNull)) { coluna.Tamanho = Convert.ToDouble(reader["tamanho"]); } else { coluna.Tamanho = 0; } coluna.Tabela_Referencia = Convert.ToString(reader["tabela_referenciada"]); coluna.Coluna_Referencia = Convert.ToString(reader["coluna_referenciada"]); coluna.IsObrigatorio = Convert.ToString(reader["is_obrigatorio"]) == "1"; coluna.IsVisivel = Convert.ToString(reader["is_visivel"]) == "1"; coluna.IsEditavel = Convert.ToString(reader["is_editavel"]) == "1"; if (reader["operacao"] is DBNull) { coluna.Operacao = TipoOperacao.NaoDefinido; } else { coluna.Operacao = (TipoOperacao)Convert.ToInt32(reader["operacao"]); } coluna.ValorCondicao = Convert.ToString(reader["valor"]); coluna.ColunaObrigada = Convert.ToString(reader["coluna_obrigada"]); colunas.Add(coluna); } f.Colunas = colunas; reader.Close(); reader.Dispose(); } } } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (connection != null) { connection.Close(); connection.Dispose(); } if (comando != null) { comando.Dispose(); } } return(lista); }
internal string[] BuscarFiltrosLayerFeicao(int idNavegador, int idProjeto, out List <string> projetosAssociados) { Comando comando = null; IDataReader reader = null; List <string> lista = new List <string>(); projetosAssociados = new List <string>(); try { string schemaUsuarioGeo = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDadosGeo = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuario"].ToUpper(); BancoDeDados bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexao"); string projetos_associados = string.Empty; if (idNavegador == 2) { comando = bancoDeDados.GetComandoSql(@"select id projeto_associado from crt_projeto_geo a where a.empreendimento = (select empreendimento from tmp_projeto_geo pg where pg.id = :projeto and pg.empreendimento = a.empreendimento union select empreendimento from crt_projeto_geo pg where pg.id = :projeto and pg.empreendimento = a.empreendimento)"); comando.AdicionarParametroEntrada("projeto", idProjeto, DbType.Int32); try { reader = bancoDeDados.ExecutarReader(comando); while (reader.Read()) { if (!string.IsNullOrEmpty(Convert.ToString(reader["projeto_associado"]))) { projetos_associados += " or PROJETO = " + Convert.ToString(reader["projeto_associado"]); projetosAssociados.Add(Convert.ToString(reader["projeto_associado"])); } } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } } } else if (idNavegador == 4 || idNavegador == 5) { comando = bancoDeDados.GetComandoSql(@"select id projeto_associado from crt_projeto_geo a where a.empreendimento = (select empreendimento from tmp_projeto_geo pg where pg.id = :projeto and pg.empreendimento = a.empreendimento union select empreendimento from crt_cad_ambiental_rural pg where pg.projeto_geo_id = :projeto and pg.empreendimento = a.empreendimento)"); comando.AdicionarParametroEntrada("projeto", idProjeto, DbType.Int32); try { reader = bancoDeDados.ExecutarReader(comando); while (reader.Read()) { if (!string.IsNullOrEmpty(Convert.ToString(reader["projeto_associado"]))) { projetos_associados += " or PROJETO = " + Convert.ToString(reader["projeto_associado"]); projetosAssociados.Add(Convert.ToString(reader["projeto_associado"])); } } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } } } comando = bancoDeDadosGeo.GetComandoSql(@"select (case when a.filtro is not null then a.filtro||' and 'else ''end)||(case when a.is_editavel = 1 then ' PROJETO = " + idProjeto.ToString() + "' else ' ( PROJETO = " + idProjeto.ToString() + projetos_associados + @")' end) filtro from tab_servico_feicao a, tab_navegador_servico ns, tab_feicao f where f.id = a.feicao and ns.navegador = :navegador and ns.servico = a.servico and ns.is_principal = 1 order by a.id_layer "); comando.AdicionarParametroEntrada("navegador", idNavegador, DbType.Int32); reader = bancoDeDadosGeo.ExecutarReader(comando); while (reader.Read()) { string filtro = Convert.ToString(reader["filtro"]); lista.Add(filtro); } } finally { if (reader != null) { reader.Close(); reader.Dispose(); } if (comando != null) { comando.Dispose(); } } return(lista.ToArray()); }
internal CenarioServicoArcGis[] BuscarCenarios(int idNavegador) { IDataReader reader = null; List <CenarioServicoArcGis> lista = new List <CenarioServicoArcGis>(); try { string schemaUsuario = ConfigurationManager.AppSettings["SchemaUsuarioGeo"].ToUpper(); BancoDeDados bancoDeDados = BancoDeDadosFactory.CriarBancoDeDados("StringConexaoGeo"); Comando comando = bancoDeDados.GetComandoSql(@"select a.id, a.nome, a.is_ativo isprincipal from " + schemaUsuario + @".tab_cenario_navegador a where a.navegador = :navegador order by a.ordem_exibicao"); comando.AdicionarParametroEntrada("navegador", idNavegador, DbType.Int32); reader = bancoDeDados.ExecutarReader(comando); CenarioServicoArcGis cenario = new CenarioServicoArcGis(); cenario.Id = 0; cenario.Nome = "Branco"; cenario.IsPrincipal = false; cenario.ExibirLogotipo = false; lista.Add(cenario); while (reader.Read()) { cenario = new CenarioServicoArcGis(); cenario.Id = Convert.ToInt32(reader["id"]); cenario.Nome = Convert.ToString(reader["nome"]); cenario.IsPrincipal = Convert.ToString(reader["isprincipal"]) == "1"; cenario.ExibirLogotipo = true; lista.Add(cenario); } if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } List <string> camadas = new List <string>(); comando = bancoDeDados.GetComandoSql("select servico from " + schemaUsuario + @".tab_navegador_camada nc where nc.navegador = :navegador"); comando.AdicionarParametroEntrada("navegador", idNavegador, DbType.Int32); reader = bancoDeDados.ExecutarReader(comando); while (reader.Read()) { camadas.Add(Convert.ToString(reader["servico"])); } if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } if (comando != null) { comando.Dispose(); comando = null; } if (lista != null) { comando = bancoDeDados.GetComandoSql("select a.servico id from " + schemaUsuario + @".tab_cenario_servico a where a.cenario_navegador = :cenario"); comando.AdicionarParametroEntrada("cenario", DbType.Int32); for (int n = 0; n < lista.Count; n++) { comando.SetarValorDoParametro("cenario", lista[n].Id); reader = bancoDeDados.ExecutarReader(comando); List <string> listaServicos = new List <string>(); string servico; while (reader.Read()) { servico = Convert.ToString(reader["id"]); listaServicos.Add(servico); } if (camadas != null) { foreach (string camada in camadas) { listaServicos.Add(camada); } } lista[n].Servicos = listaServicos.ToArray(); if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } } } } finally { if (reader != null) { reader.Close(); reader.Dispose(); reader = null; } } return(lista.ToArray()); }