Clientes.editaCliente.java Source code

Java tutorial

Introduction

Here is the source code for Clientes.editaCliente.java

Source

/*
 * 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 Clientes;

import Hibernate.Util.HibernateUtil;
import Hibernate.entidades.Clientes;
import Hibernate.entidades.Usuario;
import Integral.ExtensionFileFilter;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.List;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import Integral.Herramientas;
import Integral.Render1;
import java.awt.Desktop;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

/**
 *
 * @author ESPECIALIZADO TOLUCA
 */
public class editaCliente extends javax.swing.JPanel {

    /**
     * Creates new form editaCliente
     */
    private Usuario usr;
    private Clientes actor;
    String sessionPrograma = "";
    Herramientas h;
    int x = 0;
    //private Session session;
    int[] puestos;
    DefaultTableModel model;
    //Puestos puesto;
    String[] columnas = new String[] { "Clave", "Nombre", "Direccin", "Colonia", "C.P.", "R.F.C.", "Poblacin",
            "Estado", "Telfono", "E-mail", "Contacto", "Nextel", "Municipio", "N Ext", "Receptor",
            "email receptor" };
    private Clientes returnStatus;

    public editaCliente(Usuario usuario, String ses) {
        initComponents();
        sessionPrograma = ses;
        usr = usuario;
        formatoTabla();
        buscaDato();
    }

    DefaultTableModel ModeloTablaReporte(int renglones, String columnas[]) {
        model = new DefaultTableModel(new Object[renglones][10], columnas) {
            Class[] types = new Class[] { java.lang.Integer.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class,
                    java.lang.String.class };
            boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false, false, false,
                    false, false, false, false, false, false, false };

            public void setValueAt(Object value, int row, int col) {
                Vector vector = (Vector) this.dataVector.elementAt(row);
                Object celda = ((Vector) this.dataVector.elementAt(row)).elementAt(col);
                switch (col) {
                default:
                    vector.setElementAt(value, col);
                    this.dataVector.setElementAt(vector, row);
                    fireTableCellUpdated(row, col);
                    break;
                }
            }

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        };
        return model;
    }

    /**
     * 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() {

        nombre2 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        t_datos = new javax.swing.JTable();
        jLabel4 = new javax.swing.JLabel();
        IdClientes = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        nombre = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        Direccion = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        numero = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        Cp = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        contacto = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        nextel = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        Colonia = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        Poblacion = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        municipio = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        Estado = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        Rfc = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        Telefono = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        Email = new javax.swing.JTextField();
        b_actualizar = new javax.swing.JButton();
        b_cancelar = new javax.swing.JButton();
        Selecciona2 = new javax.swing.JButton();
        Eliminar1 = new javax.swing.JButton();
        Selecciona3 = new javax.swing.JButton();
        bt_actualiza1 = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        t_receptor = new javax.swing.JTextField();
        t_email_receptor = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        t_busca = new javax.swing.JTextField();
        b_busca = new javax.swing.JButton();
        bt_actualiza2 = new javax.swing.JButton();

        nombre2.setEnabled(false);
        nombre2.setNextFocusableComponent(Direccion);
        nombre2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                nombre2ActionPerformed(evt);
            }
        });
        nombre2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nombre2KeyTyped(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel13.setText("Contacto:");

        setBackground(new java.awt.Color(255, 255, 255));

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Edicin de Clientes",
                javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 12))); // NOI18N

        jPanel3.setBackground(new java.awt.Color(255, 255, 255));
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(
                new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true), "Lista Clientes",
                javax.swing.border.TitledBorder.RIGHT, javax.swing.border.TitledBorder.TOP,
                new java.awt.Font("Arial", 1, 11))); // NOI18N

        t_datos.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {

        }, new String[] { "Clave", "Nombre", "Direccin", "Colonia", "Poblacin", "Estado", "C.P.", "R.F.C.",
                "Telfono", "E-mail" }) {
            Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.Object.class,
                    java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class,
                    java.lang.Object.class, java.lang.Object.class, java.lang.Object.class };
            boolean[] canEdit = new boolean[] { false, false, true, true, true, true, true, true, true, true };

            public Class getColumnClass(int columnIndex) {
                return types[columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit[columnIndex];
            }
        });
        t_datos.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        t_datos.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(t_datos);

        jLabel4.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel4.setText("Clave");

        IdClientes.setEditable(false);
        IdClientes.setEnabled(false);

        jLabel2.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(36, 116, 227));
        jLabel2.setText("Nombre:");

        nombre.setEnabled(false);
        nombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nombreKeyTyped(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel3.setText("Direccin");

        Direccion.setEnabled(false);
        Direccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                DireccionKeyTyped(evt);
            }
        });

        jLabel15.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel15.setText("N ext:");

        numero.setEnabled(false);
        numero.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                numeroKeyTyped(evt);
            }
        });

        jLabel6.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel6.setText("C.P.");

        Cp.setEnabled(false);
        Cp.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                CpKeyTyped(evt);
            }
        });

        jLabel12.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel12.setText("Contacto:");

        contacto.setEnabled(false);
        contacto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                contactoKeyTyped(evt);
            }
        });

        jLabel14.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel14.setText("Nextel:");

        nextel.setEnabled(false);
        nextel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nextelKeyTyped(evt);
            }
        });

        jLabel5.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel5.setText("Colonia:");

        Colonia.setEnabled(false);
        Colonia.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                ColoniaKeyTyped(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel7.setText("Poblacin:");

        Poblacion.setEnabled(false);
        Poblacion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                PoblacionKeyTyped(evt);
            }
        });

        jLabel16.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel16.setText("Municipio:");

        municipio.setEnabled(false);
        municipio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                municipioKeyTyped(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(36, 116, 227));
        jLabel9.setText("Estado");

        Estado.setModel(new javax.swing.DefaultComboBoxModel(
                new String[] { "AGUASCALIENTES", "BAJA CALIFORNIA", "BAJA CALIFORNIA SUR", "CAMPECHE", "CHIAPAS",
                        "CHIHUAHUA", "COAHUILA", "COLIMA", "DISTRITO FEDERAL", "DURANGO", "ESTADO DE MEXICO",
                        "GUANAJUATO", "GUERRERO", "HIDALGO", "JALISCO", "MICHOACAN", "MORELOS", "NAYARIT",
                        "NUEVO LEON", "OAXACA", "PUEBLA", "QUERETARO", "QUINTANA ROO", "SAN LUIS POTOSI", "SINALOA",
                        "SONORA", "TABASCO", "TAMAULIPAS", "TLAXCALA", "VERACRUZ", "YUCATAN", "ZACATECAS" }));
        Estado.setEnabled(false);

        jLabel8.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel8.setText("R.F.C");

        Rfc.setEnabled(false);
        Rfc.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                RfcKeyTyped(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel10.setText("Telfono");

        Telefono.setEnabled(false);
        Telefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                TelefonoKeyTyped(evt);
            }
        });

        jLabel11.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(36, 116, 227));
        jLabel11.setText("E-mail");

        Email.setEnabled(false);
        Email.setNextFocusableComponent(b_actualizar);
        Email.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                EmailKeyTyped(evt);
            }
        });

        b_actualizar.setBackground(new java.awt.Color(2, 135, 242));
        b_actualizar.setForeground(new java.awt.Color(254, 254, 254));
        b_actualizar.setIcon(new ImageIcon("imagenes/guardar.png"));
        b_actualizar.setText("Actualizar");
        b_actualizar.setEnabled(false);
        b_actualizar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        b_actualizar.setMaximumSize(new java.awt.Dimension(87, 23));
        b_actualizar.setMinimumSize(new java.awt.Dimension(87, 23));
        b_actualizar.setNextFocusableComponent(b_cancelar);
        b_actualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_actualizarActionPerformed(evt);
            }
        });

        b_cancelar.setBackground(new java.awt.Color(2, 135, 242));
        b_cancelar.setForeground(new java.awt.Color(254, 254, 254));
        b_cancelar.setIcon(new ImageIcon("imagenes/cancelar.png"));
        b_cancelar.setText("Cancelar");
        b_cancelar.setEnabled(false);
        b_cancelar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        b_cancelar.setMaximumSize(new java.awt.Dimension(87, 23));
        b_cancelar.setNextFocusableComponent(nombre);
        b_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_cancelarActionPerformed(evt);
            }
        });

        Selecciona2.setBackground(new java.awt.Color(2, 135, 242));
        Selecciona2.setForeground(new java.awt.Color(254, 254, 254));
        Selecciona2.setIcon(new ImageIcon("imagenes/add-user.png"));
        Selecciona2.setText("Nuevo");
        Selecciona2.setToolTipText("Agregar un registo actual");
        Selecciona2.setFocusable(false);
        Selecciona2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Selecciona2.setMaximumSize(new java.awt.Dimension(87, 23));
        Selecciona2.setMinimumSize(new java.awt.Dimension(87, 23));
        Selecciona2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Selecciona2ActionPerformed(evt);
            }
        });

        Eliminar1.setBackground(new java.awt.Color(2, 135, 242));
        Eliminar1.setForeground(new java.awt.Color(254, 254, 254));
        Eliminar1.setIcon(new ImageIcon("imagenes/del-user.png"));
        Eliminar1.setText("Eliminar");
        Eliminar1.setToolTipText("Eliminar el registro actual");
        Eliminar1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Eliminar1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Eliminar1ActionPerformed(evt);
            }
        });

        Selecciona3.setBackground(new java.awt.Color(2, 135, 242));
        Selecciona3.setForeground(new java.awt.Color(254, 254, 254));
        Selecciona3.setIcon(new ImageIcon("imagenes/update-user.png"));
        Selecciona3.setText("Seleccionar");
        Selecciona3.setToolTipText("Seleccionar un registro de la tabla para editar");
        Selecciona3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        Selecciona3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Selecciona3ActionPerformed(evt);
            }
        });

        bt_actualiza1.setBackground(new java.awt.Color(2, 135, 242));
        bt_actualiza1.setForeground(new java.awt.Color(254, 254, 254));
        bt_actualiza1.setIcon(new ImageIcon("imagenes/tabla.png"));
        bt_actualiza1.setText("Actualizar");
        bt_actualiza1.setToolTipText("Actualizar los datos de la tabla");
        bt_actualiza1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        bt_actualiza1.setMaximumSize(new java.awt.Dimension(87, 23));
        bt_actualiza1.setMinimumSize(new java.awt.Dimension(87, 23));
        bt_actualiza1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_actualiza1ActionPerformed(evt);
            }
        });

        jLabel22.setText("Receptor:");

        t_receptor.setEnabled(false);
        t_receptor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_receptorKeyTyped(evt);
            }
        });

        t_email_receptor.setEnabled(false);
        t_email_receptor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_email_receptorKeyTyped(evt);
            }
        });

        jLabel23.setText("E-mail Receptor:");

        t_busca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                t_buscaActionPerformed(evt);
            }
        });

        b_busca.setIcon(new ImageIcon("imagenes/buscar1.png"));
        b_busca.setToolTipText("Busca una partida");
        b_busca.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_buscaActionPerformed(evt);
            }
        });

        bt_actualiza2.setBackground(new java.awt.Color(2, 135, 242));
        bt_actualiza2.setForeground(new java.awt.Color(254, 254, 254));
        bt_actualiza2.setIcon(new ImageIcon("imagenes/guardar-documento.png"));
        bt_actualiza2.setText("Exportar");
        bt_actualiza2.setToolTipText("Actualizar los datos de la tabla");
        bt_actualiza2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        bt_actualiza2.setMaximumSize(new java.awt.Dimension(87, 23));
        bt_actualiza2.setMinimumSize(new java.awt.Dimension(87, 23));
        bt_actualiza2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_actualiza2ActionPerformed(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().addContainerGap().addGroup(jPanel3Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane1)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel9).addGap(31, 31, 31)
                                .addComponent(Estado, javax.swing.GroupLayout.PREFERRED_SIZE, 177,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel8)
                                                .addGap(8, 8, 8).addComponent(Rfc,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 161,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel3Layout.createSequentialGroup().addGap(201, 201, 201)
                                                .addComponent(jLabel10)))
                                .addGap(7, 7, 7)
                                .addComponent(Telefono, javax.swing.GroupLayout.PREFERRED_SIZE, 176,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Email))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                                .addComponent(jLabel5).addGap(18, 18, 18)
                                .addComponent(Colonia, javax.swing.GroupLayout.PREFERRED_SIZE, 154,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Poblacion).addGap(62, 62, 62).addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(municipio, javax.swing.GroupLayout.PREFERRED_SIZE, 269,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(nombre, javax.swing.GroupLayout.PREFERRED_SIZE, 409,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18).addComponent(jLabel3)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(Direccion))
                        .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel3Layout.createSequentialGroup().addGap(60, 60, 60).addComponent(
                                        numero, javax.swing.GroupLayout.PREFERRED_SIZE, 103,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(jLabel15))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel6).addGap(18, 18, 18)
                                .addComponent(Cp, javax.swing.GroupLayout.PREFERRED_SIZE, 76,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(contacto, javax.swing.GroupLayout.PREFERRED_SIZE, 374,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(28, 28, 28).addComponent(jLabel14).addGap(31, 31, 31)
                                .addComponent(nextel, javax.swing.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                jPanel3Layout.createSequentialGroup()
                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 35,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(IdClientes, javax.swing.GroupLayout.PREFERRED_SIZE, 31,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(t_busca, javax.swing.GroupLayout.PREFERRED_SIZE, 336,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(b_busca, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(bt_actualiza2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(bt_actualiza1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(Selecciona3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(Eliminar1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(Selecciona2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(b_cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(b_actualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 121,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(jPanel3Layout.createSequentialGroup().addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_receptor, javax.swing.GroupLayout.PREFERRED_SIZE, 392,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel23).addGap(18, 18, 18).addComponent(t_email_receptor)))
                        .addContainerGap()));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 178,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addGroup(jPanel3Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(Eliminar1, javax.swing.GroupLayout.PREFERRED_SIZE, 36,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(Selecciona2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(Selecciona3, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(bt_actualiza1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        36, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(bt_actualiza2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        36, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(IdClientes, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel4))
                                .addComponent(t_busca, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_busca, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2)
                                .addComponent(nombre, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Direccion, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel15)
                                .addComponent(numero, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Cp, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel6).addComponent(jLabel12)
                                .addComponent(contacto, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(nextel, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel14))
                        .addGap(18, 18,
                                18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5)
                                .addComponent(Colonia, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7)
                                .addComponent(Poblacion, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel16).addComponent(municipio,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18,
                                18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel9)
                                .addComponent(Estado, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Rfc, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel8)
                                .addComponent(Telefono, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10)
                                .addComponent(Email, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(t_email_receptor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(t_receptor, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(b_cancelar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(b_actualizar, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        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().addComponent(jPanel3,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup().addComponent(jPanel3,
                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE));
    }// </editor-fold>//GEN-END:initComponents

    private void nombre2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nombre2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_nombre2ActionPerformed

    private void nombre2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nombre2KeyTyped
        // TODO add your handling code here:
    }//GEN-LAST:event_nombre2KeyTyped

    private void numeroKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_numeroKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (numero.getText().length() >= 10)
            evt.consume();
    }//GEN-LAST:event_numeroKeyTyped

    private void nextelKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nextelKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (contacto.getText().length() >= 13)
            evt.consume();
    }//GEN-LAST:event_nextelKeyTyped

    private void contactoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_contactoKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (contacto.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_contactoKeyTyped

    private void bt_actualiza1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_actualiza1ActionPerformed
        Selecciona3.requestFocus();
        borra_cajas();
        this.cajas(false);
        buscaDato();
    }//GEN-LAST:event_bt_actualiza1ActionPerformed

    private void Selecciona3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Selecciona3ActionPerformed
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        if (usr.getModificarClientes() == true) {
            if (t_datos.getSelectedRow() >= 0) {
                borra_cajas();
                IdClientes.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString());
                nombre.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 1).toString());
                Direccion.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 2).toString());
                Colonia.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 3).toString());
                Cp.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 4).toString());
                Rfc.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 5).toString());
                Poblacion.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 6).toString());
                Estado.setSelectedItem(t_datos.getValueAt(t_datos.getSelectedRow(), 7).toString());
                Telefono.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 8).toString());
                Email.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 9).toString());
                contacto.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 10).toString());
                nextel.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 11).toString());
                municipio.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 12).toString());
                numero.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 13).toString());
                t_receptor.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 14).toString());
                t_email_receptor.setText(t_datos.getValueAt(t_datos.getSelectedRow(), 15).toString());
                cajas(true);
            } else
                JOptionPane.showMessageDialog(null, "No hay un cliente seleccionado!");
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_Selecciona3ActionPerformed

    private void Eliminar1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Eliminar1ActionPerformed
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        if (usr.getModificarClientes() == true) {
            if (this.t_datos.getSelectedRow() >= 0) {
                DefaultTableModel model = (DefaultTableModel) t_datos.getModel();
                int a = t_datos.getSelectedRow();
                int opt = JOptionPane.showConfirmDialog(this, "Los datos capturados se eliminarn!");
                if (JOptionPane.YES_OPTION == opt) {
                    boolean respuesta = eliminar(t_datos.getValueAt(t_datos.getSelectedRow(), 0).toString());
                    if (respuesta == true) {
                        JOptionPane.showMessageDialog(null, "Registro eliminado!");
                        model.removeRow(a);
                        this.borra_cajas();
                        cajas(false);
                        buscaDato();
                    }
                }
            } else {
                JOptionPane.showMessageDialog(null, "Selecciona el cliente que desees eliminar!");
                nombre.requestFocus();
            }
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_Eliminar1ActionPerformed

    private void Selecciona2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Selecciona2ActionPerformed
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        if (usr.getCrearClientes() == true) {
            altaCliente obj = new altaCliente(new javax.swing.JFrame(), true, usr, sessionPrograma);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            obj.setLocation((d.width / 2) - (obj.getWidth() / 2), (d.height / 2) - (obj.getHeight() / 2));
            obj.setVisible(true);
            borra_cajas();
            cajas(false);
            buscaDato();
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_Selecciona2ActionPerformed

    private void b_actualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_actualizarActionPerformed
        h = new Herramientas(usr, 0);
        h.session(sessionPrograma);
        Session session = HibernateUtil.getSessionFactory().openSession();
        usr = (Usuario) session.get(Usuario.class, usr.getIdUsuario());
        if (usr.getModificarClientes() == true) {
            if (nombre.getText().compareTo("") != 0) {
                if (Email.getText().trim().compareTo("") != 0) {
                    boolean respuesta = modifica();
                    if (respuesta == true) {
                        JOptionPane.showMessageDialog(null, "Registro modificado");
                        this.borra_cajas();
                        buscaDato();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "Ingrese el email del cliente");
                    numero.requestFocus();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Ingrese el nombre del cliente");
                nombre.requestFocus();
            }
        } else
            JOptionPane.showMessageDialog(null, "Acceso denegado!");
        if (session != null)
            if (session.isOpen())
                session.close();
    }//GEN-LAST:event_b_actualizarActionPerformed

    private void b_cancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_cancelarActionPerformed
        nombre.requestFocus();
        int opt = JOptionPane.showConfirmDialog(this, "Los datos capturados se eliminarn!");
        if (opt == 0) {
            borra_cajas();
            cajas(false);
        }
    }//GEN-LAST:event_b_cancelarActionPerformed

    private void PoblacionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_PoblacionKeyTyped
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (Poblacion.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_PoblacionKeyTyped

    private void EmailKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_EmailKeyTyped
        if (Email.getText().length() >= 100)
            evt.consume();
    }//GEN-LAST:event_EmailKeyTyped

    private void TelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TelefonoKeyTyped
        char car = evt.getKeyChar();
        if (Telefono.getText().length() >= 13)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_TelefonoKeyTyped

    private void RfcKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_RfcKeyTyped
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (Rfc.getText().length() >= 13)
            evt.consume();
    }//GEN-LAST:event_RfcKeyTyped

    private void ColoniaKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ColoniaKeyTyped
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (Colonia.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_ColoniaKeyTyped

    private void CpKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_CpKeyTyped
        char car = evt.getKeyChar();
        if (this.Cp.getText().length() >= 5)
            evt.consume();
        if ((car < '0' || car > '9'))
            evt.consume();
    }//GEN-LAST:event_CpKeyTyped

    private void DireccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_DireccionKeyTyped
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (Direccion.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_DireccionKeyTyped

    private void nombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nombreKeyTyped
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (nombre.getText().length() >= 150)
            evt.consume();
    }//GEN-LAST:event_nombreKeyTyped

    private void municipioKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_municipioKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (municipio.getText().length() >= 20)
            evt.consume();
    }//GEN-LAST:event_municipioKeyTyped

    private void t_receptorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_receptorKeyTyped
        // TODO add your handling code here:
        evt.setKeyChar(Character.toUpperCase(evt.getKeyChar()));
        if (this.t_receptor.getText().length() >= 100)
            evt.consume();
    }//GEN-LAST:event_t_receptorKeyTyped

    private void t_email_receptorKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_t_email_receptorKeyTyped
        // TODO add your handling code here:
        if (this.t_email_receptor.getText().length() >= 100)
            evt.consume();
    }//GEN-LAST:event_t_email_receptorKeyTyped

    private void t_buscaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_t_buscaActionPerformed
        // TODO add your handling code here:
        if (this.t_busca.getText().compareToIgnoreCase("") != 0) {
            //buscaCuentas();
            if (x >= t_datos.getRowCount()) {
                x = 0;
                java.awt.Rectangle r = t_datos.getCellRect(x, 1, true);
                t_datos.scrollRectToVisible(r);
            }
            for (; x < t_datos.getRowCount(); x++) {
                if (t_datos.getValueAt(x, 1).toString().indexOf(t_busca.getText().toUpperCase()) != -1) {
                    t_datos.setRowSelectionInterval(x, x);
                    t_datos.setColumnSelectionInterval(1, 1);
                    java.awt.Rectangle r = t_datos.getCellRect(x, 1, true);
                    t_datos.scrollRectToVisible(r);
                    break;
                }
            }
            x++;
        }
    }//GEN-LAST:event_t_buscaActionPerformed

    private void b_buscaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_buscaActionPerformed
        // TODO add your handling code here:
        if (this.t_busca.getText().compareToIgnoreCase("") != 0) {
            //buscaCuentas();
            if (x >= t_datos.getRowCount()) {
                x = 0;
                java.awt.Rectangle r = t_datos.getCellRect(x, 1, true);
                t_datos.scrollRectToVisible(r);
            }
            for (; x < t_datos.getRowCount(); x++) {
                if (t_datos.getValueAt(x, 1).toString().indexOf(t_busca.getText().toUpperCase()) != -1) {
                    t_datos.setRowSelectionInterval(x, x);
                    t_datos.setColumnSelectionInterval(1, 1);
                    java.awt.Rectangle r = t_datos.getCellRect(x, 1, true);
                    t_datos.scrollRectToVisible(r);
                    break;
                }
            }
            x++;
        }
    }//GEN-LAST:event_b_buscaActionPerformed

    private void bt_actualiza2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_actualiza2ActionPerformed
        // TODO add your handling code here:
        javax.swing.JFileChooser jF1 = new javax.swing.JFileChooser();
        jF1.setFileFilter(new ExtensionFileFilter("Excel document (*.xls)", new String[] { "xls" }));
        String ruta = null;
        if (jF1.showSaveDialog(null) == jF1.APPROVE_OPTION) {
            ruta = jF1.getSelectedFile().getAbsolutePath();
            if (ruta != null) {
                File archivoXLS = new File(ruta + ".xls");
                try {
                    if (archivoXLS.exists())
                        archivoXLS.delete();
                    archivoXLS.createNewFile();
                    Workbook libro = new HSSFWorkbook();
                    FileOutputStream archivo = new FileOutputStream(archivoXLS);
                    Sheet hoja = libro.createSheet("Clientes");
                    for (int ren = 0; ren < (t_datos.getRowCount() + 1); ren++) {
                        Row fila = hoja.createRow(ren);
                        for (int col = 0; col < t_datos.getColumnCount(); col++) {
                            Cell celda = fila.createCell(col);
                            if (ren == 0) {
                                celda.setCellValue(columnas[col]);
                            } else {
                                try {
                                    celda.setCellValue(t_datos.getValueAt(ren - 1, col).toString());
                                } catch (Exception e) {
                                    celda.setCellValue("");
                                }
                            }
                        }
                    }
                    libro.write(archivo);
                    archivo.close();
                    Desktop.getDesktop().open(archivoXLS);
                } catch (Exception e) {
                    System.out.println(e);
                    JOptionPane.showMessageDialog(this, "No se pudo realizar el reporte");
                }
            }
        }
    }//GEN-LAST:event_bt_actualiza2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JTextField Colonia;
    public javax.swing.JTextField Cp;
    public javax.swing.JTextField Direccion;
    private javax.swing.JButton Eliminar1;
    public javax.swing.JTextField Email;
    public javax.swing.JComboBox Estado;
    public javax.swing.JTextField IdClientes;
    public javax.swing.JTextField Poblacion;
    public javax.swing.JTextField Rfc;
    private javax.swing.JButton Selecciona2;
    private javax.swing.JButton Selecciona3;
    public javax.swing.JTextField Telefono;
    private javax.swing.JButton b_actualizar;
    private javax.swing.JButton b_busca;
    private javax.swing.JButton b_cancelar;
    private javax.swing.JButton bt_actualiza1;
    private javax.swing.JButton bt_actualiza2;
    public javax.swing.JTextField contacto;
    private javax.swing.JLabel jLabel10;
    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 jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    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 jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTextField municipio;
    public javax.swing.JTextField nextel;
    public javax.swing.JTextField nombre;
    public javax.swing.JTextField nombre2;
    public javax.swing.JTextField numero;
    private javax.swing.JTextField t_busca;
    private javax.swing.JTable t_datos;
    public javax.swing.JTextField t_email_receptor;
    public javax.swing.JTextField t_receptor;
    // End of variables declaration//GEN-END:variables

    private List<Object[]> executeHQLQuery(String hql) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            Query q = session.createQuery(hql);
            List resultList = q.list();
            session.getTransaction().commit();
            session.disconnect();
            return resultList;
        } catch (HibernateException he) {
            he.printStackTrace();
            List lista = null;
            return lista;
        } finally {
            if (session.isOpen())
                session.close();
        }
    }

    private void buscaDato() {
        String consulta = "from Clientes";
        List<Object[]> resultList = executeHQLQuery(consulta);
        if (resultList.size() > 0) {
            t_datos.setModel(ModeloTablaReporte(resultList.size(), columnas));
            int i = 0;
            for (Object o : resultList) {
                Clientes actor = (Clientes) o;
                model.setValueAt(actor.getIdClientes(), i, 0);
                model.setValueAt(actor.getNombre(), i, 1);
                if (actor.getDireccion() != null)
                    model.setValueAt(actor.getDireccion(), i, 2);
                else
                    model.setValueAt("", i, 2);
                if (actor.getColonia() != null)
                    model.setValueAt(actor.getColonia(), i, 3);
                else
                    model.setValueAt("", i, 3);
                if (actor.getCp() != null)
                    model.setValueAt(actor.getCp(), i, 4);
                else
                    model.setValueAt("", i, 4);
                if (actor.getRfc() != null)
                    model.setValueAt(actor.getRfc(), i, 5);
                else
                    model.setValueAt("", i, 5);
                if (actor.getPoblacion() != null)
                    model.setValueAt(actor.getPoblacion(), i, 6);
                else
                    model.setValueAt("", i, 6);
                model.setValueAt(actor.getEstado(), i, 7);
                if (actor.getTelefono() != null)
                    model.setValueAt(actor.getTelefono(), i, 8);
                else
                    model.setValueAt("", i, 8);
                model.setValueAt(actor.getEmail(), i, 9);
                if (actor.getContacto() != null)
                    model.setValueAt(actor.getContacto(), i, 10);
                else
                    model.setValueAt("", i, 10);
                if (actor.getNextel() != null)
                    model.setValueAt(actor.getNextel(), i, 11);
                else
                    model.setValueAt("", i, 11);
                if (actor.getMunicipio() != null)
                    model.setValueAt(actor.getMunicipio(), i, 12);
                else
                    model.setValueAt("", i, 12);
                if (actor.getNumeroExterior() != null)
                    model.setValueAt(actor.getNumeroExterior(), i, 13);
                else
                    model.setValueAt("", i, 13);
                if (actor.getReceptor() != null)
                    model.setValueAt(actor.getReceptor(), i, 14);
                else
                    model.setValueAt("", i, 14);
                if (actor.getEmailReceptor() != null)
                    model.setValueAt(actor.getEmailReceptor(), i, 15);
                else
                    model.setValueAt("", i, 15);
                i++;
            }
        } else
            t_datos.setModel(ModeloTablaReporte(0, columnas));
        formatoTabla();
    }

    private boolean modifica() {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            Object resp = session.createQuery("from Clientes obj where obj.nombre='" + nombre.getText()
                    + "' and obj.idClientes!=" + IdClientes.getText()).uniqueResult();
            if (resp == null) {
                Clientes objeto = (Clientes) session.get(Clientes.class, Integer.parseInt(IdClientes.getText()));
                objeto.setNombre(nombre.getText());
                objeto.setDireccion(Direccion.getText());
                objeto.setColonia(Colonia.getText());
                if (Cp.getText().compareTo("") == 0)
                    objeto.setCp(null);
                else
                    objeto.setCp(Integer.parseInt(Cp.getText()));
                objeto.setRfc(Rfc.getText().trim());
                objeto.setPoblacion(Poblacion.getText().trim());
                objeto.setEstado(Estado.getSelectedItem().toString().trim());
                objeto.setTelefono(Telefono.getText().trim());
                objeto.setEmail(Email.getText().trim());
                objeto.setContacto(contacto.getText().trim());
                objeto.setNextel(nextel.getText().trim());
                objeto.setMunicipio(municipio.getText().trim());
                objeto.setNumeroExterior(numero.getText().trim());
                objeto.setReceptor(t_receptor.getText());
                objeto.setEmailReceptor(t_email_receptor.getText());
                session.update(objeto);
                session.getTransaction().commit();
                cajas(false);
                return true;
            } else {
                JOptionPane.showMessageDialog(null, "No se pueden guardar nombres duplicados!");
                return false;
            }
        } catch (HibernateException he) {
            he.printStackTrace();
            System.out.println(he.hashCode());
            session.getTransaction().rollback();
            return false;
        } finally {
            if (session.isOpen())
                session.close();
        }
    }

    private boolean eliminar(String idCliente) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            actor = (Clientes) session.get(Clientes.class, Integer.parseInt(idCliente));
            if (actor.getOrdens().isEmpty() == false) {
                session.getTransaction().rollback();
                JOptionPane.showMessageDialog(null, "El cliente esta en uso en una orden, no se puede eliminar!");
                return false;
            } else {
                session.delete(actor);
                session.getTransaction().commit();
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            session.getTransaction().rollback();
            return false;
        } finally {
            if (session.isOpen())
                session.close();
        }
    }

    public void cajas(boolean edo) {
        this.nombre.setEnabled(edo);
        this.Direccion.setEnabled(edo);
        this.Colonia.setEnabled(edo);
        this.Cp.setEnabled(edo);
        this.Rfc.setEnabled(edo);
        this.Poblacion.setEnabled(edo);
        this.Telefono.setEnabled(edo);
        this.Email.setEnabled(edo);
        this.Estado.setEnabled(edo);
        this.b_actualizar.setEnabled(edo);
        this.b_cancelar.setEnabled(edo);
        this.contacto.setEnabled(edo);
        this.municipio.setEnabled(edo);
        this.nextel.setEnabled(edo);
        this.numero.setEnabled(edo);
        this.t_receptor.setEnabled(edo);
        this.t_email_receptor.setEnabled(edo);
    }

    public void borra_cajas() {
        this.IdClientes.setText("");
        this.nombre.setText("");
        this.Direccion.setText("");
        this.Colonia.setText("");
        this.Cp.setText("");
        this.Rfc.setText("");
        this.Poblacion.setText("");
        this.Estado.setSelectedItem(null);
        this.Telefono.setText("");
        this.Email.setText("");
        this.contacto.setText("");
        this.nextel.setText("");
        this.municipio.setText("");
        this.numero.setText("");
        this.t_receptor.setText("");
        this.t_email_receptor.setText("");
    }

public void tabla_tamaos()
{
    TableColumnModel col_model = t_datos.getColumnModel();
    for (int i=0; i<t_datos.getColumnCount(); i++)
    {
         TableColumn column = col_model.getColumn(i);
          switch(i)
          {
              case 0:
                  column.setPreferredWidth(15);
                  break;
              case 1:
                  column.setPreferredWidth(150);
                  break;
              case 2:
                  column.setPreferredWidth(150);
                  break;
              case 3:
                  column.setPreferredWidth(80);
                  break;
              case 4:
                  column.setPreferredWidth(40);
                  break;
              case 5:
                  column.setPreferredWidth(40);
                  break;
              case 6:
                  column.setPreferredWidth(80);
                  break;
              case 7:
                  column.setPreferredWidth(40);
                  break;
              case 8:
                  column.setPreferredWidth(40);
                  break;
              case 9:
                  column.setPreferredWidth(80);
                  break;
              default:
                  column.setPreferredWidth(40);
                  break;    
          }
    }
    JTableHeader header = t_datos.getTableHeader();
    header.setForeground(Color.white);
}

public void formatoTabla()
{
    Color c1 = new java.awt.Color(2, 135, 242);
    for(int x=0; x<t_datos.getColumnModel().getColumnCount(); x++)
        t_datos.getColumnModel().getColumn(x).setHeaderRenderer(new Render1(c1));
    tabla_tamaos();
    t_datos.setShowVerticalLines(true);
    t_datos.setShowHorizontalLines(true);
}
}