Exemplo n.º 1
0
        private EnderecoRelatorio ObterEmpEnderecoHistorico(int empId, string empTid, BancoDeDados banco = null)
        {
            EnderecoRelatorio objeto  = new EnderecoRelatorio();
            Comando           comando = null;

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(banco))
            {
                comando = bancoDeDados.CriarComando(@"select ee.bairro Bairro, 
				   ee.cep Cep, 
				   ee.complemento Complemento, 
				   ee.distrito, 
				   e.sigla EstadoTexto, 
				   ee.logradouro Logradouro, 
				   ee.municipio_texto MunicipioTexto 
				  from {0}hst_empreendimento he, {0}hst_empreendimento_endereco ee, {0}lov_estado e 
				  where he.empreendimento_id = :empId
				  and he.tid = :empTid
				  and he.id = ee.id_hst
				  and ee.estado_id = e.id"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("empId", empId, DbType.Int32);
                comando.AdicionarParametroEntrada("empTid", empTid, DbType.String);

                objeto = bancoDeDados.ObterEntity <EnderecoRelatorio>(comando);
            }

            return(objeto);
        }
Exemplo n.º 2
0
        private EnderecoRelatorio ObterEmpEndereco(int empId, BancoDeDados banco = null)
        {
            EnderecoRelatorio objeto  = new EnderecoRelatorio();
            Comando           comando = null;

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(banco))
            {
                comando = bancoDeDados.CriarComando(@"select ee.bairro Bairro, ee.cep Cep, ee.complemento Complemento, ee.distrito, e.sigla EstadoTexto, 
				ee.logradouro Logradouro, m.texto MunicipioTexto from {0}tab_empreendimento_endereco ee, {0}lov_estado e, {0}lov_municipio m 
				where ee.estado = e.id and ee.municipio = m.id and ee.correspondencia = 0 and ee.empreendimento = :empId"                , EsquemaBanco);

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

                objeto = bancoDeDados.ObterEntity <EnderecoRelatorio>(comando);
            }

            return(objeto);
        }
        internal UnidadeConsolidacaoRelatorio Obter(int projetoDigitalId)
        {
            UnidadeConsolidacaoRelatorio unidadeConsolidacaoRelatorio = new UnidadeConsolidacaoRelatorio();

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(EsquemaBancoCredenciado))
            {
                Comando comando = bancoDeDados.CriarComando(@"select uc.id, te.id empreendimentoID, te.denominador, te.cnpj, uc.codigo_uc, uc.local_livro_disponivel, tp.situacao, 
					uc.tipo_apresentacao_produto, tec.easting_utm, tec.northing_utm from {0}tab_empreendimento te, {0}tab_empreendimento_coord tec, {0}crt_unidade_consolidacao uc, 
					{0}tab_projeto_digital tp where uc.empreendimento = te.id and tec.empreendimento = te.id and tp.empreendimento = uc.empreendimento and tp.id = :id"                    , EsquemaBancoCredenciado);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        unidadeConsolidacaoRelatorio.Id                         = reader.GetValue <int>("id");
                        unidadeConsolidacaoRelatorio.CodigoUc                   = reader.GetValue <long>("codigo_uc");
                        unidadeConsolidacaoRelatorio.LocalLivro                 = reader.GetValue <string>("local_livro_disponivel");
                        unidadeConsolidacaoRelatorio.TipoApresentacao           = reader.GetValue <string>("tipo_apresentacao_produto");
                        unidadeConsolidacaoRelatorio.Situacao                   = reader.GetValue <int>("situacao");
                        unidadeConsolidacaoRelatorio.Empreendimento.Id          = reader.GetValue <int>("empreendimentoID");
                        unidadeConsolidacaoRelatorio.Empreendimento.Denominador = reader.GetValue <string>("denominador");
                        unidadeConsolidacaoRelatorio.Empreendimento.CNPJ        = reader.GetValue <string>("cnpj");
                        unidadeConsolidacaoRelatorio.Empreendimento.EastingUtm  = reader.GetValue <int>("easting_utm");
                        unidadeConsolidacaoRelatorio.Empreendimento.NorthingUtm = reader.GetValue <int>("northing_utm");
                    }
                }

                #region Responsaveis do empreendimento

                comando = bancoDeDados.CriarComando(@"
				select nvl(p.razao_social, p.nome) NomeRazao, nvl(p.cpf, p.cnpj) CpfCnpj, lt.texto TipoTexto 
				from tab_empreendimento_responsavel e, tab_pessoa p, lov_empreendimento_tipo_resp lt 
				where p.id = e.responsavel and e.tipo = lt.id and e.empreendimento = :empreendimento"                );

                comando.AdicionarParametroEntrada("empreendimento", unidadeConsolidacaoRelatorio.Empreendimento.Id, DbType.Int32);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        ResponsavelRelatorio responsavel = new ResponsavelRelatorio();
                        responsavel.NomeRazao = reader.GetValue <string>("NomeRazao");
                        responsavel.CpfCnpj   = reader.GetValue <string>("CpfCnpj");
                        responsavel.TipoTexto = reader.GetValue <string>("TipoTexto");

                        unidadeConsolidacaoRelatorio.Empreendimento.Responsaveis.Add(responsavel);
                    }
                }

                #endregion

                #region Endereço do empreendimento

                comando = bancoDeDados.CriarComando(@"select e.cep, e.logradouro, e.bairro, e.distrito, e.numero, m.texto MunicipioTexto, uf.sigla EstadoSigla, e.corrego, e.complemento, e.correspondencia
					from {0}tab_empreendimento_endereco e, {0}lov_municipio m, {0}lov_estado uf where m.id = e.municipio and uf.id = m.estado and e.empreendimento = :empreendimento"                    , EsquemaBancoCredenciado);

                comando.AdicionarParametroEntrada("empreendimento", unidadeConsolidacaoRelatorio.Empreendimento.Id, DbType.Int32);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        EnderecoRelatorio endereco = new EnderecoRelatorio()
                        {
                            Cep             = reader.GetValue <string>("cep"),
                            Logradouro      = reader.GetValue <string>("logradouro"),
                            Bairro          = reader.GetValue <string>("bairro"),
                            Distrito        = reader.GetValue <string>("distrito"),
                            Numero          = reader.GetValue <string>("numero"),
                            MunicipioTexto  = reader.GetValue <string>("MunicipioTexto"),
                            EstadoSigla     = reader.GetValue <string>("EstadoSigla"),
                            Corrego         = reader.GetValue <string>("corrego"),
                            Complemento     = reader.GetValue <string>("complemento"),
                            Correspondencia = reader.GetValue <int>("correspondencia")
                        };

                        unidadeConsolidacaoRelatorio.Empreendimento.Enderecos.Add(endereco);
                    }
                }

                #endregion

                #region Meio Contato

                comando = bancoDeDados.CriarComando(@"select t.valor, t.meio_contato, m.texto meio_contato_texto from {0}tab_empreendimento_contato t, 
					{0}tab_meio_contato m where m.id = t.meio_contato and t.empreendimento = :empreendimento"                    , EsquemaBancoCredenciado);

                comando.AdicionarParametroEntrada("empreendimento", unidadeConsolidacaoRelatorio.Empreendimento.Id, DbType.Int32);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        ContatoRelatorio contato = new ContatoRelatorio()
                        {
                            Valor     = reader.GetValue <string>("valor"),
                            TipoTexto = reader.GetValue <string>("meio_contato_texto")
                        };

                        switch (reader.GetValue <int>("meio_contato"))
                        {
                        case 1:
                            contato.TipoContato = eTipoContato.TelefoneResidencial;
                            break;

                        case 2:
                            contato.TipoContato = eTipoContato.TelefoneCelular;
                            break;

                        case 3:
                            contato.TipoContato = eTipoContato.TelefoneFax;
                            break;

                        case 4:
                            contato.TipoContato = eTipoContato.TelefoneComercial;
                            break;

                        case 5:
                            contato.TipoContato = eTipoContato.Email;
                            break;

                        case 6:
                            contato.TipoContato = eTipoContato.NomeContato;
                            break;
                        }

                        unidadeConsolidacaoRelatorio.Empreendimento.MeiosContatos.Add(contato);
                    }
                }

                #endregion

                #region Cultura

                comando = bancoDeDados.CriarComando(@"select c.capacidade_mes, c.unidade_medida, lu.texto unidade_medida_texto, tc.texto CulturaNome, cc.cultivar CultivarNome from {0}crt_unidade_cons_cultivar c, 
					{0}tab_cultura tc, {0}tab_cultura_cultivar cc, {0}lov_crt_un_conso_un_medida lu where tc.id = c.cultura and cc.id(+) = c.cultivar and lu.id = c.unidade_medida 
					and c.unidade_consolidacao = :unidade"                    , EsquemaBancoCredenciado);

                comando.AdicionarParametroEntrada("unidade", unidadeConsolidacaoRelatorio.Id, DbType.Int32);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        CultivarRelatorio cultivar = new CultivarRelatorio()
                        {
                            CulturaNome        = reader.GetValue <string>("CulturaNome"),
                            CapacidadeMes      = reader.GetValue <string>("capacidade_mes"),
                            UnidadeMedida      = reader.GetValue <int>("unidade_medida"),
                            UnidadeMedidaTexto = reader.GetValue <string>("unidade_medida_texto"),
                            CultivarNome       = reader.GetValue <string>("CultivarNome")
                        };

                        unidadeConsolidacaoRelatorio.Cultivar.Add(cultivar);
                    }
                }

                #endregion

                #region Responsaveis Tecnico

                comando = bancoDeDados.CriarComando(@"select nvl(p.nome, p.razao_social) NomeRazao, r.numero_hab_cfo_cfoc Habilitacao, 
				(select t.extensao_habilitacao from {0}tab_hab_emi_cfo_cfoc t where t.responsavel = c.id) ExtensaoHabilitacao 
				from {0}crt_unida_conso_resp_tec r, {0}crt_unidade_consolidacao u, {0}tab_credenciado c, {0}tab_pessoa p 
				where u.id = r.unidade_consolidacao and c.id = r.responsavel_tecnico and p.id = c.pessoa and u.empreendimento = :empreendimento"                , EsquemaBancoCredenciado);

                comando.AdicionarParametroEntrada("empreendimento", unidadeConsolidacaoRelatorio.Empreendimento.Id, DbType.Int32);
                bool extensao = false;

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        extensao = reader.GetValue <bool>("ExtensaoHabilitacao");

                        ResponsavelRelatorio responsavel = new ResponsavelRelatorio()
                        {
                            NomeRazao   = reader.GetValue <string>("NomeRazao"),
                            Habilitacao = extensao ? reader.GetValue <string>("Habilitacao") + " - ES" : reader.GetValue <string>("Habilitacao")
                        };

                        unidadeConsolidacaoRelatorio.ResponsaveisTecnicos.Add(responsavel);
                    }
                }

                #endregion
            }

            return(unidadeConsolidacaoRelatorio);
        }
Exemplo n.º 4
0
        public RequerimentoRelatorio Obter(int id)
        {
            RequerimentoRelatorio requerimento = new RequerimentoRelatorio();
            string tid = string.Empty;
            int    hst = 0;
            int    aux = 0;

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(EsquemaBanco))
            {
                #region Obter TID

                Comando comando = bancoDeDados.CriarComando(@"select (case when r.situacao = 3 then 
				(select h.tid from {0}hst_requerimento h where h.data_execucao = (select max(a.data_execucao) from {0}hst_requerimento a where a.requerimento_id = :id and a.situacao_id = 2)) 
				else r.tid end) tid from {0}tab_requerimento r where r.id = :id"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("id", id, DbType.Int32);
                tid = bancoDeDados.ExecutarScalar <string>(comando);

                #endregion

                #region Requerimento

                comando = bancoDeDados.CriarComando(@"
				select r.id,
					r.autor_id,
					r.interessado_id,
					r.empreendimento_id,
					r.situacao_id,
					r.situacao_texto,
					r.agendamento_texto,
					se.municipio_texto,
					r.setor_id,
					r.informacoes,
					trunc(r.data_criacao) data_criacao,
					to_char(r.data_criacao, 'dd') dia,
					to_char(r.data_criacao, 'MM') mes,
					to_char(r.data_criacao, 'yyyy') ano
				from {0}hst_requerimento r, {0}hst_setor s, {0}hst_setor_endereco se
				where r.setor_id = s.setor_id(+)
				and r.setor_tid = se.tid(+)
				and s.id = se.id_hst
				and r.requerimento_id = :id
				and r.tid = :tid"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("id", id, DbType.Int32);
                comando.AdicionarParametroEntrada("tid", DbType.String, 36, tid);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        hst = reader.GetValue <int>("id");

                        requerimento.Id                  = id;
                        requerimento.AutorId             = reader.GetValue <int>("autor_id");
                        requerimento.Interessado.Id      = reader.GetValue <int>("interessado_id");
                        requerimento.Empreendimento.Id   = reader.GetValue <int>("empreendimento_id");
                        requerimento.SituacaoId          = reader.GetValue <int>("situacao_id");
                        requerimento.SituacaoTexto       = reader.GetValue <string>("situacao_texto");
                        requerimento.AgendamentoVistoria = reader.GetValue <string>("agendamento_texto");
                        requerimento.Municipio           = reader.GetValue <string>("municipio_texto");
                        requerimento.SetorId             = reader.GetValue <int>("setor_id");
                        requerimento.Informacoes         = reader.GetValue <string>("informacoes");
                        requerimento.DataCadastro        = reader.GetValue <DateTime>("data_criacao");
                        requerimento.DiaCadastro         = reader.GetValue <string>("dia");
                        int mes = reader.GetValue <int>("mes");
                        requerimento.MesCadastro = _configSys.Obter <List <String> >(ConfiguracaoSistema.KeyMeses).ElementAt(mes - 1);
                        requerimento.AnoCadastro = reader.GetValue <string>("ano");
                    }

                    reader.Close();
                }

                #endregion

                #region Atividades

                comando = bancoDeDados.CriarComando(@"
									select a.id, a.atividade, a.tid, b.atividade atividade_texto, b.conclusao
									  from {0}tab_requerimento_atividade a, {0}tab_atividade b
									 where a.atividade = b.id
									   and a.requerimento = :id"                                    , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    RequerimentoAtividadeRelatorio atividade;

                    while (reader.Read())
                    {
                        atividade = new RequerimentoAtividadeRelatorio();
                        atividade.IdRelacionamento = Convert.ToInt32(reader["id"]);
                        atividade.Id            = Convert.ToInt32(reader["atividade"]);
                        atividade.NomeAtividade = reader["atividade_texto"].ToString();
                        atividade.Conclusao     = reader["conclusao"].ToString();

                        #region Atividades/Finalidades/Modelos

                        comando = bancoDeDados.CriarComando(@"
												select a.id,
														a.finalidade,
														ltf.texto                finalidade_texto,
														a.modelo,
														tm.nome                  modelo_nome,
														a.titulo_anterior_tipo,
														a.titulo_anterior_id,
														a.titulo_anterior_numero,
														a.modelo_anterior_id,
														a.modelo_anterior_nome,
														a.modelo_anterior_sigla,
														a.orgao_expedidor
													from {0}tab_requerimento_ativ_finalida a,
														 {0}tab_titulo_modelo              tm,
														 {0}lov_titulo_finalidade          ltf
													where a.modelo = tm.id
													and a.finalidade = ltf.id(+)
													and a.requerimento_ativ = :id"                                                    , EsquemaBanco);

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

                        using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                        {
                            Finalidade fin;

                            while (readerAux.Read())
                            {
                                fin = new Finalidade();
                                fin.IdRelacionamento = Convert.ToInt32(readerAux["id"]);
                                fin.OrgaoExpedidor   = readerAux["orgao_expedidor"].ToString();

                                if (readerAux["finalidade"] != DBNull.Value)
                                {
                                    fin.Id    = Convert.ToInt32(readerAux["finalidade"]);
                                    fin.Texto = readerAux["finalidade_texto"].ToString();
                                }

                                if (readerAux["modelo"] != DBNull.Value)
                                {
                                    fin.TituloModelo      = Convert.ToInt32(readerAux["modelo"]);
                                    fin.TituloModeloTexto = readerAux["modelo_nome"].ToString();
                                }

                                if (readerAux["modelo_anterior_id"] != DBNull.Value)
                                {
                                    fin.TituloModeloAnteriorId = Convert.ToInt32(readerAux["modelo_anterior_id"]);
                                }

                                fin.TituloModeloAnteriorTexto = readerAux["modelo_anterior_nome"].ToString();
                                fin.TituloModeloAnteriorSigla = readerAux["modelo_anterior_sigla"].ToString();

                                if (readerAux["titulo_anterior_tipo"] != DBNull.Value)
                                {
                                    fin.TituloAnteriorTipo = Convert.ToInt32(readerAux["titulo_anterior_tipo"]);
                                }

                                if (readerAux["titulo_anterior_id"] != DBNull.Value)
                                {
                                    fin.TituloAnteriorId = Convert.ToInt32(readerAux["titulo_anterior_id"]);
                                }

                                fin.TituloAnteriorNumero = readerAux["titulo_anterior_numero"].ToString();
                                fin.EmitidoPorInterno    = (fin.TituloAnteriorTipo != 3);
                                atividade.Finalidades.Add(fin);
                            }

                            readerAux.Close();
                        }

                        #endregion

                        requerimento.Atividades.Add(atividade);
                    }

                    reader.Close();
                }

                #endregion

                #region Interessado

                comando = bancoDeDados.CriarComando(@"
				select p.id,
					p.tipo,
					p.cpf,
					p.nome,
					p.rg,
					p.apelido,
					tp.texto profissao,
					p.cnpj,
					p.razao_social,
					p.ie,
					p.nome_fantasia
				from {0}hst_requerimento    r,
					{0}hst_pessoa           p,
					{0}hst_pessoa_profissao pp,
					{0}tab_profissao        tp
				where r.interessado_id = p.pessoa_id
				and r.interessado_tid = p.tid
				and p.data_execucao = (select max(h.data_execucao) from {0}hst_pessoa h where h.pessoa_id = p.pessoa_id and h.tid = p.tid)
				and p.id = pp.id_hst(+)
				and pp.profissao_id = tp.id(+)
				and r.id = :hst"                , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        aux = reader.GetValue <int>("id");

                        requerimento.Interessado.Id   = requerimento.Interessado.Id;
                        requerimento.Interessado.Tipo = reader.GetValue <int>("tipo");

                        if (requerimento.Interessado.IsFisica)
                        {
                            requerimento.Interessado.Fisica.CPF       = reader.GetValue <string>("cpf");
                            requerimento.Interessado.Fisica.Nome      = reader.GetValue <string>("nome");
                            requerimento.Interessado.Fisica.RG        = reader.GetValue <string>("rg");
                            requerimento.Interessado.Fisica.Apelido   = reader.GetValue <string>("apelido");
                            requerimento.Interessado.Fisica.Profissao = reader.GetValue <string>("profissao");
                        }
                        else                         // juridica
                        {
                            requerimento.Interessado.Juridica.CNPJ         = reader.GetValue <string>("cnpj");
                            requerimento.Interessado.Juridica.RazaoSocial  = reader.GetValue <string>("razao_social");
                            requerimento.Interessado.Juridica.IE           = reader.GetValue <string>("ie");
                            requerimento.Interessado.Juridica.NomeFantasia = reader.GetValue <string>("nome_fantasia");
                        }
                    }

                    #region Meio de Contato

                    comando = bancoDeDados.CriarComando(@"select pc.pes_meio_cont_id id, pc.meio_contato_id, c.texto contato_texto, pc.valor
					from {0}hst_pessoa_meio_contato pc, {0}tab_meio_contato c where pc.meio_contato_id = c.id and pc.id_hst = :hst"                    , EsquemaBanco);

                    comando.AdicionarParametroEntrada("hst", aux, DbType.Int32);

                    using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                    {
                        ContatoRelatorio contato;
                        while (readerAux.Read())
                        {
                            contato             = new ContatoRelatorio();
                            contato.Id          = readerAux.GetValue <int>("id");
                            contato.PessoaId    = requerimento.Interessado.Id;
                            contato.TipoContato = (eTipoContato)Enum.Parse(contato.TipoContato.GetType(), readerAux.GetValue <string>("meio_contato_id"));
                            contato.TipoTexto   = readerAux.GetValue <string>("contato_texto");
                            contato.Valor       = readerAux.GetValue <string>("valor");
                            requerimento.Interessado.MeiosContatos.Add(contato);
                        }

                        readerAux.Close();
                    }

                    #endregion

                    #region Endereços

                    comando = bancoDeDados.CriarComando(@"
					select e.endereco_id id,
						e.cep,
						e.logradouro,
						e.bairro,
						e.estado_id,
						le.sigla estado_sigla,
						e.municipio_id,
						e.municipio_texto,
						e.numero,
						e.complemento,
						e.distrito
					from {0}hst_pessoa_endereco e, {0}lov_estado le
					where e.estado_id = le.id
					and e.id_hst = :hst"                    , EsquemaBanco);

                    comando.AdicionarParametroEntrada("hst", aux, DbType.Int32);

                    using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                    {
                        if (readerAux.Read())
                        {
                            requerimento.Interessado.Endereco.Id             = readerAux.GetValue <int>("id");
                            requerimento.Interessado.Endereco.Cep            = readerAux.GetValue <string>("cep");
                            requerimento.Interessado.Endereco.Logradouro     = readerAux.GetValue <string>("logradouro");
                            requerimento.Interessado.Endereco.Bairro         = readerAux.GetValue <string>("bairro");
                            requerimento.Interessado.Endereco.EstadoId       = readerAux.GetValue <int>("estado_id");
                            requerimento.Interessado.Endereco.EstadoSigla    = readerAux.GetValue <string>("estado_sigla");
                            requerimento.Interessado.Endereco.MunicipioId    = readerAux.GetValue <int>("municipio_id");
                            requerimento.Interessado.Endereco.MunicipioTexto = readerAux.GetValue <string>("municipio_texto");
                            requerimento.Interessado.Endereco.Numero         = readerAux.GetValue <string>("numero");
                            requerimento.Interessado.Endereco.Complemento    = readerAux.GetValue <string>("complemento");
                            requerimento.Interessado.Endereco.Distrito       = readerAux.GetValue <string>("distrito");
                        }

                        readerAux.Close();
                    }

                    #endregion

                    reader.Close();
                }

                #endregion

                #region Responsáveis

                comando = bancoDeDados.CriarComando(@"
				select p.id,
					r.responsavel_id,
					r.funcao_texto,
					r.numero_art,
					nvl(p.nome, p.razao_social) nome,
					nvl(p.cpf, p.cnpj) cpf_cnpj,
					nvl(p.rg, p.ie) rg_ie,
					p.tipo,
					trunc(p.data_nascimento) data_nascimento
				from {0}hst_requerimento_responsavel r, {0}hst_pessoa p
				where r.responsavel_id = p.pessoa_id
				and r.responsavel_tid = p.tid
				and p.data_execucao = (select max(h.data_execucao) from {0}hst_pessoa h where h.pessoa_id = p.pessoa_id and h.tid = p.tid)
				and r.id_hst = :hst"                , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    ResponsavelTecnicoRelatorio responsavel;
                    while (reader.Read())
                    {
                        aux = reader.GetValue <int>("id");

                        responsavel                = new ResponsavelTecnicoRelatorio();
                        responsavel.Id             = reader.GetValue <int>("responsavel_id");
                        responsavel.FuncaoTexto    = reader.GetValue <string>("funcao_texto");
                        responsavel.CpfCnpj        = reader.GetValue <string>("cpf_cnpj");
                        responsavel.RgIe           = reader.GetValue <string>("rg_ie");
                        responsavel.NomeRazao      = reader.GetValue <string>("nome");
                        responsavel.NumeroArt      = reader.GetValue <string>("numero_art");
                        responsavel.DataVencimento = "Falta";

                        if (reader["data_nascimento"] != null && !Convert.IsDBNull(reader["data_nascimento"]))
                        {
                            responsavel.DataNascimento = reader.GetValue <DateTime>("data_nascimento").ToShortDateString();
                        }

                        #region Meio de Contato

                        comando = bancoDeDados.CriarComando(@"select pc.pes_meio_cont_id id, pc.meio_contato_id, c.texto contato_texto, pc.valor
						from {0}hst_pessoa_meio_contato pc, {0}tab_meio_contato c where pc.meio_contato_id = c.id and pc.id_hst = :hst"                        , EsquemaBanco);

                        comando.AdicionarParametroEntrada("hst", aux, DbType.Int32);

                        using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                        {
                            ContatoRelatorio contato;
                            while (readerAux.Read())
                            {
                                contato             = new ContatoRelatorio();
                                contato.Id          = readerAux.GetValue <int>("id");
                                contato.PessoaId    = responsavel.Id;
                                contato.TipoContato = (eTipoContato)Enum.Parse(contato.TipoContato.GetType(), readerAux.GetValue <string>("meio_contato_id"));
                                contato.TipoTexto   = readerAux.GetValue <string>("contato_texto");
                                contato.Valor       = readerAux.GetValue <string>("valor");
                                responsavel.MeiosContatos.Add(contato);
                            }

                            readerAux.Close();
                        }

                        #endregion

                        #region Endereços

                        comando = bancoDeDados.CriarComando(@"
						select e.endereco_id id,
							e.cep,
							e.logradouro,
							e.bairro,
							e.estado_id,
							le.sigla estado_sigla,
							e.municipio_id,
							e.municipio_texto,
							e.numero,
							e.complemento,
							e.distrito
						from {0}hst_pessoa_endereco e, {0}lov_estado le
						where e.estado_id = le.id
						and e.id_hst = :hst"                        , EsquemaBanco);

                        comando.AdicionarParametroEntrada("hst", aux, DbType.Int32);

                        using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                        {
                            if (readerAux.Read())
                            {
                                responsavel.Endereco.Id             = readerAux.GetValue <int>("id");
                                responsavel.Endereco.Cep            = readerAux.GetValue <string>("cep");
                                responsavel.Endereco.Logradouro     = readerAux.GetValue <string>("logradouro");
                                responsavel.Endereco.Bairro         = readerAux.GetValue <string>("bairro");
                                responsavel.Endereco.EstadoId       = readerAux.GetValue <int>("estado_id");
                                responsavel.Endereco.EstadoSigla    = readerAux.GetValue <string>("estado_sigla");
                                responsavel.Endereco.MunicipioId    = readerAux.GetValue <int>("municipio_id");
                                responsavel.Endereco.MunicipioTexto = readerAux.GetValue <string>("municipio_texto");
                                responsavel.Endereco.Numero         = readerAux.GetValue <string>("numero");
                                responsavel.Endereco.Complemento    = readerAux.GetValue <string>("complemento");
                                responsavel.Endereco.Distrito       = readerAux.GetValue <string>("distrito");
                            }

                            readerAux.Close();
                        }

                        #endregion

                        requerimento.Responsaveis.Add(responsavel);
                    }

                    reader.Close();
                }

                #endregion

                #region Empreendimento

                comando = bancoDeDados.CriarComando(@"
				select e.id,
					e.codigo,
					e.cnpj,
					e.segmento_texto,
					e.denominador,
					e.nome_fantasia,
					a.atividade
				from {0}hst_requerimento            r,
					{0}hst_empreendimento           e,
					{0}hst_empreendimento_atividade a
				where r.empreendimento_id = e.empreendimento_id
				and r.empreendimento_tid = e.tid
				and e.atividade_id = a.atividade_id(+)
				and e.atividade_tid = a.tid(+)
				and r.id = :hst"                , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        aux = reader.GetValue <int>("id");

                        requerimento.Empreendimento.Id             = requerimento.Empreendimento.Id;
                        requerimento.Empreendimento.Codigo         = reader.GetValue <int>("codigo");
                        requerimento.Empreendimento.CNPJ           = reader.GetValue <string>("cnpj");
                        requerimento.Empreendimento.SegmentoTexto  = reader.GetValue <string>("segmento_texto");
                        requerimento.Empreendimento.NomeRazao      = reader.GetValue <string>("denominador");
                        requerimento.Empreendimento.NomeFantasia   = reader.GetValue <string>("nome_fantasia");
                        requerimento.Empreendimento.AtividadeTexto = reader.GetValue <string>("atividade");
                    }

                    #region Endereços

                    comando = bancoDeDados.CriarComando(@"
					select e.endereco_id id,
						e.correspondencia,
						e.cep,
						e.logradouro,
						e.bairro,
						e.estado_id,
						le.sigla estado_sigla,
						e.municipio_id,
						e.municipio_texto,
						e.numero,
						e.complemento,
						e.corrego,
						(case when e.zona = 1 then 'Urbana' else 'Rural' end) zona,
						e.distrito,
						e.complemento
					from {0}hst_empreendimento_endereco e,
						{0}lov_estado                   le
					where e.estado_id = le.id(+)
					and e.id_hst = :hst"                    , EsquemaBanco);

                    comando.AdicionarParametroEntrada("hst", aux, DbType.Int32);

                    using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                    {
                        EnderecoRelatorio end;
                        while (readerAux.Read())
                        {
                            end    = new EnderecoRelatorio();
                            end.Id = readerAux.GetValue <int>("id");
                            end.Correspondencia = readerAux.GetValue <int>("correspondencia");
                            end.Cep             = readerAux.GetValue <string>("cep");
                            end.Logradouro      = readerAux.GetValue <string>("logradouro");
                            end.Bairro          = readerAux.GetValue <string>("bairro");
                            end.EstadoId        = readerAux.GetValue <int>("estado_id");
                            end.EstadoSigla     = readerAux.GetValue <string>("estado_sigla");
                            end.MunicipioId     = readerAux.GetValue <int>("municipio_id");
                            end.MunicipioTexto  = readerAux.GetValue <string>("municipio_texto");
                            end.Numero          = readerAux.GetValue <string>("numero");
                            end.Complemento     = readerAux.GetValue <string>("complemento");
                            end.Corrego         = readerAux.GetValue <string>("corrego");
                            end.Zona            = readerAux.GetValue <string>("zona");
                            end.Distrito        = readerAux.GetValue <string>("distrito");
                            end.Complemento     = readerAux.GetValue <string>("complemento");
                            requerimento.Empreendimento.Enderecos.Add(end);
                        }

                        readerAux.Close();
                    }

                    #endregion

                    #region Coordenada

                    comando = bancoDeDados.CriarComando(@"
					select ec.coordenada_id,
						ec.tipo_coordenada_id,
						ec.tipo_coordenada_texto,
						ec.datum_id,
						ec.easting_utm,
						ec.northing_utm,
						ec.fuso_utm,
						ec.hemisferio_utm_id,
						ec.latitude_gms,
						ec.longitude_gms,
						ec.latitude_gdec,
						ec.longitude_gdec,
						ec.forma_coleta_texto,
						ec.local_coleta_texto,
						ec.datum_texto,
						ec.hemisferio_utm_texto
					from {0}hst_empreendimento_coord ec
					where ec.id_hst = :hst"                    , EsquemaBanco);

                    comando.AdicionarParametroEntrada("hst", aux, DbType.Int32);

                    using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                    {
                        if (readerAux.Read())
                        {
                            requerimento.Empreendimento.Coordenada.Id                 = readerAux.GetValue <int>("coordenada_id");
                            requerimento.Empreendimento.Coordenada.Tipo.Id            = readerAux.GetValue <int>("tipo_coordenada_id");
                            requerimento.Empreendimento.Coordenada.Tipo.Texto         = readerAux.GetValue <string>("tipo_coordenada_texto");
                            requerimento.Empreendimento.Coordenada.Datum.Id           = readerAux.GetValue <int>("datum_id");
                            requerimento.Empreendimento.Coordenada.EastingUtm         = readerAux.GetValue <double>("easting_utm");
                            requerimento.Empreendimento.Coordenada.NorthingUtm        = readerAux.GetValue <double>("northing_utm");
                            requerimento.Empreendimento.Coordenada.FusoUtm            = readerAux.GetValue <int>("fuso_utm");
                            requerimento.Empreendimento.Coordenada.HemisferioUtm      = readerAux.GetValue <int>("hemisferio_utm_id");
                            requerimento.Empreendimento.Coordenada.LatitudeGms        = readerAux.GetValue <string>("latitude_gms");
                            requerimento.Empreendimento.Coordenada.LongitudeGms       = readerAux.GetValue <string>("longitude_gms");
                            requerimento.Empreendimento.Coordenada.LatitudeGdec       = readerAux.GetValue <double>("latitude_gdec");
                            requerimento.Empreendimento.Coordenada.LongitudeGdec      = readerAux.GetValue <double>("longitude_gdec");
                            requerimento.Empreendimento.Coordenada.FormaColetaTexto   = readerAux.GetValue <string>("forma_coleta_texto");
                            requerimento.Empreendimento.Coordenada.LocalColetaTexto   = readerAux.GetValue <string>("local_coleta_texto");
                            requerimento.Empreendimento.Coordenada.DatumTexto         = readerAux.GetValue <string>("datum_texto");
                            requerimento.Empreendimento.Coordenada.HemisferioUtmTexto = readerAux.GetValue <string>("hemisferio_utm_texto");
                        }

                        readerAux.Close();
                    }

                    #endregion

                    #region Meio de Contato

                    comando = bancoDeDados.CriarComando(@"select ec.emp_contato_id id, c.id tipo_contato_id, c.texto contato_texto, ec.valor
					from {0}hst_empreendimento_contato ec, {0}tab_meio_contato c where ec.meio_contato_id = c.id and ec.id_hst = :hst"                    , EsquemaBanco);

                    comando.AdicionarParametroEntrada("hst", aux, DbType.Int32);

                    using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                    {
                        ContatoRelatorio contato;
                        while (readerAux.Read())
                        {
                            contato             = new ContatoRelatorio();
                            contato.Id          = readerAux.GetValue <int>("id");
                            contato.PessoaId    = requerimento.Empreendimento.Id;
                            contato.TipoContato = (eTipoContato)Enum.Parse(contato.TipoContato.GetType(), readerAux.GetValue <string>("tipo_contato_id"));
                            contato.TipoTexto   = readerAux.GetValue <string>("contato_texto");
                            contato.Valor       = readerAux.GetValue <string>("valor");
                            requerimento.Empreendimento.MeiosContatos.Add(contato);
                        }

                        readerAux.Close();
                    }

                    #endregion

                    reader.Close();
                }

                #endregion
            }

            if (requerimento.AutorId > 0)
            {
                using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(UsuarioCredenciado))
                {
                    #region Elaborador

                    Comando comando = bancoDeDados.CriarComando(@"
					select nvl(p.nome, p.razao_social) NomeRazaoSocial, lc.texto TipoTexto 
					from {0}tab_credenciado c, {0}tab_pessoa p, {0}lov_credenciado_tipo lc 
					where c.pessoa = p.id and c.tipo = lc.id and c.id = :id"                    , UsuarioCredenciado);

                    comando.AdicionarParametroEntrada("id", requerimento.AutorId, DbType.Int32);
                    requerimento.UsuarioCredenciado = bancoDeDados.ObterEntity <CredenciadoRelatorio>(comando);

                    #endregion
                }
            }

            return(requerimento);
        }
        public RequerimentoRelatorio Obter(int id)
        {
            RequerimentoRelatorio requerimento = new RequerimentoRelatorio();

            #region Banco do Credenciado

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(EsquemaBanco))
            {
                #region Requerimento

                Comando comando = bancoDeDados.CriarComando(@"
												select r.id,
												r.credenciado,
												trunc(r.data_criacao) data_criacao,
												r.interessado,
												r.empreendimento,
												r.situacao,
												r.agendamento agendamento,
												to_char(r.data_criacao, 'dd') dia,
												to_char(r.data_criacao, 'MM') mes,
												to_char(r.data_criacao, 'yyyy') ano,
												r.setor,
												r.informacoes,
												p.situacao projeto_digital_situacao,
												(select pe.municipio from {0}tab_pessoa_endereco pe, {0}tab_credenciado c where pe.pessoa = c.pessoa and c.id = r.credenciado) municipio
											from {0}tab_requerimento r, tab_projeto_digital p 
											where r.id = p.requerimento and r.id = :id"                                            , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        requerimento.Id           = id;
                        requerimento.AutorId      = reader.GetValue <int>("credenciado");
                        requerimento.DataCadastro = Convert.ToDateTime(reader["data_criacao"]);
                        requerimento.DiaCadastro  = reader["dia"].ToString();
                        int mes = reader.GetValue <int>("mes");
                        requerimento.MesCadastro              = _configSys.Obter <List <String> >(ConfiguracaoSistema.KeyMeses).ElementAt(mes - 1);
                        requerimento.AnoCadastro              = reader["ano"].ToString();
                        requerimento.MunicipioId              = reader.GetValue <int>("municipio");
                        requerimento.Interessado.Id           = reader.GetValue <int>("interessado");
                        requerimento.Empreendimento.Id        = reader.GetValue <int>("empreendimento");
                        requerimento.ProjetoDigitalSituacaoId = reader.GetValue <int>("projeto_digital_situacao");
                        requerimento.SituacaoId          = reader.GetValue <int>("situacao");
                        requerimento.AgendamentoVistoria = reader["agendamento"].ToString();
                        requerimento.SetorId             = reader.GetValue <int>("setor");
                        requerimento.Informacoes         = reader["informacoes"].ToString();
                    }

                    reader.Close();
                }

                #endregion

                #region Atividades

                comando = bancoDeDados.CriarComando(@"
									select a.id, a.atividade, a.tid
									  from {0}tab_requerimento_atividade a
									 where a.requerimento = :id"                                    , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    RequerimentoAtividadeRelatorio atividade;

                    while (reader.Read())
                    {
                        atividade    = new RequerimentoAtividadeRelatorio();
                        atividade.Id = Convert.ToInt32(reader["atividade"]);
                        atividade.IdRelacionamento = Convert.ToInt32(reader["id"]);

                        #region Atividades/Finalidades/Modelos
                        comando = bancoDeDados.CriarComando(@"
												select a.id,
													   a.finalidade,
													   a.modelo,
													   a.titulo_anterior_tipo,
													   a.titulo_anterior_id,
													   a.titulo_anterior_numero,
													   a.modelo_anterior_id,
													   a.modelo_anterior_nome,
													   a.modelo_anterior_sigla,
													   a.orgao_expedidor
												  from {0}tab_requerimento_ativ_finalida a       
												 where a.requerimento_ativ = :id"                                                , EsquemaBanco);

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

                        using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                        {
                            Finalidade fin;

                            while (readerAux.Read())
                            {
                                fin = new Finalidade();

                                fin.IdRelacionamento = Convert.ToInt32(readerAux["id"]);

                                fin.OrgaoExpedidor = readerAux["orgao_expedidor"].ToString();

                                if (readerAux["finalidade"] != DBNull.Value)
                                {
                                    fin.Id = Convert.ToInt32(readerAux["finalidade"]);
                                }

                                if (readerAux["modelo"] != DBNull.Value)
                                {
                                    fin.TituloModelo = Convert.ToInt32(readerAux["modelo"]);
                                }

                                if (readerAux["modelo_anterior_id"] != DBNull.Value)
                                {
                                    fin.TituloModeloAnteriorId = Convert.ToInt32(readerAux["modelo_anterior_id"]);
                                }

                                fin.TituloModeloAnteriorTexto = readerAux["modelo_anterior_nome"].ToString();
                                fin.TituloModeloAnteriorSigla = readerAux["modelo_anterior_sigla"].ToString();

                                if (readerAux["titulo_anterior_tipo"] != DBNull.Value)
                                {
                                    fin.TituloAnteriorTipo = Convert.ToInt32(readerAux["titulo_anterior_tipo"]);
                                }

                                if (readerAux["titulo_anterior_id"] != DBNull.Value)
                                {
                                    fin.TituloAnteriorId = Convert.ToInt32(readerAux["titulo_anterior_id"]);
                                }

                                fin.TituloAnteriorNumero = readerAux["titulo_anterior_numero"].ToString();
                                fin.EmitidoPorInterno    = (fin.TituloAnteriorTipo != 3);
                                atividade.Finalidades.Add(fin);
                            }
                            readerAux.Close();
                        }
                        #endregion

                        requerimento.Atividades.Add(atividade);
                    }

                    reader.Close();
                }

                #endregion

                #region Interessado

                comando = bancoDeDados.CriarComando(@"
											select p.id,
												   p.tipo,
												   p.nome,
												   p.cpf,
												   p.rg,
												   p.estado_civil,
												   p.cnpj,
												   p.razao_social,
												   p.nome_fantasia,
												   p.ie,
												   p.apelido,
												   tpp.profissao
											  from {0}tab_pessoa p, {0}tab_pessoa_profissao tpp
											 where p.id = tpp.pessoa(+)
											   and p.id = :id"                                            , EsquemaBanco);

                comando.AdicionarParametroEntrada("id", requerimento.Interessado.Id, DbType.Int32);
                PessoaRelatorio pessoa = new PessoaRelatorio();

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        pessoa.Id   = requerimento.Interessado.Id;
                        pessoa.Tipo = Convert.ToInt32(reader["tipo"]);

                        if (pessoa.IsFisica)
                        {
                            pessoa.Fisica.Nome    = reader["nome"].ToString();
                            pessoa.Fisica.CPF     = reader["cpf"].ToString();
                            pessoa.Fisica.RG      = reader["rg"].ToString();
                            pessoa.Fisica.Apelido = reader["apelido"].ToString();
                        }
                        else                         // juridica
                        {
                            pessoa.Juridica.CNPJ         = reader["cnpj"].ToString();
                            pessoa.Juridica.RazaoSocial  = reader["razao_social"].ToString();
                            pessoa.Juridica.NomeFantasia = reader["nome_fantasia"].ToString();
                            pessoa.Juridica.IE           = reader["ie"].ToString();
                        }
                    }
                    reader.Close();
                }

                #region Meio de Contato

                comando = bancoDeDados.CriarComando(@"select a.id, a.pessoa, a.meio_contato tipo_contato_id, a.valor
					from {0}tab_pessoa_meio_contato a where a.pessoa = :pessoa"                    , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    ContatoRelatorio contato;
                    while (reader.Read())
                    {
                        contato             = new ContatoRelatorio();
                        contato.Id          = Convert.ToInt32(reader["id"]);
                        contato.PessoaId    = Convert.ToInt32(reader["pessoa"]);
                        contato.TipoContato = (eTipoContato)Enum.Parse(contato.TipoContato.GetType(), reader["tipo_contato_id"].ToString());
                        contato.Valor       = reader["valor"].ToString();
                        pessoa.MeiosContatos.Add(contato);
                    }
                    reader.Close();
                }

                #endregion

                #region Endereços

                comando = bancoDeDados.CriarComando(@"
													select te.id,
														   te.pessoa,
														   te.cep,
														   te.logradouro,
														   te.bairro,
														   te.estado      estado_id,
														   te.municipio   municipio_id,
														   te.numero,
														   te.complemento,
														   te.distrito
													  from {0}tab_pessoa_endereco te
													 where te.pessoa = :pessoa"                                                    , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        pessoa.Endereco.Id          = Convert.ToInt32(reader["id"]);
                        pessoa.Endereco.Cep         = reader["cep"].ToString();
                        pessoa.Endereco.Logradouro  = reader["logradouro"].ToString();
                        pessoa.Endereco.Bairro      = reader["bairro"].ToString();
                        pessoa.Endereco.EstadoId    = Convert.IsDBNull(reader["estado_id"]) ? 0 : Convert.ToInt32(reader["estado_id"]);
                        pessoa.Endereco.MunicipioId = Convert.IsDBNull(reader["municipio_id"]) ? 0 : Convert.ToInt32(reader["municipio_id"]);
                        pessoa.Endereco.Numero      = reader["numero"].ToString();
                        pessoa.Endereco.Complemento = reader["complemento"].ToString();
                        pessoa.Endereco.Distrito    = reader["distrito"].ToString();
                    }
                    reader.Close();
                }

                #endregion

                requerimento.Interessado = pessoa;

                #endregion

                #region Responsáveis

                comando = bancoDeDados.CriarComando(@"
											select pr.id,
												   pr.responsavel,
												   pr.funcao funcao,
												   pr.numero_art,
												   nvl(p.nome, p.razao_social) nome,
												   nvl(p.cpf, p.cnpj) cpf_cnpj,
												   nvl(p.rg, p.ie) rg_ie,
												   p.tipo,
												   trunc(p.data_nascimento) data_nascimento
											  from {0}tab_requerimento_responsavel pr, {0}tab_pessoa p
											 where pr.responsavel = p.id
											   and pr.requerimento = :requerimento"                                            , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    ResponsavelTecnicoRelatorio responsavel;
                    while (reader.Read())
                    {
                        responsavel             = new ResponsavelTecnicoRelatorio();
                        responsavel.Id          = Convert.ToInt32(reader["responsavel"]);
                        responsavel.FuncaoTexto = reader["funcao"].ToString();
                        responsavel.CpfCnpj     = reader["cpf_cnpj"].ToString();
                        responsavel.RgIe        = reader["rg_ie"].ToString();
                        responsavel.NomeRazao   = reader["nome"].ToString();
                        responsavel.NumeroArt   = reader["numero_art"].ToString();

                        if (reader["data_nascimento"] != null && !Convert.IsDBNull(reader["data_nascimento"]))
                        {
                            responsavel.DataNascimento = Convert.ToDateTime(reader["data_nascimento"]).ToShortDateString();
                        }

                        responsavel.DataVencimento = "Falta";

                        #region Meio de Contato

                        comando = bancoDeDados.CriarComando(@"select a.id, a.pessoa, a.meio_contato tipo_contato_id, a.valor
							from tab_pessoa_meio_contato a
							where a.pessoa = :pessoa"                            , EsquemaBanco);

                        comando.AdicionarParametroEntrada("pessoa", responsavel.Id, DbType.Int32);

                        using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                        {
                            ContatoRelatorio contato;
                            while (readerAux.Read())
                            {
                                contato             = new ContatoRelatorio();
                                contato.Id          = Convert.ToInt32(readerAux["id"]);
                                contato.PessoaId    = Convert.ToInt32(readerAux["pessoa"]);
                                contato.TipoContato = (eTipoContato)Enum.Parse(contato.TipoContato.GetType(), readerAux["tipo_contato_id"].ToString());
                                contato.Valor       = readerAux["valor"].ToString();
                                responsavel.MeiosContatos.Add(contato);
                            }
                            readerAux.Close();
                        }

                        #endregion

                        #region Endereços

                        comando = bancoDeDados.CriarComando(@"
														select te.id,
															   te.pessoa,
															   te.cep,
															   te.logradouro,
															   te.bairro,
															   te.estado      estado_id,
															   te.municipio   municipio_id,
															   te.numero,
															   te.complemento,
															   te.distrito
														  from {0}tab_pessoa_endereco te
														 where te.pessoa = :pessoa"                                                        , EsquemaBanco);

                        comando.AdicionarParametroEntrada("pessoa", responsavel.Id, DbType.Int32);

                        using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                        {
                            while (readerAux.Read())
                            {
                                responsavel.Endereco.Id          = Convert.ToInt32(readerAux["id"]);
                                responsavel.Endereco.Cep         = readerAux["cep"].ToString();
                                responsavel.Endereco.Logradouro  = readerAux["logradouro"].ToString();
                                responsavel.Endereco.Bairro      = readerAux["bairro"].ToString();
                                responsavel.Endereco.EstadoId    = Convert.IsDBNull(readerAux["estado_id"]) ? 0 : Convert.ToInt32(readerAux["estado_id"]);
                                responsavel.Endereco.MunicipioId = Convert.IsDBNull(readerAux["municipio_id"]) ? 0 : Convert.ToInt32(readerAux["municipio_id"]);
                                responsavel.Endereco.Numero      = readerAux["numero"].ToString();
                                responsavel.Endereco.Complemento = readerAux["complemento"].ToString();
                                responsavel.Endereco.Distrito    = readerAux["distrito"].ToString();
                            }
                            readerAux.Close();
                        }

                        #endregion

                        requerimento.Responsaveis.Add(responsavel);
                    }
                    reader.Close();
                }

                #endregion

                #region Empreendimento

                if (requerimento.Empreendimento.Id > 0)
                {
                    comando = bancoDeDados.CriarComando(@"
					select e.id,
							e.codigo,
							e.segmento,
							e.denominador,
							e.cnpj,
							e.atividade,
							e.nome_fantasia,
							e.denominador razao_social
					from tab_empreendimento e
					where e.id = :id"                    , EsquemaBanco);

                    comando.AdicionarParametroEntrada("id", requerimento.Empreendimento.Id, DbType.Int32);
                    EmpreendimentoRelatorio empreendimento = new EmpreendimentoRelatorio();

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        if (reader.Read())
                        {
                            empreendimento.Id             = requerimento.Empreendimento.Id;
                            empreendimento.Codigo         = reader.GetValue <int>("codigo");
                            empreendimento.CNPJ           = reader["cnpj"].ToString();
                            empreendimento.NomeFantasia   = reader["nome_fantasia"].ToString();
                            empreendimento.Denominador    = reader["denominador"].ToString();
                            empreendimento.SegmentoTexto  = reader["segmento"].ToString();
                            empreendimento.AtividadeTexto = Convert.ToString(reader["atividade"]);
                            empreendimento.NomeRazao      = Convert.ToString(reader["razao_social"]);
                        }

                        reader.Close();
                    }

                    #region Endereços

                    comando = bancoDeDados.CriarComando(@"
											select te.id,
													te.empreendimento,
													te.correspondencia,
													te.cep,
													te.logradouro,
													te.bairro,
													te.estado estado_id,
													te.municipio municipio_id,
													te.numero,
													te.complemento,
													(case
														when te.zona = 1 then
														'Urbana'
														else
														'Rural'
													end) zona,
													te.distrito,
													te.corrego,
													te.complemento
												from tab_empreendimento_endereco te
												where te.empreendimento = :empreendimento"                                                , EsquemaBanco);

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

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        EnderecoRelatorio end;
                        while (reader.Read())
                        {
                            end    = new EnderecoRelatorio();
                            end.Id = Convert.ToInt32(reader["id"]);
                            end.Correspondencia = Convert.IsDBNull(reader["correspondencia"]) ? 0 : Convert.ToInt32(reader["correspondencia"]);
                            end.Cep             = reader["cep"].ToString();
                            end.Logradouro      = reader["logradouro"].ToString();
                            end.Bairro          = reader["bairro"].ToString();
                            end.EstadoId        = Convert.IsDBNull(reader["estado_id"]) ? 0 : Convert.ToInt32(reader["estado_id"]);
                            end.MunicipioId     = Convert.IsDBNull(reader["municipio_id"]) ? 0 : Convert.ToInt32(reader["municipio_id"]);
                            end.Numero          = reader["numero"].ToString();
                            end.Complemento     = reader["complemento"].ToString();
                            end.Corrego         = reader["corrego"].ToString();
                            end.Zona            = reader["zona"].ToString();
                            end.Distrito        = reader["distrito"].ToString();
                            end.Complemento     = reader["complemento"].ToString();
                            empreendimento.Enderecos.Add(end);
                        }
                        reader.Close();
                    }

                    #endregion

                    #region Coordenada

                    comando = bancoDeDados.CriarComando(@"
													select aec.id,
														   aec.tipo_coordenada,
														   aec.datum,
														   aec.easting_utm,
														   aec.northing_utm,
														   aec.fuso_utm,
														   aec.hemisferio_utm,
														   aec.latitude_gms,
														   aec.longitude_gms,
														   aec.latitude_gdec,
														   aec.longitude_gdec,
														   aec.forma_coleta    forma_coleta,
														   aec.local_coleta    local_coleta,
														   aec.datum           datum_texto,
														   aec.hemisferio_utm  hemisferio_utm_texto
													  from {0}tab_empreendimento_coord aec
													 where aec.empreendimento = :empreendimentoid"                                                    , EsquemaBanco);

                    comando.AdicionarParametroEntrada("empreendimentoid", empreendimento.Id, DbType.Int32);

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        if (reader.Read())
                        {
                            empreendimento.Coordenada.Id = Convert.ToInt32(reader["id"]);
                            empreendimento.Coordenada.EastingUtmTexto  = Convert.ToString(reader["easting_utm"]);
                            empreendimento.Coordenada.NorthingUtmTexto = Convert.ToString(reader["northing_utm"]);
                            empreendimento.Coordenada.FusoUtm          = Convert.IsDBNull(reader["fuso_utm"]) ? 0 : Convert.ToInt32(reader["fuso_utm"]);
                            empreendimento.Coordenada.HemisferioUtm    = Convert.IsDBNull(reader["hemisferio_utm"]) ? 0 : Convert.ToInt32(reader["hemisferio_utm"]);
                            empreendimento.Coordenada.LatitudeGms      = reader["latitude_gms"].ToString();
                            empreendimento.Coordenada.LongitudeGms     = reader["longitude_gms"].ToString();
                            empreendimento.Coordenada.LatitudeGdec     = Convert.IsDBNull(reader["latitude_gdec"]) ? 0 : Convert.ToDouble(reader["latitude_gdec"]);
                            empreendimento.Coordenada.LongitudeGdec    = Convert.IsDBNull(reader["longitude_gdec"]) ? 0 : Convert.ToDouble(reader["longitude_gdec"]);
                            empreendimento.Coordenada.Datum.Id         = Convert.ToInt32(reader["datum"]);
                            empreendimento.Coordenada.Tipo.Id          = Convert.ToInt32(reader["tipo_coordenada"]);
                            empreendimento.Coordenada.FormaColetaTexto = Convert.ToString(reader["forma_coleta"]);
                            empreendimento.Coordenada.LocalColetaTexto = Convert.ToString(reader["local_coleta"]);
                        }
                        reader.Close();
                    }

                    #endregion

                    #region Meio de Contato

                    comando = bancoDeDados.CriarComando(@"select a.id, a.empreendimento, a.meio_contato tipo_contato_id, a.valor
				  from {0}tab_empreendimento_contato a
				 where a.empreendimento = :empreendimento"                , EsquemaBanco);

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

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        ContatoRelatorio contato;
                        while (reader.Read())
                        {
                            contato             = new ContatoRelatorio();
                            contato.Id          = Convert.ToInt32(reader["id"]);
                            contato.PessoaId    = Convert.ToInt32(reader["empreendimento"]);
                            contato.TipoContato = (eTipoContato)Enum.Parse(contato.TipoContato.GetType(), reader["tipo_contato_id"].ToString());
                            contato.Valor       = reader["valor"].ToString();
                            empreendimento.MeiosContatos.Add(contato);
                        }
                        reader.Close();
                    }

                    #endregion

                    requerimento.Empreendimento = empreendimento;
                }

                #endregion

                #region Elaborador

                comando = bancoDeDados.CriarComando(@"
				select nvl(p.nome, p.razao_social) NomeRazaoSocial, lc.texto TipoTexto 
				from {0}tab_credenciado c, {0}tab_pessoa p, {0}lov_credenciado_tipo lc 
				where c.pessoa = p.id and c.tipo = lc.id and c.id = :id"                , EsquemaBanco);

                comando.AdicionarParametroEntrada("id", requerimento.AutorId, DbType.Int32);
                requerimento.UsuarioCredenciado = bancoDeDados.ObterEntity <CredenciadoRelatorio>(comando);

                #endregion
            }

            #endregion

            #region Banco do Interno

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia())
            {
                #region Requerimento

                requerimento.Municipio = ObterMunicipio(requerimento.MunicipioId, bancoDeDados);

                #region Situacao

                Comando comando = bancoDeDados.CriarComando(@"select l.texto situacao_texto from {0}lov_requerimento_situacao l where l.id = :id", EsquemaInterno);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        requerimento.SituacaoTexto = reader["situacao_texto"].ToString();
                    }
                    reader.Close();
                }

                #endregion

                #region Agendamento

                if (!string.IsNullOrWhiteSpace(requerimento.AgendamentoVistoria))
                {
                    comando = bancoDeDados.CriarComando(@"select l.texto agendamento from {0}lov_requerimento_agendamento l where l.id = :id", EsquemaInterno);

                    comando.AdicionarParametroEntrada("id", Convert.ToInt32(requerimento.AgendamentoVistoria), DbType.Int32);

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        if (reader.Read())
                        {
                            requerimento.AgendamentoVistoria = reader["agendamento"].ToString();
                        }
                        reader.Close();
                    }
                }

                #endregion

                #region Setor

                if (requerimento.SetorId > 0)
                {
                    comando = bancoDeDados.CriarComando(@"select m.texto from tab_setor_endereco se, lov_municipio m 
						where se.municipio = m.id (+) and se.setor = :setor"                        , EsquemaInterno);

                    comando.AdicionarParametroEntrada("setor", Convert.ToInt32(requerimento.SetorId), DbType.Int32);

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        if (reader.Read())
                        {
                            requerimento.Municipio = reader["texto"].ToString();
                        }
                        reader.Close();
                    }
                }

                #endregion

                #endregion

                if (requerimento.Atividades.Count > 0)
                {
                    #region Atividades

                    comando = bancoDeDados.CriarComando(@"select b.id, b.atividade atividade_texto, b.conclusao from {0}tab_atividade b", EsquemaInterno);

                    comando.DbCommand.CommandText += comando.AdicionarIn("where", "b.id", DbType.Int32, requerimento.Atividades.Select(x => x.Id).ToList());

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        while (reader.Read())
                        {
                            int idr = Convert.ToInt32(reader["id"]);
                            RequerimentoAtividadeRelatorio atividade = requerimento.Atividades.FirstOrDefault(x => x.Id == idr);
                            atividade.NomeAtividade = reader["atividade_texto"].ToString();
                            atividade.Conclusao     = reader.GetValue <string>("conclusao");
                        }

                        reader.Close();
                    }

                    #endregion

                    #region Atividades/Finalidades/Modelos

                    comando = bancoDeDados.CriarComando(@"
							select ltf.texto finalidade_texto, tm.nome modelo_nome
							  from {0}tab_titulo_modelo tm, {0}lov_titulo_finalidade ltf
							 where tm.id = :modelo and ltf.id = :fin"                            , EsquemaInterno);

                    comando.AdicionarParametroEntrada("fin", DbType.Int32);
                    comando.AdicionarParametroEntrada("modelo", DbType.Int32);

                    var finalidades = requerimento.Atividades.SelectMany(x => x.Finalidades);

                    foreach (Finalidade f in finalidades)
                    {
                        comando.SetarValorParametro("fin", f.Id);
                        comando.SetarValorParametro("modelo", f.TituloModelo);

                        using (IDataReader readerAux = bancoDeDados.ExecutarReader(comando))
                        {
                            if (readerAux.Read())
                            {
                                f.Texto             = readerAux["finalidade_texto"].ToString();
                                f.TituloModeloTexto = readerAux["modelo_nome"].ToString();
                            }

                            readerAux.Close();
                        }
                    }

                    #endregion
                }

                #region Interessado

                #region Profissao

                if (!string.IsNullOrWhiteSpace(requerimento.Interessado.Fisica.Profissao))
                {
                    comando = bancoDeDados.CriarComando(@"select texto from {0}tab_profissao where id = :id", EsquemaInterno);

                    comando.AdicionarParametroEntrada("id", Convert.ToInt32(requerimento.Interessado.Fisica.Profissao), DbType.Int32);

                    using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                    {
                        if (reader.Read())
                        {
                            requerimento.Interessado.Fisica.Profissao = reader["texto"].ToString();
                        }
                        reader.Close();
                    }
                }

                #endregion

                #region Meios de Contato

                comando = bancoDeDados.CriarComando(@"select b.id, b.texto, b.mascara from {0}tab_meio_contato b", EsquemaInterno);

                comando.DbCommand.CommandText += comando.AdicionarIn("where", "b.id", DbType.Int32, requerimento.Interessado.MeiosContatos.Select(x => x.Id).ToList());

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        int idr      = Convert.ToInt32(reader["id"]);
                        var contatos = requerimento.Interessado.MeiosContatos.Where(x => x.Id == idr).ToList();
                        contatos.ForEach(x =>
                        {
                            x.TipoTexto = reader["texto"].ToString();
                            x.Mascara   = reader.GetValue <string>("mascara");
                        });
                    }

                    reader.Close();
                }

                #endregion

                #region Endereco

                EnderecoRelatorio end = requerimento.Interessado.Endereco;
                end.MunicipioTexto = ObterMunicipio(end.MunicipioId, bancoDeDados);
                end.EstadoSigla    = ObterEstado(end.EstadoId, bancoDeDados);

                #endregion

                #endregion

                #region Responsaveis

                #region Funcao

                comando = bancoDeDados.CriarComando(@"select lf.texto funcao from {0}lov_protocolo_resp_funcao lf where lf.id = :id", EsquemaInterno);
                comando.AdicionarParametroEntrada("id", DbType.Int32);

                foreach (var resp in requerimento.Responsaveis)
                {
                    comando.SetarValorParametro("id", int.Parse(resp.FuncaoTexto));
                    resp.FuncaoTexto = bancoDeDados.ExecutarScalar <string>(comando);
                }

                #endregion

                #region Meios de Contato

                comando = bancoDeDados.CriarComando(@"select b.id, b.texto, b.mascara from {0}tab_meio_contato b", EsquemaInterno);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        int idr      = Convert.ToInt32(reader["id"]);
                        var contatos = requerimento.Responsaveis.SelectMany(x => x.MeiosContatos).Where(x => x.Id == idr).ToList();
                        contatos.ForEach(x =>
                        {
                            x.TipoTexto = reader["texto"].ToString();
                            x.Mascara   = reader.GetValue <string>("mascara");
                        });
                    }

                    reader.Close();
                }

                #endregion

                #region Endereços

                foreach (var endResp in requerimento.Responsaveis.Select(x => x.Endereco))
                {
                    endResp.MunicipioTexto = ObterMunicipio(endResp.MunicipioId, bancoDeDados);
                    endResp.EstadoSigla    = ObterEstado(endResp.EstadoId, bancoDeDados);
                }

                #endregion

                #endregion

                #region Empreendimento

                EmpreendimentoRelatorio emp = requerimento.Empreendimento;

                #region Atividade

                if (!string.IsNullOrWhiteSpace(emp.AtividadeTexto))
                {
                    comando = bancoDeDados.CriarComando(@"select a.atividade from {0}tab_empreendimento_atividade a where a.id = :id", EsquemaInterno);
                    comando.AdicionarParametroEntrada("id", Convert.ToInt32(emp.AtividadeTexto), DbType.Int32);
                    requerimento.Empreendimento.AtividadeTexto = bancoDeDados.ExecutarScalar <string>(comando);
                }

                #endregion

                #region Segmento

                if (!string.IsNullOrWhiteSpace(emp.SegmentoTexto))
                {
                    comando = bancoDeDados.CriarComando(@"select les.texto from {0}lov_empreendimento_segmento les where les.id = :id", EsquemaInterno);
                    comando.AdicionarParametroEntrada("id", Convert.ToInt32(emp.SegmentoTexto), DbType.Int32);
                    requerimento.Empreendimento.SegmentoTexto = bancoDeDados.ExecutarScalar <string>(comando);
                }

                #endregion

                #region Endereços

                foreach (var endEmp in emp.Enderecos)
                {
                    endEmp.MunicipioTexto = ObterMunicipio(endEmp.MunicipioId, bancoDeDados);
                    endEmp.EstadoSigla    = ObterEstado(endEmp.EstadoId, bancoDeDados);
                }

                #endregion

                #region Meios de Contato

                comando = bancoDeDados.CriarComando(@"select b.id, b.texto, b.mascara from tab_meio_contato b", EsquemaInterno);

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        int idr      = Convert.ToInt32(reader["id"]);
                        var contatos = emp.MeiosContatos.Where(x => x.Id == idr).ToList();
                        contatos.ForEach(x =>
                        {
                            x.TipoTexto = reader["texto"].ToString();
                            x.Mascara   = reader.GetValue <string>("mascara");
                        });
                    }

                    reader.Close();
                }

                #endregion

                #region Coordenada

                ListaBus bus = new ListaBus();

                emp.Coordenada.DatumTexto = ObterDatum(emp.Coordenada.Datum.Id, bancoDeDados);
                emp.Coordenada.Tipo.Texto = ObterTipoCoordenada(emp.Coordenada.Tipo.Id, bancoDeDados);

                if (!string.IsNullOrWhiteSpace(emp.Coordenada.HemisferioUtmTexto))
                {
                    emp.Coordenada.HemisferioUtmTexto = bus.Hemisferios.FirstOrDefault(x => x.Id == Convert.ToInt32(emp.Coordenada.HemisferioUtmTexto)).Texto;
                }

                if (!string.IsNullOrWhiteSpace(emp.Coordenada.FormaColetaTexto))
                {
                    comando = bancoDeDados.CriarComando(@"select c.texto from {0}lov_empreendimento_forma_colet c where c.id = :id", EsquemaInterno);
                    comando.AdicionarParametroEntrada("id", Convert.ToInt32(emp.Coordenada.FormaColetaTexto), DbType.Int32);
                    emp.Coordenada.FormaColetaTexto = bancoDeDados.ExecutarScalar <string>(comando);
                }

                if (!string.IsNullOrWhiteSpace(emp.Coordenada.LocalColetaTexto))
                {
                    comando = bancoDeDados.CriarComando(@"select c.texto from {0}lov_empreendimento_local_colet c where c.id = :id", EsquemaInterno);
                    comando.AdicionarParametroEntrada("id", Convert.ToInt32(emp.Coordenada.LocalColetaTexto), DbType.Int32);
                    emp.Coordenada.LocalColetaTexto = bancoDeDados.ExecutarScalar <string>(comando);
                }

                #endregion

                #endregion
            }

            #endregion

            return(requerimento);
        }