Aniadida vista
This commit is contained in:
parent
707161c72b
commit
5ba64e2335
4
src/Controlador.java
Normal file
4
src/Controlador.java
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
public class Controlador {
|
||||
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.time.LocalDate;
|
||||
@ -42,5 +43,63 @@ public class Modelo {
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet obtenerTransacciones() {
|
||||
String query = "select * " +
|
||||
"from transacciones;";
|
||||
ResultSet ret = null;
|
||||
try {
|
||||
PreparedStatement stmt = this.connection.prepareStatement(query);
|
||||
ret = stmt.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void eliminartransaccion(String nombre) {
|
||||
String query ="delete from transacciones" +
|
||||
"where nombre=?;";
|
||||
try {
|
||||
PreparedStatement stmt = this.connection.prepareStatement(query);
|
||||
stmt.setString(1, nombre);
|
||||
stmt.executeUpdate();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void modificarTransaccion(String nombreViejo, String nombre, float dinero, LocalDate fecha) {
|
||||
String query ="update transacciones" +
|
||||
"set nombre=?, dinero=?, fecha=?"+
|
||||
"where nombre=?;";
|
||||
try {
|
||||
PreparedStatement stmt = this.connection.prepareStatement(query);
|
||||
stmt.setString(1, nombre);
|
||||
stmt.setFloat(2, dinero);
|
||||
stmt.setString(3, fecha.toString());
|
||||
stmt.setString(4, nombreViejo);
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet buscarTransaccion(String nombre) {
|
||||
String query = "select * " +
|
||||
"from transacciones" +
|
||||
"where nombre=?;";
|
||||
ResultSet ret = null;
|
||||
try {
|
||||
PreparedStatement stmt = this.connection.prepareStatement(query);
|
||||
stmt.setString(1, nombre);
|
||||
ret = stmt.executeQuery();
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
64
src/Vista.java
Normal file
64
src/Vista.java
Normal file
@ -0,0 +1,64 @@
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
public class Vista extends JPanel{
|
||||
JTextField textoNombre;
|
||||
JTextField textoDinero;
|
||||
JTextField textoFecha;
|
||||
JTextField insertarNombre;
|
||||
JTextField insertarDinero;
|
||||
JTextField insertarFecha;
|
||||
JButton mostrarTodo;
|
||||
JButton aniadir;
|
||||
JButton editar;
|
||||
|
||||
public Vista() {
|
||||
this.setLayout(new GridBagLayout());
|
||||
GridBagConstraints constrain = new GridBagConstraints();
|
||||
this.textoNombre = new JTextField("nombre");
|
||||
this.textoNombre.setEditable(false);
|
||||
constrain.gridx = 0;
|
||||
constrain.gridy = 0;
|
||||
this.add(this.textoNombre, constrain);
|
||||
this.textoDinero = new JTextField("dinero");
|
||||
this.textoDinero.setEditable(false);
|
||||
constrain.gridx = 1;
|
||||
constrain.gridy = 0;
|
||||
this.add(this.textoDinero, constrain);
|
||||
this.textoFecha = new JTextField("fecha");
|
||||
this.textoFecha.setEditable(false);
|
||||
constrain.gridx = 2;
|
||||
constrain.gridy = 0;
|
||||
this.add(this.textoFecha, constrain);
|
||||
|
||||
this.insertarNombre = new JTextField("nombre");
|
||||
constrain.gridx = 0;
|
||||
constrain.gridy = 1;
|
||||
this.add(this.insertarNombre, constrain);
|
||||
this.insertarDinero = new JTextField("dinero");
|
||||
constrain.gridx = 1;
|
||||
constrain.gridy = 1;
|
||||
this.add(this.insertarDinero, constrain);
|
||||
this.insertarFecha = new JTextField("fecha");
|
||||
constrain.gridx = 2;
|
||||
constrain.gridy = 1;
|
||||
this.add(this.insertarFecha, constrain);
|
||||
|
||||
this.aniadir = new JButton("aniadir");
|
||||
constrain.gridx = 0;
|
||||
constrain.gridy = 2;
|
||||
this.add(this.aniadir, constrain);
|
||||
this.editar = new JButton("editar");
|
||||
constrain.gridx = 1;
|
||||
constrain.gridy = 2;
|
||||
this.add(this.editar, constrain);
|
||||
this.mostrarTodo = new JButton("mostrar todo");
|
||||
constrain.gridx = 2;
|
||||
constrain.gridy = 2;
|
||||
this.add(this.mostrarTodo, constrain);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user