Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package views; import ctrl.CtrlAbono; import ctrl.CtrlCliente; import entidades.Abono; import entidades.Cliente; import java.awt.Image; import java.awt.Toolkit; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; import javax.swing.SwingConstants; import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableColumn; import com.itextpdf.text.*; import com.itextpdf.text.pdf.*; import ctrl.CtrlProducto; import ctrl.CtrlVenta; import entidades.Producto; import entidades.Venta; import java.awt.Desktop; import java.io.IOException; /** * * @author wasp */ public class Clientes extends javax.swing.JFrame { // Para instanciar pantallas y ctrl public AddAbono ab; public AddProducto ap; CtrlCliente ctrlCliente = new CtrlCliente(); CtrlAbono ctrlAbono = new CtrlAbono(); CtrlVenta ctrlVenta = new CtrlVenta(); CtrlProducto ctrlProducto = new CtrlProducto(); public Clientes() { initComponents(); this.setLocationRelativeTo(null); this.setResizable(false); txtNroCliente.setEditable(false); txtNombre.setEditable(false); txtApellido.setEditable(false); txtRut.setEditable(false); txtDireccion.setEditable(false); txtReferencia.setEditable(false); txtTelefono.setEditable(false); txtID.setVisible(false); btnActualizar.setVisible(false); cbEstado.removeAllItems(); cbEstado.addItem("ACTIVO"); cbEstado.addItem("INACTIVO"); cbMoroso.removeAllItems(); cbMoroso.addItem("SI"); cbMoroso.addItem("NO"); cbEstado.setEnabled(false); cbMoroso.setEnabled(false); DefaultTableModel modelo = (DefaultTableModel) tablaProductos.getModel(); TableColumn tableColumn = tablaProductos.getColumn("ID"); tableColumn.setPreferredWidth(0); tableColumn.setMinWidth(0); tableColumn.setMaxWidth(0); DefaultTableCellRenderer modelocentrar = new DefaultTableCellRenderer(); modelocentrar.setHorizontalAlignment(SwingConstants.CENTER); tablaProductos.getColumnModel().getColumn(0).setCellRenderer(modelocentrar); tablaProductos.getColumnModel().getColumn(1).setCellRenderer(modelocentrar); tablaProductos.getColumnModel().getColumn(2).setCellRenderer(modelocentrar); tablaProductos.getColumnModel().getColumn(3).setCellRenderer(modelocentrar); tablaProductos.getColumnModel().getColumn(4).setCellRenderer(modelocentrar); int filas = modelo.getRowCount(); for (int i = 1; i <= filas; i++) { modelo.removeRow(0); } this.repaint(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); btnVolver = new javax.swing.JButton(); jLabel2 = new javax.swing.JLabel(); jPanel3 = new javax.swing.JPanel(); jLabel3 = new javax.swing.JLabel(); jScrollPane2 = new javax.swing.JScrollPane(); tablaProductos = new javax.swing.JTable(); btnAddProducto = new javax.swing.JButton(); txtTotalCompras = new javax.swing.JLabel(); jPanel4 = new javax.swing.JPanel(); jLabel12 = new javax.swing.JLabel(); btnVerAboos = new javax.swing.JButton(); fechaUAbono = new javax.swing.JLabel(); montoUAbono = new javax.swing.JLabel(); btnAddAbono = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); txtNombre = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); txtApellido = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); txtRut = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); txtDireccion = new javax.swing.JTextField(); jLabel8 = new javax.swing.JLabel(); txtTelefono = new javax.swing.JTextField(); jPanel5 = new javax.swing.JPanel(); jLabel11 = new javax.swing.JLabel(); txtSaldo = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); txtNroCliente = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); txtReferencia = new javax.swing.JTextField(); btnActualizar = new javax.swing.JButton(); jLabel14 = new javax.swing.JLabel(); cbEstado = new javax.swing.JComboBox<>(); jLabel15 = new javax.swing.JLabel(); cbMoroso = new javax.swing.JComboBox<>(); txtID = new javax.swing.JTextField(); btnEditar = new javax.swing.JButton(); btnImprimir = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setIconImage(getIconImage()); setUndecorated(true); addFocusListener(new java.awt.event.FocusAdapter() { public void focusGained(java.awt.event.FocusEvent evt) { formFocusGained(evt); } }); btnVolver.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/volver.png"))); // NOI18N btnVolver.setText("Volver al Men"); btnVolver.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnVolverActionPerformed(evt); } }); jLabel2.setFont(new java.awt.Font("DejaVu Sans Light", 0, 24)); // NOI18N jLabel2.setText("Cliente"); jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Productos")); jLabel3.setText("Total Compras: "); tablaProductos.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 } }, new String[] { "ID", "Producto", "Cantidad", "Precio", "Total" }) { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); jScrollPane2.setViewportView(tablaProductos); btnAddProducto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.png"))); // NOI18N btnAddProducto.setText("Agregar"); btnAddProducto.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddProductoActionPerformed(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 682, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(45, 45, 45) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3).addComponent(btnAddProducto) .addGroup(jPanel3Layout.createSequentialGroup().addGap(12, 12, 12).addComponent( txtTotalCompras, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 42, Short.MAX_VALUE))); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtTotalCompras, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnAddProducto)) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(33, 33, 33))); jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Abonos")); jLabel12.setText("Ultimo Abono:"); btnVerAboos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/historial.png"))); // NOI18N btnVerAboos.setText("Historial"); btnVerAboos.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnVerAboosActionPerformed(evt); } }); btnAddAbono.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/add.png"))); // NOI18N btnAddAbono.setText("Agregar"); btnAddAbono.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnAddAbonoActionPerformed(evt); } }); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(23, 23, 23).addComponent(jLabel12) .addGap(18, 18, 18).addComponent(fechaUAbono).addGap(18, 18, 18).addComponent(montoUAbono) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnVerAboos).addGap(35, 35, 35).addComponent(btnAddAbono, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(41, 41, 41))); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addGap(14, 14, 14) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel12).addComponent(btnVerAboos).addComponent(fechaUAbono) .addComponent(montoUAbono).addComponent(btnAddAbono)) .addContainerGap(26, Short.MAX_VALUE))); jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos Cliente")); jLabel4.setText("Nombre:"); txtNombre.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { txtNombreActionPerformed(evt); } }); txtNombre.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { txtNombreKeyTyped(evt); } }); jLabel6.setText("Apellido:"); txtApellido.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { txtApellidoKeyTyped(evt); } }); jLabel5.setText("Rut:"); txtRut.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { txtRutKeyTyped(evt); } }); jLabel7.setText("Direccin:"); jLabel8.setText("Telfono:"); txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { txtTelefonoKeyTyped(evt); } }); jPanel5.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(204, 204, 204), 1, true)); jLabel11.setText("Saldo: $"); javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5); jPanel5.setLayout(jPanel5Layout); jPanel5Layout .setHorizontalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap().addComponent(jLabel11) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtSaldo, javax.swing.GroupLayout.DEFAULT_SIZE, 59, Short.MAX_VALUE) .addGap(49, 49, 49))); jPanel5Layout.setVerticalGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel5Layout.createSequentialGroup().addContainerGap() .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11).addComponent(txtSaldo)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jLabel9.setText("N Cliente:"); txtNroCliente.addKeyListener(new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { txtNroClienteKeyTyped(evt); } }); jLabel13.setText("Referencia"); btnActualizar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/guardar.png"))); // NOI18N btnActualizar.setText("Actualizar"); btnActualizar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnActualizarActionPerformed(evt); } }); jLabel14.setText("Estado:"); cbEstado.setModel( new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); jLabel15.setText("Moroso:"); cbMoroso.setModel( new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" })); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout .setHorizontalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel13).addComponent(jLabel8)).addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING).addComponent( txtRut, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( txtReferencia, javax.swing.GroupLayout.PREFERRED_SIZE, 442, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(186, 186, 186) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnActualizar)))) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4).addComponent(jLabel5) .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel9) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtNroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel6).addComponent(jLabel7).addComponent(jLabel14)) .addGap(24, 24, 24) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(104, 104, 104).addComponent(jLabel15) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cbMoroso, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, Short.MAX_VALUE))) .addGap(20, 20, 20))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel9) .addComponent(txtNroCliente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel14) .addComponent(cbEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel15).addComponent(cbMoroso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6).addComponent(txtApellido, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5) .addComponent(txtRut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel7))) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(5, 5, 5) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel13) .addComponent(txtReferencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel8).addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout .createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE) .addGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnActualizar)) .addGap(15, 15, 15))))); btnEditar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/edit.png"))); // NOI18N btnEditar.setText("Editar"); btnEditar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnEditarActionPerformed(evt); } }); btnImprimir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/print.png"))); // NOI18N btnImprimir.setText("Imprimir"); btnImprimir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnImprimirActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addContainerGap()) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnEditar).addGap(24, 24, 24)) .addGroup(jPanel1Layout.createSequentialGroup().addComponent(btnVolver) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnImprimir).addGap(107, 107, 107))); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel2) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(txtID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnEditar))) .addGap(18, 18, 18) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnImprimir) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnVolver, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(12, 12, 12))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addGap(22, 22, 22) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); pack(); }// </editor-fold>//GEN-END:initComponents @Override public Image getIconImage() { Image retValue = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("images/icono.png")); return retValue; } private void btnVolverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVolverActionPerformed this.setEnabled(false); MenuCliente mc = new MenuCliente(); mc.setVisible(true); this.setVisible(false); this.setEnabled(true); }//GEN-LAST:event_btnVolverActionPerformed private void txtNombreActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNombreActionPerformed // TODO add your handling code here: }//GEN-LAST:event_txtNombreActionPerformed private void btnActualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActualizarActionPerformed this.setEnabled(false); try { Cliente c = ctrlCliente.findByID(txtID.getText()); StringBuilder mensaje = new StringBuilder(); String titulo = "Revise los siguientes datos:\n"; if (txtNroCliente.getText().isEmpty() || txtNroCliente.getText() == null) { mensaje.append("el nmero de cliente.\n"); } else if (!isNumeric(txtNroCliente.getText())) { mensaje.append("el nmero de cliente debe contener slo nmeros.\n"); } else { c.setNumeroCliente(Integer.parseInt(txtNroCliente.getText())); } if (txtNombre.getText().isEmpty() || txtNombre.getText() == null) { mensaje.append("el nombre del cliente.\n"); } else { c.setNombreCliente(txtNombre.getText()); } if (txtApellido.getText().isEmpty() || txtApellido.getText() == null) { mensaje.append("el apellido del cliente.\n"); } else { c.setApellidoCliente(txtApellido.getText()); } if (!txtRut.getText().isEmpty() && txtRut.getText() != null) { c.setRutCliente(txtRut.getText()); } else { mensaje.append("el rut del cliente.\n"); } if (!txtDireccion.getText().isEmpty() && txtDireccion.getText() != null) { c.setDireccionCliente(txtDireccion.getText()); } else { mensaje.append("la direccin del cliente.\n"); } if (!txtDireccion.getText().isEmpty() && txtDireccion.getText() != null) { c.setDireccionCliente(txtDireccion.getText()); } else { mensaje.append("la direccin del cliente.\n"); } if (!txtReferencia.getText().isEmpty() && txtReferencia.getText() != null) { c.setReferenciaCliente(txtReferencia.getText()); } else { mensaje.append("referencia del cliente.\n"); } if (!txtTelefono.getText().isEmpty() && txtTelefono.getText() != null) { c.setTelefonoCliente(txtTelefono.getText()); } else { mensaje.append("el telfono del cliente.\n"); } if (cbEstado.getSelectedItem().equals("ACTIVO")) { c.setActivoCliente(true); } else { c.setActivoCliente(false); } if (cbMoroso.getSelectedItem().equals("SI")) { c.setMorosoCliente(true); } else { c.setMorosoCliente(false); } if (cbEstado.getSelectedItem().equals("ACTIVO") && cbMoroso.getSelectedItem().equals("SI")) { btnAddAbono.setEnabled(true); btnAddProducto.setEnabled(false); } else if (cbEstado.getSelectedItem().equals("ACTIVO") && cbMoroso.getSelectedItem().equals("NO")) { btnAddProducto.setEnabled(true); btnAddAbono.setEnabled(true); } else if (cbEstado.getSelectedItem().equals("INACTIVO")) { btnAddProducto.setEnabled(false); btnAddAbono.setEnabled(false); } ctrlCliente.actualizarCliente(c); JOptionPane.showMessageDialog(null, "El cliente se ha actualizado exitosamente", "Aviso", JOptionPane.DEFAULT_OPTION); txtNroCliente.setEditable(false); txtNombre.setEditable(false); txtApellido.setEditable(false); txtRut.setEditable(false); txtDireccion.setEditable(false); txtReferencia.setEditable(false); txtTelefono.setEditable(false); txtID.setEditable(false); cbEstado.setEnabled(false); cbMoroso.setEnabled(false); btnActualizar.setVisible(false); btnEditar.setVisible(true); } catch (Exception ex) { JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } this.setEnabled(true); }//GEN-LAST:event_btnActualizarActionPerformed private void btnEditarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEditarActionPerformed this.setEnabled(false); txtNroCliente.setEditable(true); txtNombre.setEditable(true); txtApellido.setEditable(true); txtRut.setEditable(true); txtDireccion.setEditable(true); txtReferencia.setEditable(true); txtTelefono.setEditable(true); cbEstado.setEnabled(true); cbMoroso.setEnabled(true); btnEditar.setVisible(false); btnActualizar.setVisible(true); this.setEnabled(true); }//GEN-LAST:event_btnEditarActionPerformed private void btnVerAboosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnVerAboosActionPerformed this.setEnabled(false); HistorialAbonos ha = new HistorialAbonos(); DefaultTableModel modelo = (DefaultTableModel) ha.tablaAbonos.getModel(); try { ArrayList<Abono> listaAbonos = ctrlAbono.listByCliente(txtID.getText()); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); if (listaAbonos.size() > 0) { for (Abono a : listaAbonos) { String[] fila = new String[3]; fila[0] = sdf.format(a.getFechaAbono()); fila[1] = "$" + String.valueOf(a.getMontoAbono()); fila[2] = "$" + String.valueOf(a.getSaldoAbono()); modelo.addRow(fila); } } ha.tablaAbonos.setModel(modelo); ha.setVisible(true); } catch (Exception ex) { Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex); } this.setEnabled(true); }//GEN-LAST:event_btnVerAboosActionPerformed private void btnAddProductoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddProductoActionPerformed this.setEnabled(false); ap = new AddProducto(this); ap.txtIDCliente.setText(txtID.getText()); ap.setVisible(true); this.setEnabled(true); }//GEN-LAST:event_btnAddProductoActionPerformed private void btnAddAbonoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddAbonoActionPerformed this.setEnabled(false); ab = new AddAbono(this); ab.txtIDCliente.setText(txtID.getText()); ab.setVisible(true); this.setEnabled(true); }//GEN-LAST:event_btnAddAbonoActionPerformed private void formFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_formFocusGained try { // TODO add your handling code here: } catch (Exception ex) { Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex); } }//GEN-LAST:event_formFocusGained private void txtNroClienteKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroClienteKeyTyped char caracter = evt.getKeyChar(); if (((caracter < '0') || (caracter > '9')) && (caracter != '\b' /*corresponde a BACK_SPACE*/)) { evt.consume(); // ignorar el evento de teclado } // TODO add your handling code here: }//GEN-LAST:event_txtNroClienteKeyTyped private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped char caracter = evt.getKeyChar(); if (Character.isAlphabetic(caracter)) { evt.consume(); } }//GEN-LAST:event_txtNombreKeyTyped private void txtApellidoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoKeyTyped char caracter = evt.getKeyChar(); if (Character.isAlphabetic(caracter)) { evt.consume(); } }//GEN-LAST:event_txtApellidoKeyTyped private void txtRutKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtRutKeyTyped char caracter = evt.getKeyChar(); if (((caracter < '0') || (caracter > '9')) && (caracter != '\b' /*corresponde a BACK_SPACE*/) && (caracter != 'k') && (caracter != '.') && (caracter != '-')) { evt.consume(); // ignorar el evento de teclado } }//GEN-LAST:event_txtRutKeyTyped private void txtTelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyTyped char caracter = evt.getKeyChar(); if (Character.isAlphabetic(caracter)) { evt.consume(); } }//GEN-LAST:event_txtTelefonoKeyTyped private void btnImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnImprimirActionPerformed try { OutputStream file = new FileOutputStream(new File("C:\\CuotaSoft\\Historial.pdf")); Document document = new Document(); PdfWriter writer; writer = PdfWriter.getInstance(document, file); document.open(); // Se agrega titulo y datos del cliente Paragraph p = new Paragraph("Historial de Cliente \n", FontFactory.getFont("Arial", 16, Font.BOLD, BaseColor.BLACK)); p.setAlignment(Element.ALIGN_CENTER); Paragraph pNumero = new Paragraph("N Cliente: " + txtNroCliente.getText(), FontFactory.getFont("Arial", 12, Font.NORMAL, BaseColor.BLACK)); Paragraph pNombre = new Paragraph( "Nombre Cliente: " + txtNombre.getText() + " " + txtApellido.getText(), FontFactory.getFont("Arial", 12, Font.NORMAL, BaseColor.BLACK)); Paragraph pProductos = new Paragraph("Productos Comprados: ", FontFactory.getFont("Arial", 14, Font.BOLD, BaseColor.BLACK)); pProductos.setAlignment(Element.ALIGN_CENTER); Paragraph pSaldo = new Paragraph("Saldo: $" + txtSaldo.getText(), FontFactory.getFont("Arial", 14, Font.BOLD, BaseColor.BLACK)); pSaldo.setAlignment(Element.ALIGN_RIGHT); //se agregan paragraphs document.add(p); document.add(pNumero); document.add(pNombre); document.add(pSaldo); document.add(new Paragraph("\n")); document.add(pProductos); document.add(new Paragraph("\n")); //se agrega tabla productos PdfPTable pTablaProducto = new PdfPTable(4); float[] mediaCeldasProductos = { 3.30f, 3.50f, 3.50f, 3.70f }; pTablaProducto.setWidths(mediaCeldasProductos); pTablaProducto.addCell(new Paragraph("Producto", FontFactory.getFont("Arial", 12))); pTablaProducto.addCell(new Paragraph("Cantidad", FontFactory.getFont("Arial", 12))); pTablaProducto.addCell(new Paragraph("Precio", FontFactory.getFont("Arial", 12))); pTablaProducto.addCell(new Paragraph("Total", FontFactory.getFont("Arial", 12))); ArrayList<Venta> listaProductos = ctrlVenta.listByCliente(Integer.parseInt(txtID.getText())); for (Venta v : listaProductos) { Producto prod = ctrlProducto.buscarPorID(v.getProducto().getIdProducto()); pTablaProducto.addCell(new Paragraph(prod.getNombreProducto(), FontFactory.getFont("Arial", 10))); pTablaProducto.addCell( new Paragraph(String.valueOf(v.getCantidadVenta()), FontFactory.getFont("Arial", 10))); pTablaProducto.addCell(new Paragraph("$" + String.valueOf(prod.getPrecioProducto()), FontFactory.getFont("Arial", 10))); pTablaProducto.addCell( new Paragraph("$" + String.valueOf(v.getMontoVenta()), FontFactory.getFont("Arial", 10))); } document.add(pTablaProducto); Paragraph pTotalCompra = new Paragraph("Total Compras: " + txtTotalCompras.getText(), FontFactory.getFont("Arial", 12, Font.BOLD, BaseColor.BLACK)); pTotalCompra.setAlignment(Element.ALIGN_RIGHT); document.add(pTotalCompra); document.add(new Paragraph("\n")); Paragraph pAbonos = new Paragraph("Abonos: ", FontFactory.getFont("Arial", 14, Font.BOLD, BaseColor.BLACK)); pAbonos.setAlignment(Element.ALIGN_CENTER); document.add(pAbonos); document.add(new Paragraph("\n")); PdfPTable tablaAbonos = new PdfPTable(3); float[] mediaCeldasAbonos = { 3.30f, 3.50f, 3.50f }; tablaAbonos.setWidths(mediaCeldasAbonos); tablaAbonos.addCell(new Paragraph("Fecha", FontFactory.getFont("Arial", 12))); tablaAbonos.addCell(new Paragraph("Monto", FontFactory.getFont("Arial", 12))); tablaAbonos.addCell(new Paragraph("Saldo", FontFactory.getFont("Arial", 12))); ArrayList<Abono> listaAbonos = ctrlAbono.listByCliente(txtID.getText()); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); if (listaAbonos.size() > 0) { for (Abono a : listaAbonos) { tablaAbonos.addCell( new Paragraph(sdf.format(a.getFechaAbono()), FontFactory.getFont("Arial", 10))); tablaAbonos.addCell(new Paragraph("$" + String.valueOf(a.getMontoAbono()), FontFactory.getFont("Arial", 10))); tablaAbonos.addCell(new Paragraph("$" + String.valueOf(a.getSaldoAbono()), FontFactory.getFont("Arial", 10))); } } document.add(tablaAbonos); document.close(); file.close(); } catch (FileNotFoundException ex) { Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex); } catch (DocumentException ex) { Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(Clientes.class.getName()).log(Level.SEVERE, null, ex); } try { File file = new File("C:\\CuotaSoft\\Historial.pdf"); Desktop.getDesktop().open(file); } catch (Exception e) { e.printStackTrace(); } }//GEN-LAST:event_btnImprimirActionPerformed private static boolean isNumeric(String cadena) { try { Integer.parseInt(cadena); return true; } catch (NumberFormatException nfe) { return false; } } /** * @param args the command line arguments */ // Variables declaration - do not modify//GEN-BEGIN:variables public javax.swing.JButton btnActualizar; public javax.swing.JButton btnAddAbono; public javax.swing.JButton btnAddProducto; public javax.swing.JButton btnEditar; private javax.swing.JButton btnImprimir; private javax.swing.JButton btnVerAboos; private javax.swing.JButton btnVolver; public javax.swing.JComboBox<String> cbEstado; public javax.swing.JComboBox<String> cbMoroso; public javax.swing.JLabel fechaUAbono; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JPanel jPanel5; private javax.swing.JScrollPane jScrollPane2; public javax.swing.JLabel montoUAbono; public javax.swing.JTable tablaProductos; public javax.swing.JTextField txtApellido; public javax.swing.JTextField txtDireccion; public javax.swing.JTextField txtID; public javax.swing.JTextField txtNombre; public javax.swing.JTextField txtNroCliente; public javax.swing.JTextField txtReferencia; public javax.swing.JTextField txtRut; public javax.swing.JLabel txtSaldo; public javax.swing.JTextField txtTelefono; public javax.swing.JLabel txtTotalCompras; // End of variables declaration//GEN-END:variables }