/*
* EmpleadoDialog.java
*
* Created on 26 de enero de 2008, 12:55 PM
*/
package gafetes;
import gafetes.modules.sign.PanelPaint;
import gafetes.util.VariablesAmbiente;
import java.io.File;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.beans.*;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
import gafetes.beans.Empleado;
import gafetes.model.EmpleadosModel;
import java.awt.event.KeyEvent;
import javax.swing.InputMap;
import javax.swing.ActionMap;
import javax.swing.KeyStroke;
import javax.swing.JComponent;
import javax.swing.AbstractAction;
import java.awt.event.KeyEvent;
import java.awt.event.ActionEvent;
import java.awt.event.*;
//import java.awt.*;
import javax.swing.event.*;
import javax.swing.InputMap;
import javax.swing.ActionMap;
import javax.swing.KeyStroke;
import javax.swing.JComponent;
import javax.swing.Action;
import javax.swing.AbstractAction;
import java.awt.event.KeyEvent;
import java.sql.*;
import javax.swing.*;
import de.wannawork.jcalendar.JCalendarComboBox;
/**
*
* @author jalafita
*/
public class EmpleadoDialog extends javax.swing.JDialog {
/** Creates new form EmpleadoDialog */
public EmpleadoDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
initComponentsWithoutNetbeans();
//newMode();
}
private void initComponentsWithoutNetbeans(){
panelPaint = new PanelPaint();
panelPaint.setBackground(Color.white);
jButton1.setVisible(false);
jButton6.setVisible(false);
}
private void borrarFirma(){
panelPaint.repaint();
//javax.swing.JOptionPane.showMessageDialog( this, "Funcion no implementada", "Pr�xima liberacion de modulo 7-abril-2008",
// javax.swing.JOptionPane.INFORMATION_MESSAGE);
}
private void guardarFirma(){
javax.swing.JOptionPane.showMessageDialog( this, "Funcion no implementada", "Pr�xima liberacion de modulo 15-mayo-2008",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jPanel4 = new javax.swing.JPanel();
jPanel5 = new javax.swing.JPanel();
jPanel6 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
claveTextField = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
apellidosTextField = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
nombreTextField = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
areaTextField = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
puestoTextField = new javax.swing.JTextField();
jLabel7 = new javax.swing.JLabel();
rfcTextField = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
imssTextField = new javax.swing.JTextField();
jLabel9 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
rutaTextField = new javax.swing.JTextField();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
zonaTextField = new javax.swing.JTextField();
jLabel12 = new javax.swing.JLabel();
consecutivoTextField = new javax.swing.JTextField();
jLabel13 = new javax.swing.JLabel();
jButton7 = new javax.swing.JButton();
editImageButton = new javax.swing.JButton();
jLabel14 = new javax.swing.JLabel();
categoriaComboBox = new javax.swing.JComboBox();
jButton5 = new javax.swing.JButton();
jLabel15 = new javax.swing.JLabel();
rutaFirmaTextField = new javax.swing.JTextField();
jLabel16 = new javax.swing.JLabel();
fechaIngresoComboBox = new de.wannawork.jcalendar.JCalendarComboBox();
jPanel2 = new javax.swing.JPanel();
jButton4 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jButton6 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 100, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(0, 100, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jPanel3.setBackground(new java.awt.Color(236, 227, 211));
getContentPane().add(jPanel3, java.awt.BorderLayout.EAST);
jPanel4.setBackground(new java.awt.Color(236, 227, 211));
getContentPane().add(jPanel4, java.awt.BorderLayout.SOUTH);
jPanel5.setBackground(new java.awt.Color(236, 227, 211));
getContentPane().add(jPanel5, java.awt.BorderLayout.WEST);
jPanel6.setLayout(null);
jPanel6.setBackground(new java.awt.Color(236, 227, 211));
jPanel6.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jPanel6.setPreferredSize(new java.awt.Dimension(800, 550));
jLabel1.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel1.setText("Nombre");
jPanel6.add(jLabel1);
jLabel1.setBounds(20, 50, 80, 20);
jPanel6.add(claveTextField);
claveTextField.setBounds(100, 20, 140, 20);
jLabel2.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel2.setText("Clave");
jPanel6.add(jLabel2);
jLabel2.setBounds(20, 20, 80, 20);
jLabel3.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel3.setText("Apellidos");
jPanel6.add(jLabel3);
jLabel3.setBounds(20, 80, 80, 20);
apellidosTextField.setEditable(false);
jPanel6.add(apellidosTextField);
apellidosTextField.setBounds(100, 80, 450, 20);
jLabel4.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setText("Foto");
jPanel6.add(jLabel4);
jLabel4.setBounds(580, 4, 180, 20);
nombreTextField.setEditable(false);
jPanel6.add(nombreTextField);
nombreTextField.setBounds(100, 50, 450, 20);
jButton2.setBackground(new java.awt.Color(244, 244, 240));
jButton2.setFont(new java.awt.Font("Tahoma", 0, 18));
jButton2.setIcon(new javax.swing.ImageIcon(""));
jButton2.setText("Obtener foto");
jButton2.setToolTipText("Obtener foto");
jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton2.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jPanel6.add(jButton2);
jButton2.setBounds(580, 20, 180, 210);
jLabel5.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel5.setText("Area");
jPanel6.add(jLabel5);
jLabel5.setBounds(20, 140, 80, 20);
areaTextField.setEditable(false);
jPanel6.add(areaTextField);
areaTextField.setBounds(100, 140, 450, 20);
jLabel6.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel6.setText("Puesto");
jPanel6.add(jLabel6);
jLabel6.setBounds(20, 170, 80, 20);
puestoTextField.setEditable(false);
jPanel6.add(puestoTextField);
puestoTextField.setBounds(100, 170, 450, 20);
jLabel7.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel7.setText("CURP");
jPanel6.add(jLabel7);
jLabel7.setBounds(20, 110, 80, 20);
rfcTextField.setEditable(false);
jPanel6.add(rfcTextField);
rfcTextField.setBounds(100, 110, 140, 20);
jLabel8.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel8.setText("IMSS");
jPanel6.add(jLabel8);
jLabel8.setBounds(350, 110, 70, 20);
imssTextField.setEditable(false);
jPanel6.add(imssTextField);
imssTextField.setBounds(420, 110, 130, 20);
jLabel9.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel9.setText("Plantilla");
jPanel6.add(jLabel9);
jLabel9.setBounds(20, 260, 80, 20);
jComboBox1.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jComboBox1ItemStateChanged(evt);
}
});
jComboBox1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1ActionPerformed(evt);
}
});
jPanel6.add(jComboBox1);
jComboBox1.setBounds(100, 260, 220, 20);
rutaTextField.setEditable(false);
jPanel6.add(rutaTextField);
rutaTextField.setBounds(100, 300, 330, 20);
jLabel10.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel10.setText("Imagen Foto");
jPanel6.add(jLabel10);
jLabel10.setBounds(20, 300, 80, 20);
jLabel11.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel11.setText("Zona");
jPanel6.add(jLabel11);
jLabel11.setBounds(20, 200, 80, 20);
zonaTextField.setEditable(false);
jPanel6.add(zonaTextField);
zonaTextField.setBounds(100, 200, 450, 20);
jLabel12.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel12.setText("Consem");
jPanel6.add(jLabel12);
jLabel12.setBounds(20, 230, 80, 20);
consecutivoTextField.setEditable(false);
consecutivoTextField.setText("01");
jPanel6.add(consecutivoTextField);
consecutivoTextField.setBounds(100, 230, 140, 20);
jLabel13.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel13.setText("Categoria");
jPanel6.add(jLabel13);
jLabel13.setBounds(350, 230, 70, 20);
jButton7.setText("Cambiar Plantilla");
jButton7.setEnabled(false);
jButton7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton7ActionPerformed(evt);
}
});
jPanel6.add(jButton7);
jButton7.setBounds(320, 260, 130, 23);
editImageButton.setText("Editar Imagen");
editImageButton.setEnabled(false);
editImageButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editImageButtonActionPerformed(evt);
}
});
jPanel6.add(editImageButton);
editImageButton.setBounds(430, 300, 120, 23);
jLabel14.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel14.setText("Obtener firma a partir de un archivo");
jPanel6.add(jLabel14);
jLabel14.setBounds(590, 280, 180, 14);
categoriaComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9" }));
jPanel6.add(categoriaComboBox);
categoriaComboBox.setBounds(420, 230, 130, 20);
jButton5.setBackground(new java.awt.Color(244, 244, 240));
jButton5.setFont(new java.awt.Font("Tahoma", 0, 18));
jButton5.setIcon(new javax.swing.ImageIcon(""));
jButton5.setText("Obtener firma");
jButton5.setToolTipText("Obtener firma a partir de un archivo");
jButton5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton5.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
jButton5.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton5ActionPerformed(evt);
}
});
jPanel6.add(jButton5);
jButton5.setBounds(580, 300, 180, 210);
jLabel15.setFont(new java.awt.Font("Lucida Console", 0, 11));
jLabel15.setText("Ruta Firma");
jPanel6.add(jLabel15);
jLabel15.setBounds(20, 330, 80, 20);
rutaFirmaTextField.setEditable(false);
jPanel6.add(rutaFirmaTextField);
rutaFirmaTextField.setBounds(100, 330, 330, 20);
jLabel16.setText("Fecha de Ingreso");
jPanel6.add(jLabel16);
jLabel16.setBounds(20, 370, 130, 14);
jPanel6.add(fechaIngresoComboBox);
fechaIngresoComboBox.setBounds(130, 370, 190, 20);
getContentPane().add(jPanel6, java.awt.BorderLayout.CENTER);
jPanel2.setBackground(new java.awt.Color(205, 199, 182));
jButton4.setBackground(new java.awt.Color(205, 199, 182));
jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/guardar.gif")));
jButton4.setText("Guardar");
jButton4.setBorder(null);
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jPanel2.add(jButton4);
jButton1.setBackground(new java.awt.Color(205, 199, 182));
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/imprimir.gif")));
jButton1.setText("Imprimir Frente");
jButton1.setBorder(null);
jButton1.setEnabled(false);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jPanel2.add(jButton1);
jButton6.setBackground(new java.awt.Color(205, 199, 182));
jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/imprimir.gif")));
jButton6.setText("Imprimir Reverso");
jButton6.setBorder(null);
jButton6.setEnabled(false);
jButton6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton6ActionPerformed(evt);
}
});
jPanel2.add(jButton6);
jButton3.setBackground(new java.awt.Color(205, 199, 182));
jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/gafetes/images/salir.gif")));
jButton3.setText("Cerrar");
jButton3.setBorder(null);
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel2.add(jButton3);
getContentPane().add(jPanel2, java.awt.BorderLayout.NORTH);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
//Indicamos que estamos pasando la firma escaneada pasamos true
obtenerFotografia(jButton5, true);
}//GEN-LAST:event_jButton5ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
//Estamos obteniendo la fotografia pasamos false
obtenerFotografia(jButton2, false);
}//GEN-LAST:event_jButton2ActionPerformed
private void editImageButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editImageButtonActionPerformed
// TODO add your handling code here:
editarImagen();
}//GEN-LAST:event_editImageButtonActionPerformed
private void editarImagen(){
java.util.Vector configuraciones = gafetes.business.SqlHelper.getConfiguracionGlobal();
String rutaProgramaEditor = "C:\\windows\\System32\\mspaint.exe ";
for(int i=0; i < configuraciones.size(); i++)
{
if( ( (gafetes.beans.Configuracion)configuraciones.elementAt(i) ).getParametro().equals("EDITOR_IMAGENES") )
{
gafetes.beans.Configuracion config = (gafetes.beans.Configuracion)configuraciones.elementAt(i);
rutaProgramaEditor = config.getValor();
}
}
try
{
// directorio/ejecutable es el path del ejecutable y un nombre.
Process p = Runtime.getRuntime().exec (rutaProgramaEditor + " " + rutaTextField.getText().trim());
}
catch (Exception e)
{
javax.swing.JOptionPane.showMessageDialog( this, "Ocurrio el siguiente error " + e.getMessage(), "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
// Se lanza una excepci�n si no se encuentra en ejecutable o el fichero no es ejecutable.
}
}
private void loadSignModule(){
new gafetes.modules.sign.pruebas.PruebaPaint().lanzaVentanaSeparada();
}
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
// TODO add your handling code here:
gafetes.beans.Template template = new gafetes.beans.Template();
template = (gafetes.beans.Template) jComboBox1.getSelectedItem();
SelectEmpresa se = new SelectEmpresa(Application.getparentFrame(), true, template );
se.setModal(true);
gafetes.util.Misc.centerFrame(se);
se.setVisible(true);
System.out.println("El template que selecciono es el sig." + template.getId());
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
jComboBox1.removeAllItems();
jComboBox1.addItem( template );
}//GEN-LAST:event_jButton7ActionPerformed
private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox1ItemStateChanged
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jComboBox1ActionPerformed
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
printGafete(false);
}//GEN-LAST:event_jButton6ActionPerformed
private gafetes.beans.Empleado toEmpleado(){
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
e.setClave( claveTextField.getText().trim());
e.setNombre(nombreTextField.getText().trim());
e.setApellidos(apellidosTextField.getText().trim());
e.setRfc(rfcTextField.getText().trim());
e.setImss(imssTextField.getText().trim());
e.setArea(areaTextField.getText().trim());
e.setPuesto(puestoTextField.getText().trim());
e.setZona(zonaTextField.getText().trim());
e.setCategoria( (String) categoriaComboBox.getSelectedItem() );
//categoriaTextField.getText().trim());
e.setConsecutivo(consecutivoTextField.getText().trim());
e.setRutaFoto(rutaTextField.getText().trim());
e.setFechaIngreso(fechaIngresoComboBox.getCalendar());
e.setRutaFirma(rutaFirmaTextField.getText().trim());
if(editMode)
e.setId(empleado.getId());
//if(!editMode){
e.setTemplate( ((gafetes.beans.Template)jComboBox1.getSelectedItem()).getId() );
System.out.println("Le asignamos el gafete " + e.getTemplate() );
//}else
// e.setTemplate( (new Integer(((String)(jComboBox1.getSelectedItem())))).intValue() );
empleado = e;
return e;
}
private void obtenerFotografia(JButton boton, boolean firma){
String rutaFotos = gafetes.util.VariablesAmbiente.getRutaFotos();
JFileChooser fc = new JFileChooser();
//File f = new File(new File(rutaFotos).getAbsolutePath());
File f = new File(new File(rutaFotos).getAbsolutePath());
fc.setCurrentDirectory(f);
PreviewPane previewPane = new PreviewPane();
fc.setAccessory(previewPane);
fc.addPropertyChangeListener(previewPane);
int returnVal = fc.showDialog(this, "OK");
//Process the results.
if (returnVal == JFileChooser.APPROVE_OPTION) {
java.io.File file = fc.getSelectedFile();
gafetes.beans.Empleado e = new gafetes.beans.Empleado();
if(firma)
{
e.setRutaFirma(file.getAbsolutePath());
gafetes.business.SqlHelper.updateFirma(file.getAbsolutePath(),e.getId());
rutaFirmaTextField.setText(file.getAbsolutePath());
}
else
{
e.setRutaFoto(file.getAbsolutePath());
gafetes.business.SqlHelper.updatePhoto(file.getAbsolutePath(),e.getId());
rutaTextField.setText(file.getAbsolutePath());
}
Icon icon = null;
int maxImgWidth = 195;
try {
BufferedImage img = ImageIO.read(file);
float width = img.getWidth();
float height = img.getHeight();
float scale = height / width;
width = maxImgWidth;
height = (width * scale); // height should be scaled from new width
icon = new ImageIcon(img.getScaledInstance(Math.max(1, (int)width), Math.max(1, (int)height), Image.SCALE_SMOOTH));
//jButton1.setIcon(new javax.swing.ImageIcon(e.getRutaFoto()));
boton.setIcon( icon );
boton.setText("");
}
catch(java.io.IOException exa) {
// couldn't read image.
}
} else {
}
fc.setSelectedFile(null);
}
private boolean checkForEmptyFields(){
if(claveTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique la clave de empleado", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
claveTextField.requestFocus();
return false;
}
if(nombreTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique el nombre", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
nombreTextField.requestFocus();
return false;
}
if(apellidosTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique los apellidos", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
apellidosTextField.requestFocus();
return false;
}
if(rfcTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique el RFC del empleado", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
rfcTextField.requestFocus();
return false;
}
if(imssTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique el No. de Seguro Social del Empleado", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
imssTextField.requestFocus();
return false;
}
if(areaTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique el area del empleado", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
areaTextField.requestFocus();
return false;
}
if(puestoTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique el puesto", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
puestoTextField.requestFocus();
return false;
}
if(consecutivoTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique el n�mero consecutivo", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
consecutivoTextField.requestFocus();
return false;
}
if( ((String)categoriaComboBox.getSelectedItem()).equals("") ){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique la categoria", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
categoriaComboBox.requestFocus();
return false;
}
if(zonaTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Especifique la zona", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
zonaTextField.requestFocus();
return false;
}
if(rutaTextField.getText().equals("")){
javax.swing.JOptionPane.showMessageDialog( this, "Seleccione una foto para el empleado dando click a Obtener foto", "Datos incompletos",
javax.swing.JOptionPane.INFORMATION_MESSAGE);
rutaTextField.requestFocus();
return false;
}
return true;
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
boolean go = checkForEmptyFields();
if(!go){
return;
}
String mensaje;
if( editMode ){
mensaje = "�Desea actualizar la informaci�n?";
}else{
mensaje = "�Desea guardar la informaci�n?";
}
int confirm = javax.swing.JOptionPane.showOptionDialog( this,
mensaje, "Confirmaci�n",
javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE,
null,null,null);
if ( confirm == 0 ) {
if( editMode ){
String claveAnterior = empleado.getClave();
gafetes.beans.Empleado e = toEmpleado();
if( !claveAnterior.equals(e.getClave()) ){
int confirmar = javax.swing.JOptionPane.showOptionDialog( this,
"Se dispone a cambiar la clave de empleado, est� realmente seguro", "Confirmaci�n",
javax.swing.JOptionPane.YES_NO_OPTION, javax.swing.JOptionPane.QUESTION_MESSAGE,
null,null,null);
if ( confirmar == 0 )
{
gafetes.business.SqlHelper.updateEmpleado(e,claveAnterior);
jButton4.setEnabled(false);
empleado.setClave(e.getClave());
}else
return;
}else
{
gafetes.business.SqlHelper.updateEmpleado(e,claveAnterior);
jButton4.setEnabled(false);
}
}else{
gafetes.beans.Empleado e = toEmpleado();
empleado = e;
gafetes.business.SqlHelper.saveEmpleado(e);
jButton4.setEnabled(false);
}
claveTextField.setEnabled(false);
apellidosTextField.setEnabled(false);
nombreTextField.setEnabled(false);
rfcTextField.setEnabled(false);
imssTextField.setEnabled(false);
puestoTextField.setEnabled(false);
areaTextField.setEnabled(false);
rutaTextField.setEnabled(false);
zonaTextField.setEnabled(false);
consecutivoTextField.setEnabled(false);
categoriaComboBox.setEnabled(false);
jButton7.setEnabled(false);
//editImageButton.setEnabled(false);
jComboBox1.setEnabled(false);
//jButton5.setEnabled(false);
jButton1.setEnabled(true);
jButton6.setEnabled(true);
}
dispose();
}//GEN-LAST:event_jButton4ActionPerformed
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
dispose();
}//GEN-LAST:event_jButton3ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
//gafetes.print.PrintGafete pr = new gafetes.print.PrintGafete();
//pr.print(empleado,true);
printGafete(true);
}//GEN-LAST:event_jButton1ActionPerformed
private void printGafete(boolean value){
if( gafetes.business.SqlHelper.existeTemplate(empleado.getTemplate()) ){
gafetes.beans.Empleado e = gafetes.business.SqlHelper.getEmpleadoById(empleado);
gafetes.print.PrintGafete pr = new gafetes.print.PrintGafete();
pr.print(e,value);
}else{
javax.swing.JOptionPane.showMessageDialog(
new JFrame(),"El empleado no tiene asignado una plantilla, o bien la plantilla no existe en el sistema");
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new EmpleadoDialog(new javax.swing.JFrame(), true).setVisible(true);
}
});
}
public void setEditMode(gafetes.beans.Empleado e){
editMode = true;
jButton7.setEnabled(true);
editImageButton.setEnabled(true);
nombreTextField.setEditable(true);
apellidosTextField.setEditable(true);
rfcTextField.setEditable(true);
imssTextField.setEditable(true);
areaTextField.setEditable(true);
puestoTextField.setEditable(true);
zonaTextField.setEditable(true);
//consecutivoTextField.setEditable(true);
categoriaComboBox.setEditable(true);
gafetes.beans.Empleado em;
em = gafetes.business.SqlHelper.getEmpleadoById(e);
em.setId(e.getId());
empleado = em;
nombreTextField.setText(em.getNombre());
apellidosTextField.setText(em.getApellidos());
claveTextField.setText(em.getClave());
rfcTextField.setText(em.getRfc());
imssTextField.setText(em.getImss());
areaTextField.setText(em.getArea());
puestoTextField.setText(em.getPuesto());
zonaTextField.setText(em.getZona());
//consecutivoTextField.setText(em.getConsecutivo());
categoriaComboBox.removeAllItems();
categoriaComboBox.addItem(em.getCategoria());
System.out.println(em.getZona()+ em.getRfc()+em.getCategoria());
//rutaTextField.setText(em.getRutaFoto ());
rutaTextField.setText(em.getRutaFoto());
rutaFirmaTextField.setText(em.getRutaFirma());
fechaIngresoComboBox.setCalendar(em.getFechaIngreso());
//jComboBox1.addItem(""+em.getTemplate() );
gafetes.beans.Template t = gafetes.business.SqlHelper.getTemplateById( em.getTemplate());
if(t!=null)
jComboBox1.addItem(t);
else{
t.setId(-1);
t.setNombre("No Existente");
jComboBox1.addItem(t);
}
mostrarImagenEnBoton(em.getRutaFoto(), jButton2, rutaTextField);
mostrarImagenEnBoton(em.getRutaFirma(), jButton5, rutaFirmaTextField );
//jButton2.setIcon(new javax.swing.ImageIcon(e.getRutaFoto()));
}
private void mostrarImagenEnBoton(String rutaArchivo, JButton boton, JTextField cajaTexto)
{
java.io.File file = new java.io.File(rutaArchivo);
Icon icon = null;
int maxImgWidth = 195;
try {
BufferedImage img = ImageIO.read(file);
//BufferedImage img = ImageIO.read(new java.net.URL("http://localhost/comedor/"+em.getRutaFoto().substring(11)));
float width = img.getWidth();
float height = img.getHeight();
float scale = height / width;
width = maxImgWidth;
height = (width * scale); // height should be scaled from new width
icon = new ImageIcon(img.getScaledInstance(Math.max(1, (int)width), Math.max(1, (int)height), Image.SCALE_SMOOTH));
//jButton1.setIcon(new javax.swing.ImageIcon(e.getRutaFoto()));
boton.setIcon( icon );
boton.setText("Cambiar Imagen");
boton.setVerticalAlignment(javax.swing.SwingConstants.BOTTOM);
}
catch(java.lang.OutOfMemoryError ome){
System.out.println("La imagen es demasiado grande, no hay espacio en memoria para visualizarla. Edite la imagen para reducir el tama�o");
}
catch(IOException exa) {
try {
// File files = new java.io.File("c:\\Gafetes\\fotos\\unavailable.jpg");
//String rutaCompletaArchivo = VariablesAmbiente.getRutaCarpetaFotos()+e.getRutaFoto().substring(11);
//System.out.println(rutaCompletaArchivo);
String rutaArchivoNoExiste = VariablesAmbiente.getRutaFotoNoExiste();
File files = new java.io.File(rutaArchivoNoExiste);
BufferedImage img = ImageIO.read(files);
float width = img.getWidth();
float height = img.getHeight();
float scale = height / width;
width = maxImgWidth;
height = (width * scale); // height should be scaled from new width
icon = new ImageIcon(img.getScaledInstance(Math.max(1, (int)width), Math.max(1, (int)height), Image.SCALE_SMOOTH));
boton.setIcon( icon );
}catch(IOException exas){
System.out.println("No existe imagen por Default.");
}
System.out.println("couldn't read image.");
}
}
public void newMode(){
javax.swing.DefaultListModel dfm = gafetes.business.SqlHelper.getListaTemplates();
for( int i=0; i < dfm.getSize();i++){
gafetes.beans.Template t = (gafetes.beans.Template) dfm.getElementAt(i);
jComboBox1.addItem(t);
System.out.println(t.getId());
}
claveTextField.setEditable(true);
apellidosTextField.setEditable(true);
nombreTextField.setEditable(true);
rfcTextField.setEditable(true);
imssTextField.setEditable(true);
puestoTextField.setEditable(true);
zonaTextField.setEditable(true);
areaTextField.setEditable(true);
//consecutivoTextField.setEditable(true);
//jButton5.setEditable(true);
//jButton1.setEnabled(t);
//jButton6.setEnabled(true);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextField apellidosTextField;
private javax.swing.JTextField areaTextField;
private javax.swing.JComboBox categoriaComboBox;
private javax.swing.JTextField claveTextField;
private javax.swing.JTextField consecutivoTextField;
private javax.swing.JButton editImageButton;
//private javax.swing.JComboBox fechaIngresoComboBox;
private de.wannawork.jcalendar.JCalendarComboBox fechaIngresoComboBox;
private javax.swing.JTextField imssTextField;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JButton jButton5;
private javax.swing.JButton jButton6;
private javax.swing.JButton jButton7;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
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 jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JPanel jPanel6;
private javax.swing.JTextField nombreTextField;
private javax.swing.JTextField puestoTextField;
private javax.swing.JTextField rfcTextField;
private javax.swing.JTextField rutaFirmaTextField;
private javax.swing.JTextField rutaTextField;
private javax.swing.JTextField zonaTextField;
// End of variables declaration//GEN-END:variables
gafetes.beans.Empleado empleado;
private boolean editMode = false;
private PanelPaint panelPaint;
}