mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-09 18:03:09 +01:00
feat(test 20230321): solved
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package tutorialJava.examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
|
||||||
|
public class ConnectionManager {
|
||||||
|
|
||||||
|
private static Connection conn = null;
|
||||||
|
|
||||||
|
|
||||||
|
public static Connection getConnection() throws Exception {
|
||||||
|
if (conn == null) {
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
|
||||||
|
conn =
|
||||||
|
(Connection) DriverManager.getConnection (
|
||||||
|
"jdbc:mysql://localhost:3306/alquileres?serverTimezone=UTC",
|
||||||
|
"root", "1234");
|
||||||
|
}
|
||||||
|
return conn;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package tutorialJava.examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.Inquilino;
|
||||||
|
|
||||||
|
|
||||||
|
public class ControladorInquilino {
|
||||||
|
|
||||||
|
|
||||||
|
public static Inquilino
|
||||||
|
findByIdVivienda(int idVivienda) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
|
||||||
|
String sql = "select * from inquilino where "
|
||||||
|
+ "idVivienda = ?";
|
||||||
|
PreparedStatement ps = conn.prepareStatement(sql);
|
||||||
|
ps.setInt(1, idVivienda);
|
||||||
|
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
if (rs.next()) {
|
||||||
|
Inquilino i = new Inquilino();
|
||||||
|
i.setId(rs.getInt("id"));
|
||||||
|
i.setDni(rs.getString("dni"));
|
||||||
|
i.setNombreCompleto(rs.getString("nombreCompleto"));
|
||||||
|
i.setFechaInicioAlquiler(rs.getDate("fechaInicioAlquiler"));
|
||||||
|
i.setFechaFinAlquiler(rs.getDate("fechaFinAlquiler"));
|
||||||
|
i.setIdVivienda(rs.getInt("idVivienda"));
|
||||||
|
i.setIdTipoMorosidad(rs.getInt("idTipoMorosidad"));
|
||||||
|
i.setCuotaMensual(rs.getFloat("cuotaMensual"));
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param i
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static int guardaInquilino (Inquilino i) {
|
||||||
|
try {
|
||||||
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
String sql = "Update inquilino set dni = ?, "
|
||||||
|
+ "nombreCompleto = ?, fechaInicioAlquiler = ?, "
|
||||||
|
+ "fechaFinAlquiler = ?, cuotaMensual = ?, "
|
||||||
|
+ "idVivienda = ?, idTipoMorosidad = ? "
|
||||||
|
+ "where id = ?";
|
||||||
|
PreparedStatement ps = conn.prepareStatement(sql);
|
||||||
|
ps.setString(1, i.getDni());
|
||||||
|
ps.setString(2, i.getNombreCompleto());
|
||||||
|
if (i.getFechaInicioAlquiler() != null) {
|
||||||
|
ps.setDate(3, new java.sql.Date(i.getFechaInicioAlquiler().getTime()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ps.setDate(3, null);
|
||||||
|
}
|
||||||
|
if (i.getFechaFinAlquiler() != null) {
|
||||||
|
ps.setDate(4, new java.sql.Date(i.getFechaFinAlquiler().getTime()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ps.setDate(4, null);
|
||||||
|
}
|
||||||
|
ps.setFloat(5, i.getCuotaMensual());
|
||||||
|
ps.setInt(6, i.getIdVivienda());
|
||||||
|
ps.setInt(7, i.getIdTipoMorosidad());
|
||||||
|
ps.setInt(8, i.getId());
|
||||||
|
|
||||||
|
return ps.executeUpdate();
|
||||||
|
}
|
||||||
|
catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package tutorialJava.examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.Localidad;
|
||||||
|
|
||||||
|
public class ControladorLocalidad {
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Localidad> findAll() {
|
||||||
|
List<Localidad> lista = new ArrayList<Localidad>();
|
||||||
|
try {
|
||||||
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
ResultSet rs =
|
||||||
|
s.executeQuery("select * from localidad");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Localidad l = new Localidad();
|
||||||
|
l.setId(rs.getInt("id"));
|
||||||
|
l.setDescripcion(rs.getString("descripcion"));
|
||||||
|
lista.add(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return lista;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package tutorialJava.examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.TipoMorosidad;
|
||||||
|
|
||||||
|
|
||||||
|
public class ControladorTipoMorosidad {
|
||||||
|
|
||||||
|
|
||||||
|
public static List<TipoMorosidad> findAll() {
|
||||||
|
List<TipoMorosidad> lista = new ArrayList<TipoMorosidad>();
|
||||||
|
try {
|
||||||
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
ResultSet rs =
|
||||||
|
s.executeQuery("select * from tipo_morosidad");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
TipoMorosidad l = new TipoMorosidad();
|
||||||
|
l.setId(rs.getInt("id"));
|
||||||
|
l.setDescripcion(rs.getString("descripcion"));
|
||||||
|
lista.add(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return lista;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package tutorialJava.examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.Vivienda;
|
||||||
|
|
||||||
|
|
||||||
|
public class ControladorVivienda {
|
||||||
|
|
||||||
|
|
||||||
|
public static List<Vivienda>
|
||||||
|
findAllByLocalidadAndFilterDescription(int idLocalidad,
|
||||||
|
String filterDescription) {
|
||||||
|
|
||||||
|
List<Vivienda> lista = new ArrayList<Vivienda>();
|
||||||
|
try {
|
||||||
|
Connection conn = ConnectionManager.getConnection();
|
||||||
|
|
||||||
|
String sql = "select * from vivienda where "
|
||||||
|
+ "idLocalidad = ? and descripcion like ?";
|
||||||
|
PreparedStatement ps = conn.prepareStatement(sql);
|
||||||
|
ps.setInt(1, idLocalidad);
|
||||||
|
ps.setString(2, "%" + filterDescription + "%");
|
||||||
|
|
||||||
|
ResultSet rs = ps.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
Vivienda v = new Vivienda();
|
||||||
|
v.setId(rs.getInt("id"));
|
||||||
|
v.setDescripcion(rs.getString("descripcion"));
|
||||||
|
v.setIdLocalidad(rs.getInt("idLocalidad"));
|
||||||
|
lista.add(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
return lista;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package tutorialJava.examenes.examen20250321.modelo;
|
package tutorialJava.examenes.examen20250321.modelo;
|
||||||
|
|
||||||
public class TipoLocalidad {
|
public class Localidad {
|
||||||
private int id;
|
private int id;
|
||||||
private String descripcion;
|
private String descripcion;
|
||||||
|
|
||||||
public TipoLocalidad() {
|
public Localidad() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public TipoLocalidad(int id, String descripcion) {
|
public Localidad(int id, String descripcion) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.descripcion = descripcion;
|
this.descripcion = descripcion;
|
||||||
@@ -32,7 +32,7 @@ public class TipoLocalidad {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TipoMorosidad [id=" + id + ", descripcion=" + descripcion + "]";
|
return descripcion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ public class TipoMorosidad {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "TipoMorosidad [id=" + id + ", descripcion=" + descripcion + "]";
|
return descripcion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class Vivienda {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Vivienda [id=" + id + ", descripcion=" + descripcion + ", idLocalidad=" + idLocalidad + "]";
|
return descripcion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,16 +5,34 @@ import java.awt.EventQueue;
|
|||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
|
|
||||||
|
import tutorialJava.examenes.examen20250321.controlador.ControladorInquilino;
|
||||||
|
import tutorialJava.examenes.examen20250321.controlador.ControladorLocalidad;
|
||||||
|
import tutorialJava.examenes.examen20250321.controlador.ControladorTipoMorosidad;
|
||||||
|
import tutorialJava.examenes.examen20250321.controlador.ControladorVivienda;
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.Inquilino;
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.Localidad;
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.TipoMorosidad;
|
||||||
|
import tutorialJava.examenes.examen20250321.modelo.Vivienda;
|
||||||
|
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
public class GestionAlquileres extends JFrame {
|
public class GestionAlquileres extends JFrame {
|
||||||
|
|
||||||
@@ -27,6 +45,12 @@ public class GestionAlquileres extends JFrame {
|
|||||||
private JTextField jtfFechaFin;
|
private JTextField jtfFechaFin;
|
||||||
private JTextField jtfCuotaMensual;
|
private JTextField jtfCuotaMensual;
|
||||||
private JTextField jtfFiltroVivienda;
|
private JTextField jtfFiltroVivienda;
|
||||||
|
private JComboBox<Localidad> jcbLocalidad;
|
||||||
|
private JComboBox<TipoMorosidad> jcbTipoMorosidad;
|
||||||
|
private JComboBox<Vivienda> jcbVivienda;
|
||||||
|
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
private JLabel jlblCuotaConIva;
|
||||||
|
private JCheckBox chkActivo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch the application.
|
* Launch the application.
|
||||||
@@ -36,6 +60,7 @@ public class GestionAlquileres extends JFrame {
|
|||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
GestionAlquileres frame = new GestionAlquileres();
|
GestionAlquileres frame = new GestionAlquileres();
|
||||||
|
frame.pack();
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -49,7 +74,6 @@ public class GestionAlquileres extends JFrame {
|
|||||||
*/
|
*/
|
||||||
public GestionAlquileres() {
|
public GestionAlquileres() {
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setBounds(100, 100, 450, 300);
|
|
||||||
contentPane = new JPanel();
|
contentPane = new JPanel();
|
||||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
|
||||||
@@ -78,14 +102,14 @@ public class GestionAlquileres extends JFrame {
|
|||||||
gbc_lblNewLabel_1.gridy = 1;
|
gbc_lblNewLabel_1.gridy = 1;
|
||||||
contentPane.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
contentPane.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||||
|
|
||||||
JComboBox jcbLocalidades = new JComboBox();
|
jcbLocalidad = new JComboBox();
|
||||||
GridBagConstraints gbc_jcbLocalidades = new GridBagConstraints();
|
GridBagConstraints gbc_jcbLocalidad = new GridBagConstraints();
|
||||||
gbc_jcbLocalidades.gridwidth = 2;
|
gbc_jcbLocalidad.gridwidth = 2;
|
||||||
gbc_jcbLocalidades.insets = new Insets(0, 0, 5, 0);
|
gbc_jcbLocalidad.insets = new Insets(0, 0, 5, 0);
|
||||||
gbc_jcbLocalidades.fill = GridBagConstraints.HORIZONTAL;
|
gbc_jcbLocalidad.fill = GridBagConstraints.HORIZONTAL;
|
||||||
gbc_jcbLocalidades.gridx = 1;
|
gbc_jcbLocalidad.gridx = 1;
|
||||||
gbc_jcbLocalidades.gridy = 1;
|
gbc_jcbLocalidad.gridy = 1;
|
||||||
contentPane.add(jcbLocalidades, gbc_jcbLocalidades);
|
contentPane.add(jcbLocalidad, gbc_jcbLocalidad);
|
||||||
|
|
||||||
JLabel lblNewLabel_12 = new JLabel("Filtro de vivienda");
|
JLabel lblNewLabel_12 = new JLabel("Filtro de vivienda");
|
||||||
GridBagConstraints gbc_lblNewLabel_12 = new GridBagConstraints();
|
GridBagConstraints gbc_lblNewLabel_12 = new GridBagConstraints();
|
||||||
@@ -105,6 +129,11 @@ public class GestionAlquileres extends JFrame {
|
|||||||
jtfFiltroVivienda.setColumns(10);
|
jtfFiltroVivienda.setColumns(10);
|
||||||
|
|
||||||
JButton btnFiltroVivienda = new JButton("Filtrar viviendas");
|
JButton btnFiltroVivienda = new JButton("Filtrar viviendas");
|
||||||
|
btnFiltroVivienda.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
filtrarViviendas();
|
||||||
|
}
|
||||||
|
});
|
||||||
GridBagConstraints gbc_btnFiltroVivienda = new GridBagConstraints();
|
GridBagConstraints gbc_btnFiltroVivienda = new GridBagConstraints();
|
||||||
gbc_btnFiltroVivienda.insets = new Insets(0, 0, 5, 0);
|
gbc_btnFiltroVivienda.insets = new Insets(0, 0, 5, 0);
|
||||||
gbc_btnFiltroVivienda.gridx = 2;
|
gbc_btnFiltroVivienda.gridx = 2;
|
||||||
@@ -119,7 +148,12 @@ public class GestionAlquileres extends JFrame {
|
|||||||
gbc_lblNewLabel_2.gridy = 3;
|
gbc_lblNewLabel_2.gridy = 3;
|
||||||
contentPane.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
contentPane.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||||
|
|
||||||
JComboBox jcbVivienda = new JComboBox();
|
jcbVivienda = new JComboBox();
|
||||||
|
jcbVivienda.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
cargarInquilino();
|
||||||
|
}
|
||||||
|
});
|
||||||
GridBagConstraints gbc_jcbVivienda = new GridBagConstraints();
|
GridBagConstraints gbc_jcbVivienda = new GridBagConstraints();
|
||||||
gbc_jcbVivienda.gridwidth = 2;
|
gbc_jcbVivienda.gridwidth = 2;
|
||||||
gbc_jcbVivienda.insets = new Insets(0, 0, 5, 0);
|
gbc_jcbVivienda.insets = new Insets(0, 0, 5, 0);
|
||||||
@@ -210,7 +244,12 @@ public class GestionAlquileres extends JFrame {
|
|||||||
contentPane.add(jtfFechaInicio, gbc_jtfFechaInicio);
|
contentPane.add(jtfFechaInicio, gbc_jtfFechaInicio);
|
||||||
jtfFechaInicio.setColumns(10);
|
jtfFechaInicio.setColumns(10);
|
||||||
|
|
||||||
JCheckBox chkActivo = new JCheckBox("Alquiler en activo");
|
chkActivo = new JCheckBox("Alquiler en activo");
|
||||||
|
chkActivo.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
checkAlquierActivo();
|
||||||
|
}
|
||||||
|
});
|
||||||
GridBagConstraints gbc_chkActivo = new GridBagConstraints();
|
GridBagConstraints gbc_chkActivo = new GridBagConstraints();
|
||||||
gbc_chkActivo.gridwidth = 3;
|
gbc_chkActivo.gridwidth = 3;
|
||||||
gbc_chkActivo.insets = new Insets(0, 0, 5, 0);
|
gbc_chkActivo.insets = new Insets(0, 0, 5, 0);
|
||||||
@@ -245,7 +284,7 @@ public class GestionAlquileres extends JFrame {
|
|||||||
gbc_lblNewLabel_13.gridy = 11;
|
gbc_lblNewLabel_13.gridy = 11;
|
||||||
contentPane.add(lblNewLabel_13, gbc_lblNewLabel_13);
|
contentPane.add(lblNewLabel_13, gbc_lblNewLabel_13);
|
||||||
|
|
||||||
JComboBox jcbTipoMorosidad = new JComboBox();
|
jcbTipoMorosidad = new JComboBox();
|
||||||
GridBagConstraints gbc_jcbTipoMorosidad = new GridBagConstraints();
|
GridBagConstraints gbc_jcbTipoMorosidad = new GridBagConstraints();
|
||||||
gbc_jcbTipoMorosidad.gridwidth = 2;
|
gbc_jcbTipoMorosidad.gridwidth = 2;
|
||||||
gbc_jcbTipoMorosidad.insets = new Insets(0, 0, 5, 5);
|
gbc_jcbTipoMorosidad.insets = new Insets(0, 0, 5, 5);
|
||||||
@@ -279,7 +318,7 @@ public class GestionAlquileres extends JFrame {
|
|||||||
gbc_lblNewLabel_10.gridy = 13;
|
gbc_lblNewLabel_10.gridy = 13;
|
||||||
contentPane.add(lblNewLabel_10, gbc_lblNewLabel_10);
|
contentPane.add(lblNewLabel_10, gbc_lblNewLabel_10);
|
||||||
|
|
||||||
JLabel jlblCuotaConIva = new JLabel("??? €");
|
jlblCuotaConIva = new JLabel("??? €");
|
||||||
GridBagConstraints gbc_jlblCuotaConIva = new GridBagConstraints();
|
GridBagConstraints gbc_jlblCuotaConIva = new GridBagConstraints();
|
||||||
gbc_jlblCuotaConIva.gridwidth = 2;
|
gbc_jlblCuotaConIva.gridwidth = 2;
|
||||||
gbc_jlblCuotaConIva.insets = new Insets(0, 0, 5, 0);
|
gbc_jlblCuotaConIva.insets = new Insets(0, 0, 5, 0);
|
||||||
@@ -288,11 +327,179 @@ public class GestionAlquileres extends JFrame {
|
|||||||
contentPane.add(jlblCuotaConIva, gbc_jlblCuotaConIva);
|
contentPane.add(jlblCuotaConIva, gbc_jlblCuotaConIva);
|
||||||
|
|
||||||
JButton btnGuardar = new JButton("Guardar cambios");
|
JButton btnGuardar = new JButton("Guardar cambios");
|
||||||
|
btnGuardar.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
guardarInquilino();
|
||||||
|
}
|
||||||
|
});
|
||||||
GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
|
GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
|
||||||
gbc_btnGuardar.gridwidth = 3;
|
gbc_btnGuardar.gridwidth = 3;
|
||||||
gbc_btnGuardar.gridx = 0;
|
gbc_btnGuardar.gridx = 0;
|
||||||
gbc_btnGuardar.gridy = 14;
|
gbc_btnGuardar.gridy = 14;
|
||||||
contentPane.add(btnGuardar, gbc_btnGuardar);
|
contentPane.add(btnGuardar, gbc_btnGuardar);
|
||||||
|
|
||||||
|
// Carga de todas las localidades y tipos de morosidad
|
||||||
|
cargarLocalidades();
|
||||||
|
cargarTiposMorosidad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void cargarLocalidades() {
|
||||||
|
for(Localidad l : ControladorLocalidad.findAll()) {
|
||||||
|
jcbLocalidad.addItem(l);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void cargarTiposMorosidad() {
|
||||||
|
for(TipoMorosidad l : ControladorTipoMorosidad.findAll()) {
|
||||||
|
jcbTipoMorosidad.addItem(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void filtrarViviendas() {
|
||||||
|
Localidad localidadSeleccionada =
|
||||||
|
(Localidad) this.jcbLocalidad.getSelectedItem();
|
||||||
|
int idLocalidadSeleccionada = localidadSeleccionada.getId();
|
||||||
|
String filtroVivienda = this.jtfFiltroVivienda.getText();
|
||||||
|
|
||||||
|
List<Vivienda> viviendas = ControladorVivienda
|
||||||
|
.findAllByLocalidadAndFilterDescription(
|
||||||
|
idLocalidadSeleccionada, filtroVivienda);
|
||||||
|
|
||||||
|
this.jcbVivienda.removeAllItems();
|
||||||
|
for (Vivienda v : viviendas) {
|
||||||
|
this.jcbVivienda.addItem(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void cargarInquilino() {
|
||||||
|
if (jcbVivienda.getItemCount() > 0) {
|
||||||
|
Vivienda viviendaSeleccionada =
|
||||||
|
(Vivienda) jcbVivienda.getSelectedItem();
|
||||||
|
int idVivienda = viviendaSeleccionada.getId();
|
||||||
|
|
||||||
|
Inquilino i = ControladorInquilino
|
||||||
|
.findByIdVivienda(idVivienda);
|
||||||
|
|
||||||
|
if (i != null) {
|
||||||
|
this.jtfId.setText("" + i.getId());
|
||||||
|
this.jtfDni.setText(i.getDni());
|
||||||
|
this.jtfNombreInquilino.setText(i.getNombreCompleto());
|
||||||
|
if (i.getFechaInicioAlquiler() != null) {
|
||||||
|
this.jtfFechaInicio.setText(
|
||||||
|
sdf.format(i.getFechaInicioAlquiler()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.jtfFechaInicio.setText("");
|
||||||
|
}
|
||||||
|
if (i.getFechaFinAlquiler() != null) {
|
||||||
|
this.jtfFechaFin.setText(
|
||||||
|
sdf.format(i.getFechaFinAlquiler()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.jtfFechaFin.setText("");
|
||||||
|
}
|
||||||
|
// Tipo de morosidad
|
||||||
|
for(int j = 0; j < this.jcbTipoMorosidad.getItemCount(); j++) {
|
||||||
|
if (this.jcbTipoMorosidad.getItemAt(j).getId() ==
|
||||||
|
i.getIdTipoMorosidad()) {
|
||||||
|
this.jcbTipoMorosidad.setSelectedIndex(j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Cuota mensual
|
||||||
|
this.jtfCuotaMensual.setText("" + i.getCuotaMensual());
|
||||||
|
this.jlblCuotaConIva.setText("" + (i.getCuotaMensual() * 1.21));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void checkAlquierActivo() {
|
||||||
|
if (chkActivo.isSelected()) {
|
||||||
|
this.jtfFechaFin.setEnabled(false);
|
||||||
|
this.jtfFechaFin.setText("");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.jtfFechaFin.setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private void guardarInquilino() {
|
||||||
|
Inquilino i = new Inquilino();
|
||||||
|
i.setId(Integer.parseInt(this.jtfId.getText()));
|
||||||
|
i.setDni(this.jtfDni.getText());
|
||||||
|
if (this.jtfNombreInquilino.getText().trim().equals("")) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Introduzca un nombre para el inquilino");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
i.setNombreCompleto(this.jtfNombreInquilino.getText());
|
||||||
|
Date fechaInicio = getFechaFromString(this.jtfFechaInicio.getText());
|
||||||
|
if (!jtfFechaInicio.getText().trim().equals("") &&
|
||||||
|
fechaInicio == null) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Fecha de inicio no válida, use formato dd/MM/yyyy");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i.setFechaInicioAlquiler(fechaInicio);
|
||||||
|
}
|
||||||
|
Date fechaFin = getFechaFromString(this.jtfFechaFin.getText());
|
||||||
|
if (!jtfFechaFin.getText().trim().equals("") &&
|
||||||
|
fechaFin == null) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Fecha de fin no válida, use formato dd/MM/yyyy");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
i.setFechaFinAlquiler(fechaFin);
|
||||||
|
}
|
||||||
|
TipoMorosidad morosidadSeleccionada =
|
||||||
|
(TipoMorosidad) this.jcbTipoMorosidad.getSelectedItem();
|
||||||
|
i.setIdTipoMorosidad(morosidadSeleccionada.getId());
|
||||||
|
Vivienda viviendaSeleccionada =
|
||||||
|
(Vivienda) this.jcbVivienda.getSelectedItem();
|
||||||
|
i.setIdVivienda(viviendaSeleccionada.getId());
|
||||||
|
i.setCuotaMensual(Float.parseFloat(this.jtfCuotaMensual.getText()));
|
||||||
|
|
||||||
|
if (ControladorInquilino.guardaInquilino(i) > 0) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Inquilino almacenado");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JOptionPane.showMessageDialog(null, "Algo ha fallado");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private Date getFechaFromString(String strDate) {
|
||||||
|
try {
|
||||||
|
return sdf.parse(strDate);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user