public ConsideracaoFinal Obter(int fiscalizacaoId, BancoDeDados banco = null)
        {
            ConsideracaoFinal consideracaoFinal = new ConsideracaoFinal();

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(banco))
            {
                Comando comando = bancoDeDados.CriarComando(@"
					select t.id                        Id,
						   t.fiscalizacao              FiscalizacaoId,
						   t.justificar                Justificar,
						   t.descrever                 Descrever,
						   t.tem_reparacao             HaReparacao,
						   t.reparacao                 Reparacao,
						   t.tem_termo_comp            HaTermoCompromisso,
						   t.tem_termo_comp_justificar TermoCompromissoJustificar,
						   t.tid                       Tid,
						   t.arquivo_termo             arquivo_id,
						   ta.nome                     arquivo_nome
					  from {0}tab_fisc_consid_final t,
						   {0}tab_arquivo           ta
					 where t.arquivo_termo = ta.id(+)
					   and t.fiscalizacao = :fiscalizacao"                    , EsquemaBanco);

                comando.AdicionarParametroEntrada("fiscalizacao", fiscalizacaoId, DbType.Int32);

                consideracaoFinal = bancoDeDados.ObterEntity <ConsideracaoFinal>(comando, (IDataReader reader, ConsideracaoFinal item) =>
                {
                    item.Arquivo      = new Arquivo();
                    item.Arquivo.Id   = reader.GetValue <int>("arquivo_id");
                    item.Arquivo.Nome = reader.GetValue <string>("arquivo_nome");
                });

                #region Testemunhas

                comando = bancoDeDados.CriarComando(@"
					select t.id               Id,
						   t.consid_final     ConsideracaoFinalId,
						   t.idaf             TestemunhaIDAF,
						   t.testemunha       TestemunhaId,
						   t.nome             TestemunhaNome,
						   t.endereco         TestemunhaEndereco,
						   t.tid              Tid,
						   t.testemunha_setor TestemunhaSetorId,
                           t.cpf              TestemunhaCPF
					  from {0}tab_fisc_consid_final_test t
					 where t.consid_final = :consid_final"                    , EsquemaBanco);

                comando.AdicionarParametroEntrada("consid_final", consideracaoFinal.Id, DbType.Int32);

                consideracaoFinal.Testemunhas = bancoDeDados.ObterEntityList <ConsideracaoFinalTestemunha>(comando);

                #endregion

                #region Assinantes
                comando = bancoDeDados.CriarComando(@"select ta.id, ta.consid_final, f.id func_id, f.nome func_nome, ta.cargo, c.nome cargo_nome, ta.tid 
					from {0}tab_fisc_consid_final_ass ta, {0}tab_funcionario f, {0}tab_cargo c 
					where ta.funcionario = f.id and ta.cargo = c.id and ta.consid_final = :consid_final"                    , EsquemaBanco);
                comando.AdicionarParametroEntrada("consid_final", consideracaoFinal.Id, DbType.Int32);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    FiscalizacaoAssinante item;
                    while (reader.Read())
                    {
                        item                      = new FiscalizacaoAssinante();
                        item.Id                   = reader.GetValue <int>("id");
                        item.Tid                  = reader.GetValue <String>("tid");
                        item.FuncionarioId        = reader.GetValue <int>("func_id");
                        item.FuncionarioNome      = reader.GetValue <String>("func_nome");
                        item.FuncionarioCargoId   = reader.GetValue <int>("cargo");
                        item.FuncionarioCargoNome = reader.GetValue <String>("cargo_nome");
                        item.Selecionado          = true;

                        consideracaoFinal.Assinantes.Add(item);
                    }
                    reader.Close();
                }
                #endregion

                #region Anexos

                comando = bancoDeDados.CriarComando(@"
				select a.id Id,
					   a.ordem Ordem,
					   a.descricao Descricao,
					   b.nome,
					   b.extensao,
					   b.id arquivo_id,
					   b.caminho,
					   a.tid Tid
				  from {0}tab_fisc_consid_final_arq a, 
					   {0}tab_arquivo b
				 where a.arquivo = b.id
				   and a.consid_final = :consid_final
				 order by a.ordem"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("consid_final", consideracaoFinal.Id, DbType.Int32);

                consideracaoFinal.Anexos = bancoDeDados.ObterEntityList <Anexo>(comando, (IDataReader reader, Anexo item) =>
                {
                    item.Arquivo.Id       = reader.GetValue <int>("arquivo_id");
                    item.Arquivo.Caminho  = reader.GetValue <string>("caminho");
                    item.Arquivo.Nome     = reader.GetValue <string>("nome");
                    item.Arquivo.Extensao = reader.GetValue <string>("extensao");
                });

                #endregion

                #region Anexos IUF

                comando = bancoDeDados.CriarComando(@"
				select a.id Id,
					   a.ordem Ordem,
					   a.descricao Descricao,
					   b.nome,
					   b.extensao,
					   b.id arquivo_id,
					   b.caminho,
					   a.tid Tid
				  from {0}tab_fisc_consid_final_iuf a, 
					   {0}tab_arquivo b
				 where a.arquivo = b.id
				   and a.consid_final = :consid_final
				 order by a.ordem"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("consid_final", consideracaoFinal.Id, DbType.Int32);

                consideracaoFinal.AnexosIUF = bancoDeDados.ObterEntityList <Anexo>(comando, (IDataReader reader, Anexo item) =>
                {
                    item.Arquivo.Id       = reader.GetValue <int>("arquivo_id");
                    item.Arquivo.Caminho  = reader.GetValue <string>("caminho");
                    item.Arquivo.Nome     = reader.GetValue <string>("nome");
                    item.Arquivo.Extensao = reader.GetValue <string>("extensao");
                });

                #endregion
            }
            return(consideracaoFinal);
        }
Exemplo n.º 2
0
        internal Acompanhamento Obter(int id, bool simplificado = false, BancoDeDados banco = null)
        {
            Acompanhamento acompanhamento = new Acompanhamento();

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(banco))
            {
                #region Acompanhamento da Fiscalização

                Comando comando = bancoDeDados.CriarComando(@"select t.id, t.fiscalizacao, t.numero_sufixo, t.data_vistoria, t.situacao, ls.texto situacao_texto, t.data_situacao, 
				t.motivo_situacao, t.agente_fiscal, f.nome agente_fiscal_nome, t.setor, t.area_total, t.area_florestal_nativa, t.reserva_legal, t.possui_area_embargada, 
				t.opniao_area_embargo, t.ativ_area_embargada, t.atviv_area_embargada_especific, t.uso_area_solo, t.caract_solo_area_danificada, t.declividade_media_area, 
				t.infr_resultou_erosao, t.infr_resultou_erosao_especific, t.houve_apreensao_material, t.opniao_destin_material_apreend, t.houve_desrespeito_tad, 
				t.houve_desrespeito_tad_especifi, t.informacoes_relevante_processo, t.neces_repar_dano_amb, t.neces_repar_dano_amb_especific, t.firmou_termo_comprom, 
				t.firmou_termo_comprom_especific, t.arquivo_termo arquivo_termo_id, ter.nome arquivo_termo_nome, t.arquivo, t.tid from tab_acompanhamento_fisc t, 
				lov_acomp_fisc_situacao ls, tab_funcionario f, tab_arquivo ter where t.id = :id and t.situacao = ls.id and t.agente_fiscal = f.id 
				and t.arquivo_termo = ter.id(+)"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("id", id, DbType.Int32);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        acompanhamento.Id                     = id;
                        acompanhamento.FiscalizacaoId         = reader.GetValue <int>("fiscalizacao");
                        acompanhamento.NumeroSufixo           = reader.GetValue <string>("numero_sufixo");
                        acompanhamento.DataVistoria.DataTexto = reader.GetValue <string>("data_vistoria");
                        acompanhamento.SituacaoId             = reader.GetValue <int>("situacao");
                        acompanhamento.SituacaoTexto          = reader.GetValue <string>("situacao_texto");
                        acompanhamento.DataSituacao.DataTexto = reader.GetValue <string>("data_situacao");
                        acompanhamento.Motivo                 = reader.GetValue <string>("motivo_situacao");
                        acompanhamento.AgenteId               = reader.GetValue <int>("agente_fiscal");
                        acompanhamento.AgenteNome             = reader.GetValue <string>("agente_fiscal_nome");
                        acompanhamento.SetorId                = reader.GetValue <int>("setor");
                        acompanhamento.AreaTotal              = reader.GetValue <decimal>("area_total").ToStringTrunc(4);
                        acompanhamento.AreaFlorestalNativa    = reader.GetValue <decimal>("area_florestal_nativa").ToStringTrunc(4);
                        acompanhamento.ReservalegalTipo       = reader.GetValue <int>("reserva_legal");
                        acompanhamento.PossuiAreaEmbargadaOuAtividadeInterditada = reader.GetValue <bool?>("possui_area_embargada");
                        acompanhamento.OpniaoAreaEmbargo      = reader.GetValue <string>("opniao_area_embargo");
                        acompanhamento.AtividadeAreaEmbargada = reader.GetValue <int>("ativ_area_embargada");
                        acompanhamento.AtividadeAreaEmbargadaEspecificarTexto = reader.GetValue <string>("atviv_area_embargada_especific");
                        acompanhamento.UsoAreaSoloDescricao              = reader.GetValue <string>("uso_area_solo");
                        acompanhamento.CaracteristicaSoloAreaDanificada  = reader.GetValue <int>("caract_solo_area_danificada");
                        acompanhamento.AreaDeclividadeMedia              = reader.GetValue <decimal>("declividade_media_area").ToStringTrunc();
                        acompanhamento.InfracaoResultouErosao            = reader.GetValue <int>("infr_resultou_erosao");
                        acompanhamento.InfracaoResultouErosaoEspecificar = reader.GetValue <string>("infr_resultou_erosao_especific");
                        acompanhamento.HouveApreensaoMaterial            = reader.GetValue <bool?>("houve_apreensao_material");
                        acompanhamento.OpniaoDestMaterialApreend         = reader.GetValue <string>("opniao_destin_material_apreend");
                        acompanhamento.HouveDesrespeitoTAD                        = reader.GetValue <int>("houve_desrespeito_tad");
                        acompanhamento.HouveDesrespeitoTADEspecificar             = reader.GetValue <string>("houve_desrespeito_tad_especifi");
                        acompanhamento.InformacoesRelevanteProcesso               = reader.GetValue <string>("informacoes_relevante_processo");
                        acompanhamento.RepararDanoAmbiental                       = reader.GetValue <int>("neces_repar_dano_amb");
                        acompanhamento.RepararDanoAmbientalEspecificar            = reader.GetValue <string>("neces_repar_dano_amb_especific");
                        acompanhamento.FirmouTermoRepararDanoAmbiental            = reader.GetValue <int>("firmou_termo_comprom");
                        acompanhamento.FirmouTermoRepararDanoAmbientalEspecificar = reader.GetValue <string>("firmou_termo_comprom_especific");
                        acompanhamento.PdfLaudo.Id = reader.GetValue <int>("arquivo");
                        acompanhamento.Tid         = reader.GetValue <string>("tid");


                        if (reader["arquivo_termo_id"] != null && !Convert.IsDBNull(reader["arquivo_termo_id"]))
                        {
                            Arquivo arquivo = new Arquivo();
                            arquivo.Id             = reader.GetValue <Int32>("arquivo_termo_id");
                            arquivo.Nome           = reader.GetValue <String>("arquivo_termo_nome");
                            acompanhamento.Arquivo = arquivo;
                        }
                    }

                    reader.Close();
                }

                #endregion Acompanhamento da Fiscalização

                if (acompanhamento == null || acompanhamento.Id <= 0 || simplificado)
                {
                    return(acompanhamento);
                }

                #region Assinantes

                comando = bancoDeDados.CriarComando(@"select ta.id, f.id func_id, f.nome func_nome, ta.cargo, c.nome cargo_nome, ta.tid 
				from {0}tab_acomp_fisc_assinante ta, {0}tab_funcionario f, {0}tab_cargo c where ta.funcionario = f.id and ta.cargo = c.id 
				and ta.acompanhamento = :acompanhamento"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("acompanhamento", acompanhamento.Id, DbType.Int32);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    FiscalizacaoAssinante item;

                    while (reader.Read())
                    {
                        item                      = new FiscalizacaoAssinante();
                        item.Id                   = reader.GetValue <int>("id");
                        item.Tid                  = reader.GetValue <string>("tid");
                        item.FuncionarioId        = reader.GetValue <int>("func_id");
                        item.FuncionarioNome      = reader.GetValue <string>("func_nome");
                        item.FuncionarioCargoId   = reader.GetValue <int>("cargo");
                        item.FuncionarioCargoNome = reader.GetValue <string>("cargo_nome");
                        item.Selecionado          = true;

                        acompanhamento.Assinantes.Add(item);
                    }

                    reader.Close();
                }

                #endregion Assinantes

                #region Anexos

                comando = bancoDeDados.CriarComando(@"select a.id Id, a.ordem Ordem, a.descricao Descricao, b.nome, b.extensao, b.id arquivo_id, b.caminho, a.tid Tid
				from {0}tab_acomp_fisc_arquivo a, {0}tab_arquivo b where a.arquivo = b.id and a.acompanhamento = :acompanhamento order by a.ordem"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("acompanhamento", acompanhamento.Id, DbType.Int32);

                acompanhamento.Anexos = bancoDeDados.ObterEntityList <Anexo>(comando, (IDataReader reader, Anexo item) =>
                {
                    item.Arquivo.Id       = reader.GetValue <int>("arquivo_id");
                    item.Arquivo.Caminho  = reader.GetValue <string>("caminho");
                    item.Arquivo.Nome     = reader.GetValue <string>("nome");
                    item.Arquivo.Extensao = reader.GetValue <string>("extensao");
                });

                #endregion Anexos
            }

            return(acompanhamento);
        }