Examen 2025/03/21
This commit is contained in:
51
.idea/workspace.xml
generated
51
.idea/workspace.xml
generated
@@ -4,20 +4,20 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e2c4f742-461e-4c7a-a6e0-b5f4b8e8f229" name="Changes" comment="Examen 2025/01/31">
|
<list default="true" id="e2c4f742-461e-4c7a-a6e0-b5f4b8e8f229" name="Changes" comment="Examen 2025/03/21">
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio01/Main.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/ExamenesProgramacion.eml" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio01/Producto.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/ExamenesProgramacion.userlibraries" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio02/Letra.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/librerias/Driver_MySQL_Connector_J/mysql-connector-java-8.0.19.jar" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio02/Main.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/controlador/ControladorInquilino.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio03/Main.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/controlador/ControladorLocalidad.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio03/Prestamo.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/controlador/ControladorMorosidad.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/Main.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/controlador/ControladorVivienda.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/Matematico.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/controlador/GestorConexiones.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/NumeroMenor100Exception.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/modelo/Inquilino.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/listener/CheckeadorNums.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/modelo/Localidad.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/listener/NumRepetidoEvent.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/modelo/Morosidad.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04/listener/NumsListener.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/modelo/Vivienda.java" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250221/utils/Utils.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/examenes/examen20250321/vista/GestionAlquiler.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@@ -54,25 +54,32 @@
|
|||||||
"Application.Ejercicio_c.executor": "Run",
|
"Application.Ejercicio_c.executor": "Run",
|
||||||
"Application.Ejercicio_d.executor": "Run",
|
"Application.Ejercicio_d.executor": "Run",
|
||||||
"Application.Ejercicio_e.executor": "Run",
|
"Application.Ejercicio_e.executor": "Run",
|
||||||
|
"Application.GestionAlquiler.executor": "Run",
|
||||||
"Application.Main.executor": "Run",
|
"Application.Main.executor": "Run",
|
||||||
"Application.Zoologico.executor": "Run",
|
"Application.Zoologico.executor": "Run",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
|
"com.codeium.enabled": "true",
|
||||||
"dart.analysis.tool.window.visible": "false",
|
"dart.analysis.tool.window.visible": "false",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "main",
|
||||||
"kotlin-language-version-configured": "true",
|
"kotlin-language-version-configured": "true",
|
||||||
"last_opened_file_path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/examenes/examen20250221/ejercicio04",
|
"last_opened_file_path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/librerias",
|
||||||
"onboarding.tips.debug.path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/net/h4ckx0r/Main.java",
|
"onboarding.tips.debug.path": "/Users/h4ckx0r/IdeaProjects/ExamenesProgramacion/src/main/java/net/h4ckx0r/Main.java",
|
||||||
|
"project.structure.last.edited": "Libraries",
|
||||||
|
"project.structure.proportion": "0.0",
|
||||||
|
"project.structure.side.proportion": "0.2",
|
||||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
"show.migrate.to.gradle.popup": "false"
|
"show.migrate.to.gradle.popup": "false"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="CopyFile.RECENT_KEYS">
|
<key name="CopyFile.RECENT_KEYS">
|
||||||
|
<recent name="$PROJECT_DIR$/librerias" />
|
||||||
<recent name="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04" />
|
<recent name="$PROJECT_DIR$/src/main/java/examenes/examen20250221/ejercicio04" />
|
||||||
<recent name="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04" />
|
<recent name="$PROJECT_DIR$/src/main/java/examenes/examen20250131/ejercicio04" />
|
||||||
</key>
|
</key>
|
||||||
<key name="CopyClassDialog.RECENTS_KEY">
|
<key name="CopyClassDialog.RECENTS_KEY">
|
||||||
|
<recent name="examenes.examen20250321.controlador" />
|
||||||
<recent name="examenes.examen20250221.ejercicio04" />
|
<recent name="examenes.examen20250221.ejercicio04" />
|
||||||
<recent name="examenes.examen20241213" />
|
<recent name="examenes.examen20241213" />
|
||||||
<recent name="examenes.examen20241122" />
|
<recent name="examenes.examen20241122" />
|
||||||
@@ -192,7 +199,15 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1738328024100</updated>
|
<updated>1738328024100</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="14" />
|
<task id="LOCAL-00014" summary="Examen 2025/02/21">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1740142696710</created>
|
||||||
|
<option name="number" value="00014" />
|
||||||
|
<option name="presentableId" value="LOCAL-00014" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1740142696710</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="15" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="Vcs.Log.Tabs.Properties">
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
@@ -220,6 +235,8 @@
|
|||||||
<MESSAGE value="Examen 2024/11/21" />
|
<MESSAGE value="Examen 2024/11/21" />
|
||||||
<MESSAGE value="Examen 2024/12/13" />
|
<MESSAGE value="Examen 2024/12/13" />
|
||||||
<MESSAGE value="Examen 2025/01/31" />
|
<MESSAGE value="Examen 2025/01/31" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="Examen 2025/01/31" />
|
<MESSAGE value="Examen 2025/02/21" />
|
||||||
|
<MESSAGE value="Examen 2025/03/21" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="Examen 2025/03/21" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
9
ExamenesProgramacion.eml
Normal file
9
ExamenesProgramacion.eml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<component LANGUAGE_LEVEL="JDK_23" inheritJdk="true">
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes"/>
|
||||||
|
<contentEntry url="file://$MODULE_DIR$">
|
||||||
|
<testFolder url="file://$MODULE_DIR$/src/test/java"/>
|
||||||
|
<testFolder url="file://$MODULE_DIR$/src/test/resources"/>
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target"/>
|
||||||
|
</contentEntry>
|
||||||
|
</component>
|
||||||
3
ExamenesProgramacion.userlibraries
Normal file
3
ExamenesProgramacion.userlibraries
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<eclipse-userlibraries />
|
||||||
|
|
||||||
Binary file not shown.
@@ -0,0 +1,68 @@
|
|||||||
|
package examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import examenes.examen20250321.modelo.Inquilino;
|
||||||
|
import examenes.examen20250321.modelo.Vivienda;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class ControladorInquilino {
|
||||||
|
public static Inquilino obtenerInquilino(Vivienda v) {
|
||||||
|
Connection conn = GestorConexiones.getConnection();
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement pt = conn.prepareStatement("select * from inquilino where idVivienda = ? limit 1;");
|
||||||
|
pt.setInt(1, v.getId());
|
||||||
|
|
||||||
|
ResultSet rs = pt.executeQuery();
|
||||||
|
|
||||||
|
rs.next();
|
||||||
|
|
||||||
|
return new Inquilino(
|
||||||
|
rs.getInt("id"),
|
||||||
|
rs.getString("dni"),
|
||||||
|
rs.getString("nombreCompleto"),
|
||||||
|
rs.getDate("fechaInicioAlquiler"),
|
||||||
|
rs.getDate("fechaFinAlquiler"),
|
||||||
|
rs.getFloat("cuotaMensual"),
|
||||||
|
rs.getInt("idVivienda"),
|
||||||
|
rs.getInt("idTipoMorosidad")
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int guardarInquilino(Inquilino i) {
|
||||||
|
Connection conn = GestorConexiones.getConnection();
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement pt = conn.prepareStatement("update inquilino set " +
|
||||||
|
"dni = ?," +
|
||||||
|
"nombreCompleto = ?," +
|
||||||
|
"fechaInicioAlquiler = ?," +
|
||||||
|
"fechaFinAlquiler = ?," +
|
||||||
|
"cuotaMensual = ?," +
|
||||||
|
"idVivienda = ?," +
|
||||||
|
"idTipoMorosidad = ?" +
|
||||||
|
" where id = ?");
|
||||||
|
|
||||||
|
pt.setString(1, i.getDni());
|
||||||
|
pt.setString(2, i.getNombreCompleto());
|
||||||
|
pt.setDate(3, new Date(i.getFechaInicioAlquiler().getTime()));
|
||||||
|
if (i.getFechaFinAlquiler() != null) {
|
||||||
|
pt.setDate(4, new Date(i.getFechaFinAlquiler().getTime()));
|
||||||
|
} else pt.setDate(4, null);
|
||||||
|
pt.setFloat(5, i.getCuotaMensual());
|
||||||
|
pt.setInt(6, i.getIdVivienda());
|
||||||
|
pt.setInt(7, i.getIdTipoMorosidad());
|
||||||
|
pt.setInt(8, i.getId());
|
||||||
|
|
||||||
|
return pt.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import examenes.examen20250321.modelo.Localidad;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ControladorLocalidad {
|
||||||
|
public static List<Localidad> getAllLocalidades() {
|
||||||
|
Connection conn = GestorConexiones.getConnection();
|
||||||
|
List<Localidad> localidades = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Statement st = conn.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery("select * from localidad;");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
localidades.add(new Localidad(rs.getInt("id"), rs.getString("descripcion")));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return localidades;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import examenes.examen20250321.modelo.Localidad;
|
||||||
|
import examenes.examen20250321.modelo.Morosidad;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ControladorMorosidad {
|
||||||
|
public static List<Morosidad> getAllMorosidades() { // Morosidades?? Vaya nombre me invento
|
||||||
|
Connection conn = GestorConexiones.getConnection();
|
||||||
|
List<Morosidad> morosidades = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
Statement st = conn.createStatement();
|
||||||
|
ResultSet rs = st.executeQuery("select * from tipo_morosidad;");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
morosidades.add(new Morosidad(rs.getInt("id"), rs.getString("descripcion")));
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return morosidades;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import examenes.examen20250321.modelo.Localidad;
|
||||||
|
import examenes.examen20250321.modelo.Vivienda;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class ControladorVivienda {
|
||||||
|
public static List<Vivienda> getAllViviendasFromLocalidadYFiltrado(Localidad l, String textoAFiltrar) {
|
||||||
|
Connection conn = GestorConexiones.getConnection();
|
||||||
|
List<Vivienda> viviendas = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
PreparedStatement pt = null;
|
||||||
|
if (Objects.equals(textoAFiltrar, "")) {
|
||||||
|
pt = conn.prepareStatement("select * from vivienda where idLocalidad = ?;");
|
||||||
|
} else {
|
||||||
|
pt = conn.prepareStatement("select * from vivienda where idLocalidad = ? and descripcion like ?;");
|
||||||
|
pt.setString(2, "%" + textoAFiltrar + "%");
|
||||||
|
}
|
||||||
|
pt.setInt(1, l.getId());
|
||||||
|
ResultSet rs = pt.executeQuery();
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
viviendas.add(new Vivienda(rs.getInt("id"), rs.getString("descripcion"), rs.getInt("idLocalidad")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return viviendas;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package examenes.examen20250321.controlador;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
|
||||||
|
public class GestorConexiones {
|
||||||
|
|
||||||
|
private static Connection openConnection;
|
||||||
|
|
||||||
|
private static String getMySQLConnectionString() {
|
||||||
|
String host = "127.0.0.1:3310";
|
||||||
|
String schema = "alquileres";
|
||||||
|
String properties = "?autoReconnect=true&serverTimezone=Europe/Madrid&useSSL=False&allowPublicKeyRetrieval=TRUE";
|
||||||
|
String user = "root";
|
||||||
|
String password = "1234";
|
||||||
|
|
||||||
|
return "jdbc:mysql://" + user + ":" + password + "@" + host + "/" + schema + properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Connection getConnection() {
|
||||||
|
if (openConnection == null) {
|
||||||
|
try {
|
||||||
|
openConnection = DriverManager.getConnection(getMySQLConnectionString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return openConnection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getMySQLDriver() {
|
||||||
|
return "com.mysql.cj.jdbc.Driver";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
106
src/main/java/examenes/examen20250321/modelo/Inquilino.java
Normal file
106
src/main/java/examenes/examen20250321/modelo/Inquilino.java
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
package examenes.examen20250321.modelo;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Inquilino {
|
||||||
|
private int id;
|
||||||
|
private String dni;
|
||||||
|
private String nombreCompleto;
|
||||||
|
private Date fechaInicioAlquiler;
|
||||||
|
private Date fechaFinAlquiler;
|
||||||
|
private float cuotaMensual;
|
||||||
|
private int idVivienda;
|
||||||
|
private int idTipoMorosidad;
|
||||||
|
|
||||||
|
public Inquilino() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Inquilino(int id, String dni, String nombreCompleto, Date fechaInicioAlquiler, Date fechaFinAlquiler, float cuotaMensual, int idVivienda, int idTipoMorosidad) {
|
||||||
|
this.id = id;
|
||||||
|
this.dni = dni;
|
||||||
|
this.nombreCompleto = nombreCompleto;
|
||||||
|
this.fechaInicioAlquiler = fechaInicioAlquiler;
|
||||||
|
this.fechaFinAlquiler = fechaFinAlquiler;
|
||||||
|
this.cuotaMensual = cuotaMensual;
|
||||||
|
this.idVivienda = idVivienda;
|
||||||
|
this.idTipoMorosidad = idTipoMorosidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDni() {
|
||||||
|
return dni;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDni(String dni) {
|
||||||
|
this.dni = dni;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNombreCompleto() {
|
||||||
|
return nombreCompleto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNombreCompleto(String nombreCompleto) {
|
||||||
|
this.nombreCompleto = nombreCompleto;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getFechaInicioAlquiler() {
|
||||||
|
return fechaInicioAlquiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFechaInicioAlquiler(Date fechaInicioAlquiler) {
|
||||||
|
this.fechaInicioAlquiler = fechaInicioAlquiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getFechaFinAlquiler() {
|
||||||
|
return fechaFinAlquiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFechaFinAlquiler(Date fechaFinAlquiler) {
|
||||||
|
this.fechaFinAlquiler = fechaFinAlquiler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getCuotaMensual() {
|
||||||
|
return cuotaMensual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCuotaMensual(float cuotaMensual) {
|
||||||
|
this.cuotaMensual = cuotaMensual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIdVivienda() {
|
||||||
|
return idVivienda;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdVivienda(int idVivienda) {
|
||||||
|
this.idVivienda = idVivienda;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIdTipoMorosidad() {
|
||||||
|
return idTipoMorosidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdTipoMorosidad(int idTipoMorosidad) {
|
||||||
|
this.idTipoMorosidad = idTipoMorosidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Inquilino{" +
|
||||||
|
"id=" + id +
|
||||||
|
", dni='" + dni + '\'' +
|
||||||
|
", nombreCompleto='" + nombreCompleto + '\'' +
|
||||||
|
", fechaInicioAlquiler=" + fechaInicioAlquiler +
|
||||||
|
", fechaFinAlquiler=" + fechaFinAlquiler +
|
||||||
|
", cuotaMensual=" + cuotaMensual +
|
||||||
|
", idVivienda=" + idVivienda +
|
||||||
|
", idTipoMorosidad=" + idTipoMorosidad +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/main/java/examenes/examen20250321/modelo/Localidad.java
Normal file
35
src/main/java/examenes/examen20250321/modelo/Localidad.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package examenes.examen20250321.modelo;
|
||||||
|
|
||||||
|
public class Localidad {
|
||||||
|
private int id;
|
||||||
|
private String descripcion;
|
||||||
|
|
||||||
|
public Localidad() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Localidad(int id, String descripcion) {
|
||||||
|
this.id = id;
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescripcion() {
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescripcion(String descripcion) {
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/main/java/examenes/examen20250321/modelo/Morosidad.java
Normal file
35
src/main/java/examenes/examen20250321/modelo/Morosidad.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package examenes.examen20250321.modelo;
|
||||||
|
|
||||||
|
public class Morosidad {
|
||||||
|
private int id;
|
||||||
|
private String descripcion;
|
||||||
|
|
||||||
|
public Morosidad() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Morosidad(int id, String descripcion) {
|
||||||
|
this.id = id;
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescripcion() {
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescripcion(String descripcion) {
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
}
|
||||||
45
src/main/java/examenes/examen20250321/modelo/Vivienda.java
Normal file
45
src/main/java/examenes/examen20250321/modelo/Vivienda.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package examenes.examen20250321.modelo;
|
||||||
|
|
||||||
|
public class Vivienda {
|
||||||
|
private int id;
|
||||||
|
private String descripcion;
|
||||||
|
private int idLocalidad;
|
||||||
|
|
||||||
|
public Vivienda() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vivienda(int id, String descripcion, int idLocalidad) {
|
||||||
|
this.id = id;
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
this.idLocalidad = idLocalidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescripcion() {
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescripcion(String descripcion) {
|
||||||
|
this.descripcion = descripcion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIdLocalidad() {
|
||||||
|
return idLocalidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdLocalidad(int idLocalidad) {
|
||||||
|
this.idLocalidad = idLocalidad;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return descripcion;
|
||||||
|
}
|
||||||
|
}
|
||||||
464
src/main/java/examenes/examen20250321/vista/GestionAlquiler.java
Normal file
464
src/main/java/examenes/examen20250321/vista/GestionAlquiler.java
Normal file
@@ -0,0 +1,464 @@
|
|||||||
|
package examenes.examen20250321.vista;
|
||||||
|
|
||||||
|
import examenes.examen20250321.controlador.ControladorInquilino;
|
||||||
|
import examenes.examen20250321.controlador.ControladorLocalidad;
|
||||||
|
import examenes.examen20250321.controlador.ControladorMorosidad;
|
||||||
|
import examenes.examen20250321.controlador.ControladorVivienda;
|
||||||
|
import examenes.examen20250321.modelo.Inquilino;
|
||||||
|
import examenes.examen20250321.modelo.Localidad;
|
||||||
|
import examenes.examen20250321.modelo.Morosidad;
|
||||||
|
import examenes.examen20250321.modelo.Vivienda;
|
||||||
|
|
||||||
|
import java.awt.EventQueue;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.border.EmptyBorder;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.List;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class GestionAlquiler extends JFrame {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private JPanel contentPane;
|
||||||
|
|
||||||
|
private JComboBox<Localidad> comboBoxLocalidad;
|
||||||
|
private JComboBox<Vivienda> comboBoxVivienda;
|
||||||
|
private JComboBox<Morosidad> comboBoxMorosidad;
|
||||||
|
|
||||||
|
|
||||||
|
private JTextField textFieldFiltroVivienda;
|
||||||
|
private JTextField textFieldDni;
|
||||||
|
private JTextField textFieldId;
|
||||||
|
private JTextField textFieldNombreCompleto;
|
||||||
|
private JTextField textFieldFechaInicio;
|
||||||
|
private JCheckBox checkBoxAlquiler;
|
||||||
|
private JTextField textFieldFechaFin;
|
||||||
|
private JTextField textFieldCuotaMensualidad;
|
||||||
|
|
||||||
|
|
||||||
|
private JLabel labelCalculoConIva;
|
||||||
|
|
||||||
|
|
||||||
|
private SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch the application.
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
EventQueue.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
GestionAlquiler frame = new GestionAlquiler();
|
||||||
|
frame.cargarLocalidad();
|
||||||
|
frame.filtrarVivienda();
|
||||||
|
frame.cargarMorosidad();
|
||||||
|
frame.setVisible(true);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the frame.
|
||||||
|
*/
|
||||||
|
public GestionAlquiler() {
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
setBounds(100, 100, 500, 480);
|
||||||
|
contentPane = new JPanel();
|
||||||
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
|
||||||
|
setContentPane(contentPane);
|
||||||
|
contentPane.setLayout(new BorderLayout(0, 0));
|
||||||
|
|
||||||
|
JPanel panel = new JPanel();
|
||||||
|
contentPane.add(panel, BorderLayout.NORTH);
|
||||||
|
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
JLabel lblNewLabel = new JLabel("Gestión de alquileres");
|
||||||
|
lblNewLabel.setFont(new Font("Lucida Grande", Font.BOLD, 16));
|
||||||
|
lblNewLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
panel.add(lblNewLabel);
|
||||||
|
|
||||||
|
JPanel panel_1 = new JPanel();
|
||||||
|
panel.add(panel_1);
|
||||||
|
GridBagLayout gbl_panel_1 = new GridBagLayout();
|
||||||
|
gbl_panel_1.columnWidths = new int[]{0, 0, 0, 0};
|
||||||
|
gbl_panel_1.rowHeights = new int[]{0, 0, 0, 0};
|
||||||
|
gbl_panel_1.columnWeights = new double[]{1.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||||
|
gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||||
|
panel_1.setLayout(gbl_panel_1);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_1 = new JLabel("Localidad:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_1.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_1.gridx = 0;
|
||||||
|
gbc_lblNewLabel_1.gridy = 0;
|
||||||
|
panel_1.add(lblNewLabel_1, gbc_lblNewLabel_1);
|
||||||
|
|
||||||
|
comboBoxLocalidad = new JComboBox<>();
|
||||||
|
GridBagConstraints gbc_comboBox = new GridBagConstraints();
|
||||||
|
gbc_comboBox.gridwidth = 2;
|
||||||
|
gbc_comboBox.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_comboBox.gridx = 1;
|
||||||
|
gbc_comboBox.gridy = 0;
|
||||||
|
panel_1.add(comboBoxLocalidad, gbc_comboBox);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_2 = new JLabel("Filtro de vivienda:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_2.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_2.gridx = 0;
|
||||||
|
gbc_lblNewLabel_2.gridy = 1;
|
||||||
|
panel_1.add(lblNewLabel_2, gbc_lblNewLabel_2);
|
||||||
|
|
||||||
|
textFieldFiltroVivienda = new JTextField();
|
||||||
|
GridBagConstraints gbc_textField = new GridBagConstraints();
|
||||||
|
gbc_textField.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_textField.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_textField.gridx = 1;
|
||||||
|
gbc_textField.gridy = 1;
|
||||||
|
panel_1.add(textFieldFiltroVivienda, gbc_textField);
|
||||||
|
textFieldFiltroVivienda.setColumns(10);
|
||||||
|
|
||||||
|
JButton btnNewButton = new JButton("Filtrar viviendas");
|
||||||
|
btnNewButton.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
filtrarVivienda();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
|
||||||
|
gbc_btnNewButton.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_btnNewButton.gridx = 2;
|
||||||
|
gbc_btnNewButton.gridy = 1;
|
||||||
|
panel_1.add(btnNewButton, gbc_btnNewButton);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_3 = new JLabel("Vivienda:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_3.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_3.insets = new Insets(0, 0, 0, 5);
|
||||||
|
gbc_lblNewLabel_3.gridx = 0;
|
||||||
|
gbc_lblNewLabel_3.gridy = 2;
|
||||||
|
panel_1.add(lblNewLabel_3, gbc_lblNewLabel_3);
|
||||||
|
|
||||||
|
comboBoxVivienda = new JComboBox<>();
|
||||||
|
comboBoxVivienda.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
cargarInquilinoEnPantalla();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
GridBagConstraints gbc_comboBox_1 = new GridBagConstraints();
|
||||||
|
gbc_comboBox_1.gridwidth = 2;
|
||||||
|
gbc_comboBox_1.insets = new Insets(0, 0, 0, 5);
|
||||||
|
gbc_comboBox_1.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_comboBox_1.gridx = 1;
|
||||||
|
gbc_comboBox_1.gridy = 2;
|
||||||
|
panel_1.add(comboBoxVivienda, gbc_comboBox_1);
|
||||||
|
|
||||||
|
JPanel panel_2 = new JPanel();
|
||||||
|
contentPane.add(panel_2, BorderLayout.CENTER);
|
||||||
|
panel_2.setLayout(new BoxLayout(panel_2, BoxLayout.Y_AXIS));
|
||||||
|
|
||||||
|
JLabel lblNewLabel_4 = new JLabel("Datos del inquilino");
|
||||||
|
lblNewLabel_4.setFont(new Font("Lucida Grande", Font.BOLD, 16));
|
||||||
|
lblNewLabel_4.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
panel_2.add(lblNewLabel_4);
|
||||||
|
|
||||||
|
JPanel panel_1_1 = new JPanel();
|
||||||
|
panel_2.add(panel_1_1);
|
||||||
|
GridBagLayout gbl_panel_1_1 = new GridBagLayout();
|
||||||
|
gbl_panel_1_1.columnWidths = new int[]{0, 0, 0, 0};
|
||||||
|
gbl_panel_1_1.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||||
|
gbl_panel_1_1.columnWeights = new double[]{1.0, 1.0, 0.0, Double.MIN_VALUE};
|
||||||
|
gbl_panel_1_1.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
|
||||||
|
panel_1_1.setLayout(gbl_panel_1_1);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_1_1 = new JLabel("Id:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_1_1 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_1_1.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_1_1.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_1_1.gridx = 0;
|
||||||
|
gbc_lblNewLabel_1_1.gridy = 0;
|
||||||
|
panel_1_1.add(lblNewLabel_1_1, gbc_lblNewLabel_1_1);
|
||||||
|
|
||||||
|
textFieldId = new JTextField();
|
||||||
|
textFieldId.setEnabled(false);
|
||||||
|
GridBagConstraints gbc_textField_2 = new GridBagConstraints();
|
||||||
|
gbc_textField_2.gridwidth = 2;
|
||||||
|
gbc_textField_2.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_textField_2.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_textField_2.gridx = 1;
|
||||||
|
gbc_textField_2.gridy = 0;
|
||||||
|
panel_1_1.add(textFieldId, gbc_textField_2);
|
||||||
|
textFieldId.setColumns(10);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_2_1 = new JLabel("DNI:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_2_1 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_2_1.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_2_1.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_2_1.gridx = 0;
|
||||||
|
gbc_lblNewLabel_2_1.gridy = 1;
|
||||||
|
panel_1_1.add(lblNewLabel_2_1, gbc_lblNewLabel_2_1);
|
||||||
|
|
||||||
|
textFieldDni = new JTextField();
|
||||||
|
textFieldDni.setColumns(10);
|
||||||
|
GridBagConstraints gbc_textField_1 = new GridBagConstraints();
|
||||||
|
gbc_textField_1.gridwidth = 2;
|
||||||
|
gbc_textField_1.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_textField_1.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_textField_1.gridx = 1;
|
||||||
|
gbc_textField_1.gridy = 1;
|
||||||
|
panel_1_1.add(textFieldDni, gbc_textField_1);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_3_1 = new JLabel("Nombre completo:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_3_1 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_3_1.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_3_1.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_3_1.gridx = 0;
|
||||||
|
gbc_lblNewLabel_3_1.gridy = 2;
|
||||||
|
panel_1_1.add(lblNewLabel_3_1, gbc_lblNewLabel_3_1);
|
||||||
|
|
||||||
|
textFieldNombreCompleto = new JTextField();
|
||||||
|
GridBagConstraints gbc_textField_3 = new GridBagConstraints();
|
||||||
|
gbc_textField_3.gridwidth = 2;
|
||||||
|
gbc_textField_3.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_textField_3.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_textField_3.gridx = 1;
|
||||||
|
gbc_textField_3.gridy = 2;
|
||||||
|
panel_1_1.add(textFieldNombreCompleto, gbc_textField_3);
|
||||||
|
textFieldNombreCompleto.setColumns(10);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_10 = new JLabel("Fecha inicio:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_10 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_10.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_10.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_10.gridx = 0;
|
||||||
|
gbc_lblNewLabel_10.gridy = 3;
|
||||||
|
panel_1_1.add(lblNewLabel_10, gbc_lblNewLabel_10);
|
||||||
|
|
||||||
|
textFieldFechaInicio = new JTextField();
|
||||||
|
GridBagConstraints gbc_textFieldFechaInicio = new GridBagConstraints();
|
||||||
|
gbc_textFieldFechaInicio.gridwidth = 2;
|
||||||
|
gbc_textFieldFechaInicio.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_textFieldFechaInicio.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_textFieldFechaInicio.gridx = 1;
|
||||||
|
gbc_textFieldFechaInicio.gridy = 3;
|
||||||
|
panel_1_1.add(textFieldFechaInicio, gbc_textFieldFechaInicio);
|
||||||
|
textFieldFechaInicio.setColumns(10);
|
||||||
|
|
||||||
|
checkBoxAlquiler = new JCheckBox("Alquiler en activo");
|
||||||
|
checkBoxAlquiler.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
alternarFechaFin();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
GridBagConstraints gbc_chckbxNewCheckBox = new GridBagConstraints();
|
||||||
|
gbc_chckbxNewCheckBox.gridwidth = 2;
|
||||||
|
gbc_chckbxNewCheckBox.anchor = GridBagConstraints.WEST;
|
||||||
|
gbc_chckbxNewCheckBox.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_chckbxNewCheckBox.gridx = 1;
|
||||||
|
gbc_chckbxNewCheckBox.gridy = 4;
|
||||||
|
panel_1_1.add(checkBoxAlquiler, gbc_chckbxNewCheckBox);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_5 = new JLabel("Fecha de fin:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_5 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_5.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_5.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_5.gridx = 0;
|
||||||
|
gbc_lblNewLabel_5.gridy = 5;
|
||||||
|
panel_1_1.add(lblNewLabel_5, gbc_lblNewLabel_5);
|
||||||
|
|
||||||
|
textFieldFechaFin = new JTextField();
|
||||||
|
GridBagConstraints gbc_textField_4 = new GridBagConstraints();
|
||||||
|
gbc_textField_4.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_textField_4.gridwidth = 2;
|
||||||
|
gbc_textField_4.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_textField_4.gridx = 1;
|
||||||
|
gbc_textField_4.gridy = 5;
|
||||||
|
panel_1_1.add(textFieldFechaFin, gbc_textField_4);
|
||||||
|
textFieldFechaFin.setColumns(10);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_6 = new JLabel("Tipo de morosidad:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_6 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_6.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_6.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_6.gridx = 0;
|
||||||
|
gbc_lblNewLabel_6.gridy = 6;
|
||||||
|
panel_1_1.add(lblNewLabel_6, gbc_lblNewLabel_6);
|
||||||
|
|
||||||
|
comboBoxMorosidad = new JComboBox<>();
|
||||||
|
GridBagConstraints gbc_comboBox_2 = new GridBagConstraints();
|
||||||
|
gbc_comboBox_2.gridwidth = 2;
|
||||||
|
gbc_comboBox_2.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_comboBox_2.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_comboBox_2.gridx = 1;
|
||||||
|
gbc_comboBox_2.gridy = 6;
|
||||||
|
panel_1_1.add(comboBoxMorosidad, gbc_comboBox_2);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_7 = new JLabel("Cuota mensual (€):");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_7 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_7.insets = new Insets(0, 0, 5, 5);
|
||||||
|
gbc_lblNewLabel_7.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_7.gridx = 0;
|
||||||
|
gbc_lblNewLabel_7.gridy = 7;
|
||||||
|
panel_1_1.add(lblNewLabel_7, gbc_lblNewLabel_7);
|
||||||
|
|
||||||
|
textFieldCuotaMensualidad = new JTextField();
|
||||||
|
GridBagConstraints gbc_textField_5 = new GridBagConstraints();
|
||||||
|
gbc_textField_5.gridwidth = 2;
|
||||||
|
gbc_textField_5.insets = new Insets(0, 0, 5, 0);
|
||||||
|
gbc_textField_5.fill = GridBagConstraints.HORIZONTAL;
|
||||||
|
gbc_textField_5.gridx = 1;
|
||||||
|
gbc_textField_5.gridy = 7;
|
||||||
|
panel_1_1.add(textFieldCuotaMensualidad, gbc_textField_5);
|
||||||
|
textFieldCuotaMensualidad.setColumns(10);
|
||||||
|
|
||||||
|
JLabel lblNewLabel_8 = new JLabel("Total mensual (IVA incluido) €:");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_8 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_8.anchor = GridBagConstraints.EAST;
|
||||||
|
gbc_lblNewLabel_8.insets = new Insets(0, 0, 0, 5);
|
||||||
|
gbc_lblNewLabel_8.gridx = 0;
|
||||||
|
gbc_lblNewLabel_8.gridy = 8;
|
||||||
|
panel_1_1.add(lblNewLabel_8, gbc_lblNewLabel_8);
|
||||||
|
|
||||||
|
labelCalculoConIva = new JLabel("0 €");
|
||||||
|
GridBagConstraints gbc_lblNewLabel_9 = new GridBagConstraints();
|
||||||
|
gbc_lblNewLabel_9.gridwidth = 2;
|
||||||
|
gbc_lblNewLabel_9.gridx = 1;
|
||||||
|
gbc_lblNewLabel_9.gridy = 8;
|
||||||
|
panel_1_1.add(labelCalculoConIva, gbc_lblNewLabel_9);
|
||||||
|
|
||||||
|
JButton btnNewButton_1 = new JButton("Guardar cambios");
|
||||||
|
btnNewButton_1.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
guardarCambios();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
btnNewButton_1.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||||||
|
panel_2.add(btnNewButton_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cargarLocalidad() {
|
||||||
|
List<Localidad> localidades = ControladorLocalidad.getAllLocalidades();
|
||||||
|
|
||||||
|
for (Localidad l : localidades) {
|
||||||
|
comboBoxLocalidad.addItem(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cargarMorosidad() {
|
||||||
|
List<Morosidad> morosidades = ControladorMorosidad.getAllMorosidades();
|
||||||
|
|
||||||
|
for (Morosidad m : morosidades) {
|
||||||
|
comboBoxMorosidad.addItem(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void filtrarVivienda() {
|
||||||
|
Localidad l = (Localidad) comboBoxLocalidad.getSelectedItem();
|
||||||
|
String textoFilrar = textFieldFiltroVivienda.getText();
|
||||||
|
|
||||||
|
List<Vivienda> viviendas = ControladorVivienda.getAllViviendasFromLocalidadYFiltrado(l, textoFilrar);
|
||||||
|
|
||||||
|
comboBoxVivienda.removeAllItems();
|
||||||
|
|
||||||
|
for (Vivienda v : viviendas) {
|
||||||
|
comboBoxVivienda.addItem(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void cargarInquilinoEnPantalla() {
|
||||||
|
Vivienda v = (Vivienda) comboBoxVivienda.getSelectedItem();
|
||||||
|
if (v != null) {
|
||||||
|
Inquilino inquilino = ControladorInquilino.obtenerInquilino(v);
|
||||||
|
textFieldId.setText("" + inquilino.getId());
|
||||||
|
textFieldDni.setText(inquilino.getDni());
|
||||||
|
textFieldNombreCompleto.setText(inquilino.getNombreCompleto());
|
||||||
|
textFieldFechaInicio.setText(sdf.format(inquilino.getFechaInicioAlquiler()));
|
||||||
|
if (inquilino.getFechaFinAlquiler() == null) {
|
||||||
|
textFieldFechaFin.setText("");
|
||||||
|
checkBoxAlquiler.setSelected(true);
|
||||||
|
textFieldFechaFin.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
textFieldFechaFin.setText(sdf.format(inquilino.getFechaFinAlquiler()));
|
||||||
|
checkBoxAlquiler.setSelected(false);
|
||||||
|
textFieldFechaFin.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < comboBoxMorosidad.getItemCount(); i++) {
|
||||||
|
if (comboBoxMorosidad.getItemAt(i).getId() == inquilino.getIdTipoMorosidad()) {
|
||||||
|
comboBoxMorosidad.setSelectedIndex(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
textFieldCuotaMensualidad.setText("" + inquilino.getCuotaMensual());
|
||||||
|
labelCalculoConIva.setText((inquilino.getCuotaMensual() * 1.21) + " €");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void alternarFechaFin() {
|
||||||
|
if (checkBoxAlquiler.isSelected()) {
|
||||||
|
textFieldFechaFin.setText("");
|
||||||
|
textFieldFechaFin.setEnabled(false);
|
||||||
|
} else {
|
||||||
|
textFieldFechaFin.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void guardarCambios() {
|
||||||
|
Inquilino inquilino = new Inquilino();
|
||||||
|
|
||||||
|
inquilino.setId(Integer.parseInt(textFieldId.getText()));
|
||||||
|
inquilino.setDni(textFieldDni.getText());
|
||||||
|
|
||||||
|
if (Objects.equals(textFieldNombreCompleto.getText(), "")) {
|
||||||
|
JOptionPane.showMessageDialog(this, "No puedes dejar un nombre vacío");
|
||||||
|
return;
|
||||||
|
} else inquilino.setNombreCompleto(textFieldNombreCompleto.getText());
|
||||||
|
|
||||||
|
try {
|
||||||
|
inquilino.setFechaInicioAlquiler(sdf.parse(textFieldFechaInicio.getText()));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Tiene que haber fecha de inicio y tiene que estar en este formato: dd/MM/yyyy");
|
||||||
|
//throw new RuntimeException(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!checkBoxAlquiler.isSelected()) {
|
||||||
|
try {
|
||||||
|
inquilino.setFechaFinAlquiler(sdf.parse(textFieldFechaFin.getText()));
|
||||||
|
} catch (ParseException e) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Si el alquiler no está activo tiene que haber fecha de fin y tiene que estar en este formato: dd/MM/yyyy");
|
||||||
|
//throw new RuntimeException(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inquilino.setIdTipoMorosidad(((Morosidad) comboBoxMorosidad.getSelectedItem()).getId());
|
||||||
|
inquilino.setCuotaMensual(Float.parseFloat(textFieldCuotaMensualidad.getText()));
|
||||||
|
inquilino.setIdVivienda(((Vivienda) comboBoxVivienda.getSelectedItem()).getId());
|
||||||
|
|
||||||
|
if (ControladorInquilino.guardarInquilino(inquilino) > 0) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Se ha guardado correctamente el cambio");
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "No se ha podido guardar el cambio");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user