Clientes.altaCliente.java Source code

Java tutorial

Introduction

Here is the source code for Clientes.altaCliente.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 java.util.List;
import javax.swing.ImageIcon;
import javax.swing.InputMap;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import Integral.Herramientas;

/**
 *
 * @author ESPECIALIZADO TOLUCA
 */
public class altaCliente extends javax.swing.JDialog {

    public static final Clientes RET_CANCEL = null;
    InputMap map = new InputMap();
    DefaultTableModel model;
    Usuario user;
    String sessionPrograma;
    Herramientas h;
    private Clientes returnStatus;

    /** Creates new form acceso */
    public altaCliente(java.awt.Frame parent, boolean modal, Usuario u, String ses) {
        super(parent, modal);
        user = u;
        sessionPrograma = ses;
        initComponents();
        t_nombre_cliente.requestFocus();
    }

    private void doClose(Clientes o) {
        returnStatus = o;
        setVisible(false);
        dispose();
    }

    public Clientes getReturnStatus() {
        return returnStatus;
    }

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

        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        t_nombre_cliente = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        t_direccion_cliente = new javax.swing.JTextField();
        jLabel21 = new javax.swing.JLabel();
        t_numero = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        t_colonia_cliente = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        t_cp_cliente = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        t_rfc_cliente = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        t_poblacion_cliente = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        c_estado_cliente = new javax.swing.JComboBox();
        jLabel15 = new javax.swing.JLabel();
        t_telefono_cliente = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        t_email_cliente = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        t_contacto = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        t_nextel = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        t_municipio = new javax.swing.JTextField();
        b_guardar = new javax.swing.JButton();
        b_cancelar = new javax.swing.JButton();
        jLabel17 = new javax.swing.JLabel();
        jLabel22 = new javax.swing.JLabel();
        t_receptor = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        t_email_receptor = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Alta de clientes");
        setResizable(false);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

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

        t_nombre_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_nombre_clienteKeyTyped(evt);
            }
        });

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

        t_direccion_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_direccion_clienteKeyTyped(evt);
            }
        });

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

        t_numero.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_numeroKeyTyped(evt);
            }
        });

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

        t_colonia_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_colonia_clienteKeyTyped(evt);
            }
        });

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

        t_cp_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_cp_clienteKeyTyped(evt);
            }
        });

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

        t_rfc_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_rfc_clienteKeyTyped(evt);
            }
        });

        jLabel13.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel13.setText("Poblacin");

        t_poblacion_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_poblacion_clienteKeyTyped(evt);
            }
        });

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

        c_estado_cliente.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" }));
        c_estado_cliente.setName(""); // NOI18N

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

        t_telefono_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_telefono_clienteKeyTyped(evt);
            }
        });

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

        t_email_cliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_email_clienteKeyTyped(evt);
            }
        });

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

        t_contacto.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_contactoKeyTyped(evt);
            }
        });

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

        t_nextel.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_nextelKeyTyped(evt);
            }
        });

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

        t_municipio.setNextFocusableComponent(b_guardar);
        t_municipio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                t_municipioKeyTyped(evt);
            }
        });

        b_guardar.setBackground(new java.awt.Color(2, 135, 242));
        b_guardar.setForeground(new java.awt.Color(253, 251, 251));
        b_guardar.setIcon(new ImageIcon("imagenes/guardar.png"));
        b_guardar.setText("Guardar");
        b_guardar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        b_guardar.setNextFocusableComponent(b_cancelar);
        b_guardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_guardarActionPerformed(evt);
            }
        });

        b_cancelar.setBackground(new java.awt.Color(2, 135, 242));
        b_cancelar.setForeground(new java.awt.Color(253, 251, 251));
        b_cancelar.setIcon(new ImageIcon("imagenes/cancelar.png"));
        b_cancelar.setText("Cancelar");
        b_cancelar.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        b_cancelar.setNextFocusableComponent(t_nombre_cliente);
        b_cancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                b_cancelarActionPerformed(evt);
            }
        });

        jLabel17.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        jLabel17.setText("Nota: Los clientes son los dueos de las unidades a reparar.");

        jLabel22.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel22.setText("Receptor:");

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

        jLabel23.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
        jLabel23.setText("E-mail Receptor:");

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

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jLabel17).addGap(120, 120, 120))
                                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                                        .addComponent(jLabel23).addGap(18, 18, 18).addComponent(t_email_receptor)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addComponent(b_cancelar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(b_guardar)
                        .addContainerGap())
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addGroup(jPanel2Layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout
                                        .createSequentialGroup().addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(t_direccion_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                388, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21,
                                                Short.MAX_VALUE)
                                        .addComponent(jLabel21).addGap(18, 18, 18).addComponent(t_numero,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 114,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        jPanel2Layout.createSequentialGroup().addComponent(jLabel8)
                                                .addGap(18, 18, 18).addComponent(t_nombre_cliente))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                        jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                                                        false)
                                                .addGroup(
                                                        jPanel2Layout.createSequentialGroup().addComponent(jLabel15)
                                                                .addGap(18, 18, 18).addComponent(t_telefono_cliente,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 174,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(18, 18, 18).addComponent(jLabel16))
                                                .addGroup(jPanel2Layout.createSequentialGroup()
                                                        .addGroup(jPanel2Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.LEADING)
                                                                .addComponent(jLabel13).addComponent(jLabel10))
                                                        .addPreferredGap(
                                                                javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                        .addGroup(jPanel2Layout
                                                                .createParallelGroup(
                                                                        javax.swing.GroupLayout.Alignment.TRAILING)
                                                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                                        jPanel2Layout.createSequentialGroup()
                                                                                .addComponent(t_colonia_cliente,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                                                                        159,
                                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                                .addGap(18, 18, 18)
                                                                                .addComponent(jLabel11))
                                                                .addComponent(
                                                                        t_poblacion_cliente,
                                                                        javax.swing.GroupLayout.Alignment.LEADING,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 226,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                                                .addGap(18, 18, 18)
                                                .addGroup(jPanel2Layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                                .addComponent(t_cp_cliente,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 93,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                                .addGap(18, 18, 18).addComponent(jLabel12)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                                .addComponent(t_rfc_cliente))
                                                        .addGroup(jPanel2Layout.createSequentialGroup()
                                                                .addGap(0, 0, Short.MAX_VALUE)
                                                                .addComponent(jLabel14)
                                                                .addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                                .addComponent(c_estado_cliente,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE, 170,
                                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                        .addComponent(t_email_cliente)))
                                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout
                                        .createSequentialGroup()
                                        .addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel18).addComponent(jLabel19))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(jPanel2Layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(jPanel2Layout.createSequentialGroup()
                                                        .addComponent(t_nextel,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE, 114,
                                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addGap(79, 79, 79).addComponent(jLabel20)
                                                        .addGap(18, 18, 18).addComponent(t_municipio))
                                                .addComponent(t_contacto))))
                                .addGap(13, 13, 13))
                        .addGroup(jPanel2Layout.createSequentialGroup().addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(t_receptor).addContainerGap()))));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t_nombre_cliente, 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.LEADING)
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel21, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(t_numero, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(t_direccion_cliente, 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(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t_colonia_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(t_cp_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel12).addComponent(t_rfc_cliente,
                                        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(jLabel13, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t_poblacion_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel14).addComponent(c_estado_cliente,
                                        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(t_telefono_cliente, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel15, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 20,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t_email_cliente, 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(jLabel18, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(t_contacto, 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)
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(t_municipio, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(t_nextel, 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(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(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                        .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))
                                        .addGap(18, 18, 18).addComponent(jLabel17))
                                .addGroup(jPanel2Layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(b_guardar, javax.swing.GroupLayout.PREFERRED_SIZE, 59,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(b_cancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 59,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap()));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(
                jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                Short.MAX_VALUE));

        pack();
    }// </editor-fold>//GEN-END:initComponents

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

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

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

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

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

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

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

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

    private void b_guardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_b_guardarActionPerformed
        b_cancelar.requestFocus();
        h = new Herramientas(user, 0);
        h.session(sessionPrograma);
        if (t_nombre_cliente.getText().trim().compareTo("") != 0) {
            if (t_email_cliente.getText().trim().compareTo("") != 0) {
                if (consultaCliente(t_nombre_cliente.getText()) == false) {
                    Clientes nuevoCliente = new Clientes();
                    if (t_nombre_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setNombre(t_nombre_cliente.getText());
                    if (t_direccion_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setDireccion(t_direccion_cliente.getText());
                    if (t_colonia_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setColonia(t_colonia_cliente.getText());
                    if (t_cp_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setCp(Integer.parseInt(t_cp_cliente.getText()));
                    if (t_rfc_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setRfc(t_rfc_cliente.getText());
                    if (t_poblacion_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setPoblacion(t_poblacion_cliente.getText());
                    if (c_estado_cliente.getSelectedItem().toString().compareTo("") != 0)
                        nuevoCliente.setEstado(c_estado_cliente.getSelectedItem().toString());
                    if (t_telefono_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setTelefono(t_telefono_cliente.getText());
                    if (t_email_cliente.getText().compareTo("") != 0)
                        nuevoCliente.setEmail(t_email_cliente.getText());
                    if (t_contacto.getText().compareTo("") != 0)
                        nuevoCliente.setContacto(t_contacto.getText());
                    if (t_nextel.getText().compareTo("") != 0)
                        nuevoCliente.setNextel(t_nextel.getText());
                    if (t_municipio.getText().compareTo("") != 0)
                        nuevoCliente.setMunicipio(t_municipio.getText());
                    if (t_numero.getText().compareTo("") != 0)
                        nuevoCliente.setNumeroExterior(t_numero.getText());
                    nuevoCliente.setPais("MX");
                    nuevoCliente.setReceptor(t_receptor.getText());
                    nuevoCliente.setEmailReceptor(t_email_receptor.getText());
                    Integer respuesta = guardarCliente(nuevoCliente);
                    if (respuesta == null) {
                        b_guardar.setEnabled(true);
                    } else {
                        JOptionPane.showMessageDialog(null, "Registro almacenado con la clave:  " + respuesta);
                        this.borra_cajas();
                        t_nombre_cliente.requestFocus();
                    }
                } else {
                    JOptionPane.showMessageDialog(null, "El nombre del cliente ya existe!");
                    this.borra_cajas();
                    t_nombre_cliente.requestFocus();
                }
            } else {
                JOptionPane.showMessageDialog(null, "Debe introducir el email del cliente!");
                t_email_cliente.requestFocus();
            }
        } else {
            JOptionPane.showMessageDialog(null, "Debe introducir el nombre del cliente!");
            t_nombre_cliente.requestFocus();
        }
    }//GEN-LAST:event_b_guardarActionPerformed

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

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

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

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

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

    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

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton b_cancelar;
    private javax.swing.JButton b_guardar;
    public javax.swing.JComboBox c_estado_cliente;
    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 jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    public javax.swing.JTextField t_colonia_cliente;
    public javax.swing.JTextField t_contacto;
    public javax.swing.JTextField t_cp_cliente;
    public javax.swing.JTextField t_direccion_cliente;
    public javax.swing.JTextField t_email_cliente;
    public javax.swing.JTextField t_email_receptor;
    public javax.swing.JTextField t_municipio;
    public javax.swing.JTextField t_nextel;
    public javax.swing.JTextField t_nombre_cliente;
    public javax.swing.JTextField t_numero;
    public javax.swing.JTextField t_poblacion_cliente;
    public javax.swing.JTextField t_receptor;
    public javax.swing.JTextField t_rfc_cliente;
    public javax.swing.JTextField t_telefono_cliente;
    // End of variables declaration//GEN-END:variables

    private List<Object[]> executeHQLQuery(String hql) {
        try {
            Session session = HibernateUtil.getSessionFactory().openSession();
            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;
        }
    }

    private Integer guardarCliente(Clientes obj) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        Integer IdClientes = null;
        try {
            session.beginTransaction();
            IdClientes = (Integer) session.save(obj);
            session.save(obj);
            session.getTransaction().commit();
            return null;
        } catch (HibernateException he) {
            he.printStackTrace();
            session.getTransaction().rollback();
            return null;
        } finally {
            session.close();
            return IdClientes;
        }
    }

    public boolean consultaCliente(String nombre) {
        List<Object[]> resultList = executeHQLQuery("from Clientes obj where obj.nombre='" + nombre + "'");
        if (resultList.size() > 0)
            return true;
        else
            return false;
    }

    private void borra_cajas() {
        this.t_nombre_cliente.setText("");
        this.t_direccion_cliente.setText("");
        this.t_colonia_cliente.setText("");
        this.t_cp_cliente.setText("");
        this.t_rfc_cliente.setText("");
        this.t_poblacion_cliente.setText("");
        this.t_telefono_cliente.setText("");
        this.t_email_cliente.setText("");
        this.t_numero.setText("");
        this.t_contacto.setText("");
        this.t_nextel.setText("");
        this.t_municipio.setText("");
        this.t_receptor.setText("");
        this.t_email_receptor.setText("");
        this.t_receptor.setText("");
        this.t_email_receptor.setText("");
    }
}