Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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 VistasResto;
- import atenciondelresto.Conexion;
- import atenciondelresto.Producto;
- import atenciondelresto.ProductoData;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Fabricio
- */
- public class VistaProducto extends javax.swing.JInternalFrame {
- private int id;
- private ProductoData productoData;
- private Conexion conexion;
- /**
- * Creates new form VistaProducto
- */
- public VistaProducto() {
- initComponents();
- try {
- conexion = new Conexion("jdbc:mysql://localhost/resto", "root", "");
- productoData = new ProductoData(conexion);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(VistaProducto.class.getName()).log(Level.SEVERE, null, ex);
- } catch (SQLException ex) {
- Logger.getLogger(VistaProducto.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- jLabel4 = new javax.swing.JLabel();
- txtNombre = new javax.swing.JTextField();
- txtCodigo = new javax.swing.JTextField();
- txtCantidad = new javax.swing.JTextField();
- txtPrecio = new javax.swing.JTextField();
- btnGuardar = new javax.swing.JButton();
- btnBorrar = new javax.swing.JButton();
- btnModificar = new javax.swing.JButton();
- btnConsultar = new javax.swing.JButton();
- setBackground(new java.awt.Color(0, 153, 153));
- setClosable(true);
- setTitle("Productos");
- jLabel1.setText("Nombre");
- jLabel2.setText("Codigo");
- jLabel3.setText("Cantidad");
- jLabel4.setText("Precio");
- txtNombre.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtNombreActionPerformed(evt);
- }
- });
- txtCodigo.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtCodigoActionPerformed(evt);
- }
- });
- txtCantidad.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtCantidadActionPerformed(evt);
- }
- });
- txtPrecio.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- txtPrecioActionPerformed(evt);
- }
- });
- btnGuardar.setText("Guardar");
- btnGuardar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
- btnGuardar.setPreferredSize(new java.awt.Dimension(80, 27));
- btnGuardar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnGuardarActionPerformed(evt);
- }
- });
- btnBorrar.setText("Borrar");
- btnBorrar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
- btnBorrar.setPreferredSize(new java.awt.Dimension(80, 27));
- btnBorrar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnBorrarActionPerformed(evt);
- }
- });
- btnModificar.setText("Modificar");
- btnModificar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
- btnModificar.setPreferredSize(new java.awt.Dimension(80, 27));
- btnModificar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnModificarActionPerformed(evt);
- }
- });
- btnConsultar.setText("Consultar");
- btnConsultar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
- btnConsultar.setPreferredSize(new java.awt.Dimension(80, 27));
- btnConsultar.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- btnConsultarActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(15, 15, 15)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addGap(18, 18, 18)
- .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addGap(25, 25, 25)
- .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addGap(15, 15, 15)
- .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel4)
- .addGap(34, 34, 34)
- .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))))
- .addGroup(layout.createSequentialGroup()
- .addGap(26, 26, 26)
- .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(29, 29, 29)
- .addComponent(btnBorrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(31, 31, 31)
- .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(30, 30, 30)
- .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addContainerGap(31, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(16, 16, 16)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(3, 3, 3)
- .addComponent(jLabel1))
- .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(21, 21, 21)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(3, 3, 3)
- .addComponent(jLabel2))
- .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(21, 21, 21)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(3, 3, 3)
- .addComponent(jLabel3))
- .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(21, 21, 21)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(3, 3, 3)
- .addComponent(jLabel4))
- .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnBorrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addContainerGap())
- );
- pack();
- }// </editor-fold>
- private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- //*****BOTON GUARDAR*****
- private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String nombre=txtNombre.getText();
- String codigo=txtCodigo.getText();
- String cantidad=txtCantidad.getText();
- String precio=txtPrecio.getText();
- Producto producto=new Producto(nombre, codigo, cantidad, precio);
- productoData.guardarProducto(producto);
- JOptionPane.showMessageDialog(null, "Se Guardo Correctamente el Producto");
- txtNombre.setText("");
- txtCodigo.setText("");
- txtCantidad.setText("");
- txtPrecio.setText("");
- }
- private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- //*****BOTON BORRAR*****
- private void btnBorrarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if(!txtNombre.getText().equals("")){
- int confirma = JOptionPane.showConfirmDialog(rootPane, "¿Seguro que desea Borrar el Producto?");
- if (confirma==0){
- String nombre=txtNombre.getText());
- productoData.borrarProducto(nombre);
- JOptionPane.showMessageDialog(null, "Se Borro el Producto");
- txtNombre.setText("");
- txtCodigo.setText("");
- txtCantidad.setText("");
- txtPrecio.setText("");
- }
- }else{JOptionPane.showMessageDialog(null, "Debe buscar un Producto para Borrar");}
- }
- private void txtCantidadActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- //*****BOTON MODIFICAR*****
- private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- if(!txtNombre.getText().equals("")){
- String nombre=txtNombre.getText();
- String codigo=txtCodigo.getText();
- String cantidad=txtCantidad.getText();
- String precio=txtPrecio.getText();
- Producto producto=new Producto(id, nombre, codigo, cantidad, precio);
- productoData.modificarProducto(producto);
- JOptionPane.showMessageDialog(null, "¡El Producto se Modifico!");
- txtNombre.setText("");
- txtCodigo.setText("");
- txtCantidad.setText("");
- txtPrecio.setText("");
- }else{JOptionPane.showMessageDialog(null, "Debe buscar un Producto para Modificar");}
- }
- private void txtPrecioActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- //*****BOTON CONSULTAR*****
- private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- String nombre=txtNombre.getText(JOptionPane.showInputDialog("Ingrese Nombre");
- Producto producto=productoData.consultarProducto(nombre);
- txtNombre.setText(producto.getNombre()+"");
- txtCodigo.setText(producto.getCodigo()+"");
- txtCantidad.setText(producto.getCantidad()+"");
- txtPrecio.setText(producto.getPrecio()+"");
- id=producto.getId_producto();
- }
- // Variables declaration - do not modify
- private javax.swing.JButton btnBorrar;
- private javax.swing.JButton btnConsultar;
- private javax.swing.JButton btnGuardar;
- private javax.swing.JButton btnModificar;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JTextField txtCantidad;
- private javax.swing.JTextField txtCodigo;
- private javax.swing.JTextField txtNombre;
- private javax.swing.JTextField txtPrecio;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement