You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
SIPRP/trunk/PlanosActuacao/src/java/db/providers/UtilizadoresDataProvider.java

130 lines
5.5 KiB

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package db.providers;
import db.entidades.Utilizador;
import global.Global;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
/**
*
* @author lluis
*/
public class UtilizadoresDataProvider extends GenericDataProvider{
public Utilizador getUtilizador(Integer id) throws Exception
{
Utilizador u = new Utilizador();
Statement st = createStatement();
String sql = "SELECT * FROM utilizadores WHERE id = " + id;
ResultSet rs = st.executeQuery(sql);
rs.first();
u.setId(new Integer(rs.getInt("id")));
u.setLogin(rs.getString("login"));
u.setPassword(rs.getString("password"));
u.setData_password(rs.getDate("data_password"));
u.setEmail(rs.getString("email"));
u.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
u.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
u.setAdministrador(rs.getString("administrador"));
u.setTipo(new Integer(rs.getInt("tipo")));
u.setNumero_cedula(rs.getString("numero_cedula"));
u.setCap(rs.getString("cap"));
u.setNome(rs.getString("nome"));
u.setMedico_id(new Integer(rs.getInt("medico_id")));
u.setFuncionario_hst_id(new Integer(rs.getInt("funcionario_hst_id")));
u.setActivo(rs.getString("activo"));
u.setResponsavel_loja(rs.getString("responsavel_loja"));
u.setGestor_geral(rs.getString("gestor_geral"));
u.setApagado(rs.getString("apagado"));
return u;
}
public ArrayList getUtilizadoresListByTipo(Integer tipo, String responsavel_loja, Integer estabelecimento_id) throws Exception
{
ArrayList list = new ArrayList();
Statement st = createStatement();
String sql = "";
String estabelecimento_constraint = "";
if(tipo.intValue() == Global.DIRECTOR_LOJA || tipo.intValue() == Global.RESPONSAVEL_SEGURANCA || tipo.intValue() == Global.DIRECTOR_NACIONAL_SEGURANCA)
{
estabelecimento_constraint = " AND estabelecimento_id = " + estabelecimento_id;
}
if(tipo.intValue() == Global.RESPONSAVEL_SEGURANCA && responsavel_loja.matches("y"))
{
sql = "SELECT * FROM utilizadores WHERE activo = 'y' AND apagado = 'n' AND responsavel_loja = 'y' AND tipo = " + tipo + estabelecimento_constraint;
}
else if(tipo.intValue() == Global.DIRECTOR_LOJA || tipo.intValue() == Global.TECNICO_HS || tipo.intValue() == Global.DIRECTOR_NACIONAL_SEGURANCA)
{
sql = "SELECT * FROM utilizadores WHERE activo = 'y' AND apagado = 'n' AND tipo = " + tipo + estabelecimento_constraint;
}
System.out.println("UTILIZADORES LIST BY TIPO SQL : " + sql);
ResultSet rs = st.executeQuery(sql);
if(rs.isBeforeFirst())
{
rs.first();
do
{
Utilizador u = new Utilizador();
u.setId(new Integer(rs.getInt("id")));
u.setLogin(rs.getString("login"));
u.setPassword(rs.getString("password"));
u.setData_password(rs.getDate("data_password"));
u.setEmail(rs.getString("email"));
u.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
u.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
u.setAdministrador(rs.getString("administrador"));
u.setTipo(new Integer(rs.getInt("tipo")));
u.setNumero_cedula(rs.getString("numero_cedula"));
u.setCap(rs.getString("cap"));
u.setNome(rs.getString("nome"));
u.setMedico_id(new Integer(rs.getInt("medico_id")));
u.setFuncionario_hst_id(new Integer(rs.getInt("funcionario_hst_id")));
u.setActivo(rs.getString("activo"));
u.setResponsavel_loja(rs.getString("responsavel_loja"));
list.add(u);
}while(rs.next());
}
return list;
}
public ArrayList getUtilizadoresList() throws Exception
{
ArrayList list = new ArrayList();
Statement st = createStatement();
String sql = "select * from utilizadores where activo = 'y' and apagado = 'n'";
ResultSet rs = st.executeQuery(sql);
rs.first();
do
{
Utilizador u = new Utilizador();
u.setId(new Integer(rs.getInt("id")));
u.setLogin(rs.getString("login"));
u.setPassword(rs.getString("password"));
u.setData_password(rs.getDate("data_password"));
u.setEmail(rs.getString("email"));
u.setEmpresa_id(new Integer(rs.getInt("empresa_id")));
u.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
u.setAdministrador(rs.getString("administrador"));
u.setTipo(new Integer(rs.getInt("tipo")));
u.setNumero_cedula(rs.getString("numero_cedula"));
u.setCap(rs.getString("cap"));
u.setNome(rs.getString("nome"));
u.setMedico_id(new Integer(rs.getInt("medico_id")));
u.setFuncionario_hst_id(new Integer(rs.getInt("funcionario_hst_id")));
u.setActivo(rs.getString("activo"));
u.setResponsavel_loja(rs.getString("responsavel_loja"));
list.add(u);
}while(rs.next());
return list;
}
}