public CFORelatorio()
 {
     Produtor                   = new PessoaRelatorio();
     Empreendimento             = new EmpreendimentoRelatorio();
     Produtos                   = new List <IdentificacaoProdutoRelatorio>();
     TratamentosFitossanitarios = new List <TratamentoFitossanitarioRelatorio>();
     ResponsavelTecnico         = new ResponsavelTecnicoRelatorio();
 }
 public HabilitarEmissaoCFOCFOCRelatorio()
 {
     Responsavel   = new PessoaRelatorio();
     Foto          = new Blocos.Arquivo.Arquivo();
     Foto.Conteudo = new byte[0];
     Profissao     = new ProfissaoRelatorio();
     DataCadastro  = new DateTime();
     Pragas        = new List <PragaHabilitarEmissaoRelatorio>();
     SituacaoTexto = "Ativo";
 }
Example #3
0
        private PessoaRelatorio ObterAutuado(int empResponsavelId, BancoDeDados banco = null)
        {
            PessoaRelatorio objeto  = new PessoaRelatorio();
            Comando         comando = null;

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(banco))
            {
                comando = bancoDeDados.CriarComando(@" select nvl(p.nome, p.razao_social) Nome, nvl(p.cpf, p.cnpj) CPF from {0}tab_pessoa p where p.id = :empResponsavelId  ", EsquemaBanco);

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

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

            return(objeto);
        }
Example #4
0
        private PessoaRelatorio ObterEmpResponsavel(int empId, BancoDeDados banco = null)
        {
            PessoaRelatorio objeto  = new PessoaRelatorio();
            Comando         comando = null;

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(banco))
            {
                comando = bancoDeDados.CriarComando(@" select nvl(tp.cpf, tp.cnpj) CPF, nvl(tp.nome, tp.razao_social) Nome from tab_pessoa tp, tab_fisc_local_infracao tfli where 
					fli.pessoa = tp.id and tfli.id = :localIfracaoId union all select te.cnpj, te.denominador from tab_empreendimento te, tab_fisc_local_infracao tfli where tfli.empreendimento = te.id
					and tfli.id = :localIfracaoId  "                    , EsquemaBanco);

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

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

            return(objeto);
        }
        internal UnidadeProducaoRelatorio Obter(int projetoDigitalId)
        {
            UnidadeProducaoRelatorio unidade = null;

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(EsquemaBancoCredenciado))
            {
                Comando comando = bancoDeDados.CriarComando(@"select c.id, c.propriedade_codigo, c.local_livro, e.denominador, e.cnpj, ee.cep, ee.logradouro, ee.bairro,  ee.distrito,
				ee.numero, lm.texto municipio_texto, le.sigla estado_sigla,  ee.corrego,  ee.complemento, tp.situacao projeto_situacao from crt_unidade_producao c, tab_empreendimento e,
				tab_empreendimento_endereco ee, lov_municipio lm, lov_estado le, tab_projeto_digital tp where e.id = tp.empreendimento and c.empreendimento = e.id and e.id = 
				ee.empreendimento  and ee.correspondencia = 0 and le.id = ee.estado and lm.id = ee.municipio and tp.id = :id"                , EsquemaBancoCredenciado);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    while (reader.Read())
                    {
                        unidade    = new UnidadeProducaoRelatorio();
                        unidade.Id = reader.GetValue <int>("id");
                        unidade.CodigoPropriedade          = reader.GetValue <Int64>("propriedade_codigo").ToString("D4");
                        unidade.LocalLivro                 = reader.GetValue <string>("local_livro");
                        unidade.Empreendimento.Denominador = reader.GetValue <string>("denominador");
                        unidade.Empreendimento.CNPJ        = reader.GetValue <string>("cnpj");
                        unidade.Situacao = (eProjetoDigitalSituacao)reader.GetValue <int>("projeto_situacao");
                        unidade.Empreendimento.Enderecos.Add(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>("municipio_texto"),
                            EstadoSigla     = reader.GetValue <string>("estado_sigla"),
                            Corrego         = reader.GetValue <string>("corrego"),
                            Complemento     = reader.GetValue <string>("complemento"),
                            Correspondencia = 0
                        });
                    }

                    reader.Close();
                }

                #region Unidade de produção

                comando = bancoDeDados.CriarComando(@"select c.id, c.codigo_up, cc.easting_utm, cc.northing_utm, c.area,  cu.cultivar, tc.texto cultura, c.data_plantio_ano_producao,
				 c.estimativa_quant_ano, lc.texto estimativa from crt_unidade_producao_unidade  c, crt_unidade_producao_un_coord cc, tab_cultura_cultivar cu, lov_crt_uni_prod_uni_medida lc,
				 tab_cultura tc where  tc.id(+) = cu.cultura and c.estimativa_unid_medida = lc.id and c.cultivar = cu.id(+) and c.id = cc.unidade_producao_unidade and c.unidade_producao = :unidade"                , EsquemaBancoCredenciado);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    UnidadeProducaoItemRelatorio item;
                    while (reader.Read())
                    {
                        item               = new UnidadeProducaoItemRelatorio();
                        item.Id            = reader.GetValue <int>("id");
                        item.CodigoUP      = reader.GetValue <string>("codigo_up");
                        item.Latitude      = reader.GetValue <string>("easting_utm");
                        item.Longitude     = reader.GetValue <string>("northing_utm");
                        item.AreaHa        = reader.GetValue <string>("area");
                        item.CultivarNome  = reader.GetValue <string>("cultivar");
                        item.CulturaNome   = reader.GetValue <string>("cultura");
                        item.DataPlantio   = reader.GetValue <string>("data_plantio_ano_producao");
                        item.QuantidadeAno = reader.GetValue <string>("estimativa_quant_ano");
                        item.UnidadeMedida = reader.GetValue <string>("estimativa");
                        unidade.UP.Add(item);
                    }

                    reader.Close();
                }

                #endregion

                #region Produtores

                comando = bancoDeDados.CriarComando(@"select nvl(p.nome, p.razao_social) nome, nvl(p.cpf, p.cnpj) cpf_cnpj, e.cep, e.logradouro, e.bairro, e.distrito, e.numero, lm.texto municipio_texto, le.sigla estado_sigla,
					e.complemento, (select m.valor from tab_pessoa_meio_contato m where m.pessoa = p.id and m.meio_contato = 1) tel_residencial, (select m.valor from tab_pessoa_meio_contato m where m.pessoa = p.id and m.meio_contato = 2) tel_celular,
					(select m.valor from tab_pessoa_meio_contato m where m.pessoa = p.id and m.meio_contato = 3) tel_fax, (select m.valor from tab_pessoa_meio_contato m where m.pessoa = p.id and m.meio_contato = 4) tel_comercial,
					(select m.valor from tab_pessoa_meio_contato m where m.pessoa = p.id and m.meio_contato = 5) email from crt_unidade_prod_un_produtor c , tab_pessoa p, tab_pessoa_endereco e, lov_municipio lm, lov_estado le
					where c.produtor = p.id and p.id = e.pessoa and e.municipio = lm.id and e.estado = le.id and c.unidade_producao_unidade in 
					(select id from crt_unidade_producao_unidade where unidade_producao = :unidade)"                    , EsquemaBancoCredenciado);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    PessoaRelatorio produtor = null;
                    while (reader.Read())
                    {
                        if (unidade.Produtores.Exists(x => x.CPFCNPJ == reader.GetValue <string>("cpf_cnpj")))
                        {
                            continue;
                        }

                        produtor = new PessoaRelatorio();
                        produtor.NomeRazaoSocial         = reader.GetValue <string>("nome");
                        produtor.CPFCNPJ                 = reader.GetValue <string>("cpf_cnpj");
                        produtor.Endereco.Cep            = reader.GetValue <string>("cep");
                        produtor.Endereco.Logradouro     = reader.GetValue <string>("logradouro");
                        produtor.Endereco.Bairro         = reader.GetValue <string>("bairro");
                        produtor.Endereco.Distrito       = reader.GetValue <string>("distrito");
                        produtor.Endereco.Numero         = reader.GetValue <string>("numero");
                        produtor.Endereco.MunicipioTexto = reader.GetValue <string>("municipio_texto");
                        produtor.Endereco.EstadoSigla    = reader.GetValue <string>("estado_sigla");
                        produtor.Endereco.Complemento    = reader.GetValue <string>("complemento");
                        produtor.MeiosContatos.Add(new ContatoRelatorio()
                        {
                            Valor = reader.GetValue <string>("tel_residencial"), TipoContato = eTipoContato.TelefoneResidencial
                        });
                        produtor.MeiosContatos.Add(new ContatoRelatorio()
                        {
                            Valor = reader.GetValue <string>("tel_celular"), TipoContato = eTipoContato.TelefoneCelular
                        });
                        produtor.MeiosContatos.Add(new ContatoRelatorio()
                        {
                            Valor = reader.GetValue <string>("tel_fax"), TipoContato = eTipoContato.TelefoneFax
                        });
                        produtor.MeiosContatos.Add(new ContatoRelatorio()
                        {
                            Valor = reader.GetValue <string>("tel_comercial"), TipoContato = eTipoContato.TelefoneComercial
                        });
                        produtor.MeiosContatos.Add(new ContatoRelatorio()
                        {
                            Valor = reader.GetValue <string>("email"), TipoContato = eTipoContato.Email
                        });
                        unidade.Produtores.Add(produtor);
                    }

                    reader.Close();
                }

                #endregion

                #region Responsaveis Tecnicos

                comando = bancoDeDados.CriarComando(@"select r.unidade_producao_unidade, nvl(p.nome, p.razao_social) nome, h.numero_habilitacao, 
				(select t.extensao_habilitacao from {0}tab_hab_emi_cfo_cfoc t where t.responsavel = c.id) extensao_habilitacao 
				from {0}crt_unidade_prod_un_resp_tec r, {0}tab_credenciado c, {0}tab_pessoa p, 
				{1}tab_hab_emi_cfo_cfoc h where  r.responsavel_tecnico = h.responsavel and r.responsavel_tecnico = c.id and c.pessoa = p.id and r.unidade_producao_unidade 
				in (select id from {0}crt_unidade_producao_unidade where unidade_producao = :unidade)"                , EsquemaBancoCredenciado, EsquemaBanco);
                comando.AdicionarParametroEntrada("unidade", unidade.Id, DbType.Int32);

                bool extensao = false;
                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    ResponsavelTecnicoRelatorio item = null;

                    while (reader.Read())
                    {
                        extensao = reader.GetValue <bool>("extensao_habilitacao");

                        item                   = new ResponsavelTecnicoRelatorio();
                        item.NomeRazao         = reader.GetValue <string>("nome");
                        item.NumeroHabilitacao = extensao ? reader.GetValue <string>("numero_habilitacao") + " - ES" : reader.GetValue <string>("numero_habilitacao");
                        unidade.UP.Single(x => x.Id == reader.GetValue <int>("unidade_producao_unidade")).Responsaveis.Add(item);
                    }

                    reader.Close();
                }

                #endregion Responsaveis Tecnicos
            }

            return(unidade);
        }
        internal ProtocoloRelatorio Obter(int id, BancoDeDados banco = null)
        {
            ProtocoloRelatorio protocolo = new ProtocoloRelatorio();

            using (BancoDeDados bancoDeDados = BancoDeDados.ObterInstancia(banco))
            {
                #region Protocolo
                Comando comando = bancoDeDados.CriarComando(@"
				select d.*, f.nome funcionario_nome, lm.texto municipio, le.texto estado, le.sigla uf,
						(select stragg(c.nome) from {0}tab_funcionario_cargo fc, {0}tab_cargo c where fc.funcionario = f.id and c.id = fc.cargo) funcionario_cargo
					from (select p.nome protocolo_nome,
								e.codigo emp_codigo,
								p.protocolo,
								lp.texto protocolo_texto,
								p.tipo protocolo_tipo,
								t.texto protocolo_tipo_texto,
								p.numero || '/' || p.ano protocolo_numero,
								p.fiscalizacao fiscalizacao_numero,
								to_char(p.data_criacao, 'DD/MM/yyyy') data_criacao,
								a.tipo interessado_tipo,
								coalesce(a.nome, a.razao_social, p.interessado_livre) interessado_nomerazaosocial,
								nvl(a.cpf, a.cnpj) interessado_cpfcnpj,
								e.denominador empreendimento_nome,
								e.cnpj empreendimento_cnpj,
								r.numero requerimento_numero,
								nvl(p.checagem, p.checagem_pendencia) checagem,
								nvl(p.setor, (select a.setor from {0}tab_protocolo_associado pa, {0}tab_protocolo a where pa.protocolo = a.id and pa.associado = :id)) setor,
								nvl(p.emposse, (select a.emposse from {0}tab_protocolo_associado pa, {0}tab_protocolo a where pa.protocolo = a.id and pa.associado = :id)) emposse,
								pro_ass.numero numero_associado,
								pro_ass.tipo tipo_associado,
								p.assunto, (select fd.nome from tab_funcionario fd where fd.id = p.destinatario) destinatario, (select s.nome from tab_setor s where s.id = p.destinatario_setor) destinatario_setor, p.descricao
							from {0}tab_protocolo p,
								(select pa.id, pa.numero || '/' || pa.ano numero, ta.texto tipo from {0}tab_protocolo pa, {0}lov_protocolo ta where pa.protocolo = ta.id) pro_ass,
								{0}lov_protocolo_tipo t,
								{0}lov_protocolo lp,
								{0}tab_pessoa a,
								{0}tab_empreendimento e,
								{0}tab_requerimento r
							where t.id = p.tipo
							and p.protocolo = lp.id
							and p.interessado = a.id(+)
							and p.empreendimento = e.id(+)
							and p.requerimento = r.id(+)
							and p.protocolo_associado = pro_ass.id(+)
							and p.id = :id) d,
						{0}tab_funcionario f,
						{0}tab_setor s,
						{0}tab_setor_endereco se,
						{0}lov_municipio lm,
						{0}lov_estado le
					where f.id = d.emposse
					and s.id = d.setor
					and se.setor(+) = s.id
					and se.municipio = lm.id(+)
					and se.estado = le.id(+)"                    , EsquemaBanco);

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

                using (IDataReader reader = bancoDeDados.ExecutarReader(comando))
                {
                    if (reader.Read())
                    {
                        PessoaRelatorio interessado = new PessoaRelatorio();

                        interessado.Tipo = reader.GetValue <int>("interessado_tipo");
                        if (interessado.IsFisica)
                        {
                            interessado.Fisica.Nome = reader.GetValue <String>("interessado_nomerazaosocial");
                            interessado.Fisica.CPF  = reader.GetValue <String>("interessado_cpfcnpj");
                        }
                        else
                        {
                            interessado.Juridica.RazaoSocial = reader.GetValue <String>("interessado_nomerazaosocial");
                            interessado.Juridica.CNPJ        = reader.GetValue <String>("interessado_cpfcnpj");
                        }

                        EmpreendimentoRelatorio empreendimento = new EmpreendimentoRelatorio();

                        empreendimento.NomeRazao           = reader.GetValue <String>("empreendimento_nome");
                        empreendimento.Codigo              = reader.GetValue <Int32>("emp_codigo");
                        empreendimento.CNPJ                = reader.GetValue <String>("empreendimento_cnpj");
                        protocolo.Nome                     = reader.GetValue <String>("protocolo_nome");
                        protocolo.ProtocoloProcDoc         = reader.GetValue <Int32>("protocolo");
                        protocolo.ProtocoloTexto           = reader.GetValue <String>("protocolo_texto");
                        protocolo.Numero                   = reader.GetValue <String>("protocolo_numero");
                        protocolo.ProtocoloTipo            = reader.GetValue <Int32>("protocolo_tipo");
                        protocolo.TipoTexto                = reader.GetValue <String>("protocolo_tipo_texto");
                        protocolo.ChecagemNumero           = reader.GetValue <String>("checagem");
                        protocolo.RequerimentoNumero       = reader.GetValue <String>("requerimento_numero");
                        protocolo.FiscalizacaoNumero       = reader.GetValue <String>("fiscalizacao_numero");
                        protocolo.Data                     = reader.GetValue <String>("data_criacao");
                        protocolo.SetorId                  = reader.GetValue <Int32>("setor");
                        protocolo.OrgaoMunicipio           = reader.GetValue <String>("municipio");
                        protocolo.OrgaoUF                  = reader.GetValue <String>("uf");
                        protocolo.UsuarioNome              = reader.GetValue <String>("funcionario_nome");
                        protocolo.UsuarioCargo             = reader.GetValue <String>("funcionario_cargo");
                        protocolo.ProtocoloAssociadoNumero = reader.GetValue <String>("numero_associado");
                        protocolo.ProtocoloAssociadoTipo   = reader.GetValue <String>("tipo_associado");
                        protocolo.Destinatario             = reader.GetValue <String>("destinatario");
                        protocolo.SetorDestinatario        = reader.GetValue <String>("destinatario_setor");
                        protocolo.Assunto                  = reader.GetValue <String>("assunto");
                        protocolo.Descricao                = reader.GetValue <String>("descricao");
                        protocolo.Interessado              = interessado;
                        protocolo.Empreendimento           = empreendimento;
                    }

                    reader.Close();
                }

                #endregion
            }

            return(protocolo);
        }
        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);
        }