Beans

32
Aleix Collado Serrano 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

description

Desc

Transcript of Beans

  • Aleix Collado Serrano

    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

  • Aleix Collado Serrano

    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";

  • Aleix Collado Serrano

    String clave = "02pghojnt";

    String driver = "com.mysql.jdbc.Driver";

    BaseDatosSQL db= new BaseDatosSQL(urlDB, usuario, clave, driver);

    db.setCrearConexion();

    if(db.isCrearConexion()){

    if(DEBUG)System.out.println("Conectado");

    if(DEBUG)System.out.println("LISTA INCIAL DE PRODUCTOS");

    viewProductos(db);

    if(DEBUG)System.out.println("CREAMOS VENTA EN ID 1 CON CANTIDAD 2");

    crearVenta(db,1,0);

    if(DEBUG)System.out.println("LISTA DE PRODUCTOS DESPUES DE LA VENDA");

    viewProductos(db);

    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();

    }

    private static void viewProductos(BaseDatosSQL bd){

    ArrayList lista= new ArrayList();

  • Aleix Collado Serrano

    lista = bd.consultaProducto("SELECT * FROM PRODUCTOS");

    if(lista!=null)

    for(int i=0; i 0){

    String tabla= "VENTAS";

    int idventa=bd.obtenerUltimoID(tabla);

    BeanVenta ven= new BeanVenta(idventa, prod.getIdProducto(), fechaActual,

    cantidad);

    if(bd.insertarVenta(ven)>0) System.out.println("INSERTADA");

    } else

    System.out.println("ERROR. NO HAY SUFICIENTE STOCK");

    } else System.out.println("NO EXISTE EL PRODUCTO REQUERIDO");

    }

    private static void ViewVentas(BaseDatosSQL db) {

    ArrayList lista= new ArrayList();

    lista = db.consultaVenta("SELECT * FROM VENTAS");

    if(lista!=null)

    for(int i=0; i

  • Aleix Collado Serrano

    BeanProducto prod= db.consultaUnProducto(p.getIdproducto());

    System.out.println("ID Pedido=>"+p.getNumersoventa()+"* Producto:

    "+prod.getDescripcion()+"* Cantidad: "+p.getCantidad()+"* Fecha: " +p.getFechaventa());

    }

    }

    private static void VerPedidos(BaseDatosSQL db) {

    ArrayList lista= new ArrayList();

    lista = db.consultaPedido("SELECT * FROM PEDIDOS");

    if(lista!=null)

    for(int i=0; i

  • Aleix Collado Serrano

    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 {

    private static Connection conexion;

    private String URI;

  • Aleix Collado Serrano

    private String usuario;

    private String clave;

    private String driver;

    private boolean makeConexion;

    public BaseDatosSQL() {

    }

    public BaseDatosSQL(String URI, String usuario, String clave, String driver) {

    this.URI = URI;

    this.usuario = usuario;

    this.clave = clave;

    this.driver = driver;

    }

    public Connection getConexion() {

    return conexion;

    }

    public void cerrarConexion() {

    try {

    conexion.close();

    } catch (SQLException e) {

    e.printStackTrace();

    }

    }

    public boolean isCrearConexion() {

    return makeConexion;

    }

  • Aleix Collado Serrano

    public void setCrearConexion() {

    makeConexion = false;

    try {

    Class.forName("com.mysql.jdbc.Driver");

    conexion = DriverManager.getConnection(URI, usuario, clave);

    makeConexion = true;

    } catch (Exception e) {

    System.out.println("Problemas con la conexin");

    e.printStackTrace();

    }

    }

    public ArrayList consultaProducto(String consulta) {

    ArrayList lista = new ArrayList();

    try {

    Statement sentencia = getConexion().createStatement();

    ResultSet resul = sentencia.executeQuery(consulta);

    while (resul.next()) {

    BeanProducto p = new BeanProducto(resul.getInt(1), resul.getString(2),

    resul.getInt(3), resul.getInt(4), resul.getFloat(5));

    lista.add(p);

    }

    resul.close();

    sentencia.close();

    } catch (SQLException e) {

    System.out.println("Problemas al consultar productos");

    e.printStackTrace();

    }

    return lista;

    }

  • Aleix Collado Serrano

    public ArrayList consultaPedido(String consulta) {

    ArrayList lista = new ArrayList();

    try {

    Statement sentence = getConexion().createStatement();

    ResultSet resul = sentence.executeQuery(consulta);

    while (resul.next()) {

    BeanPedido p = new BeanPedido(resul.getInt(1), resul.getInt(2),

    resul.getDate(3), resul.getInt(4));

    lista.add(p);

    }

    resul.close();

    sentence.close();

    } catch (SQLException e) {

    System.out.println("Problemas al consultar pedidos");

    e.printStackTrace();

    }

    return lista;

    }

    public ArrayList consultaVenta(String consulta) {

    ArrayList lista = new ArrayList();

    try {

    Statement sentencia = getConexion().createStatement();

    ResultSet resul = sentencia.executeQuery(consulta);

    while (resul.next()) {

    BeanVenta p = new BeanVenta(resul.getInt(1), resul.getInt(2),

    resul.getDate(3), resul.getInt(4));

    lista.add(p);

    }

    resul.close();

    sentencia.close();

  • Aleix Collado Serrano

    } catch (SQLException e) {

    System.out.println("Problemas al consultar ventas");

    e.printStackTrace();

    }

    return lista;

    }

    public int obtenerUltimoID(String tabla) {

    int id = 0;

    String consulta = "SELECT MAX(ID) FROM " + tabla;

    try {

    Statement sentencia = getConexion().createStatement();

    ResultSet resul = sentencia.executeQuery(consulta);

    resul.next();

    id = resul.getInt(1) + 1;

    resul.close();

    sentencia.close();

    } catch (SQLException e) {

    System.out.println("Problemas al obtener mximo id. en " + tabla);

    e.printStackTrace();

    }

    return id;

    }

    public int insertarVenta(BeanVenta ven) {

    int filas = 0;

    String sql = "INSERT INTO VENTAS VALUES ( ?,?,?,?)";

    try {

    PreparedStatement sentencia = getConexion().prepareStatement(sql);

    sentencia.setInt(1, ven.getNumersoventa());

    sentencia.setInt(2, ven.getIdproducto());

  • Aleix Collado Serrano

    sentencia.setDate(3, (Date) ven.getFechaventa());

    sentencia.setInt(4, ven.getCantidad());

    filas = sentencia.executeUpdate();

    sentencia.close();

    } catch (SQLException e) {

    System.out.println("ERROR AL INSERTAR VENTA");

    e.printStackTrace();

    }

    return filas;

    }

    public int actStock(BeanProducto producto, int cantidad, Date fechaActual) {

    BeanPedido pedido = new BeanPedido();

    producto.addPropertyChangeListener(pedido); //Aadimos el Listener

    int nuevostock = producto.getStockActual() - cantidad; //Calculo del nuevo stock

    producto.setStockActual(nuevostock); //Se actualiza el stock

    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());

  • Aleix Collado Serrano

    pedido.setNumeroPedido(numeropedido);

    pedido.setFecha(fechaActual);

    sql = "INSERT INTO PEDIDOS VALUES ( ?,?,?,?)";

    sentencia = getConexion().prepareStatement(sql);

    sentencia.setInt(1, pedido.getNumeroPedido());

    sentencia.setInt(2, pedido.getIdProducto());

    sentencia.setDate(3, (Date) pedido.getFecha());

    sentencia.setInt(4, pedido.getCantidad());

    filas = sentencia.executeUpdate();

    System.out.println("PEDIDO " + numeropedido + " GENERADO ...");

    filas = -1; //No se puede realizar la venta

    sentencia.close();

    } else { // Se actualiza el stock en la BD

    sql = "UPDATE PRODUCTOS SET STOCKACTUAL = ? WHERE ID = ?";

    sentencia = getConexion().prepareStatement(sql);

    sentencia.setInt(1, producto.getStockActual());

    sentencia.setInt(2, producto.getIdProducto());

    filas = sentencia.executeUpdate();

    System.out.println("STOCK ACTUALIZADO ...");

    sentencia.close();

    }

    } catch (SQLException e) {

    System.out.println("PROBLEMAS AL ACTUALIZAR EL STOCK ...");

    filas = -1; //No se puede realizar la venta

    }

    return filas;

    }

    //Obtener un producto a travs de su ID

    public BeanProducto consultaUnProducto(int idProducto) {

    BeanProducto p = null;

  • Aleix Collado Serrano

    String consulta = "SELECT * FROM PRODUCTOS WHERE ID = ? ";

    try {

    PreparedStatement sentencia = getConexion().prepareStatement(consulta);

    sentencia.setInt(1, idProducto);

    ResultSet resul = sentencia.executeQuery();

    resul.next();

    p = new BeanProducto(resul.getInt(1), resul.getString(2), resul.getInt(3), resul.getInt(4),

    resul.getFloat(5));

    resul.close();

    sentencia.close();

    } catch (SQLException e) {

    System.out.println("PROBLEMAS AL OBTENER EL PRODUCTOS CON ID: " + idProducto);

    e.printStackTrace();

    }

    return p; //devuelve el producto demandado

    }

    }

    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;

  • Aleix Collado Serrano

    /**

    *

    * @author Aleix Collado

    */

    public class BeanPedido implements Serializable, PropertyChangeListener {

    private int numeroPedido;

    private int idProducto;

    private Date fecha;

    private int cantidad;

    private boolean pedir;

    @Override

    public void propertyChange (PropertyChangeEvent evt) {

    System.out.println("Stock anterior: " + evt.getOldValue());

    System.out.println("Stock actual: " + evt.getNewValue());

    }

    public BeanPedido() {

    }

    public BeanPedido(int numeroPedido, int idProducto, Date fecha, int cantidad) {

    this.idProducto=idProducto;

    this.numeroPedido=numeroPedido;

    this.fecha=fecha;

    this.cantidad=cantidad;

    }

    public int getNumeroPedido() {

    return numeroPedido;

  • Aleix Collado Serrano

    }

    public void setNumeroPedido(int numeroPedido) {

    this.numeroPedido = numeroPedido;

    }

    public int getIdProducto() {

    return idProducto;

    }

    public void setIdProducto(int idProducto) {

    this.idProducto = idProducto;

    }

    public Date getFecha() {

    return fecha;

    }

    public void setFecha(Date fecha) {

    this.fecha = fecha;

    }

    public int getCantidad() {

    return cantidad;

    }

    public void setCantidad(int cantidad) {

    this.cantidad = cantidad;

    }

    public boolean isPedir() {

  • Aleix Collado Serrano

    return pedir;

    }

    public void setPedir(boolean pedir) {

    this.pedir = pedir;

    }

    }

    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 {

    private String descripcion;

    private int idProducto;

  • Aleix Collado Serrano

    private int stockActual;

    private int stockMinimo;

    private float pvp;

    private PropertyChangeSupport propertySupport;

    public BeanProducto() {

    propertySupport = new PropertyChangeSupport(this);

    }

    public BeanProducto(int idProducto, String descripcion, int stockActual, int stockMinimo,

    float pvp) {

    propertySupport = new PropertyChangeSupport(this);

    this.idProducto=idProducto;

    this.descripcion=descripcion;

    this.stockActual=stockActual;

    this.stockMinimo=stockMinimo;

    this.pvp=pvp;

    }

    public int getStockActual() {

    return stockActual;

    }

    public void setStockActual(int stockNuevo) {

    int stockAnterior=stockActual;

    stockActual = stockNuevo;

    if (stockActual

  • Aleix Collado Serrano

    }

    }

    public String getDescripcion() {

    return descripcion;

    }

    public void setDescripcion(String descripcion) {

    this.descripcion = descripcion;

    }

    public int getIdProducto() {

    return idProducto;

    }

    public void setIdProducto(int idProducto) {

    this.idProducto = idProducto;

    }

    public int getStockMinimo() {

    return stockMinimo;

    }

    public void setStockMinimo(int stockMinimo) {

    this.stockMinimo = stockMinimo;

    }

    public float getPvp() {

    return pvp;

    }

  • Aleix Collado Serrano

    public void setPvp(float pvp) {

    this.pvp = pvp;

    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {

    propertySupport.addPropertyChangeListener(listener);

    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {

    propertySupport.removePropertyChangeListener(listener);

    }

    }

    BeanVenta.java package MisBeans;

    import java.io.Serializable;

    import java.sql.Date;

    /**

    *

    * @author Aleix Collado

    */

    public class BeanVenta {

    private static final long serialVersionUID = 1L;

    private int numersoventa;

    private int idproducto;

    private java.sql.Date fechaventa;

    private int cantidad;

  • Aleix Collado Serrano

    public BeanVenta() {

    }

    public BeanVenta(int numersoventa, int idproducto, Date fechaventa, int cantidad) {

    this.numersoventa = numersoventa;

    this.idproducto = idproducto;

    this.fechaventa = fechaventa;

    this.cantidad = cantidad;

    }

    public int getNumersoventa() {

    return numersoventa;

    }

    public void setNumersoventa(int numersoventa) {

    this.numersoventa = numersoventa;

    }

    public int getIdproducto() {

    return idproducto;

    }

    public void setIdproducto(int idproducto) {

    this.idproducto = idproducto;

    }

    public Date getFechaventa() {

    return fechaventa;

    }

    public void setFechaventa(Date fechaventa) {

  • Aleix Collado Serrano

    this.fechaventa = fechaventa;

    }

    public int getCantidad() {

    return cantidad;

    }

    public void setCantidad(int cantidad) {

    this.cantidad = cantidad;

    }

    }

    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

    */

  • Aleix Collado Serrano

    public class BeanPedido implements Serializable,PropertyChangeListener {

    private int numeroPedido,idProducto,cantidad;

    private Date fecha;

    private boolean pedir;

    public int getNumeroPedido() {

    return numeroPedido;

    }

    public void setNumeroPedido(int numeroPedido) {

    this.numeroPedido = numeroPedido;

    }

    public int getIdProducto() {

    return idProducto;

    }

    public void setIdProducto(int idProducto) {

    this.idProducto = idProducto;

    }

    public int getCantidad() {

    return cantidad;

    }

    public void setCantidad(int cantidad) {

    this.cantidad = cantidad;

    }

  • Aleix Collado Serrano

    public Date getFecha() {

    return fecha;

    }

    public void setFecha(Date fecha) {

    this.fecha = fecha;

    }

    public boolean isPedir() {

    return pedir;

    }

    public void setPedir(boolean pedir) {

    this.pedir = pedir;

    }

    public BeanPedido() {

    }

    public BeanPedido(int numeroPedido, int idProducto, int cantidad, Date fecha) {

    this.numeroPedido = numeroPedido;

    this.idProducto = idProducto;

    this.cantidad = cantidad;

    this.fecha = fecha;

    }

    @Override

    public void propertyChange(PropertyChangeEvent evt) {

  • Aleix Collado Serrano

    System.out.println("Stock Anterior: "+evt.getOldValue());

    System.out.println("Stock Actual: "+evt.getNewValue());

    this.setPedir(true);

    }

    }

    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 static final String PROP_SAMPLE_PROPERTY = "sampleProperty";

    private String descripcion;

    private int stockMin;

    private int idProducto;

  • Aleix Collado Serrano

    private int stockActual;

    private float pvp;

    public String getDescripcion() {

    return descripcion;

    }

    public void setDescripcion(String descripcion) {

    this.descripcion = descripcion;

    }

    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 int getStockMin() {

    return stockMin;

    }

    public void setStockMin(int stockMin) {

    this.stockMin = stockMin;

    }

    public int getIdProducto() {

  • Aleix Collado Serrano

    return idProducto;

    }

    public void setIdProducto(int idProducto) {

    this.idProducto = idProducto;

    }

    public int getStockActual() {

    return stockActual;

    }

    public void setStockActual(int stockActual) {

    int stockAnterior = stockActual;

    if(stockActual < getStockMin()) {// Hay que realizar pedido

    propertySupport.firePropertyChange("stockActual", stockAnterior, this.stockActual);

    }

    }

    public float getPvp() {

    return pvp;

    }

    public void setPvp(float pvp) {

    this.pvp = pvp;

    }

    public PropertyChangeSupport getPropertySupport() {

    return propertySupport;

    }

  • Aleix Collado Serrano

    public void setPropertySupport(PropertyChangeSupport propertySupport) {

    this.propertySupport = propertySupport;

    }

    private PropertyChangeSupport propertySupport;

    public BeanProducto() {

    propertySupport = new PropertyChangeSupport(this);

    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {

    propertySupport.addPropertyChangeListener(listener);

    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {

    propertySupport.removePropertyChangeListener(listener);

    }

    }

  • Aleix Collado Serrano

    Base de Datos

    Capturas

  • Aleix Collado Serrano

    SQL -- --------------------------------------------------------

    -- Host: 92.222.85.107

    -- Versin del servidor: 5.5.41-MariaDB - MariaDB Server

    -- SO del servidor: Linux

    -- HeidiSQL Versin: 9.1.0.4867

    -- --------------------------------------------------------

    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;

    /*!40101 SET NAMES utf8mb4 */;

    /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,

    FOREIGN_KEY_CHECKS=0 */;

    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO'

    */;

    -- Volcando estructura de base de datos para tienda

    DROP DATABASE IF EXISTS `tienda`;

    CREATE DATABASE IF NOT EXISTS `tienda` /*!40100 DEFAULT CHARACTER SET latin1 */;

    USE `tienda`;

  • Aleix Collado Serrano

    -- Volcando estructura para tabla tienda.pedidos

    DROP TABLE IF EXISTS `pedidos`;

    CREATE TABLE IF NOT EXISTS `pedidos` (

    `ID` mediumint(9) NOT NULL,

    `IDPRODUCTO` mediumint(9) NOT NULL,

    `FECHAPEDIDO` date DEFAULT NULL,

    `CANTIDAD` tinyint(4) DEFAULT NULL,

    PRIMARY KEY (`ID`),

    KEY `IDPRODUCTO` (`IDPRODUCTO`)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    -- Volcando datos para la tabla tienda.pedidos: 5 rows

    DELETE FROM `pedidos`;

    /*!40000 ALTER TABLE `pedidos` DISABLE KEYS */;

    INSERT INTO `pedidos` (`ID`, `IDPRODUCTO`, `FECHAPEDIDO`, `CANTIDAD`) VALUES

    (1, 1, '2015-04-12', 5),

    (2, 2, '2015-04-17', 20),

    (3, 1, '2015-04-23', 10),

    (4, 3, '2015-04-23', 15),

    (5, 2, '2015-04-23', 25);

    /*!40000 ALTER TABLE `pedidos` ENABLE KEYS */;

    -- Volcando estructura para tabla tienda.productos

    DROP TABLE IF EXISTS `productos`;

    CREATE TABLE IF NOT EXISTS `productos` (

    `ID` mediumint(9) NOT NULL,

    `DESCRIPCION` varchar(50) DEFAULT NULL,

    `STOCKACTUAL` tinyint(4) DEFAULT NULL,

    `STOCKMINIMO` tinyint(4) DEFAULT NULL,

  • Aleix Collado Serrano

    `PVP` float DEFAULT NULL,

    PRIMARY KEY (`ID`)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    -- Volcando datos para la tabla tienda.productos: 6 rows

    DELETE FROM `productos`;

    /*!40000 ALTER TABLE `productos` DISABLE KEYS */;

    INSERT INTO `productos` (`ID`, `DESCRIPCION`, `STOCKACTUAL`, `STOCKMINIMO`, `PVP`)

    VALUES

    (1, 'Naranjas', 75, 25, 1),

    (2, 'Fresas', 50, 15, 2),

    (3, 'Cerezas', 63, 20, 5),

    (4, 'Nectarinas', 40, 10, 3),

    (5, 'Manzanas', 100, 30, 1),

    (0, 'Ciruela', 25, 12, 3);

    /*!40000 ALTER TABLE `productos` ENABLE KEYS */;

    -- Volcando estructura para tabla tienda.ventas

    DROP TABLE IF EXISTS `ventas`;

    CREATE TABLE IF NOT EXISTS `ventas` (

    `ID` mediumint(9) NOT NULL,

    `IDPRODUCTO` mediumint(9) NOT NULL,

    `FECHAVENTA` date DEFAULT NULL,

    `CANTIDAD` tinyint(4) DEFAULT NULL,

    PRIMARY KEY (`ID`),

    KEY `IDPRODUCTO` (`IDPRODUCTO`)

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

    -- Volcando datos para la tabla tienda.ventas: 10 rows

    DELETE FROM `ventas`;

  • Aleix Collado Serrano

    /*!40000 ALTER TABLE `ventas` DISABLE KEYS */;

    INSERT INTO `ventas` (`ID`, `IDPRODUCTO`, `FECHAVENTA`, `CANTIDAD`) VALUES

    (1, 1, '2015-04-12', 15),

    (2, 1, '2015-04-17', 25),

    (3, 2, '2015-04-23', 10),

    (4, 1, '2015-04-23', 10),

    (5, 3, '2015-04-23', 20),

    (6, 3, '2015-05-03', 2),

    (7, 3, '2015-05-04', 0),

    (8, 3, '2015-05-05', 0),

    (9, 3, '2015-05-13', 0),

    (10, 3, '2015-05-13', 0);

    /*!40000 ALTER TABLE `ventas` ENABLE KEYS */;

    /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;

    /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1,

    @OLD_FOREIGN_KEY_CHECKS) */;

    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;