/*
* 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 GUI;
import Administracion.Administrador;
import Inventario.almacen.Ingrediente;
import Pedidos.Platillo;
import SistemaDeKioscos.ServicioDeAccesoABaseDeDatos;
import SistemaDeKioscos.ServicioDeNotificacion;
import java.util.Vector;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
/**
*
* @author Mao
*/
public class VentanaPlatillos extends javax.swing.JFrame {
ServicioDeAccesoABaseDeDatos baseDeDatos;
Administrador admin;
/**
* Creates new form alimentos
*/
public VentanaPlatillos() {
initComponents();
baseDeDatos = new ServicioDeAccesoABaseDeDatos();
admin = new Administrador();
}
public VentanaPlatillos(ServicioDeAccesoABaseDeDatos baseDeDatos, Administrador admin) {
this.baseDeDatos = baseDeDatos;
this.admin = admin;
initComponents();
Vector<String> categoriasDePlatillos = baseDeDatos.obtenerCategoriasDePlatillos();
DefaultComboBoxModel modeloCategorias = new DefaultComboBoxModel(categoriasDePlatillos);
cmbCategoria.setModel(modeloCategorias);
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
pnlOperaciones = new javax.swing.JPanel();
btnBuscar = new javax.swing.JButton();
btnNuevo = new javax.swing.JButton();
btnModificar = new javax.swing.JButton();
btnQuitar = new javax.swing.JButton();
pnlPrincipal = new javax.swing.JPanel();
lblNombre = new javax.swing.JLabel();
txtNombre = new javax.swing.JTextField();
lblCategoria = new javax.swing.JLabel();
cmbCategoria = new javax.swing.JComboBox();
lblIngredientes = new javax.swing.JLabel();
lblPrecio = new javax.swing.JLabel();
lblIva = new javax.swing.JLabel();
txtPrecio = new javax.swing.JTextField();
txtIva = new javax.swing.JTextField();
btnIngredientes = new javax.swing.JButton();
tablaIngredientes = new javax.swing.JScrollPane();
tabIngredientes = new javax.swing.JTable();
btnSalir = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setResizable(false);
pnlOperaciones.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
btnBuscar.setMnemonic('B');
btnBuscar.setText("Buscar");
btnBuscar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnBuscarActionPerformed(evt);
}
});
btnNuevo.setMnemonic('N');
btnNuevo.setText("Nuevo");
btnNuevo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnNuevoActionPerformed(evt);
}
});
btnModificar.setMnemonic('M');
btnModificar.setText("Modificar");
btnModificar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnModificarActionPerformed(evt);
}
});
btnQuitar.setMnemonic('Q');
btnQuitar.setText("Quitar");
btnQuitar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnQuitarActionPerformed(evt);
}
});
javax.swing.GroupLayout pnlOperacionesLayout = new javax.swing.GroupLayout(pnlOperaciones);
pnlOperaciones.setLayout(pnlOperacionesLayout);
pnlOperacionesLayout.setHorizontalGroup(
pnlOperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlOperacionesLayout.createSequentialGroup()
.addContainerGap(17, Short.MAX_VALUE)
.addGroup(pnlOperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlOperacionesLayout.createSequentialGroup()
.addGroup(pnlOperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnModificar)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlOperacionesLayout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(btnQuitar)))
.addGap(17, 17, 17))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlOperacionesLayout.createSequentialGroup()
.addGroup(pnlOperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btnNuevo)
.addComponent(btnBuscar))
.addGap(25, 25, 25))))
);
pnlOperacionesLayout.setVerticalGroup(
pnlOperacionesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlOperacionesLayout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(btnBuscar)
.addGap(45, 45, 45)
.addComponent(btnNuevo)
.addGap(78, 78, 78)
.addComponent(btnModificar)
.addGap(71, 71, 71)
.addComponent(btnQuitar)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pnlPrincipal.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
lblNombre.setText("Nombre");
txtNombre.setText("Nombre del platillo");
lblCategoria.setText("Categoria");
cmbCategoria.setEditable(true);
lblIngredientes.setText("Ingredientes");
lblPrecio.setText("Precio: $");
lblIva.setText("IVA: $");
txtPrecio.setText("0");
txtIva.setText("0");
btnIngredientes.setMnemonic('E');
btnIngredientes.setText("Editar Ingredientes");
btnIngredientes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnIngredientesActionPerformed(evt);
}
});
tabIngredientes.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"Ingrediente", "Cant"
}
));
tablaIngredientes.setViewportView(tabIngredientes);
javax.swing.GroupLayout pnlPrincipalLayout = new javax.swing.GroupLayout(pnlPrincipal);
pnlPrincipal.setLayout(pnlPrincipalLayout);
pnlPrincipalLayout.setHorizontalGroup(
pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPrincipalLayout.createSequentialGroup()
.addContainerGap()
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPrincipalLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(pnlPrincipalLayout.createSequentialGroup()
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(pnlPrincipalLayout.createSequentialGroup()
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPrincipalLayout.createSequentialGroup()
.addComponent(lblPrecio)
.addGap(18, 18, 18)
.addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(108, 108, 108))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPrincipalLayout.createSequentialGroup()
.addComponent(lblIva)
.addGap(18, 18, 18)
.addComponent(txtIva, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(121, 121, 121)))
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblIngredientes)
.addComponent(tablaIngredientes, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addComponent(btnIngredientes))
.addGap(288, 288, 288))
.addGroup(pnlPrincipalLayout.createSequentialGroup()
.addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 446, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cmbCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(231, 231, 231))))
.addGroup(pnlPrincipalLayout.createSequentialGroup()
.addComponent(lblNombre)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(lblCategoria)
.addGap(87, 87, 87))))
);
pnlPrincipalLayout.setVerticalGroup(
pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPrincipalLayout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblNombre)
.addComponent(lblCategoria))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(cmbCategoria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlPrincipalLayout.createSequentialGroup()
.addGap(23, 23, 23)
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPrecio)
.addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(63, 63, 63)
.addGroup(pnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblIva)
.addComponent(txtIva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlPrincipalLayout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
.addComponent(lblIngredientes)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tablaIngredientes, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addComponent(btnIngredientes, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45))))
);
btnSalir.setMnemonic('S');
btnSalir.setText("Salir");
btnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSalirActionPerformed(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()
.addComponent(pnlPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(pnlOperaciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 375, Short.MAX_VALUE)
.addComponent(btnSalir)
.addGap(292, 292, 292))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(pnlOperaciones, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlPrincipal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(btnSalir)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalirActionPerformed
System.exit(0);//TODO tal vez un dispose y regresar al menú de administración
}//GEN-LAST:event_btnSalirActionPerformed
private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
//buscar por nombre de platillo
String nombreDePlatillo = JOptionPane.showInputDialog("Escriba el Nombre de Platillo");
Platillo p = baseDeDatos.buscarPlatillo(nombreDePlatillo);
if (p != null) {
txtNombre.setText(p.getNombrePlatillo());
txtPrecio.setText(p.getPrecio() + "");
txtIva.setText(p.getIva() + "");
cmbCategoria.setSelectedItem(p.getCategoria());
//TODO mostrar ingredientes del platillo
// Vector<Ingrediente> ingredientesPlatillo = baseDeDatos.obtenerIngredientesDePlatillo(nombreDePlatillo);
// for (int i = 0; i < ingredientesPlatillo.size(); i++) {
// Ingrediente ingredeintito = ingredientesPlatillo.elementAt(i);
//TODO modelo de tabla
// }
}
}//GEN-LAST:event_btnBuscarActionPerformed
private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
int opc = JOptionPane.showConfirmDialog(this, "¿Desea usar los datos de la ventana para el nuevo platillo?");
if (opc == JOptionPane.YES_OPTION) {
String nombrePlatillo = txtNombre.getText();
double precio = Double.parseDouble(txtPrecio.getText());
int opcion = JOptionPane.showConfirmDialog(this, "¿Desea autocalcular el IVA?");
double iva = 0;
if (opcion == JOptionPane.OK_OPTION) {
iva = precio * 0.16;
}
String catego = (String) cmbCategoria.getSelectedItem();
Platillo p = new Platillo();
p.setNombrePlatillo(nombrePlatillo);
p.setPrecio(precio);
p.setIva(iva);
p.setCategoria(catego);
baseDeDatos.agregarNuevoPlatillo(nombrePlatillo, precio, iva, catego);
admin.AgregarNuevoPlatillo(p);
//TODO para bebidas y carnes preguntar datos extras
} else if (opc == JOptionPane.NO_OPTION) {
String nombrePlatillo = JOptionPane.showInputDialog("Escriba el Nombre de Platillo");
//TODO manejar errores de nulo
double precio = Double.parseDouble(JOptionPane.showInputDialog("Escriba el precio", 0.0f));
int opcion = JOptionPane.showConfirmDialog(this, "¿Se le cobrará IVA por este producto al cliente?");
double iva = 0;
if (opcion == JOptionPane.OK_OPTION) {
iva = precio * 0.16;
}
String catego = JOptionPane.showInputDialog("Escriba la categoría del producto");
Platillo p = new Platillo();
p.setNombrePlatillo(nombrePlatillo);
p.setPrecio(precio);
p.setIva(iva);
p.setCategoria(catego);
// p.setObservaciones(txtaDatos.getText());
//TODO falta ver si se le agregan platillos después
baseDeDatos.agregarNuevoPlatillo(nombrePlatillo, precio, iva, catego);
admin.AgregarNuevoPlatillo(p);
//if(catego=="Bebidas"){
//}
}
}//GEN-LAST:event_btnNuevoActionPerformed
private void btnModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModificarActionPerformed
int opcion = JOptionPane.showConfirmDialog(this, "¿Desea guardar las modificaciones?En caso de que desee cambiar el nombre elija no");
if (opcion == JOptionPane.YES_OPTION) {
System.out.println(cmbCategoria.getSelectedItem());
baseDeDatos.actualizarPlatillo(txtNombre.getText(), txtPrecio.getText(), txtIva.getText(), (String) cmbCategoria.getSelectedItem());//TODO probar posible error con el combo
} else if (opcion == JOptionPane.NO_OPTION) {
int opcion1 = JOptionPane.showConfirmDialog(this, "¿Desea cambiar el nombre?");
if (opcion == JOptionPane.YES_OPTION) {
String nombreAnterior = JOptionPane.showInputDialog("Nombre anterior");
String nuevoNombre = JOptionPane.showInputDialog("Nuevo nombre");
baseDeDatos.cambiarNombreDePlatillo(nombreAnterior, nuevoNombre);
}
}
//String platillo = JOptionPane.showInputDialog("Escriba el Nombre de Platillo que se va a modificar con los datos que se ven");
// if (platillo != "") {
// baseDeDatos.modificarPlatillo(platillo);
//TODO este es super urgente para cambiar precio
//}
}//GEN-LAST:event_btnModificarActionPerformed
private void btnQuitarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuitarActionPerformed
admin.quitarPlatillo();
}//GEN-LAST:event_btnQuitarActionPerformed
private void btnIngredientesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIngredientesActionPerformed
VentanaIngredientes ventanaIngredientes = new VentanaIngredientes(baseDeDatos);
//TODO decirle a la ventana ingredientes en este caso a que platillo se le van a agregar o cambiar los ingredientes
}//GEN-LAST:event_btnIngredientesActionPerformed
public ServicioDeAccesoABaseDeDatos getBaseDeDatos() {
return baseDeDatos;
}
public void setBaseDeDatos(ServicioDeAccesoABaseDeDatos baseDeDatos) {
this.baseDeDatos = baseDeDatos;
}
public Administrador getAdmin() {
return admin;
}
public void setAdmin(Administrador admin) {
this.admin = admin;
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(VentanaPlatillos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(VentanaPlatillos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(VentanaPlatillos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(VentanaPlatillos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VentanaPlatillos().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnBuscar;
private javax.swing.JButton btnIngredientes;
private javax.swing.JButton btnModificar;
private javax.swing.JButton btnNuevo;
private javax.swing.JButton btnQuitar;
private javax.swing.JButton btnSalir;
private javax.swing.JComboBox cmbCategoria;
private javax.swing.JLabel lblCategoria;
private javax.swing.JLabel lblIngredientes;
private javax.swing.JLabel lblIva;
private javax.swing.JLabel lblNombre;
private javax.swing.JLabel lblPrecio;
private javax.swing.JPanel pnlOperaciones;
private javax.swing.JPanel pnlPrincipal;
private javax.swing.JTable tabIngredientes;
private javax.swing.JScrollPane tablaIngredientes;
private javax.swing.JTextField txtIva;
private javax.swing.JTextField txtNombre;
private javax.swing.JTextField txtPrecio;
// End of variables declaration//GEN-END:variables
}