Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Contenido
Usar Beans..................................................................................................................................... 2
Beans.java ................................................................................................................................. 2
Beans ............................................................................................................................................. 6
BaseDatosSQL.java .................................................................................................................... 6
BeanPedido.java ...................................................................................................................... 13
BeanProducto.java .................................................................................................................. 16
BeanVenta.java ....................................................................................................................... 19
BeanPedido.java ...................................................................................................................... 21
BeanProducto.java ...................................................................................................................... 24
Usar Beans
Beans.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package usarbeans;
import java.util.ArrayList;
import MisBeans.BeanPedido;
import MisBeans.BeanProducto;
import MisBeans.BeanVenta;
import BaseDatos.BaseDatosSQL;
import java.sql.Date;
/**
*
* @author Aleix Collado
*/
public class Beans {
/**
* @param args the command line arguments
*/
final static boolean DEBUG = true;
public static void main(String[] args) {
// TODO code application logic here
String urlDB = "jdbc:mysql://92.222.85.107/tienda";
String usuario = "root";
if(db.isCrearConexion()){
if(DEBUG)System.out.println("Conectado");
if(DEBUG)System.out.println("LISTA DE VENTAS");
ViewVentas(db);
if(DEBUG)System.out.println("LISTA PEDIDOS");
VerPedidos(db);
} else System.out.println("Error de Conexion");
db.cerrarConexion();
}
}
}
} else
System.out.println("ERROR. NO HAY SUFICIENTE STOCK");
} else System.out.println("NO EXISTE EL PRODUCTO REQUERIDO");
}
}
}
}
}
Beans
BaseDatosSQL.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package BaseDatos;
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.sql.*;
import MisBeans.BeanPedido;
import MisBeans.BeanProducto;
import MisBeans.BeanVenta;
/**
*
* @author martinezp
*/
public class BaseDatosSQL {
public BaseDatosSQL() {
}
int filas = 0;
String sql = "";
PreparedStatement sentencia = null;
try {
if (pedido.isPedir()) { //No se actualiza el stock en la BD
System.out.println("REALIZAR PEDIDO DEL PRODUCTO: " +
producto.getDescripcion());
String tabla = "PEDIDOS";
int numeropedido = obtenerUltimoID(tabla);
pedido.setCantidad(cantidad);
pedido.setIdProducto(producto.getIdProducto());
BeanPedido.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package MisBeans;
import java.beans.*;
import java.io.Serializable;
import java.util.Date;
@Override
public void propertyChange (PropertyChangeEvent evt) {
System.out.println("Stock anterior: " + evt.getOldValue());
System.out.println("Stock actual: " + evt.getNewValue());
}
public BeanPedido() {
BeanProducto.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package MisBeans;
import java.beans.*;
import java.io.Serializable;
/**
*
* @author Aleix Collado
*/
public class BeanProducto implements Serializable {
public BeanProducto() {
propertySupport = new PropertyChangeSupport(this);
}
BeanVenta.java
package MisBeans;
import java.io.Serializable;
import java.sql.Date;
/**
*
* @author Aleix Collado
*/
public class BeanVenta {
BeanPedido.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bibliotecabeans;
import java.beans.*;
import java.io.Serializable;
import java.util.Date;
/**
*
* @author aleixcolser
*/
public BeanPedido() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
BeanProducto.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bibliotecabeans;
import java.beans.*;
import java.io.Serializable;
/**
*
* @author aleixcolser
*/
public class BeanProducto implements Serializable {
public BeanProducto(String descripcion, int stockMin, int idProducto, int stockActual, float
pvp) {
propertySupport = new PropertyChangeSupport(this);
this.descripcion = descripcion;
this.stockMin = stockMin;
this.idProducto = idProducto;
this.stockActual = stockActual;
this.pvp = pvp;
}
}
public BeanProducto() {
propertySupport = new PropertyChangeSupport(this);
}
Base de Datos
Capturas
SQL
-- --------------------------------------------------------- Host:
92.222.85.107
-- --------------------------------------------------------