DTO
Publicado por IAMS (1 intervención) el 29/01/2024 20:01:24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class Entrar implements ActionListener{
private JTextField campoId;
private JPasswordField campoPassword;
private JRadioButton botonRecep;
private JRadioButton botonAdmin;
private RecepDAO rDAO;
private RecepDTO recepcionistaDTO;
private AdministradoresDTO adminDTO;
private AdministradoresDAO adminDAO;
private VRegistro vistaRegis;
private JFrame ventanaRegistro;
public Entrar(VRegistro vistaRegis) {
this.vistaRegis=vistaRegis;
}
@Override
public void actionPerformed(ActionEvent e) {
String id = vistaRegis.getCampoId().getText();
String password = new String(vistaRegis.getCampoPassword().getPassword());
if (!id.isEmpty() && !password.isEmpty()) {
// Verificar qué botón está seleccionado
if (vistaRegis.getRecep().isSelected()) {
// Lógica para recepcionista
recepcionistaDTO = new RecepDTO(Integer.parseInt(id));
recepcionistaDTO.setId_recep(Integer.parseInt(id));
rDAO = new RecepDAO();
rDAO.buscarRecep(recepcionistaDTO);
int id_hotel=recepcionistaDTO.getId_hotel();
System.out.println(id_hotel);
// Verifica la contraseña llamando al método en el DAO
DTO:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class RecepDTO {
private int id_recep;
private String password;
private String nombre;
private String apellido1;
private String apellido2;
private int tlf;
private int id_hotel;
public RecepDTO(int id_recep,String password,String nombre,String apellido1,int tlf,int id_hotel){
this.id_recep = id_recep;
this.password = password;
this.nombre = nombre;
this.apellido1 = apellido1;
this.apellido2 = null;
this.tlf = tlf;
this.id_hotel = id_hotel;
}
public RecepDTO(int id_recep,String password,String nombre,String apellido1,String apellido2,int tlf,int id_hotel){
this.id_recep = id_recep;
this.password = password;
this.nombre = nombre;
this.apellido1 = apellido1;
this.apellido2 = apellido2;
this.tlf = tlf;
this.id_hotel = id_hotel;
}
public RecepDTO(){
this.id_recep = 0;
this.password ="";
this.nombre = "";
this.apellido1 = "";
this.apellido2 = "";
this.tlf = 0;
this.id_hotel = 0;
}
public RecepDTO(int id_recep){
this.id_recep = id_recep;
this.password = password;
this.nombre = nombre;
this.apellido1 = apellido1;
this.apellido2 = apellido2;
this.tlf = tlf;
this.id_hotel = id_hotel;
}
DAO:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public class RecepDAO implements Consultas{
private RecepDTO recep = new RecepDTO();
private PreparedStatement ps = null;
private Conexion con = null;
private ArrayList<RecepDTO> receps = new ArrayList<RecepDTO>();
private ResultSet resultSet = null;
private String suceso;
public void buscarRecep(RecepDTO rDTO) {
this.suceso = "La consulta se ha realizado con exito";
this.receps.clear();
this.con = new Conexion();
try {
if(rDTO.getId_recep()!= 0) {
System.out.println("Entra 1");
this.ps = this.con.getConnect().prepareStatement(BUSCAR_RECEPCIONISTAS_ID);
this.ps.setInt(1, rDTO.getId_recep());
this.resultSet = this.ps.executeQuery();
if(this.resultSet.next()==true) {
System.out.println("Entra 2");
this.setRecep(new RecepDTO());
this.recep.setId_recep(Integer.parseInt(resultSet.getString(1)));
this.recep.setPassword(resultSet.getString(2));
this.recep.setNombre(resultSet.getString(3));
this.recep.setApellido1(resultSet.getString(4));
this.recep.setApellido2(resultSet.getString(5));
this.recep.setTlf(Integer.parseInt(resultSet.getString(6)));
this.recep.setId_hotel(Integer.parseInt(resultSet.getString(7)));
}else{
this.suceso = "El recepcionista no existe";
this.getRecep().setId_recep(0);
}
} else {
this.suceso = "El recepcionista no existe";
this.getRecep().setId_recep(0);
}
}catch(Exception e) {
this.suceso = "Error: "+e;
}finally {
con.cerrarConexion(this.resultSet, this.con.getConnect(), this.ps);
}
}
Valora esta pregunta


0