vistas.ModPersonal.java Source code

Java tutorial

Introduction

Here is the source code for vistas.ModPersonal.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 vistas;

import com.toedter.calendar.JDateChooser;
import vistas.*;
import controlador.BuscarDomicilio;
import controlador.ControladorGrupoFamiliar;
import controlador.ControladorGrupoFamiliar;
import controlador.ControladorUsuario;
import controlador.ControladorUsuario;
import modelo.Usuario;
import java.awt.event.KeyEvent;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import modelo.GestionConexion;
import org.apache.commons.codec.digest.DigestUtils;

/**
 *
 * @author martinrh83
 */
public class ModPersonal extends javax.swing.JFrame {

    private GestionConexion conexion;
    private Usuario user;
    private ControladorUsuario control;

    /**
     * Creates new form AltaProducto
     */
    public ModPersonal(ControladorUsuario cont, GestionConexion conn, Usuario us) throws ParseException {
        control = cont;
        conexion = conn;
        user = us;
        initComponents();
        this.setLocationRelativeTo(null);
        control.modificarEmpleado(this);
    }

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

        jLabel1 = new javax.swing.JLabel();
        txt_idUserM = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txt_NameM = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        btnFin_APer = new javax.swing.JButton();
        txt_apellidoM = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        txt_DniM = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txt_userM = new javax.swing.JTextField();
        combo_tipoM = new javax.swing.JComboBox();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        txt_horaM = new javax.swing.JTextField();
        jDateChooser1M = new com.toedter.calendar.JDateChooser();
        btnCancelar_APer = new javax.swing.JButton();
        btnAgregar_APer = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Gestion Personal");
        setResizable(false);

        jLabel1.setText("ID usuario:");

        txt_idUserM.setEditable(false);

        jLabel2.setText("Nombre");

        txt_NameM.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txt_NameM.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_NameMKeyTyped(evt);
            }
        });

        jLabel3.setText("Tipo:");

        btnFin_APer.setText("Finalizar");
        btnFin_APer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFin_APerActionPerformed(evt);
            }
        });

        txt_apellidoM.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txt_apellidoM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_apellidoMActionPerformed(evt);
            }
        });
        txt_apellidoM.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_apellidoMKeyTyped(evt);
            }
        });

        jLabel10.setText("Apellido:");

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

        jLabel11.setText("DNI");

        jLabel5.setText("Usuario:");

        combo_tipoM.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Empleado", "Administrador" }));
        combo_tipoM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                combo_tipoMActionPerformed(evt);
            }
        });

        jLabel7.setText("Carga Horaria:");

        jLabel8.setText("Fecha Ingreso:");

        txt_horaM.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txt_horaMActionPerformed(evt);
            }
        });
        txt_horaM.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txt_horaMKeyTyped(evt);
            }
        });

        btnCancelar_APer.setText("Cancelar");
        btnCancelar_APer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelar_APerActionPerformed(evt);
            }
        });

        btnAgregar_APer.setText("Aceptar");
        btnAgregar_APer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAgregar_APerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                        layout.createSequentialGroup().addGap(47, 47, 47)
                                .addComponent(btnAgregar_APer, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGap(52, 52, 52).addComponent(btnCancelar_APer).addGap(50, 50, 50)
                                .addComponent(btnFin_APer).addGap(70, 70, 70))
                .addGroup(layout.createSequentialGroup().addGap(16, 16, 16).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 54,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(layout.createSequentialGroup().addGroup(layout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 53,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 46,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 60,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
                                                        false)
                                                .addComponent(txt_userM, javax.swing.GroupLayout.DEFAULT_SIZE, 120,
                                                        Short.MAX_VALUE)
                                                .addComponent(txt_idUserM, javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        120, Short.MAX_VALUE)
                                                .addComponent(txt_NameM, javax.swing.GroupLayout.Alignment.TRAILING,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE)
                                                .addComponent(txt_DniM)))
                                .addComponent(combo_tipoM, javax.swing.GroupLayout.PREFERRED_SIZE, 125,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                .addComponent(jLabel7).addComponent(jLabel8))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(layout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(txt_horaM).addComponent(jDateChooser1M,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                                .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 60,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(18, 18, 18).addComponent(txt_apellidoM,
                                                javax.swing.GroupLayout.PREFERRED_SIZE, 115,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                .addGroup(layout.createSequentialGroup().addGap(24, 24, 24).addGroup(layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
                        .addComponent(txt_idUserM, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel5).addComponent(txt_userM,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 25, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txt_NameM, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel10).addComponent(txt_apellidoM,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(jLabel11)
                                        .addComponent(txt_DniM, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel8))
                                .addComponent(jDateChooser1M, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3)
                                .addComponent(combo_tipoM, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel7).addComponent(txt_horaM,
                                        javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(30, 30, 30)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(btnFin_APer, javax.swing.GroupLayout.PREFERRED_SIZE, 23,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnAgregar_APer).addComponent(btnCancelar_APer))
                        .addContainerGap(19, Short.MAX_VALUE)));

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

    public Usuario getUser() {
        return user;
    }

    public void setUser(Usuario user) {
        this.user = user;
    }

    public JComboBox getCombo_tipoM() {
        return combo_tipoM;
    }

    public void setCombo_tipoM(JComboBox combo_tipoM) {
        this.combo_tipoM = combo_tipoM;
    }

    public JDateChooser getjDateChooser1M() {
        return jDateChooser1M;
    }

    public void setjDateChooser1M(JDateChooser jDateChooser1M) {
        this.jDateChooser1M = jDateChooser1M;
    }

    public JTextField getTxt_DniM() {
        return txt_DniM;
    }

    public void setTxt_DniM(JTextField txt_DniM) {
        this.txt_DniM = txt_DniM;
    }

    public JTextField getTxt_NameM() {
        return txt_NameM;
    }

    public void setTxt_NameM(JTextField txt_NameM) {
        this.txt_NameM = txt_NameM;
    }

    public JTextField getTxt_apellidoM() {
        return txt_apellidoM;
    }

    public void setTxt_apellidoM(JTextField txt_apellidoM) {
        this.txt_apellidoM = txt_apellidoM;
    }

    public JTextField getTxt_horaM() {
        return txt_horaM;
    }

    public void setTxt_horaM(JTextField txt_horaM) {
        this.txt_horaM = txt_horaM;
    }

    public JTextField getTxt_idUserM() {
        return txt_idUserM;
    }

    public void setTxt_idUserM(JTextField txt_idUserM) {
        this.txt_idUserM = txt_idUserM;
    }

    public JTextField getTxt_userM() {
        return txt_userM;
    }

    public void setTxt_userM(JTextField txt_userM) {
        this.txt_userM = txt_userM;
    }

    public void limpiar() {
        txt_DniM.setText(null);
        txt_NameM.setText(null);
        txt_apellidoM.setText(null);
        txt_horaM.setText(null);
        txt_userM.setText(null);

    }

    private void btnAgregar_APerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAgregar_APerActionPerformed
        user.setIdUsuario(Integer.valueOf(txt_idUserM.getText()));
        user.setUserUsuario(txt_userM.getText());
        user.setNomUsuario(txt_NameM.getText());
        user.setApellidoUsuario(txt_apellidoM.getText());
        user.setDniUsuario(Integer.valueOf(txt_DniM.getText()));
        user.setTipoUsuario(combo_tipoM.getSelectedItem().toString());
        user.setCargaHoraria(Integer.valueOf(txt_horaM.getText()));
        Date fechaIngreso = jDateChooser1M.getDate();
        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
        user.setFechaIngreso(formato.format(fechaIngreso));
        System.out.println(user.getNomUsuario());
        control.updateUsuario();
        control.mostrarusuarios();
        this.dispose();
    }//GEN-LAST:event_btnAgregar_APerActionPerformed

    private void txt_DniMKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_DniMKeyTyped
        char car = evt.getKeyChar();
        if (txt_DniM.getText().length() >= 9) {
            JOptionPane.showMessageDialog(this, "Permitido hasta 8 digitos");
            evt.consume();
        }
        if ((car < '0' || car > '9')) {
            JOptionPane.showMessageDialog(this, "Solo numeros");
            evt.consume();
        }
    }//GEN-LAST:event_txt_DniMKeyTyped

    private void txt_apellidoMKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_apellidoMKeyTyped
        char car = evt.getKeyChar();
        if ((car < 'a' || car > 'z') && (car < 'A' || car > 'Z') && (car != (char) KeyEvent.VK_SPACE)
                && (car != (char) KeyEvent.VK_BACK_SPACE)) {
            JOptionPane.showMessageDialog(this, "Ingrese solo letras");
            evt.consume();
        }
    }//GEN-LAST:event_txt_apellidoMKeyTyped

    private void txt_horaMKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_horaMKeyTyped
        char car = evt.getKeyChar();
        if (txt_horaM.getText().length() >= 8) {
            JOptionPane.showMessageDialog(this, "Permitido hasta 8 digitos");
            evt.consume();
        }
        if ((car < '0' || car > '9') && (car != (char) KeyEvent.VK_BACK_SPACE)) {
            JOptionPane.showMessageDialog(this, "Solo numeros");
            evt.consume();
        }

    }//GEN-LAST:event_txt_horaMKeyTyped

    private void btnFin_APerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFin_APerActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnFin_APerActionPerformed

    private void btnCancelar_APerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelar_APerActionPerformed
        this.limpiar();
    }//GEN-LAST:event_btnCancelar_APerActionPerformed

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

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

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

    private void txt_NameMKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txt_NameMKeyTyped
        char car = evt.getKeyChar();
        if ((car < 'a' || car > 'z') && (car < 'A' || car > 'Z') && (car != (char) KeyEvent.VK_SPACE)
                && (car != (char) KeyEvent.VK_BACK_SPACE)) {
            JOptionPane.showMessageDialog(this, "Ingrese solo letras");
            evt.consume();
        }
    }//GEN-LAST:event_txt_NameMKeyTyped

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAgregar_APer;
    private javax.swing.JButton btnCancelar_APer;
    private javax.swing.JButton btnFin_APer;
    private javax.swing.JComboBox combo_tipoM;
    private com.toedter.calendar.JDateChooser jDateChooser1M;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JTextField txt_DniM;
    private javax.swing.JTextField txt_NameM;
    private javax.swing.JTextField txt_apellidoM;
    private javax.swing.JTextField txt_horaM;
    public javax.swing.JTextField txt_idUserM;
    private javax.swing.JTextField txt_userM;
    // End of variables declaration//GEN-END:variables
}