Created
November 27, 2024 17:26
-
-
Save Yalico23/ae687a4297057278c247595818bc36ad to your computer and use it in GitHub Desktop.
Vistas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import controller.Ctrl_Usuario; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import javax.swing.JOptionPane; | |
import model.Usuario; | |
public class FrmLogin extends javax.swing.JFrame { | |
public FrmLogin() { | |
initComponents(); | |
this.setResizable(false); | |
this.setLocationRelativeTo(null); | |
this.setTitle("Login - Sistema de ventas"); | |
this.setSize(new Dimension(700, 500)); | |
jtxtusuario.setDocument(new LimitarCaracteres(20)); | |
jtxtpassword.setDocument(new LimitarCaracteres(20)); | |
} | |
private void jtxtusuarioKeyPressed(java.awt.event.KeyEvent evt) { | |
if (evt.getKeyCode() == evt.VK_ENTER) { | |
jtxtpassword.requestFocus(); | |
} | |
private void jtxtpasswordKeyPressed(java.awt.event.KeyEvent evt) { | |
if (evt.getKeyCode() == evt.VK_ENTER) { | |
this.Login(); | |
} | |
} | |
private void Login() { | |
if (!jtxtusuario.getText().isEmpty() && !jtxtpassword.getText().isEmpty()) { | |
Ctrl_Usuario controlUsuario = new Ctrl_Usuario(); | |
Usuario usuario = new Usuario(); | |
usuario.setUsuario(jtxtusuario.getText().trim()); | |
usuario.setPassword(jtxtpassword.getText().trim()); | |
int tipoUsuario = controlUsuario.loginUser(usuario); | |
if (tipoUsuario != -1) { | |
if (tipoUsuario == 0) { | |
FrmMenu menu = new FrmMenu(); | |
menu.setVisible(true); | |
this.dispose(); | |
} | |
if (tipoUsuario == 1) { | |
FrmMenuAdmin menu = new FrmMenuAdmin(); | |
menu.setVisible(true); | |
this.dispose(); | |
} | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Ingrese sus credenciales"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import conexion.Conexion; | |
import controller.Ctrl_Kardex; | |
import controller.Ctrl_Venta; | |
import controller.PDF_Boleta; | |
import helpers.CodigoMovimiento; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import javax.swing.table.*; | |
import java.sql.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.swing.JOptionPane; | |
import model.Kardex; | |
import model.Venta; | |
import java.util.Date; | |
public class InterBoleta extends javax.swing.JInternalFrame { | |
private int idCliente; | |
private int idProducto; | |
private int stockDisponible; | |
private String dniCliente; | |
private List<Object[]> productosSeleccionados = new ArrayList<>() | |
public InterBoleta() { | |
initComponents(); | |
this.setSize(new Dimension(800, 600)); | |
this.setTitle("Venta"); | |
this.agregarListenersTablas(); | |
this.cargarTablaProductoFinal(); | |
jtxtcantidad.setDocument(new LimitarCaracteres(6)); | |
jtxtcliente.setDocument(new LimitarCaracteres(15)); | |
jtxtproducto.setDocument(new LimitarCaracteres(15)); | |
} | |
private void agregarListenersTablas() { | |
jTableCliente.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
seleccionarCliente(); | |
} | |
}); | |
jTableProducto.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
seleccionarProducto(); | |
} | |
}); | |
jTableProductoFinal.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
int fila = jTableProductoFinal.rowAtPoint(e.getPoint()); | |
int columna = jTableProductoFinal.columnAtPoint(e.getPoint()); | |
// Si se hace clic en la columna 5 (índice 4) | |
if (columna == 4) { | |
eliminarProductoSeleccionado(fila); | |
} | |
} | |
}); | |
} | |
private void cargarTablaProductoFinal() { | |
this.CargarTotales(); | |
DefaultTableModel model = (DefaultTableModel) jTableProductoFinal.getModel(); | |
model.setRowCount(0); // Limpiar la tabla | |
for (Object[] producto : productosSeleccionados) { | |
model.addRow(new Object[]{producto[0], producto[1], producto[2], producto[3], "Eliminar"}); | |
} | |
} | |
private void eliminarProductoSeleccionado(int fila) { | |
if (fila >= 0 && fila < productosSeleccionados.size()) { | |
// Mostrar cuadro de diálogo de confirmación | |
int respuesta = JOptionPane.showConfirmDialog( | |
null, | |
"¿Estás seguro de que deseas eliminar este producto?", | |
"Confirmación de eliminación", | |
JOptionPane.YES_NO_OPTION, | |
JOptionPane.WARNING_MESSAGE | |
); | |
// Si el usuario selecciona "Sí", elimina el producto | |
if (respuesta == JOptionPane.YES_OPTION) { | |
productosSeleccionados.remove(fila); | |
// Recargar la tabla después de eliminar el producto | |
cargarTablaProductoFinal(); | |
JOptionPane.showMessageDialog(null, | |
"Producto eliminado de la venta", | |
"Accion efectuada", | |
JOptionPane.INFORMATION_MESSAGE); | |
} | |
} | |
private void seleccionarCliente() { | |
int fila = jTableCliente.getSelectedRow(); | |
if (fila >= 0) { | |
idCliente = (int) jTableCliente.getValueAt(fila, 0); | |
dniCliente = (String) jTableCliente.getValueAt(fila, 2); | |
EnviarDatosClienteSeleccionada(idCliente); | |
} | |
} | |
private void seleccionarProducto() { | |
int fila = jTableProducto.getSelectedRow(); | |
if (fila >= 0) { | |
idProducto = (int) jTableProducto.getValueAt(fila, 0); | |
EnviarDatosProductosSeleccionada(idProducto); | |
} | |
} | |
private void jtxtclienteKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
// Llamar al método para buscar cliente | |
this.buscarCliente(jtxtcliente.getText().trim()); | |
} | |
private void jtxtproductoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
this.buscarProducto(jtxtproducto.getText().trim()); | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtcantidad.getText().trim().isEmpty() && !jtxtproductofinal.getText().trim().isEmpty()) { | |
int cantidad = Integer.parseInt(jtxtcantidad.getText().trim()); | |
// Verificar si la cantidad ingresada excede el stock disponible | |
if (cantidad > stockDisponible) { | |
JOptionPane.showMessageDialog(null, "La cantidad ingresada excede el stock disponible. Stock disponible: " + stockDisponible); | |
return; // Salir del método para evitar que el producto se agregue a la venta | |
} | |
if (cantidad > 0) { | |
// Verificar si el producto ya está en la lista | |
boolean productoExistente = false; | |
for (Object[] producto : productosSeleccionados) { | |
if ((int) producto[0] == idProducto) { | |
productoExistente = true; | |
// Aquí podrías sumar la cantidad si deseas permitir agregar más del mismo producto | |
break; | |
} | |
} | |
if (!productoExistente) { | |
Object[] producto = {idProducto, jtxtproductofinal.getText(), cantidad, jtxtprecio.getText()}; | |
productosSeleccionados.add(producto); | |
// Actualizar la tabla con los productos seleccionados | |
cargarTablaProductoFinal(); | |
jtxtcantidad.setText(""); // Limpiar el campo de cantidad | |
jtxtproductofinal.setText(""); // Limpiar el campo del producto | |
} else { | |
JOptionPane.showMessageDialog(null, "Este producto ya ha sido agregado."); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "La cantidad debe ser mayor a cero"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Producto o cantidad vacíos"); | |
} | |
} | |
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!productosSeleccionados.isEmpty() && !jtxtclientefinal.getText().trim().isEmpty()) { | |
Venta venta = new Venta(); | |
Ctrl_Venta ctrl_Venta = new Ctrl_Venta(); | |
venta.setFechaEmision(new Date()); | |
venta.setIdCliente(idCliente); | |
venta.setTotal(Double.parseDouble(jtxttotal.getText().trim())); | |
Kardex kardex = new Kardex(); | |
Ctrl_Kardex ck = new Ctrl_Kardex(); | |
kardex.setFechaMovimiento(new Date()); | |
kardex.setEntidadNombre(jtxtclientefinal.getText().trim()); | |
kardex.setTipoMovimiento("Salida"); | |
if (ctrl_Venta.guardar(venta, productosSeleccionados)) { | |
kardex.setDocumento(CodigoMovimiento.getCodigo()); | |
if (!ck.guardar(kardex, productosSeleccionados)) { | |
JOptionPane.showMessageDialog(null, "Error al cargar en el Kardex"); | |
} | |
PDF_Boleta ventaPDF = new PDF_Boleta(); | |
ventaPDF.DatosClientes(idCliente); | |
ventaPDF.generarFactura(productosSeleccionados, Double.parseDouble(jtxttotal.getText()), Double.parseDouble(jtxtsubtotal.getText().trim()), CodigoMovimiento.getCodigo()); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al crear la venta"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Falta cliente o tabla vacia"); | |
} | |
} | |
private void jtxtcantidadKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
if (!Character.isDigit(c)) { | |
evt.consume(); | |
} | |
} | |
private void buscarCliente(String busqueda) { | |
String sql = "SELECT idCliente, nombre, DNI FROM tb_cliente WHERE (nombre LIKE ? OR DNI LIKE ?) AND estado != 0"; | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement(sql)) { | |
pst.setString(1, "%" + busqueda + "%"); | |
pst.setString(2, "%" + busqueda + "%"); | |
try (ResultSet rs = pst.executeQuery()) { | |
DefaultTableModel model = (DefaultTableModel) jTableCliente.getModel(); | |
model.setRowCount(0); // Limpiar tabla | |
while (rs.next()) { | |
model.addRow(new Object[]{rs.getInt("idCliente"), rs.getString("nombre"), rs.getString("DNI")}); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al buscar cliente: " + e.getMessage()); | |
} | |
} | |
private void EnviarDatosClienteSeleccionada(int idCliente) { | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement("SELECT * FROM tb_cliente WHERE idCliente = ? AND estado != 0")) { | |
pst.setInt(1, idCliente); | |
try (ResultSet rs = pst.executeQuery()) { | |
if (rs.next()) { | |
jtxtclientefinal.setText(rs.getString("nombre")); // Actualizar el campo con el nombre del cliente | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar cliente " + e); | |
} | |
} | |
private void buscarProducto(String busqueda) { | |
String sql = "SELECT idProducto, nombre, precio, stock FROM tb_producto WHERE nombre LIKE ? AND estado != 0"; | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement(sql)) { | |
pst.setString(1, "%" + busqueda + "%"); | |
try (ResultSet rs = pst.executeQuery()) { | |
DefaultTableModel model = (DefaultTableModel) jTableProducto.getModel(); | |
model.setRowCount(0); // Limpiar tabla | |
while (rs.next()) { | |
model.addRow(new Object[]{rs.getInt("idProducto"), rs.getString("nombre"), rs.getDouble("precio"), rs.getInt("stock")}); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al buscar producto: " + e.getMessage()); | |
} | |
} | |
private void EnviarDatosProductosSeleccionada(int idProducto) { | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement("SELECT * FROM tb_producto WHERE idProducto = ? ")) { | |
pst.setInt(1, idProducto); | |
try (ResultSet rs = pst.executeQuery()) { | |
if (rs.next()) { | |
jtxtproductofinal.setText(rs.getString("nombre")); // Actualizar el campo con el nombre del producto | |
jtxtprecio.setText(rs.getString("precio")); | |
stockDisponible = rs.getInt("stock"); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar producto: " + e); | |
} | |
} | |
// Object[] producto = {idProducto, jtxtproductofinal.getText(), cantidad , jtxtprecio.getText()}; | |
private void CargarTotales() { | |
double subtotal = 0; | |
double total = 0; | |
for (Object[] p : productosSeleccionados) { | |
double precioProducto = Double.parseDouble(p[3].toString()); | |
int cantidadProductos = Integer.parseInt(p[2].toString()); | |
subtotal += (double) precioProducto * cantidadProductos; | |
} | |
double igv = subtotal * 0.18; | |
total = igv + subtotal; | |
subtotal = Math.round(subtotal * 100.0) / 100.0; | |
total = Math.round(total * 100.0) / 100.0; | |
jtxtsubtotal.setText(String.valueOf(subtotal)); | |
jtxttotal.setText(String.valueOf(total)); | |
} | |
private void Limpiar() { | |
jtxtcantidad.setText(""); | |
jtxtcliente.setText(""); | |
jtxtclientefinal.setText(""); | |
jtxtprecio.setText(""); | |
jtxtproducto.setText(""); | |
jtxtproductofinal.setText(""); | |
jtxtsubtotal.setText(""); | |
jtxttotal.setText(""); | |
productosSeleccionados.removeAll(productosSeleccionados); | |
this.cargarTablaProductoFinal(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import controller.Ctrl_Categoria; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import javax.swing.JOptionPane; | |
import model.Categoria; | |
public class InterCategoria extends javax.swing.JInternalFrame { | |
public InterCategoria() { | |
initComponents(); | |
this.setSize(new Dimension(400,200)); | |
this.setTitle("Nueva Categoria"); | |
jtxtDescripcionCategoria.setDocument(new LimitarCaracteres(15)); | |
} | |
private void jbtnGuardarActionPerformed(java.awt.event.ActionEvent evt) { | |
Categoria categoria = new Categoria(); | |
Ctrl_Categoria controlCategoria = new Ctrl_Categoria(); | |
if (jtxtDescripcionCategoria.getText().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Agregar nombre categoria"); | |
} else { | |
if (!controlCategoria.existeCategoria(jtxtDescripcionCategoria.getText().trim())) { | |
categoria.setDescripcion(jtxtDescripcionCategoria.getText().trim()); | |
categoria.setEstado(1); | |
if (controlCategoria.guardar(categoria)) { | |
JOptionPane.showMessageDialog(null, "Registro Guardado"); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al guardar"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "La categoria ya existe"); | |
} | |
} | |
jtxtDescripcionCategoria.setText(""); | |
} | |
private void jtxtDescripcionCategoriaKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import controller.Ctrl_Cliente; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import javax.swing.JOptionPane; | |
import model.Cliente; | |
public class InterCliente extends javax.swing.JInternalFrame { | |
private final static String EMAIL_REGEX = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; | |
public InterCliente() { | |
initComponents(); | |
this.setSize(new Dimension(400, 300)); | |
this.setTitle("Nuevo Cliente"); | |
jtxtnombre.setDocument(new LimitarCaracteres(40)); | |
jtxtTelefono.setDocument(new LimitarCaracteres(9)); | |
jtxtDireccion.setDocument(new LimitarCaracteres(50)); | |
jtxtDNI.setDocument(new LimitarCaracteres(8)); | |
jtxtEmail.setDocument(new LimitarCaracteres(40)); | |
} | |
private void jbtnGuardarActionPerformed(java.awt.event.ActionEvent evt) { | |
Cliente cliente = new Cliente(); | |
Ctrl_Cliente ctrl_Cliente = new Ctrl_Cliente(); | |
if (this.validar()) { | |
if (!this.emailValido(jtxtEmail.getText().trim())) { | |
JOptionPane.showMessageDialog(null, "Formato Email no valido"); | |
return; | |
} | |
if (!ctrl_Cliente.clienteExiste(jtxtDNI.getText().trim())) { // Existe gente con el mismo nombre y apellido dni no | |
cliente.setNombre(jtxtnombre.getText().trim()); | |
cliente.setDireccion(jtxtDireccion.getText().trim()); | |
cliente.setEmail(jtxtEmail.getText().trim()); | |
cliente.setTelefono(jtxtTelefono.getText().trim()); | |
cliente.setDNI(jtxtDNI.getText().trim()); | |
cliente.setEstado(1); | |
if (ctrl_Cliente.guardar(cliente)) { | |
JOptionPane.showMessageDialog(null, "Cliente Guardado!"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al guardar cliente"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "El cliente ya existe (DNI)"); | |
} | |
} | |
} | |
private boolean validar() { | |
if (jtxtnombre.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxtDireccion.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo direccion"); | |
return false; | |
} | |
if (jtxtEmail.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo email"); | |
return false; | |
} | |
if (jtxtTelefono.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono"); | |
return false; | |
} | |
if (jtxtDNI.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo DNI"); | |
return false; | |
} | |
return true; | |
} | |
private void jtxtDireccionKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
// Llamar al método para buscar cliente | |
} | |
private void jtxtTelefonoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Verificar si el carácter no es un número ni el signo + | |
if (!Character.isDigit(c)) { | |
// Cancelar el evento si no es un número ni el signo + | |
evt.consume(); | |
} | |
} | |
private void jtxtDNIKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
if (!Character.isDigit(c)) { | |
// Cancelar el evento si no es un número ni el signo + | |
evt.consume(); | |
} | |
} | |
private void jtxtnombreKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
// Llamar al método para buscar cliente | |
} | |
private void jtxtEmailKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
// Llamar al método para buscar cliente | |
} | |
private void Limpiar() { | |
jtxtTelefono.setText(""); | |
jtxtnombre.setText(""); | |
jtxtDireccion.setText(""); | |
jtxtDNI.setText(""); | |
jtxtEmail.setText(""); | |
jtxtnombre.requestFocus(); | |
} | |
private boolean emailValido(String valor) { | |
return valor.matches(EMAIL_REGEX); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import conexion.Conexion; | |
import controller.Ctrl_Kardex; | |
import controller.Ctrl_Venta; | |
import controller.PDF_Factura; | |
import helpers.CodigoMovimiento; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import javax.swing.table.*; | |
import java.sql.*; | |
import java.util.ArrayList; | |
import java.util.List; | |
import javax.swing.JOptionPane; | |
import model.Kardex; | |
import model.Venta; | |
import java.util.Date; | |
public class InterFactura extends javax.swing.JInternalFrame { | |
private int idCliente; | |
private int idProducto; | |
private int stockDisponible; | |
private String dniCliente; | |
private List<Object[]> productosSeleccionados = new ArrayList<>(); | |
public InterFactura() { | |
initComponents(); | |
this.setSize(new Dimension(800, 600)); | |
this.setTitle("Venta"); | |
this.agregarListenersTablas(); | |
this.cargarTablaProductoFinal(); | |
jtxtcantidad.setDocument(new LimitarCaracteres(6)); | |
jtxtcliente.setDocument(new LimitarCaracteres(15)); | |
jtxtproducto.setDocument(new LimitarCaracteres(15)); | |
} | |
private void agregarListenersTablas() { | |
jTableCliente.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
seleccionarCliente(); | |
} | |
}); | |
jTableProducto.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
seleccionarProducto(); | |
} | |
}); | |
jTableProductoFinal.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
int fila = jTableProductoFinal.rowAtPoint(e.getPoint()); | |
int columna = jTableProductoFinal.columnAtPoint(e.getPoint()); | |
// Si se hace clic en la columna 5 (índice 4) | |
if (columna == 4) { | |
eliminarProductoSeleccionado(fila); | |
} | |
} | |
}); | |
} | |
private void cargarTablaProductoFinal() { | |
this.CargarTotales(); | |
DefaultTableModel model = (DefaultTableModel) jTableProductoFinal.getModel(); | |
model.setRowCount(0); // Limpiar la tabla | |
for (Object[] producto : productosSeleccionados) { | |
model.addRow(new Object[]{producto[0], producto[1], producto[2], producto[3], "Eliminar"}); | |
} | |
} | |
private void eliminarProductoSeleccionado(int fila) { | |
if (fila >= 0 && fila < productosSeleccionados.size()) { | |
// Mostrar cuadro de diálogo de confirmación | |
int respuesta = JOptionPane.showConfirmDialog( | |
null, | |
"¿Estás seguro de que deseas eliminar este producto?", | |
"Confirmación de eliminación", | |
JOptionPane.YES_NO_OPTION, | |
JOptionPane.WARNING_MESSAGE | |
); | |
// Si el usuario selecciona "Sí", elimina el producto | |
if (respuesta == JOptionPane.YES_OPTION) { | |
productosSeleccionados.remove(fila); | |
// Recargar la tabla después de eliminar el producto | |
cargarTablaProductoFinal(); | |
JOptionPane.showMessageDialog(null, | |
"Producto eliminado de la venta", | |
"Accion efectuada", | |
JOptionPane.INFORMATION_MESSAGE); | |
} | |
} | |
} | |
private void seleccionarCliente() { | |
int fila = jTableCliente.getSelectedRow(); | |
if (fila >= 0) { | |
idCliente = (int) jTableCliente.getValueAt(fila, 0); | |
dniCliente = (String) jTableCliente.getValueAt(fila, 2); | |
EnviarDatosClienteSeleccionada(idCliente); | |
} | |
} | |
private void seleccionarProducto() { | |
int fila = jTableProducto.getSelectedRow(); | |
if (fila >= 0) { | |
idProducto = (int) jTableProducto.getValueAt(fila, 0); | |
EnviarDatosProductosSeleccionada(idProducto); | |
} | |
} | |
private void jtxtclienteKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
// Llamar al método para buscar cliente | |
this.buscarCliente(jtxtcliente.getText().trim()); | |
} | |
private void jtxtproductoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
this.buscarProducto(jtxtproducto.getText().trim()); | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtcantidad.getText().trim().isEmpty() && !jtxtproductofinal.getText().trim().isEmpty()) { | |
int cantidad = Integer.parseInt(jtxtcantidad.getText().trim()); | |
// Verificar si la cantidad ingresada excede el stock disponible | |
if (cantidad > stockDisponible) { | |
JOptionPane.showMessageDialog(null, "La cantidad ingresada excede el stock disponible. Stock disponible: " + stockDisponible); | |
return; // Salir del método para evitar que el producto se agregue a la venta | |
} | |
if (cantidad > 0) { | |
// Verificar si el producto ya está en la lista | |
boolean productoExistente = false; | |
for (Object[] producto : productosSeleccionados) { | |
if ((int) producto[0] == idProducto) { | |
productoExistente = true; | |
// Aquí podrías sumar la cantidad si deseas permitir agregar más del mismo producto | |
break; | |
} | |
} | |
if (!productoExistente) { | |
Object[] producto = {idProducto, jtxtproductofinal.getText(), cantidad, jtxtprecio.getText()}; | |
productosSeleccionados.add(producto); | |
// Actualizar la tabla con los productos seleccionados | |
cargarTablaProductoFinal(); | |
jtxtcantidad.setText(""); // Limpiar el campo de cantidad | |
jtxtproductofinal.setText(""); // Limpiar el campo del producto | |
} else { | |
JOptionPane.showMessageDialog(null, "Este producto ya ha sido agregado."); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "La cantidad debe ser mayor a cero"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Producto o cantidad vacíos"); | |
} | |
} | |
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!productosSeleccionados.isEmpty() && !jtxtclientefinal.getText().trim().isEmpty()) { | |
Venta venta = new Venta(); | |
Ctrl_Venta ctrl_Venta = new Ctrl_Venta(); | |
venta.setFechaEmision(new Date()); | |
venta.setIdCliente(idCliente); | |
venta.setTotal(Double.parseDouble(jtxttotal.getText().trim())); | |
Kardex kardex = new Kardex(); | |
Ctrl_Kardex ck = new Ctrl_Kardex(); | |
kardex.setFechaMovimiento(new Date()); | |
kardex.setEntidadNombre(jtxtclientefinal.getText().trim()); | |
kardex.setTipoMovimiento("Salida"); | |
if (ctrl_Venta.guardar(venta, productosSeleccionados)) { | |
kardex.setDocumento(CodigoMovimiento.getCodigo()); | |
if (!ck.guardar(kardex, productosSeleccionados)) { | |
JOptionPane.showMessageDialog(null, "Error al cargar en el Kardex"); | |
} | |
PDF_Factura ventaPDF = new PDF_Factura(); | |
ventaPDF.DatosClientes(idCliente); | |
ventaPDF.generarFactura(productosSeleccionados, Double.parseDouble(jtxttotal.getText()), Double.parseDouble(jtxtsubtotal.getText().trim()), CodigoMovimiento.getCodigo()); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al crear la venta"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Falta cliente o tabla vacia"); | |
} | |
} | |
private void jtxtcantidadKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
if (!Character.isDigit(c)) { | |
evt.consume(); | |
} | |
} | |
private void buscarCliente(String busqueda) { | |
String sql = "SELECT idCliente, nombre, DNI FROM tb_cliente WHERE (nombre LIKE ? OR DNI LIKE ?) AND estado != 0"; | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement(sql)) { | |
pst.setString(1, "%" + busqueda + "%"); | |
pst.setString(2, "%" + busqueda + "%"); | |
try (ResultSet rs = pst.executeQuery()) { | |
DefaultTableModel model = (DefaultTableModel) jTableCliente.getModel(); | |
model.setRowCount(0); // Limpiar tabla | |
while (rs.next()) { | |
model.addRow(new Object[]{rs.getInt("idCliente"), rs.getString("nombre"), rs.getString("DNI")}); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al buscar cliente: " + e.getMessage()); | |
} | |
} | |
private void EnviarDatosClienteSeleccionada(int idCliente) { | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement("SELECT * FROM tb_cliente WHERE idCliente = ? AND estado != 0")) { | |
pst.setInt(1, idCliente); | |
try (ResultSet rs = pst.executeQuery()) { | |
if (rs.next()) { | |
jtxtclientefinal.setText(rs.getString("nombre")); // Actualizar el campo con el nombre del cliente | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar cliente " + e); | |
} | |
} | |
private void buscarProducto(String busqueda) { | |
String sql = "SELECT idProducto, nombre, precio, stock FROM tb_producto WHERE nombre LIKE ? AND estado != 0"; | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement(sql)) { | |
pst.setString(1, "%" + busqueda + "%"); | |
try (ResultSet rs = pst.executeQuery()) { | |
DefaultTableModel model = (DefaultTableModel) jTableProducto.getModel(); | |
model.setRowCount(0); // Limpiar tabla | |
while (rs.next()) { | |
model.addRow(new Object[]{rs.getInt("idProducto"), rs.getString("nombre"), rs.getDouble("precio"), rs.getInt("stock")}); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al buscar producto: " + e.getMessage()); | |
} | |
} | |
private void EnviarDatosProductosSeleccionada(int idProducto) { | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement("SELECT * FROM tb_producto WHERE idProducto = ? ")) { | |
pst.setInt(1, idProducto); | |
try (ResultSet rs = pst.executeQuery()) { | |
if (rs.next()) { | |
jtxtproductofinal.setText(rs.getString("nombre")); // Actualizar el campo con el nombre del producto | |
jtxtprecio.setText(rs.getString("precio")); | |
stockDisponible = rs.getInt("stock"); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar producto: " + e); | |
} | |
} | |
// Object[] producto = {idProducto, jtxtproductofinal.getText(), cantidad , jtxtprecio.getText()}; | |
private void CargarTotales() { | |
double subtotal = 0; | |
double total = 0; | |
for (Object[] p : productosSeleccionados) { | |
double precioProducto = Double.parseDouble(p[3].toString()); | |
int cantidadProductos = Integer.parseInt(p[2].toString()); | |
subtotal += (double) precioProducto * cantidadProductos; | |
} | |
double igv = subtotal * 0.18; | |
total = igv + subtotal; | |
subtotal = Math.round(subtotal * 100.0) / 100.0; | |
total = Math.round(total * 100.0) / 100.0; | |
jtxtsubtotal.setText(String.valueOf(subtotal)); | |
jtxttotal.setText(String.valueOf(total)); | |
} | |
private void Limpiar() { | |
jtxtcantidad.setText(""); | |
jtxtcliente.setText(""); | |
jtxtclientefinal.setText(""); | |
jtxtprecio.setText(""); | |
jtxtproducto.setText(""); | |
jtxtproductofinal.setText(""); | |
jtxtsubtotal.setText(""); | |
jtxttotal.setText(""); | |
productosSeleccionados.removeAll(productosSeleccionados); | |
this.cargarTablaProductoFinal(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.Ctrl_Categoria; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.sql.*; | |
import javax.swing.JOptionPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
import model.Categoria; | |
public class InterGestionarCategorias extends javax.swing.JInternalFrame { | |
private int idCategoria; | |
public InterGestionarCategorias() { | |
initComponents(); | |
this.setSize(new Dimension(600, 400)); | |
this.setTitle("Gestionar Categorias"); | |
this.CargarTablaCategoria(); | |
jtxt_descripcionCategoria.setDocument(new LimitarCaracteres(20)); | |
} | |
private void jbtn_actualizarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxt_descripcionCategoria.getText().trim().isEmpty()) { | |
Categoria categoria = new Categoria(); | |
Ctrl_Categoria ctrl_Categoria = new Ctrl_Categoria(); | |
categoria.setDescripcion(jtxt_descripcionCategoria.getText().trim()); | |
if (ctrl_Categoria.modificar(categoria, idCategoria)) { | |
JOptionPane.showMessageDialog(null, "Categoria Modificada"); | |
jtxt_descripcionCategoria.setText(""); | |
this.CargarTablaCategoria(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al actualizar"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione una categoria"); | |
} | |
} | |
private void jbtn_eliminarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxt_descripcionCategoria.getText().trim().isEmpty()) { | |
// Mostrar diálogo de confirmación | |
int confirmacion = JOptionPane.showConfirmDialog( | |
null, | |
"¿Estás seguro de que deseas modificar esta categoría?", | |
"Confirmación", | |
JOptionPane.YES_NO_OPTION, | |
JOptionPane.QUESTION_MESSAGE | |
); | |
// Verificar si el usuario seleccionó "Sí" | |
if (confirmacion == JOptionPane.YES_OPTION) { | |
Ctrl_Categoria ctrl_Categoria = new Ctrl_Categoria(); | |
if (ctrl_Categoria.cambiarEstado(idCategoria, true)) { | |
JOptionPane.showMessageDialog(null, "Categoría Modificada"); | |
jtxt_descripcionCategoria.setText(""); | |
this.CargarTablaCategoria(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al actualizar"); | |
} | |
} else { | |
// El usuario seleccionó "No" o cerró el diálogo | |
JOptionPane.showMessageDialog(null, "Operación cancelada"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione una categoría"); | |
} | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxt_descripcionCategoria.getText().trim().isEmpty()) { | |
// Mostrar diálogo de confirmación | |
int confirmacion = JOptionPane.showConfirmDialog( | |
null, | |
"¿Estás seguro de que deseas modificar esta categoría?", | |
"Confirmación", | |
JOptionPane.YES_NO_OPTION, | |
JOptionPane.QUESTION_MESSAGE | |
); | |
// Verificar si el usuario seleccionó "Sí" | |
if (confirmacion == JOptionPane.YES_OPTION) { | |
Ctrl_Categoria ctrl_Categoria = new Ctrl_Categoria(); | |
if (ctrl_Categoria.cambiarEstado(idCategoria, false)) { | |
JOptionPane.showMessageDialog(null, "Categoría Modificada"); | |
jtxt_descripcionCategoria.setText(""); | |
this.CargarTablaCategoria(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al actualizar"); | |
} | |
} else { | |
// El usuario seleccionó "No" o cerró el diálogo | |
JOptionPane.showMessageDialog(null, "Operación cancelada"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione una categoría"); | |
} | |
} | |
//Metodo para mostrar todas las categorias | |
private void CargarTablaCategoria() { | |
Connection con = Conexion.conectar(); | |
DefaultTableModel model = new DefaultTableModel(){ | |
@Override | |
public boolean isCellEditable(int row, int column) { | |
return false; // Todas las celdas no serán editables | |
} | |
}; | |
String sql = "select idCategoria,descripcion,estado from tb_categoria"; | |
Statement st; | |
try { | |
st = con.createStatement(); | |
ResultSet rs = st.executeQuery(sql); | |
InterGestionarCategorias.jtableCategorias = new JTable(model); | |
InterGestionarCategorias.jScrollPane1.setViewportView(InterGestionarCategorias.jtableCategorias); | |
model.addColumn("idCategoria"); | |
model.addColumn("Descripcion"); | |
model.addColumn("Estado"); | |
while (rs.next()) { | |
Object fila[] = new Object[3]; | |
for (int i = 0; i < 3; i++) { | |
fila[i] = rs.getObject(i + 1); | |
} | |
model.addRow(fila); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al rellenar la tabla categoria " + e); | |
} | |
jtableCategorias.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
int fila_point = jtableCategorias.rowAtPoint(e.getPoint()); | |
int columna_point = 0; | |
if (fila_point > -1) { | |
idCategoria = (int) model.getValueAt(fila_point, columna_point); | |
EnviarDatosCategoriaSeleccionada(idCategoria); | |
} | |
} | |
}); | |
} | |
private void EnviarDatosCategoriaSeleccionada(int idCategoria) { | |
try { | |
Connection con = Conexion.conectar(); | |
PreparedStatement pst = con.prepareStatement("select * from tb_categoria where idCategoria = '" + idCategoria + "'"); | |
ResultSet rs = pst.executeQuery(); | |
if (rs.next()) { | |
jtxt_descripcionCategoria.setText(rs.getString("descripcion")); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar categoria " + e); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.Ctrl_Cliente; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.sql.*; | |
import javax.swing.Icon; | |
import javax.swing.ImageIcon; | |
import javax.swing.JOptionPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
import model.Cliente; | |
public class InterGestionarClientes extends javax.swing.JInternalFrame { | |
private int idCliente; | |
private final static String EMAIL_REGEX = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; | |
public InterGestionarClientes() { | |
initComponents(); | |
this.setSize(new Dimension(900, 500)); | |
this.setTitle("Gestionar Clientes"); | |
this.CargarClientes(); | |
ImageIcon wallpaper = new ImageIcon("src/img/fondo3.jpg"); | |
Icon icon = new ImageIcon(wallpaper.getImage().getScaledInstance(900, 500, WIDTH)); | |
jwallspaper.setIcon(icon); | |
this.repaint(); | |
jtxtnombre.setDocument(new LimitarCaracteres(25)); | |
jtxtDni.setDocument(new LimitarCaracteres(8)); | |
jtxtTelefono.setDocument(new LimitarCaracteres(9)); | |
jtxtEmail.setDocument(new LimitarCaracteres(30)); | |
jtxtdireccion.setDocument(new LimitarCaracteres(50)); | |
} | |
private void jbtn_actualizarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
Cliente cliente = new Cliente(); | |
Ctrl_Cliente ctrl_cliente = new Ctrl_Cliente(); | |
if (this.validar()) { | |
if (!this.emailValido(jtxtEmail.getText().trim())) { | |
JOptionPane.showMessageDialog(null, "Formato Email no Valido"); | |
return; | |
} | |
cliente.setDNI(jtxtDni.getText().trim()); | |
cliente.setEmail(jtxtEmail.getText().trim()); | |
cliente.setTelefono(jtxtTelefono.getText().trim()); | |
cliente.setDireccion(jtxtdireccion.getText().trim()); | |
cliente.setNombre(jtxtnombre.getText().trim()); | |
if (ctrl_cliente.modificar(cliente, idCliente)) { | |
JOptionPane.showMessageDialog(null, "Cliente Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al modificar al cliente"); | |
} | |
} | |
} | |
private boolean validar() { | |
if (jtxtnombre.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxtdireccion.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo direccion"); | |
return false; | |
} | |
if (jtxtEmail.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo email"); | |
return false; | |
} | |
if (jtxtTelefono.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono"); | |
return false; | |
} | |
if (jtxtDni.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo DNI"); | |
return false; | |
} | |
return true; | |
} | |
private void jbtn_eliminarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombre.getText().trim().isEmpty()) { | |
// Mostrar diálogo de confirmación | |
int confirmacion = JOptionPane.showConfirmDialog( | |
null, | |
"¿Estás seguro de que deseas modificar este cliente?", | |
"Confirmación", | |
JOptionPane.YES_NO_OPTION, | |
JOptionPane.QUESTION_MESSAGE | |
); | |
// Verificar si el usuario seleccionó "Sí" | |
if (confirmacion == JOptionPane.YES_OPTION) { | |
Ctrl_Cliente ctrl_cliente = new Ctrl_Cliente(); | |
if (ctrl_cliente.cambiarEstado(idCliente, true)) { | |
JOptionPane.showMessageDialog(null, "Cliente Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al dar alta"); | |
} | |
} else { | |
// El usuario seleccionó "No" o cerró el diálogo | |
JOptionPane.showMessageDialog(null, "Operación cancelada"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un Cliente"); | |
} | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombre.getText().trim().isEmpty()) { | |
int confirmacion = JOptionPane.showConfirmDialog( | |
null, | |
"¿Está seguro de dar de alta al cliente?", | |
"Confirmación", | |
JOptionPane.YES_NO_OPTION | |
); | |
if (confirmacion == JOptionPane.YES_OPTION) { | |
Ctrl_Cliente ctrl_cliente = new Ctrl_Cliente(); | |
if (ctrl_cliente.cambiarEstado(idCliente, false)) { | |
JOptionPane.showMessageDialog(null, "Cliente Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al dar de alta"); | |
} | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un Cliente"); | |
} | |
} | |
private void jtxtDniKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
if (!Character.isDigit(c)) { | |
evt.consume(); | |
} | |
} | |
private void jtxtTelefonoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtnombreKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtdireccionKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtEmailKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void CargarClientes() { | |
Connection con = Conexion.conectar(); | |
DefaultTableModel model = new DefaultTableModel() { | |
@Override | |
public boolean isCellEditable(int row, int column) { | |
return false; // Todas las celdas no serán editables | |
} | |
}; | |
String sql = "select idCliente, nombre, direccion, email, telefono, DNI, estado from tb_cliente"; | |
Statement st; | |
try { | |
st = con.createStatement(); | |
ResultSet rs = st.executeQuery(sql); | |
InterGestionarClientes.jtbleClientes = new JTable(model); | |
InterGestionarClientes.jScrollPane1.setViewportView(InterGestionarClientes.jtbleClientes); | |
model.addColumn("N°"); | |
model.addColumn("Nombre"); | |
model.addColumn("Direccion"); | |
model.addColumn("Email"); | |
model.addColumn("Telefono"); | |
model.addColumn("DNI"); | |
model.addColumn("Estado"); | |
while (rs.next()) { | |
Object fila[] = new Object[7]; | |
for (int i = 0; i < 7; i++) { | |
fila[i] = rs.getObject(i + 1); | |
} | |
model.addRow(fila); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al rellenar la tabla clientes " + e); | |
} | |
jtbleClientes.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
int fila_point = jtbleClientes.rowAtPoint(e.getPoint()); | |
int columna_point = 0; | |
if (fila_point > -1) { | |
idCliente = (int) model.getValueAt(fila_point, columna_point); | |
EnviarDatosProductosSeleccionada(idCliente); | |
} | |
} | |
}); | |
} | |
private void EnviarDatosProductosSeleccionada(int idCliente) { | |
try { | |
Connection con = Conexion.conectar(); | |
PreparedStatement pst = con.prepareStatement("select * from tb_cliente where idCliente = '" + idCliente + "'"); | |
ResultSet rs = pst.executeQuery(); | |
if (rs.next()) { | |
jtxtnombre.setText(rs.getString("nombre")); | |
jtxtDni.setText(rs.getString("DNI")); | |
jtxtdireccion.setText(rs.getString("direccion")); | |
jtxtEmail.setText(rs.getString("email")); | |
jtxtTelefono.setText(rs.getString("telefono")); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar cliente " + e); | |
} | |
} | |
private void Limpiar() { | |
jtxtTelefono.setText(""); | |
jtxtnombre.setText(""); | |
jtxtEmail.setText(""); | |
jtxtdireccion.setText(""); | |
jtxtDni.setText(""); | |
jtxtnombre.requestFocus(); | |
this.CargarClientes(); | |
} | |
private boolean emailValido(String valor) { | |
return valor.matches(EMAIL_REGEX); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.Ctrl_Producto; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.KeyEvent; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.sql.*; | |
import javax.swing.Icon; | |
import javax.swing.ImageIcon; | |
import javax.swing.JOptionPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
import model.Producto; | |
public class InterGestionarProductos extends javax.swing.JInternalFrame { | |
/** | |
* Creates new form InterGestionarCategorias | |
*/ | |
private int idProducto; | |
private int idCategoriacombo; | |
private int idCategoriaTabla; | |
public InterGestionarProductos() { | |
initComponents(); | |
this.setSize(new Dimension(900, 500)); | |
this.setTitle("Gestionar Productos"); | |
this.CargarTablaProductos(); | |
jtxtnombre.setDocument(new LimitarCaracteres(40)); | |
ImageIcon wallpaper = new ImageIcon("src/img/fondo3.jpg"); | |
Icon icon = new ImageIcon(wallpaper.getImage().getScaledInstance(900, 500, WIDTH)); | |
jwallspaper.setIcon(icon); | |
this.repaint(); | |
this.CargarComboCategoria(); | |
jtxtnombre.setDocument(new LimitarCaracteres(15)); | |
jtxtdescripcion.setDocument(new LimitarCaracteres(30)); | |
jtxtprecio.setDocument(new LimitarCaracteres(10)); | |
} | |
private void jbtn_actualizarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
if (this.validar()) { | |
Producto producto = new Producto(); | |
Ctrl_Producto ctrl_Producto = new Ctrl_Producto(); | |
producto.setIdProducto(idProducto); | |
producto.setNombre(jtxtnombre.getText().trim()); | |
producto.setPrecio(Double.parseDouble(jtxtprecio.getText())); | |
producto.setDescripcion(jtxtdescripcion.getText().trim()); | |
int idCat = 0; | |
if (jcbxCategoria.getSelectedIndex() == 0) { | |
idCat = idCategoriaTabla; | |
} else { | |
idCategoriacombo = IdCategoria(); | |
idCat = idCategoriacombo; | |
} | |
producto.setIdCategoria(idCat); | |
System.out.println("Producto: " + producto); | |
if (ctrl_Producto.modificar(producto, idProducto)) { | |
JOptionPane.showMessageDialog(null, "Categoria Modificada"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al actualizar"); | |
} | |
} | |
} | |
private boolean validar() { | |
if (jtxtnombre.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxtprecio.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo precio"); | |
return false; | |
} | |
if (jtxtdescripcion.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo descripcion"); | |
return false; | |
} | |
return true; | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombre.getText().trim().isEmpty()) { | |
// Pregunta al usuario si está seguro de dar de alta | |
int respuesta = JOptionPane.showConfirmDialog(null, | |
"¿Estás seguro de dar de alta este producto?", | |
"Confirmar", | |
JOptionPane.YES_NO_OPTION); | |
// Si el usuario selecciona "Sí" | |
if (respuesta == JOptionPane.YES_OPTION) { | |
Ctrl_Producto ctrl_producto = new Ctrl_Producto(); | |
if (ctrl_producto.cambiarEstado(idProducto, false)) { | |
JOptionPane.showMessageDialog(null, "Producto Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al actualizar"); | |
} | |
} else { | |
// Si el usuario selecciona "No", no hace nada o puedes agregar un mensaje | |
JOptionPane.showMessageDialog(null, "Operación cancelada"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un producto"); | |
} | |
} | |
private void jbtn_eliminarCategoria1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombre.getText().trim().isEmpty()) { | |
// Pregunta al usuario si está seguro de dar de alta | |
int respuesta = JOptionPane.showConfirmDialog(null, | |
"¿Estás seguro de dar de baja este producto?", | |
"Confirmar", | |
JOptionPane.YES_NO_OPTION); | |
// Si el usuario selecciona "Sí" | |
if (respuesta == JOptionPane.YES_OPTION) { | |
Ctrl_Producto ctrl_producto = new Ctrl_Producto(); | |
if (ctrl_producto.cambiarEstado(idProducto, true)) { | |
JOptionPane.showMessageDialog(null, "Producto Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al actualizar"); | |
} | |
} else { | |
// Si el usuario selecciona "No", no hace nada o puedes agregar un mensaje | |
JOptionPane.showMessageDialog(null, "Operación cancelada"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un producto"); | |
} | |
} | |
private void jtxtnombreKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtdescripcionKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtprecioKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
String text = jtxtprecio.getText(); | |
// Permite dígitos, un solo punto decimal, Backspace y Delete | |
if (!Character.isDigit(c) && c != '.' && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) { | |
evt.consume(); // Consume el evento si el carácter no es válido | |
} | |
// Verifica que no se pueda ingresar más de un punto decimal | |
if (c == '.' && text.contains(".")) { | |
evt.consume(); // Si ya existe un punto decimal, no permite otro | |
} | |
// Verifica si ya hay un punto decimal y si hay más de 2 dígitos después de él | |
if (text.contains(".")) { | |
int index = text.indexOf('.'); | |
String decimals = text.substring(index + 1); | |
// Si ya hay dos decimales, no permite ingresar más caracteres | |
if (decimals.length() >= 2 && Character.isDigit(c)) { | |
evt.consume(); | |
} | |
} | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.Ctrl_Proveedor; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.sql.*; | |
import javax.swing.Icon; | |
import javax.swing.ImageIcon; | |
import javax.swing.JOptionPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
import model.Proveedor; | |
public class InterGestionarProveedores extends javax.swing.JInternalFrame { | |
/** | |
* Creates new form InterGestionarCategorias | |
*/ | |
private int idProveedor; | |
private final static String EMAIL_REGEX = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; | |
public InterGestionarProveedores() { | |
initComponents(); | |
this.setSize(new Dimension(1100, 550)); //1100, 550 | |
this.setTitle("Gestionar Proveedores"); | |
this.CargarProveedores(); | |
ImageIcon wallpaper = new ImageIcon("src/img/fondo3.jpg"); | |
Icon icon = new ImageIcon(wallpaper.getImage().getScaledInstance(1100, 550, WIDTH)); | |
jwallspaper.setIcon(icon); | |
this.repaint(); | |
jtxtnombreResponsable.setDocument(new LimitarCaracteres(40)); | |
jtxttelefonoResponsable.setDocument(new LimitarCaracteres(9)); | |
jtxtrazonSocial.setDocument(new LimitarCaracteres(30)); | |
jtxtdireccion.setDocument(new LimitarCaracteres(30)); | |
jtxtTelefonoEmpresa.setDocument(new LimitarCaracteres(9)); | |
jtxtemailEmpresa.setDocument(new LimitarCaracteres(30)); | |
jtxtruc.setDocument(new LimitarCaracteres(11)); | |
} | |
private void jbtn_actualizarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
Proveedor proveedor = new Proveedor(); | |
Ctrl_Proveedor ctrl_proveedor = new Ctrl_Proveedor(); | |
if (this.validar()) { | |
if (!this.emailValido(jtxtemailEmpresa.getText().trim())) { | |
JOptionPane.showMessageDialog(null, "Formato Email no Valido"); | |
return; | |
} | |
proveedor.setContactoNombre(jtxtnombreResponsable.getText().trim()); | |
proveedor.setContactoTelefono(jtxttelefonoResponsable.getText().trim()); | |
proveedor.setDireccion(jtxtdireccion.getText().trim()); | |
proveedor.setEmail(jtxtemailEmpresa.getText().trim()); | |
proveedor.setRazonSocial(jtxtrazonSocial.getText().trim()); | |
proveedor.setRuc(jtxtruc.getText().trim()); | |
proveedor.setTelefono(jtxtTelefonoEmpresa.getText().trim()); | |
if (ctrl_proveedor.modificar(proveedor, idProveedor)) { | |
JOptionPane.showMessageDialog(null, "Proveedor Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al modificar al proveedor"); | |
} | |
} | |
} | |
private boolean validar() { | |
if (jtxtnombreResponsable.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxttelefonoResponsable.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono responsable"); | |
return false; | |
} | |
if (jtxtTelefonoEmpresa.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono empresa"); | |
return false; | |
} | |
if (jtxtrazonSocial.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo razon social"); | |
return false; | |
} | |
if (jtxtruc.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo RUC"); | |
return false; | |
} | |
if (jtxtemailEmpresa.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo email"); | |
return false; | |
} | |
if (jtxtdireccion.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo direccion"); | |
return false; | |
} | |
return true; | |
} | |
private void jbtn_eliminarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombreResponsable.getText().trim().isEmpty()) { | |
// Mostrar diálogo de confirmación | |
int confirmacion = JOptionPane.showConfirmDialog( | |
null, | |
"¿Estás seguro de que deseas modificar este proveedor?", | |
"Confirmación", | |
JOptionPane.YES_NO_OPTION, | |
JOptionPane.QUESTION_MESSAGE | |
); | |
// Verificar si el usuario seleccionó "Sí" | |
if (confirmacion == JOptionPane.YES_OPTION) { | |
Ctrl_Proveedor ctrl_proveedor = new Ctrl_Proveedor(); | |
if (ctrl_proveedor.cambiarEstado(idProveedor, true)) { | |
JOptionPane.showMessageDialog(null, "Proveedor Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al dar alta"); | |
} | |
} else { | |
// El usuario seleccionó "No" o cerró el diálogo | |
JOptionPane.showMessageDialog(null, "Operación cancelada"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un Proveedor"); | |
} | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombreResponsable.getText().trim().isEmpty()) { | |
// Pregunta al usuario si está seguro de modificar el proveedor | |
int respuesta = JOptionPane.showConfirmDialog(null, | |
"¿Estás seguro de modificar este proveedor?", | |
"Confirmar", | |
JOptionPane.YES_NO_OPTION); | |
// Si el usuario selecciona "Sí" | |
if (respuesta == JOptionPane.YES_OPTION) { | |
Ctrl_Proveedor ctrl_proveedor = new Ctrl_Proveedor(); | |
if (ctrl_proveedor.cambiarEstado(idProveedor, false)) { | |
JOptionPane.showMessageDialog(null, "Proveedor modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al modificar el proveedor"); | |
} | |
} else { | |
// Si el usuario selecciona "No" | |
JOptionPane.showMessageDialog(null, "Operación cancelada"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un proveedor"); | |
} | |
} | |
private void jtxtTelefonoEmpresaKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtdireccionKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtnombreResponsableKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtrazonSocialKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxttelefonoResponsableKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtrucKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
if (!Character.isDigit(c)) { | |
evt.consume(); | |
} | |
} | |
private void jtxtemailEmpresaKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void CargarProveedores() { | |
Connection con = Conexion.conectar(); | |
DefaultTableModel model = new DefaultTableModel() { | |
@Override | |
public boolean isCellEditable(int row, int column) { | |
return false; // Todas las celdas no serán editables | |
} | |
}; | |
String sql = "select idProveedor, contactoNombre, contactoTelefono, razonSocial, direccion, telefono, email, ruc , estado from tb_proveedor"; | |
Statement st; | |
try { | |
st = con.createStatement(); | |
ResultSet rs = st.executeQuery(sql); | |
InterGestionarProveedores.jtbleProveedores = new JTable(model); | |
InterGestionarProveedores.jScrollPane1.setViewportView(InterGestionarProveedores.jtbleProveedores); | |
model.addColumn("N°"); | |
model.addColumn("N. Responsable"); | |
model.addColumn("T. Responsable"); | |
model.addColumn("Razon Social"); | |
model.addColumn("Direccion"); | |
model.addColumn("Telefono"); | |
model.addColumn("Email"); | |
model.addColumn("ruc"); | |
model.addColumn("Estado"); | |
while (rs.next()) { | |
Object fila[] = new Object[9]; | |
for (int i = 0; i < 9; i++) { | |
fila[i] = rs.getObject(i + 1); | |
} | |
model.addRow(fila); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al rellenar la tabla proveedores " + e); | |
} | |
jtbleProveedores.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
int fila_point = jtbleProveedores.rowAtPoint(e.getPoint()); | |
int columna_point = 0; | |
if (fila_point > -1) { | |
idProveedor = (int) model.getValueAt(fila_point, columna_point); | |
EnviarDatosProveedoresSeleccionada(idProveedor); | |
} | |
} | |
}); | |
} | |
private void EnviarDatosProveedoresSeleccionada(int idProveedor) { | |
try { | |
Connection con = Conexion.conectar(); | |
PreparedStatement pst = con.prepareStatement("select * from tb_proveedor where idProveedor = '" + idProveedor + "'"); | |
ResultSet rs = pst.executeQuery(); | |
if (rs.next()) { | |
jtxtnombreResponsable.setText(rs.getString("contactoNombre")); | |
jtxttelefonoResponsable.setText(rs.getString("contactoTelefono")); | |
jtxtrazonSocial.setText(rs.getString("razonSocial")); | |
jtxtdireccion.setText(rs.getString("direccion")); | |
jtxtTelefonoEmpresa.setText(rs.getString("telefono")); | |
jtxtemailEmpresa.setText(rs.getString("email")); | |
jtxtruc.setText(rs.getString("ruc")); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar proveedor " + e); | |
} | |
} | |
private void Limpiar() { | |
jtxtdireccion.setText(""); | |
jtxtnombreResponsable.setText(""); | |
jtxttelefonoResponsable.setText(""); | |
jtxtrazonSocial.setText(""); | |
jtxtTelefonoEmpresa.setText(""); | |
jtxtemailEmpresa.setText(""); | |
jtxtruc.setText(""); | |
jtxtnombreResponsable.requestFocus(); | |
this.CargarProveedores(); | |
} | |
private boolean emailValido(String valor) { | |
return valor.matches(EMAIL_REGEX); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.Ctrl_Compra; | |
import controller.Ctrl_Kardex; | |
import helpers.CodigoMovimiento; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.sql.*; | |
import javax.swing.Icon; | |
import javax.swing.ImageIcon; | |
import javax.swing.JOptionPane; | |
import javax.swing.JTextField; | |
import javax.swing.table.DefaultTableModel; | |
import model.Kardex; | |
public class InterGestionarStock extends javax.swing.JInternalFrame { | |
/** | |
* Creates new form InterGestionarCategorias | |
*/ | |
private int idProducto; | |
private int stockProducto; | |
private int idProveedor; | |
private String rucProveedor; | |
private String razonSocialProveedor; | |
private static final String ERROR_PRODUCTO_NO_SELECCIONADO = "Producto no seleccionado"; | |
private static final String ERROR_PROVEEDOR_NO_SELECCIONADO = "Proveedor no seleccionado"; | |
private static final String ERROR_CANTIDAD_NO_SELECCIONADA = "Cantidad no seleccionada"; | |
public InterGestionarStock() { | |
initComponents(); | |
this.setSize(new Dimension(900, 500)); | |
this.setTitle("Gestionar Stock Productos"); | |
this.agregarListenerTablas(); | |
jtxtcantidad.setDocument(new LimitarCaracteres(10)); | |
jtxtproducto.setDocument(new LimitarCaracteres(15)); | |
jtxtproveedor.setDocument(new LimitarCaracteres(15)); | |
ImageIcon wallpaper = new ImageIcon("src/img/fondo3.jpg"); | |
Icon icon = new ImageIcon(wallpaper.getImage().getScaledInstance(900, 500, WIDTH)); | |
jwallspaper.setIcon(icon); | |
this.repaint(); | |
} | |
private void agregarListenerTablas() { | |
jtbleProductos.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
seleccionarProductos(); | |
} | |
}); | |
jtbleProveedor.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
seleccionarProveedor(); | |
} | |
}); | |
} | |
private void seleccionarProductos() { | |
int fila = jtbleProductos.getSelectedRow(); | |
if (fila >= 0) { | |
idProducto = (int) jtbleProductos.getValueAt(fila, 0); | |
Object value = jtbleProductos.getValueAt(fila, 2); | |
if (value instanceof String) { | |
// Si es un String, intenta convertirlo a Integer | |
try { | |
stockProducto = Integer.parseInt((String) value); | |
} catch (NumberFormatException e) { | |
System.out.println("Error al convertir stockProducto: " + e.getMessage()); | |
return; // O maneja el error como prefieras | |
} | |
} else if (value instanceof Integer) { | |
stockProducto = (Integer) value; | |
} else { | |
System.out.println("Tipo de dato inesperado: " + (value != null ? value.getClass().getName() : "null")); | |
return; // O maneja el error como prefieras | |
} | |
EnviarDatosProductosSeleccionada(idProducto); | |
} | |
} | |
private void seleccionarProveedor() { | |
int fila = jtbleProveedor.getSelectedRow(); | |
if (fila >= 0) { | |
idProveedor = (int) jtbleProveedor.getValueAt(fila, 0); | |
rucProveedor = (String) jtbleProveedor.getValueAt(fila, 2); | |
razonSocialProveedor = (String) jtbleProveedor.getValueAt(fila, 1); | |
EnviarDatosProveedorSeleccionada(idProveedor); | |
} | |
} | |
private void EnviarDatosProductosSeleccionada(int id) { | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement("SELECT * FROM tb_producto WHERE idProducto = ? AND estado != 0")) { | |
pst.setInt(1, id); | |
try (ResultSet rs = pst.executeQuery()) { | |
if (rs.next()) { | |
jtxtproductofinal.setText(rs.getString("nombre")); // Actualizar el campo con el nombre del cliente | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar producto " + e); | |
} | |
} | |
private void EnviarDatosProveedorSeleccionada(int id) { | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement("SELECT * FROM tb_proveedor WHERE idProveedor = ? AND estado != 0")) { | |
pst.setInt(1, id); | |
try (ResultSet rs = pst.executeQuery()) { | |
if (rs.next()) { | |
jtxtproveedorfinal.setText(rs.getString("razonSocial")); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar proveedor " + e); | |
} | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (this.validar()) { | |
Kardex kardex = new Kardex(); | |
Ctrl_Kardex ck = new Ctrl_Kardex(); | |
Ctrl_Compra cp = new Ctrl_Compra(); | |
int cantidadIngresada = Integer.parseInt(jtxtcantidad.getText().trim()); | |
if (cp.guardar()) { | |
kardex.setFechaMovimiento(new java.util.Date()); | |
kardex.setDocumento(CodigoMovimiento.getCodigo()); | |
kardex.setEntidadNombre(razonSocialProveedor); | |
kardex.setTipoMovimiento("Ingreso"); | |
kardex.setCantidadIngresos(cantidadIngresada); | |
kardex.setCantidadSalidas(0); | |
kardex.setSaldoUnidades(stockProducto + cantidadIngresada); | |
kardex.setIdProducto(idProducto); | |
if (ck.guardar(kardex)) { | |
JOptionPane.showMessageDialog(null, "Productos Ingresados Correctamente"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error ingresar productos"); | |
} | |
} | |
} | |
} | |
private void jtxtproductoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Solo permite letras (mayúsculas y minúsculas) y espacio | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignorar el carácter no permitido | |
} | |
this.buscarProducto(jtxtproducto.getText().trim()); | |
} | |
private void jtxtproveedorKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
this.buscarProveedor(jtxtproveedor.getText().trim()); | |
} | |
private void jtxtcantidadKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Solo permite dígitos (números enteros) | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignorar el carácter no permitido | |
} | |
} | |
private boolean validar() { | |
boolean esProductoValido = validarCampoNoVacio(jtxtproductofinal, ERROR_PRODUCTO_NO_SELECCIONADO); | |
boolean esProveedorValido = validarCampoNoVacio(jtxtproveedorfinal, ERROR_PROVEEDOR_NO_SELECCIONADO); | |
boolean esCantidadValida = validarCampoNoVacio(jtxtcantidad, ERROR_CANTIDAD_NO_SELECCIONADA); | |
return esProductoValido && esProveedorValido && esCantidadValida; | |
} | |
private boolean validarCampoNoVacio(JTextField campo, String mensajeError) { | |
if (campo.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, mensajeError); | |
return false; | |
} | |
return true; | |
} | |
private void buscarProducto(String busqueda) { | |
String sql = "SELECT idProducto, nombre, stock FROM tb_producto WHERE nombre LIKE ? AND estado != 0"; | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement(sql)) { | |
pst.setString(1, "%" + busqueda + "%"); | |
try (ResultSet rs = pst.executeQuery()) { | |
DefaultTableModel model = (DefaultTableModel) jtbleProductos.getModel(); | |
model.setRowCount(0); // Limpiar tabla | |
while (rs.next()) { | |
model.addRow(new Object[]{rs.getInt("idProducto"), rs.getString("nombre"), rs.getString("stock")}); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al buscar producto: " + e.getMessage()); | |
} | |
} | |
private void buscarProveedor(String busqueda) { | |
String sql = "SELECT idProveedor, razonSocial, ruc ,contactoNombre FROM tb_proveedor WHERE (razonSocial LIKE ? OR ruc LIKE ? OR contactoNombre = ?) AND estado != 0"; | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement(sql)) { | |
pst.setString(1, "%" + busqueda + "%"); | |
pst.setString(2, "%" + busqueda + "%"); | |
pst.setString(3, "%" + busqueda + "%"); | |
try (ResultSet rs = pst.executeQuery()) { | |
DefaultTableModel model = (DefaultTableModel) jtbleProveedor.getModel(); | |
model.setRowCount(0); // Limpiar tabla | |
while (rs.next()) { | |
model.addRow(new Object[]{rs.getInt("idProveedor"), rs.getString("razonSocial"), rs.getString("ruc"), rs.getString("contactoNombre")}); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al buscar proveedor: " + e.getMessage()); | |
} | |
} | |
private void Limpiar() { | |
jtxtcantidad.setText(""); | |
jtxtproducto.setText(""); | |
jtxtproveedor.setText(""); | |
jtxtproductofinal.setText(""); | |
jtxtproveedorfinal.setText(""); | |
jtxtproducto.requestFocus(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.Ctrl_Usuario; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.sql.*; | |
import javax.swing.Icon; | |
import javax.swing.ImageIcon; | |
import javax.swing.JOptionPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
import model.Usuario; | |
public class InterGestionarUsuarios extends javax.swing.JInternalFrame { | |
/** | |
* Creates new form InterGestionarCategorias | |
*/ | |
private int idUsuario; | |
private final static String EMAIL_REGEX = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; | |
private int estadoUsuario; | |
public InterGestionarUsuarios() { | |
initComponents(); | |
this.setSize(new Dimension(900, 500)); | |
this.setTitle("Gestionar Clientes"); | |
this.CargarClientes(); | |
ImageIcon wallpaper = new ImageIcon("src/img/fondo3.jpg"); | |
Icon icon = new ImageIcon(wallpaper.getImage().getScaledInstance(900, 500, WIDTH)); | |
jwallspaper.setIcon(icon); | |
this.repaint(); | |
jtxtnombre.setDocument(new LimitarCaracteres(25)); | |
jtxtapellido.setDocument(new LimitarCaracteres(25)); | |
jtxtusuario.setDocument(new LimitarCaracteres(25)); | |
jtxtcorreo.setDocument(new LimitarCaracteres(40)); | |
jtxtpassword.setDocument(new LimitarCaracteres(20)); | |
jtxttelefono.setDocument(new LimitarCaracteres(9)); | |
} | |
private void jbtn_actualizarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
Usuario usuario = new Usuario(); | |
Ctrl_Usuario ctrl_Usuario = new Ctrl_Usuario(); | |
if (this.validar()) { | |
if (!this.emailValido(jtxtcorreo.getText().trim())) { | |
JOptionPane.showMessageDialog(null, "Formato Email no Valido"); | |
return; | |
} | |
if (!this.passwordValido(jtxtpassword.getText().trim())) { | |
JOptionPane.showMessageDialog(null, "Formato Password no Valido"); | |
return; | |
} | |
usuario.setIdUsuario(idUsuario); | |
usuario.setNombre(jtxtnombre.getText().trim()); | |
usuario.setApellido(jtxtapellido.getText().trim()); | |
usuario.setCorreo(jtxtcorreo.getText().trim()); | |
usuario.setPassword(jtxtpassword.getText().trim()); | |
usuario.setUsuario(jtxtusuario.getText().trim()); | |
usuario.setTelefono(jtxttelefono.getText().trim()); | |
usuario.setEstado(estadoUsuario); | |
ctrl_Usuario.modificar(usuario, idUsuario); | |
if (ctrl_Usuario.modificar(usuario, idUsuario)) { | |
JOptionPane.showMessageDialog(null, "Usuario Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al modificar al cliente"); | |
} | |
} | |
} | |
private boolean validar() { | |
if (jtxtnombre.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxtusuario.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo direccion"); | |
return false; | |
} | |
if (jtxtapellido.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo email"); | |
return false; | |
} | |
if (jtxtcorreo.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono"); | |
return false; | |
} | |
if (jtxtpassword.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo DNI"); | |
return false; | |
} | |
return true; | |
} | |
private void jbtn_eliminarCategoriaActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombre.getText().trim().isEmpty()) { | |
int confirmacion = JOptionPane.showConfirmDialog( | |
null, | |
"¿Está seguro de dar de baja al Usuario?", | |
"Confirmación", | |
JOptionPane.YES_NO_OPTION | |
); | |
if (confirmacion == JOptionPane.YES_OPTION) { | |
Ctrl_Usuario ctrl_Usuario = new Ctrl_Usuario(); | |
if (ctrl_Usuario.cambiarEstado(idUsuario, true)) { | |
JOptionPane.showMessageDialog(null, "Usuario Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al dar de alta"); | |
} | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un Usuario"); | |
} | |
} | |
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { | |
if (!jtxtnombre.getText().trim().isEmpty()) { | |
int confirmacion = JOptionPane.showConfirmDialog( | |
null, | |
"¿Está seguro de dar de alta al Usuario?", | |
"Confirmación", | |
JOptionPane.YES_NO_OPTION | |
); | |
if (confirmacion == JOptionPane.YES_OPTION) { | |
Ctrl_Usuario ctrl_Usuario = new Ctrl_Usuario(); | |
if (ctrl_Usuario.cambiarEstado(idUsuario, false)) { | |
JOptionPane.showMessageDialog(null, "Usuario Modificado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al dar de alta"); | |
} | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Seleccione un Usuario"); | |
} | |
} | |
private void jtxtpasswordKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtcorreoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtnombreKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtusuarioKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtapellidoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxttelefonoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void CargarClientes() { | |
Connection con = Conexion.conectar(); | |
DefaultTableModel model = new DefaultTableModel() { | |
@Override | |
public boolean isCellEditable(int row, int column) { | |
return false; // Todas las celdas no serán editables | |
} | |
}; | |
String sql = "select idUsuario, nombre, apellido, usuario, correo, password, telefono, estado from tb_usuario"; | |
Statement st; | |
try { | |
st = con.createStatement(); | |
ResultSet rs = st.executeQuery(sql); | |
InterGestionarUsuarios.jtbleUsuarios = new JTable(model); | |
InterGestionarUsuarios.jScrollPane1.setViewportView(InterGestionarUsuarios.jtbleUsuarios); | |
model.addColumn("N°"); | |
model.addColumn("Nombre"); | |
model.addColumn("Apellido"); | |
model.addColumn("Usuario"); | |
model.addColumn("Correo"); | |
model.addColumn("Password"); | |
model.addColumn("Telefono"); | |
model.addColumn("Estado"); | |
while (rs.next()) { | |
Object fila[] = new Object[8]; | |
for (int i = 0; i < 8; i++) { | |
fila[i] = rs.getObject(i + 1); | |
} | |
model.addRow(fila); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al rellenar la tabla usuarios " + e); | |
} | |
jtbleUsuarios.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
int fila_point = jtbleUsuarios.rowAtPoint(e.getPoint()); | |
int columna_point = 0; | |
if (fila_point > -1) { | |
idUsuario = (int) model.getValueAt(fila_point, columna_point); | |
estadoUsuario = (int) model.getValueAt(fila_point, 7); | |
EnviarDatosProductosSeleccionada(idUsuario); | |
} | |
} | |
}); | |
} | |
private void EnviarDatosProductosSeleccionada(int id) { | |
try { | |
Connection con = Conexion.conectar(); | |
String sql = "SELECT u.nombre, u.apellido, u.usuario, u.correo, p.password, u.telefono " | |
+ "FROM tb_passwordUsuario p " | |
+ "INNER JOIN tb_usuario u ON u.idUsuario = p.idUsuario " | |
+ "WHERE u.idUsuario = ?"; | |
PreparedStatement pst = con.prepareStatement(sql); | |
pst.setInt(1, id); // Se asigna el parámetro de ID de usuario | |
ResultSet rs = pst.executeQuery(); | |
if (rs.next()) { | |
jtxtnombre.setText(rs.getString("nombre")); | |
jtxtapellido.setText(rs.getString("apellido")); | |
jtxtusuario.setText(rs.getString("usuario")); | |
jtxtcorreo.setText(rs.getString("correo")); | |
jtxtpassword.setText(rs.getString("password")); | |
jtxttelefono.setText(rs.getString("telefono")); | |
} else { | |
System.out.println("No se encontró ningún usuario con el ID especificado."); | |
} | |
con.close(); | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar cliente: " + e); | |
} | |
} | |
private void Limpiar() { | |
jtxtnombre.setText(""); | |
jtxtapellido.setText(""); | |
jtxtusuario.setText(""); | |
jtxtcorreo.setText(""); | |
jtxtpassword.setText(""); | |
jtxttelefono.setText(""); | |
this.CargarClientes(); | |
} | |
private boolean emailValido(String valor) { | |
return valor.matches(EMAIL_REGEX); | |
} | |
private boolean passwordValido(String password) { | |
// Expresión regular para validar la contraseña | |
String passwordPattern = "^(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*(),.?\":{}|<>]).{8,}$"; | |
return password.matches(passwordPattern); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.PDF_Kardex; | |
import java.util.Date; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import java.sql.*; | |
import javax.swing.Icon; | |
import javax.swing.ImageIcon; | |
import javax.swing.JOptionPane; | |
import javax.swing.table.DefaultTableModel; | |
public class InterKardex extends javax.swing.JInternalFrame { | |
private int idProducto; | |
private String nombre; | |
public InterKardex() { | |
initComponents(); | |
this.setSize(new Dimension(800, 400)); // 800, 400 | |
this.setTitle("Generar Kardex"); | |
ImageIcon wallpaper = new ImageIcon("src/img/fondo3.jpg"); | |
Icon icon = new ImageIcon(wallpaper.getImage().getScaledInstance(900, 500, WIDTH)); | |
jwallspaper.setIcon(icon); | |
this.repaint(); | |
jtxtproducto.setDocument(new LimitarCaracteres(15)); | |
jdatefin.setDate(new Date()); | |
this.agregarListenersTablas(); | |
} | |
private void agregarListenersTablas() { | |
jtbleProductos.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent e) { | |
seleccionarProducto(); | |
} | |
}); | |
} | |
private void seleccionarProducto() { | |
int fila = jtbleProductos.getSelectedRow(); | |
if (fila >= 0) { | |
Object value = jtbleProductos.getValueAt(fila, 3); | |
// Verificar si el valor es una instancia de String | |
if (value instanceof String) { | |
nombre = (String) value; // Asigna el valor directamente | |
} else if (value instanceof java.sql.Date) { | |
// Convierte la fecha a una cadena en el formato que prefieras (opcional) | |
java.sql.Date date = (java.sql.Date) value; | |
nombre = date.toString(); // Convierte la fecha a String | |
} | |
// Envía los datos del nombre seleccionado | |
EnviarDatosClienteSeleccionada(nombre); | |
} | |
} | |
private void EnviarDatosClienteSeleccionada(String nombre) { | |
System.out.println("nombre : " + nombre); | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement("SELECT * FROM tb_producto WHERE nombre = ?")) { | |
pst.setString(1, nombre); | |
try (ResultSet rs = pst.executeQuery()) { | |
if (rs.next()) { | |
jtxtProductoFinal.setText(rs.getString("nombre")); // Actualizar el campo con el nombre del cliente | |
idProducto = rs.getInt("idProducto"); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al seleccionar producto " + e); | |
} | |
} | |
@SuppressWarnings("unchecked") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
private void initComponents() { | |
jLabel2 = new javax.swing.JLabel(); | |
jPanel1 = new javax.swing.JPanel(); | |
jScrollPane1 = new javax.swing.JScrollPane(); | |
jtbleProductos = new javax.swing.JTable(); | |
jLabel1 = new javax.swing.JLabel(); | |
jdateinicio = new com.toedter.calendar.JDateChooser(); | |
jLabel3 = new javax.swing.JLabel(); | |
jdatefin = new com.toedter.calendar.JDateChooser(); | |
jbtn_generarKardex = new javax.swing.JButton(); | |
jtxtProductoFinal = new javax.swing.JTextField(); | |
jLabel4 = new javax.swing.JLabel(); | |
jtxtproducto = new javax.swing.JTextField(); | |
jwallspaper = new javax.swing.JLabel(); | |
setClosable(true); | |
setIconifiable(true); | |
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); | |
jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N | |
jLabel2.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel2.setText("Kardex de Productos"); | |
getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 10, -1, -1)); | |
jPanel1.setBackground(new java.awt.Color(255, 255, 255)); | |
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder()); | |
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); | |
jtbleProductos.setModel(new javax.swing.table.DefaultTableModel( | |
new Object [][] { | |
{null, null, null, null, null, null, null, null}, | |
{null, null, null, null, null, null, null, null}, | |
{null, null, null, null, null, null, null, null}, | |
{null, null, null, null, null, null, null, null} | |
}, | |
new String [] { | |
"Fecha", "Documento", "Nombre", "Producto", "T. Movimiento", "C. Ingresos", "C. Salidas", "Saldos" | |
} | |
) { | |
boolean[] canEdit = new boolean [] { | |
false, false, false, false, false, false, false, false | |
}; | |
public boolean isCellEditable(int rowIndex, int columnIndex) { | |
return canEdit [columnIndex]; | |
} | |
}); | |
jScrollPane1.setViewportView(jtbleProductos); | |
jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 750, 170)); | |
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel1.setForeground(new java.awt.Color(0, 0, 0)); | |
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel1.setText("Buscar Producto:"); | |
jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, 130, -1)); | |
jPanel1.add(jdateinicio, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 230, 210, -1)); | |
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel3.setForeground(new java.awt.Color(0, 0, 0)); | |
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel3.setText("Fecha Fin:"); | |
jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(370, 230, 90, -1)); | |
jPanel1.add(jdatefin, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 230, 210, -1)); | |
jbtn_generarKardex.setBackground(new java.awt.Color(255, 204, 51)); | |
jbtn_generarKardex.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N | |
jbtn_generarKardex.setForeground(new java.awt.Color(0, 0, 0)); | |
jbtn_generarKardex.setText("Generar Kardex"); | |
jbtn_generarKardex.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jbtn_generarKardexActionPerformed(evt); | |
} | |
}); | |
jPanel1.add(jbtn_generarKardex, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 270, 240, 30)); | |
jtxtProductoFinal.setEnabled(false); | |
jPanel1.add(jtxtProductoFinal, new org.netbeans.lib.awtextra.AbsoluteConstraints(290, 270, 240, 30)); | |
jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel4.setForeground(new java.awt.Color(0, 0, 0)); | |
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel4.setText("Fecha Inicio:"); | |
jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 230, 100, -1)); | |
jtxtproducto.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtproductoKeyTyped(evt); | |
} | |
}); | |
jPanel1.add(jtxtproducto, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 10, 300, 30)); | |
getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 40, 770, 320)); | |
getContentPane().add(jwallspaper, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 890, 470)); | |
pack(); | |
}// </editor-fold> | |
private void jbtn_generarKardexActionPerformed(java.awt.event.ActionEvent evt) { | |
Timestamp inicioTimestamp = this.fecha(jdateinicio.getDate()); | |
Timestamp finTimestamp = this.fecha(jdatefin.getDate()); | |
PDF_Kardex pdfk = new PDF_Kardex(); | |
if (this.validar(inicioTimestamp, finTimestamp)) { | |
//JOptionPane.showMessageDialog(null, "Exito al generar Kardex"); | |
if(!pdfk.generarKardex(idProducto, inicioTimestamp, finTimestamp)){ | |
JOptionPane.showMessageDialog(null, "Error al generar Kardex"); | |
} | |
}else{ | |
jdateinicio.setDate(null); | |
jdatefin.setDate(new Date()); | |
} | |
} | |
private Timestamp fecha(Date fecha) { | |
Timestamp inicioTimestamp = (fecha != null) ? new Timestamp(fecha.getTime()) : null; | |
return inicioTimestamp; | |
} | |
private boolean validar(Timestamp a, Timestamp b) { | |
if(jtxtProductoFinal.getText().trim().isEmpty()){ | |
JOptionPane.showMessageDialog(null, "Ingresar Producto"); | |
return false; | |
} | |
if (a == null) { | |
JOptionPane.showMessageDialog(null, "Agregar una fecha de Inicio"); | |
return false; | |
} | |
if (b == null) { | |
JOptionPane.showMessageDialog(null, "Agregar una fecha de Fin"); | |
return false; | |
} | |
if (b.before(a)) { | |
JOptionPane.showMessageDialog(null, "La fecha de Fin no puede ser anterior a la fecha de Inicio"); | |
return false; | |
} | |
return true; | |
} | |
private void jtxtproductoKeyTyped(java.awt.event.KeyEvent evt) { | |
// Obtener el carácter ingresado | |
char caracter = evt.getKeyChar(); | |
// Verificar si el carácter es un número o un carácter especial | |
if (!Character.isLetter(caracter) && !Character.isWhitespace(caracter)) { | |
evt.consume(); // Cancela el evento si el carácter no es permitido | |
} | |
// Llamar al método de búsqueda después de la validación | |
this.buscarProducto(jtxtproducto.getText().trim()); | |
} | |
private void buscarProducto(String busqueda) { | |
String sql = "SELECT \n" | |
+ " k.fechaMovimiento, \n" | |
+ " k.documento, \n" | |
+ " k.entidadNombre, \n" | |
+ " p.nombre, \n" | |
+ " k.tipoMovimiento, \n" | |
+ " k.cantidadIngresos, \n" | |
+ " k.cantidadSalidas, \n" | |
+ " k.saldoUnidades \n" | |
+ "FROM \n" | |
+ " tb_kardex_movimientos k \n" | |
+ "INNER JOIN \n" | |
+ " tb_producto p ON p.idProducto = k.idProducto \n" | |
+ "WHERE \n" | |
+ " p.nombre LIKE ?"; | |
try (Connection con = Conexion.conectar(); PreparedStatement pst = con.prepareStatement(sql)) { | |
pst.setString(1, "%" + busqueda + "%"); | |
try (ResultSet rs = pst.executeQuery()) { | |
DefaultTableModel model = (DefaultTableModel) jtbleProductos.getModel(); | |
model.setRowCount(0); // Limpiar tabla | |
while (rs.next()) { | |
model.addRow(new Object[]{rs.getDate("fechaMovimiento"), rs.getString("documento"), rs.getString("entidadNombre"), rs.getString("nombre"), rs.getString("tipoMovimiento"), rs.getInt("cantidadIngresos"), rs.getInt("cantidadSalidas"), rs.getInt("saldoUnidades")}); | |
} | |
} | |
} catch (SQLException e) { | |
System.out.println("Error al buscar Producto: " + e.getMessage()); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import conexion.Conexion; | |
import controller.Ctrl_Producto; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import java.awt.event.KeyEvent; | |
import java.sql.*; | |
import javax.swing.JOptionPane; | |
import model.Producto; | |
public class InterProducto extends javax.swing.JInternalFrame { | |
int ontenerIdCategoria = 0; | |
public InterProducto() { | |
initComponents(); | |
this.setSize(new Dimension(400, 300)); | |
this.setTitle("Nuevo Producto"); | |
this.cargarComboCategorias(); | |
jtxtnombre.setDocument(new LimitarCaracteres(15)); | |
jtxtdescripcion.setDocument(new LimitarCaracteres(30)); | |
jtxtprecio.setDocument(new LimitarCaracteres(10)); | |
} | |
private void jbtnGuardarActionPerformed(java.awt.event.ActionEvent evt) { | |
Producto producto = new Producto(); | |
Ctrl_Producto ctrl_Producto = new Ctrl_Producto(); | |
String Categoria = jcbxCategorias.getSelectedItem().toString().trim(); | |
if (this.validar()) { | |
if (!ctrl_Producto.existeProducto(jtxtnombre.getText().trim())) { | |
try { | |
producto.setNombre(jtxtnombre.getText().trim()); | |
producto.setPrecio(Double.parseDouble(jtxtprecio.getText().trim())); | |
producto.setDescripcion(jtxtdescripcion.getText().trim()); | |
this.IdCategoria(); | |
producto.setIdCategoria(ontenerIdCategoria); | |
producto.setEstado(1); | |
if (ctrl_Producto.guardar(producto)) { | |
JOptionPane.showMessageDialog(null, "Registro Guardado"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al guardar"); | |
} | |
} catch (Exception e) { | |
JOptionPane.showMessageDialog(null, "Error al guardar " + e); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "Este producto ya existe"); | |
} | |
} | |
} | |
private boolean validar() { | |
if (jtxtnombre.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxtprecio.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo precio"); | |
return false; | |
} | |
if (jtxtdescripcion.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo descripcion"); | |
return false; | |
} | |
if (jcbxCategorias.getSelectedIndex() == 0) { | |
JOptionPane.showMessageDialog(null, "Seleccionar un campo"); | |
return false; | |
} | |
return true; | |
} | |
private void jtxtprecioKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
String text = jtxtprecio.getText(); | |
// Permite dígitos, un solo punto decimal, Backspace y Delete | |
if (!Character.isDigit(c) && c != '.' && c != KeyEvent.VK_BACK_SPACE && c != KeyEvent.VK_DELETE) { | |
evt.consume(); // Consume el evento si el carácter no es válido | |
} | |
// Verifica que no se pueda ingresar más de un punto decimal | |
if (c == '.' && text.contains(".")) { | |
evt.consume(); // Si ya existe un punto decimal, no permite otro | |
} | |
// Verifica si ya hay un punto decimal y si hay más de 2 dígitos después de él | |
if (text.contains(".")) { | |
int index = text.indexOf('.'); | |
String decimals = text.substring(index + 1); | |
// Si ya hay dos decimales, no permite ingresar más caracteres | |
if (decimals.length() >= 2 && Character.isDigit(c)) { | |
evt.consume(); | |
} | |
} | |
} | |
private void jtxtnombreKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtdescripcionKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void cargarComboCategorias() { | |
Connection cn = Conexion.conectar(); | |
String sql = "select * from tb_categoria where estado != 0"; | |
Statement st; | |
try { | |
st = cn.createStatement(); | |
ResultSet rs = st.executeQuery(sql); | |
jcbxCategorias.removeAll(); | |
jcbxCategorias.addItem("Seleccione Categoria:"); | |
while (rs.next()) { | |
jcbxCategorias.addItem(rs.getString("descripcion")); | |
} | |
cn.close(); | |
} catch (SQLException e) { | |
JOptionPane.showMessageDialog(null, "Error al cargar las categorias"); | |
} | |
} | |
private int IdCategoria() { | |
String sql = "select * from tb_categoria where descripcion = '" + this.jcbxCategorias.getSelectedItem() + "'"; | |
Statement st; | |
try { | |
Connection cn = Conexion.conectar(); | |
st = cn.createStatement(); | |
ResultSet rs = st.executeQuery(sql); | |
while (rs.next()) { | |
ontenerIdCategoria = rs.getInt("idCategoria"); | |
} | |
} catch (SQLException e) { | |
JOptionPane.showMessageDialog(null, "Error al obtener la categoria"); | |
} | |
return ontenerIdCategoria; | |
} | |
private void Limpiar() { | |
jtxtdescripcion.setText(""); | |
jtxtnombre.setText(""); | |
jtxtprecio.setText(""); | |
this.cargarComboCategorias(); | |
jcbxCategorias.setSelectedIndex(0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import controller.Ctrl_Proveedor; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import javax.swing.JOptionPane; | |
import model.Proveedor; | |
public class InterProveedores extends javax.swing.JInternalFrame { | |
private final static String EMAIL_REGEX = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; | |
public InterProveedores() { | |
initComponents(); | |
this.setSize(new Dimension(500, 350)); | |
this.setTitle("Nuevo Proveedor"); | |
jtxtnombre.setDocument(new LimitarCaracteres(25)); | |
jtxtdireccion.setDocument(new LimitarCaracteres(40)); | |
jtxttelefonoResponsable.setDocument(new LimitarCaracteres(9)); | |
jtxtemail.setDocument(new LimitarCaracteres(30)); | |
jtxttelefonoempresa.setDocument(new LimitarCaracteres(9)); | |
jtxtrazonsocial.setDocument(new LimitarCaracteres(30)); | |
jtxtruc.setDocument(new LimitarCaracteres(11)); | |
} | |
/** | |
* 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(); | |
jLabel5 = new javax.swing.JLabel(); | |
jLabel8 = new javax.swing.JLabel(); | |
jLabel10 = new javax.swing.JLabel(); | |
jLabel11 = new javax.swing.JLabel(); | |
jtxtdireccion = new javax.swing.JTextField(); | |
jtxtnombre = new javax.swing.JTextField(); | |
jtxttelefonoResponsable = new javax.swing.JTextField(); | |
jbtnGuardar = new javax.swing.JButton(); | |
jtxttelefonoempresa = new javax.swing.JTextField(); | |
jLabel12 = new javax.swing.JLabel(); | |
jtxtemail = new javax.swing.JTextField(); | |
jLabel13 = new javax.swing.JLabel(); | |
jtxtruc = new javax.swing.JTextField(); | |
jLabel14 = new javax.swing.JLabel(); | |
jtxtrazonsocial = new javax.swing.JTextField(); | |
jwallpaper = new javax.swing.JLabel(); | |
setClosable(true); | |
setIconifiable(true); | |
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); | |
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N | |
jLabel1.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel1.setText("Nuevo Proveedor"); | |
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 10, -1, -1)); | |
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel5.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel5.setText("Nombre de contacto:"); | |
jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 160, -1)); | |
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel8.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel8.setText("Telefono de contacto:"); | |
jLabel8.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 160, -1)); | |
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel10.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel10.setText("Telefono:"); | |
jLabel10.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(60, 110, 120, -1)); | |
jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel11.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel11.setText("Direccion:"); | |
jLabel11.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 230, 90, -1)); | |
jtxtdireccion.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtdireccion.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jtxtdireccionActionPerformed(evt); | |
} | |
}); | |
jtxtdireccion.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtdireccionKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtdireccion, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 230, 260, -1)); | |
jtxtnombre.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtnombre.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtnombreKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtnombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 50, 260, -1)); | |
jtxttelefonoResponsable.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxttelefonoResponsable.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxttelefonoResponsableKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxttelefonoResponsable, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 80, 260, -1)); | |
jbtnGuardar.setBackground(new java.awt.Color(0, 204, 255)); | |
jbtnGuardar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jbtnGuardar.setForeground(new java.awt.Color(0, 0, 0)); | |
jbtnGuardar.setText("Guardar"); | |
jbtnGuardar.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jbtnGuardarActionPerformed(evt); | |
} | |
}); | |
getContentPane().add(jbtnGuardar, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 270, 140, 30)); | |
jtxttelefonoempresa.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxttelefonoempresa.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxttelefonoempresaKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxttelefonoempresa, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 110, 260, -1)); | |
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel12.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel12.setText("RUC:"); | |
jLabel12.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 170, 90, -1)); | |
jtxtemail.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtemail.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtemailKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtemail, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 200, 260, -1)); | |
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel13.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel13.setText("Email:"); | |
jLabel13.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 200, 90, -1)); | |
jtxtruc.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtruc.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jtxtrucActionPerformed(evt); | |
} | |
}); | |
jtxtruc.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtrucKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtruc, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 170, 260, -1)); | |
jLabel14.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel14.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel14.setText("Razon Social:"); | |
jLabel14.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(40, 140, 140, -1)); | |
jtxtrazonsocial.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtrazonsocial.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtrazonsocialKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtrazonsocial, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 140, 260, -1)); | |
jwallpaper.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/fondo3.jpg"))); // NOI18N | |
getContentPane().add(jwallpaper, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 490, 320)); | |
pack(); | |
}// </editor-fold> | |
private void jbtnGuardarActionPerformed(java.awt.event.ActionEvent evt) { | |
Proveedor proveedor = new Proveedor(); | |
Ctrl_Proveedor ctrl_Proveedor = new Ctrl_Proveedor(); | |
if (this.validar()) { | |
if (!this.emailValido(jtxtemail.getText().trim())) { | |
JOptionPane.showMessageDialog(null, "Formato Email no valido"); | |
return; | |
} | |
if (!ctrl_Proveedor.proveedorExiste(jtxtruc.getText().trim())) { // Existe gente con el mismo nombre y apellido dni no | |
proveedor.setContactoNombre(jtxtnombre.getText().trim()); | |
proveedor.setContactoTelefono(jtxttelefonoResponsable.getText().trim()); | |
proveedor.setDireccion(jtxtdireccion.getText().trim()); | |
proveedor.setEmail(jtxtemail.getText().trim()); | |
proveedor.setRazonSocial(jtxtrazonsocial.getText().trim()); | |
proveedor.setRuc(jtxtruc.getText().trim()); | |
proveedor.setTelefono(jtxttelefonoempresa.getText().trim()); | |
proveedor.setEstado(1); | |
if (ctrl_Proveedor.guardar(proveedor)) { | |
JOptionPane.showMessageDialog(null, "Proveedor Guardado!"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al guardar proveedor"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "El proveedor ya existe RUC"); | |
} | |
} | |
} | |
private boolean validar() { | |
if (jtxtnombre.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxttelefonoResponsable.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono responsable"); | |
return false; | |
} | |
if (jtxttelefonoempresa.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono empresa"); | |
return false; | |
} | |
if (jtxtrazonsocial.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo razon social"); | |
return false; | |
} | |
if (jtxtruc.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo RUC"); | |
return false; | |
} | |
if (jtxtemail.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo email"); | |
return false; | |
} | |
if (jtxtdireccion.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo direccion"); | |
return false; | |
} | |
return true; | |
} | |
private void jtxttelefonoResponsableKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtdireccionKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtrucKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxttelefonoempresaKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtnombreKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtrazonsocialKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtemailKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void Limpiar() { | |
jtxtdireccion.setText(""); | |
jtxtnombre.setText(""); | |
jtxttelefonoResponsable.setText(""); | |
jtxtemail.setText(""); | |
jtxttelefonoempresa.setText(""); | |
jtxtruc.setText(""); | |
jtxtrazonsocial.setText(""); | |
jtxtnombre.requestFocus(); | |
} | |
private boolean emailValido(String valor) { | |
return valor.matches(EMAIL_REGEX); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package view; | |
import controller.Ctrl_Usuario; | |
import helpers.LimitarCaracteres; | |
import java.awt.Dimension; | |
import javax.swing.JOptionPane; | |
import model.Usuario; | |
public class InterUsuario extends javax.swing.JInternalFrame { | |
private final static String EMAIL_REGEX = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"; | |
public InterUsuario() { | |
initComponents(); | |
this.setSize(new Dimension(400, 350)); | |
this.setTitle("Nuevo Cliente"); | |
jtxtnombre.setDocument(new LimitarCaracteres(20)); | |
jtxttelefono.setDocument(new LimitarCaracteres(9)); | |
jtxtapellido.setDocument(new LimitarCaracteres(20)); | |
jtxtcorreo.setDocument(new LimitarCaracteres(40)); | |
jtxtusuario.setDocument(new LimitarCaracteres(20)); | |
jtxtpassword.setDocument(new LimitarCaracteres(20)); | |
} | |
/** | |
* 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(); | |
jLabel5 = new javax.swing.JLabel(); | |
jLabel8 = new javax.swing.JLabel(); | |
jLabel10 = new javax.swing.JLabel(); | |
jLabel11 = new javax.swing.JLabel(); | |
jtxttelefono = new javax.swing.JTextField(); | |
jtxtnombre = new javax.swing.JTextField(); | |
jtxtapellido = new javax.swing.JTextField(); | |
jbtnGuardar = new javax.swing.JButton(); | |
jtxtusuario = new javax.swing.JTextField(); | |
jLabel12 = new javax.swing.JLabel(); | |
jtxtcorreo = new javax.swing.JTextField(); | |
jLabel13 = new javax.swing.JLabel(); | |
jtxtpassword = new javax.swing.JPasswordField(); | |
jwallpaper = new javax.swing.JLabel(); | |
setClosable(true); | |
setIconifiable(true); | |
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); | |
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N | |
jLabel1.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel1.setText("Nuevo Usuario"); | |
getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 10, -1, -1)); | |
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel5.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel5.setText("Nombre:"); | |
jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(21, 50, 90, -1)); | |
jLabel8.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel8.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel8.setText("Apellido:"); | |
jLabel8.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 80, 90, -1)); | |
jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel10.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel10.setText("Usuario:"); | |
jLabel10.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 110, 90, -1)); | |
jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel11.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel11.setText("Telefono:"); | |
jLabel11.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 200, 90, -1)); | |
jtxttelefono.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxttelefono.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jtxttelefonoActionPerformed(evt); | |
} | |
}); | |
jtxttelefono.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxttelefonoKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxttelefono, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 200, 220, -1)); | |
jtxtnombre.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtnombre.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtnombreKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtnombre, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 50, 220, -1)); | |
jtxtapellido.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtapellido.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtapellidoKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtapellido, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 80, 220, -1)); | |
jbtnGuardar.setBackground(new java.awt.Color(0, 204, 255)); | |
jbtnGuardar.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jbtnGuardar.setForeground(new java.awt.Color(0, 0, 0)); | |
jbtnGuardar.setText("Guardar"); | |
jbtnGuardar.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
jbtnGuardarActionPerformed(evt); | |
} | |
}); | |
getContentPane().add(jbtnGuardar, new org.netbeans.lib.awtextra.AbsoluteConstraints(130, 240, 140, 30)); | |
jtxtusuario.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtusuario.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtusuarioKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtusuario, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 110, 220, -1)); | |
jLabel12.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel12.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel12.setText("Correo:"); | |
jLabel12.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 90, -1)); | |
jtxtcorreo.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N | |
jtxtcorreo.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtcorreoKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtcorreo, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 140, 220, -1)); | |
jLabel13.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N | |
jLabel13.setForeground(new java.awt.Color(255, 255, 255)); | |
jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); | |
jLabel13.setText("Password:"); | |
jLabel13.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); | |
getContentPane().add(jLabel13, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 170, 90, -1)); | |
jtxtpassword.addKeyListener(new java.awt.event.KeyAdapter() { | |
public void keyTyped(java.awt.event.KeyEvent evt) { | |
jtxtpasswordKeyTyped(evt); | |
} | |
}); | |
getContentPane().add(jtxtpassword, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 170, 220, -1)); | |
jwallpaper.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/fondo3.jpg"))); // NOI18N | |
getContentPane().add(jwallpaper, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 390, 320)); | |
pack(); | |
}// </editor-fold> | |
private void jbtnGuardarActionPerformed(java.awt.event.ActionEvent evt) { | |
Usuario usuario = new Usuario(); | |
Ctrl_Usuario ctrl_Usuario = new Ctrl_Usuario(); | |
if (this.validar()) { | |
if (!this.emailValido(jtxtcorreo.getText().trim())) { | |
JOptionPane.showMessageDialog(null, "Formato Email no valido"); | |
return; | |
} | |
String password = jtxtpassword.getText().trim(); | |
// Validar contraseña con los requisitos establecidos | |
if (!this.passwordValido(password)) { | |
JOptionPane.showMessageDialog(null, "La contraseña debe tener al menos 8 caracteres, incluir una mayúscula, un número y un signo especial."); | |
return; | |
} | |
if (!ctrl_Usuario.usuarioExiste(jtxtusuario.getText().trim())) { // Existe gente con el mismo nombre y apellido dni no | |
usuario.setApellido(jtxtapellido.getText().trim()); | |
usuario.setCorreo(jtxtcorreo.getText().trim()); | |
usuario.setEstado(1); | |
usuario.setNombre(jtxtnombre.getText().trim()); | |
usuario.setPassword(jtxtpassword.getText().trim()); | |
usuario.setTelefono(jtxttelefono.getText().trim()); | |
usuario.setUsuario(jtxtusuario.getText().trim()); | |
if (ctrl_Usuario.crearUsuario(usuario)) { | |
JOptionPane.showMessageDialog(null, "Usuario Guardado!"); | |
this.Limpiar(); | |
} else { | |
JOptionPane.showMessageDialog(null, "Error al guardar usuario"); | |
} | |
} else { | |
JOptionPane.showMessageDialog(null, "El Usuario ya existe (Usuario)"); | |
} | |
} | |
} | |
private void jtxtapellidoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxttelefonoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Verificar si el carácter no es un número ni el signo + | |
if (!Character.isDigit(c)) { | |
// Cancelar el evento si no es un número ni el signo + | |
evt.consume(); | |
} | |
} | |
private void jtxtcorreoKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtnombreKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtusuarioKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (!Character.isLetter(c) && !Character.isDigit(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void jtxtpasswordKeyTyped(java.awt.event.KeyEvent evt) { | |
char c = evt.getKeyChar(); | |
// Permitir solo letras, espacios y dígitos | |
if (Character.isSpaceChar(c)) { | |
evt.consume(); // Ignora el carácter si no es letra, espacio o dígito | |
} | |
} | |
private void Limpiar() { | |
jtxttelefono.setText(""); | |
jtxtnombre.setText(""); | |
jtxtapellido.setText(""); | |
jtxtcorreo.setText(""); | |
jtxtusuario.setText(""); | |
jtxtcorreo.setText(""); | |
jtxtpassword.setText(""); | |
jtxtnombre.requestFocus(); | |
} | |
private boolean emailValido(String valor) { | |
return valor.matches(EMAIL_REGEX); | |
} | |
private boolean passwordValido(String password) { | |
// Expresión regular para validar la contraseña | |
String passwordPattern = "^(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*(),.?\":{}|<>]).{8,}$"; | |
return password.matches(passwordPattern); | |
} | |
private boolean validar() { | |
if (jtxtnombre.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo nombre"); | |
return false; | |
} | |
if (jtxtapellido.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo apellido"); | |
return false; | |
} | |
if (jtxtusuario.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo usuario"); | |
return false; | |
} | |
if (jtxtcorreo.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo correo"); | |
return false; | |
} | |
if (jtxtpassword.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo contraseña"); | |
return false; | |
} | |
if (jtxttelefono.getText().trim().isEmpty()) { | |
JOptionPane.showMessageDialog(null, "Rellenar campo telefono"); | |
return false; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍