Advertisement
GiselHerrera

Codigo Producto

Oct 25th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 15.58 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package VistasResto;
  7. import atenciondelresto.Conexion;
  8. import atenciondelresto.Producto;
  9. import atenciondelresto.ProductoData;
  10. import java.sql.SQLException;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import javax.swing.JOptionPane;
  14.  
  15. /**
  16.  *
  17.  * @author Fabricio
  18.  */
  19. public class VistaProducto extends javax.swing.JInternalFrame {
  20.     private int id;
  21.     private ProductoData productoData;
  22.     private Conexion conexion;
  23.  
  24.     /**
  25.      * Creates new form VistaProducto
  26.      */
  27.     public VistaProducto() {
  28.         initComponents();
  29.       try {
  30.             conexion = new Conexion("jdbc:mysql://localhost/resto", "root", "");
  31.             productoData = new ProductoData(conexion);
  32.        
  33.         } catch (ClassNotFoundException ex) {
  34.             Logger.getLogger(VistaProducto.class.getName()).log(Level.SEVERE, null, ex);
  35.         } catch (SQLException ex) {
  36.             Logger.getLogger(VistaProducto.class.getName()).log(Level.SEVERE, null, ex);
  37.         }
  38.         }
  39.  
  40.     /**
  41.      * This method is called from within the constructor to initialize the form.
  42.      * WARNING: Do NOT modify this code. The content of this method is always
  43.      * regenerated by the Form Editor.
  44.      */
  45.     @SuppressWarnings("unchecked")
  46.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  47.     private void initComponents() {
  48.  
  49.         jLabel1 = new javax.swing.JLabel();
  50.         jLabel2 = new javax.swing.JLabel();
  51.         jLabel3 = new javax.swing.JLabel();
  52.         jLabel4 = new javax.swing.JLabel();
  53.         txtNombre = new javax.swing.JTextField();
  54.         txtCodigo = new javax.swing.JTextField();
  55.         txtCantidad = new javax.swing.JTextField();
  56.         txtPrecio = new javax.swing.JTextField();
  57.         btnGuardar = new javax.swing.JButton();
  58.         btnBorrar = new javax.swing.JButton();
  59.         btnModificar = new javax.swing.JButton();
  60.         btnConsultar = new javax.swing.JButton();
  61.  
  62.         setBackground(new java.awt.Color(0, 153, 153));
  63.         setClosable(true);
  64.         setTitle("Productos");
  65.  
  66.         jLabel1.setText("Nombre");
  67.  
  68.         jLabel2.setText("Codigo");
  69.  
  70.         jLabel3.setText("Cantidad");
  71.  
  72.         jLabel4.setText("Precio");
  73.  
  74.         txtNombre.addActionListener(new java.awt.event.ActionListener() {
  75.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  76.                 txtNombreActionPerformed(evt);
  77.             }
  78.         });
  79.  
  80.         txtCodigo.addActionListener(new java.awt.event.ActionListener() {
  81.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  82.                 txtCodigoActionPerformed(evt);
  83.             }
  84.         });
  85.  
  86.         txtCantidad.addActionListener(new java.awt.event.ActionListener() {
  87.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  88.                 txtCantidadActionPerformed(evt);
  89.             }
  90.         });
  91.  
  92.         txtPrecio.addActionListener(new java.awt.event.ActionListener() {
  93.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  94.                 txtPrecioActionPerformed(evt);
  95.             }
  96.         });
  97.  
  98.         btnGuardar.setText("Guardar");
  99.         btnGuardar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
  100.         btnGuardar.setPreferredSize(new java.awt.Dimension(80, 27));
  101.         btnGuardar.addActionListener(new java.awt.event.ActionListener() {
  102.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  103.                 btnGuardarActionPerformed(evt);
  104.             }
  105.         });
  106.  
  107.         btnBorrar.setText("Borrar");
  108.         btnBorrar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
  109.         btnBorrar.setPreferredSize(new java.awt.Dimension(80, 27));
  110.         btnBorrar.addActionListener(new java.awt.event.ActionListener() {
  111.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  112.                 btnBorrarActionPerformed(evt);
  113.             }
  114.         });
  115.  
  116.         btnModificar.setText("Modificar");
  117.         btnModificar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
  118.         btnModificar.setPreferredSize(new java.awt.Dimension(80, 27));
  119.         btnModificar.addActionListener(new java.awt.event.ActionListener() {
  120.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  121.                 btnModificarActionPerformed(evt);
  122.             }
  123.         });
  124.  
  125.         btnConsultar.setText("Consultar");
  126.         btnConsultar.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
  127.         btnConsultar.setPreferredSize(new java.awt.Dimension(80, 27));
  128.         btnConsultar.addActionListener(new java.awt.event.ActionListener() {
  129.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  130.                 btnConsultarActionPerformed(evt);
  131.             }
  132.         });
  133.  
  134.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  135.         getContentPane().setLayout(layout);
  136.         layout.setHorizontalGroup(
  137.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  138.             .addGroup(layout.createSequentialGroup()
  139.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  140.                     .addGroup(layout.createSequentialGroup()
  141.                         .addGap(15, 15, 15)
  142.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143.                             .addGroup(layout.createSequentialGroup()
  144.                                 .addComponent(jLabel1)
  145.                                 .addGap(18, 18, 18)
  146.                                 .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))
  147.                             .addGroup(layout.createSequentialGroup()
  148.                                 .addComponent(jLabel2)
  149.                                 .addGap(25, 25, 25)
  150.                                 .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
  151.                             .addGroup(layout.createSequentialGroup()
  152.                                 .addComponent(jLabel3)
  153.                                 .addGap(15, 15, 15)
  154.                                 .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
  155.                             .addGroup(layout.createSequentialGroup()
  156.                                 .addComponent(jLabel4)
  157.                                 .addGap(34, 34, 34)
  158.                                 .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))))
  159.                     .addGroup(layout.createSequentialGroup()
  160.                         .addGap(26, 26, 26)
  161.                         .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  162.                         .addGap(29, 29, 29)
  163.                         .addComponent(btnBorrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  164.                         .addGap(31, 31, 31)
  165.                         .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  166.                         .addGap(30, 30, 30)
  167.                         .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
  168.                 .addContainerGap(31, Short.MAX_VALUE))
  169.         );
  170.         layout.setVerticalGroup(
  171.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  172.             .addGroup(layout.createSequentialGroup()
  173.                 .addGap(16, 16, 16)
  174.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  175.                     .addGroup(layout.createSequentialGroup()
  176.                         .addGap(3, 3, 3)
  177.                         .addComponent(jLabel1))
  178.                     .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  179.                 .addGap(21, 21, 21)
  180.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  181.                     .addGroup(layout.createSequentialGroup()
  182.                         .addGap(3, 3, 3)
  183.                         .addComponent(jLabel2))
  184.                     .addComponent(txtCodigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  185.                 .addGap(21, 21, 21)
  186.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  187.                     .addGroup(layout.createSequentialGroup()
  188.                         .addGap(3, 3, 3)
  189.                         .addComponent(jLabel3))
  190.                     .addComponent(txtCantidad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  191.                 .addGap(21, 21, 21)
  192.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  193.                     .addGroup(layout.createSequentialGroup()
  194.                         .addGap(3, 3, 3)
  195.                         .addComponent(jLabel4))
  196.                     .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  197.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
  198.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  199.                     .addComponent(btnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  200.                     .addComponent(btnBorrar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  201.                     .addComponent(btnModificar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  202.                     .addComponent(btnConsultar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  203.                 .addContainerGap())
  204.         );
  205.  
  206.         pack();
  207.     }// </editor-fold>                        
  208.  
  209.     private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {                                          
  210.         // TODO add your handling code here:
  211.     }                                        
  212.  
  213.    
  214.         //*****BOTON GUARDAR*****
  215.     private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {                                          
  216.         // TODO add your handling code here:
  217.         String nombre=txtNombre.getText();
  218.         String codigo=txtCodigo.getText();  
  219.         String cantidad=txtCantidad.getText();
  220.         String precio=txtPrecio.getText();
  221.        
  222.         Producto producto=new Producto(nombre, codigo, cantidad, precio);
  223.         productoData.guardarProducto(producto);
  224.         JOptionPane.showMessageDialog(null, "Se Guardo Correctamente el Producto");
  225.         txtNombre.setText("");
  226.         txtCodigo.setText("");
  227.         txtCantidad.setText("");
  228.         txtPrecio.setText("");  
  229.     }                                          
  230.  
  231.     private void txtCodigoActionPerformed(java.awt.event.ActionEvent evt) {                                          
  232.         // TODO add your handling code here:
  233.     }                                        
  234.  
  235.         //*****BOTON BORRAR*****
  236.     private void btnBorrarActionPerformed(java.awt.event.ActionEvent evt) {                                          
  237.         // TODO add your handling code here:
  238.        
  239.         if(!txtNombre.getText().equals("")){
  240.             int confirma = JOptionPane.showConfirmDialog(rootPane, "¿Seguro que desea Borrar el Producto?");
  241.             if (confirma==0){
  242.                 String nombre=txtNombre.getText());
  243.                 productoData.borrarProducto(nombre);
  244.                 JOptionPane.showMessageDialog(null, "Se Borro el Producto");
  245.                 txtNombre.setText("");
  246.                 txtCodigo.setText("");
  247.                 txtCantidad.setText("");
  248.                 txtPrecio.setText("");
  249.             }
  250.         }else{JOptionPane.showMessageDialog(null, "Debe buscar un Producto para Borrar");}
  251.        
  252.     }                                        
  253.  
  254.     private void txtCantidadActionPerformed(java.awt.event.ActionEvent evt) {                                            
  255.         // TODO add your handling code here:
  256.     }                                          
  257.  
  258.         //*****BOTON MODIFICAR*****
  259.     private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {                                            
  260.         // TODO add your handling code here:
  261.         if(!txtNombre.getText().equals("")){
  262.              String nombre=txtNombre.getText();
  263.              String codigo=txtCodigo.getText();  
  264.              String cantidad=txtCantidad.getText();
  265.              String precio=txtPrecio.getText();
  266.        
  267.             Producto producto=new Producto(id, nombre, codigo, cantidad, precio);
  268.             productoData.modificarProducto(producto);
  269.             JOptionPane.showMessageDialog(null, "¡El Producto se Modifico!");
  270.             txtNombre.setText("");
  271.             txtCodigo.setText("");
  272.             txtCantidad.setText("");
  273.             txtPrecio.setText("");
  274.         }else{JOptionPane.showMessageDialog(null, "Debe buscar un Producto para Modificar");}
  275.     }                                            
  276.  
  277.     private void txtPrecioActionPerformed(java.awt.event.ActionEvent evt) {                                          
  278.         // TODO add your handling code here:  
  279.     }                                        
  280.  
  281.         //*****BOTON CONSULTAR*****
  282.     private void btnConsultarActionPerformed(java.awt.event.ActionEvent evt) {                                            
  283.         // TODO add your handling code here:
  284.         String nombre=txtNombre.getText(JOptionPane.showInputDialog("Ingrese Nombre");
  285.         Producto producto=productoData.consultarProducto(nombre);
  286.         txtNombre.setText(producto.getNombre()+"");
  287.         txtCodigo.setText(producto.getCodigo()+"");
  288.         txtCantidad.setText(producto.getCantidad()+"");
  289.         txtPrecio.setText(producto.getPrecio()+"");
  290.         id=producto.getId_producto();
  291.        
  292.     }                                            
  293.  
  294.     // Variables declaration - do not modify                    
  295.     private javax.swing.JButton btnBorrar;
  296.     private javax.swing.JButton btnConsultar;
  297.     private javax.swing.JButton btnGuardar;
  298.     private javax.swing.JButton btnModificar;
  299.     private javax.swing.JLabel jLabel1;
  300.     private javax.swing.JLabel jLabel2;
  301.     private javax.swing.JLabel jLabel3;
  302.     private javax.swing.JLabel jLabel4;
  303.     private javax.swing.JTextField txtCantidad;
  304.     private javax.swing.JTextField txtCodigo;
  305.     private javax.swing.JTextField txtNombre;
  306.     private javax.swing.JTextField txtPrecio;
  307.     // End of variables declaration                  
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement