/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JFIdentificacion.java
 *
 * Created on 22-oct-2010, 12:00:36
 */

package vistas;

import java.util.ArrayList;
import java.util.List;
import javabbuva.*;

/**
 *
 * @author Adrian
 */
public class JFIdentificacion extends javax.swing.JFrame {

    Sucursal su;
    boolean validado;
    JFPrincipal p;

    /** Creates new form JFIdentificacion */
    public JFIdentificacion(Sucursal su, JFPrincipal p) {
        this.su = su;
        this.p = p;
        validado = false;
        initComponents();
    }

    /** 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();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTlogin = new javax.swing.JTextField();
        jLerror = new javax.swing.JLabel();
        jLbienvenido = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jBentrar = new javax.swing.JButton();
        jBvalidar = new javax.swing.JButton();
        jTcontraseña = new javax.swing.JPasswordField();
        jClista = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14));
        jLabel1.setForeground(new java.awt.Color(0, 102, 0));
        jLabel1.setText("IDENTIFICACIÓN EN EL SISTEMA.");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setText("Login:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel3.setText("Password:");

        jLerror.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLerror.setForeground(new java.awt.Color(204, 0, 0));

        jLbienvenido.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLbienvenido.setForeground(new java.awt.Color(0, 102, 0));

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setText("Escoja caja:");

        jBentrar.setText("Entrar");
        jBentrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBentrarActionPerformed(evt);
            }
        });

        jBvalidar.setText("Validar");
        jBvalidar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBvalidarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(57, 57, 57)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(24, 24, 24)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel3))
                                .addGap(63, 63, 63)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jTcontraseña)
                                    .addComponent(jTlogin, javax.swing.GroupLayout.DEFAULT_SIZE, 120, Short.MAX_VALUE))
                                .addGap(29, 29, 29)
                                .addComponent(jBvalidar))
                            .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLbienvenido, javax.swing.GroupLayout.PREFERRED_SIZE, 356, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jLabel4)
                        .addGap(37, 37, 37)
                        .addComponent(jClista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jBentrar)))
                .addContainerGap(20, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(39, 39, 39)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTlogin, 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(jLabel3)
                            .addComponent(jTcontraseña, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(24, 24, 24))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jBvalidar)
                        .addGap(42, 42, 42)))
                .addComponent(jLerror, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLbienvenido, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jClista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(jBentrar)
                .addContainerGap())
        );

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

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
        List<Caja> cajas = new ArrayList();
        cajas = su.getCaja();
        //DefaultListModel dlm = new DefaultListModel();
        int i = 0;
        while(i<cajas.size()){
            //dlm.addElement(cajas.get(i).getIdentificador());
            jClista.addItem(cajas.get(i).getIdentificador());
            i++;
        }
    }//GEN-LAST:event_formWindowOpened

    private void jBentrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBentrarActionPerformed
        // TODO add your handling code here:
        jLerror.setText("");
        jLbienvenido.setText("");
        if(validado == true){
            su.empezar(jTlogin.getText(),String.valueOf(jClista.getSelectedItem()));
            new JFArqueoInicial(this.su,this.p).setVisible(true);
            this.dispose();
        }else
            jLerror.setText("Valide primero");
    }//GEN-LAST:event_jBentrarActionPerformed

    private void jBvalidarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBvalidarActionPerformed
        // TODO add your handling code here:
        jLerror.setText("");
        jLbienvenido.setText("");
        if(su.comprobarEmpleado(jTlogin.getText(), jTcontraseña.getText())){
            jLbienvenido.setText("Bienvenido "+su.dameNombreEmpleado(jTlogin.getText()));
            validado = true;
        }
        else{
            jLerror.setText("El empleado no existe o la contraseña no es valida");
            validado = false;
        }

    }//GEN-LAST:event_jBvalidarActionPerformed

    /**
    * @param args the command line arguments
    */
    /*public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFIdentificacion().setVisible(true);
            }
        });
    }*/

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBentrar;
    private javax.swing.JButton jBvalidar;
    private javax.swing.JComboBox jClista;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLbienvenido;
    private javax.swing.JLabel jLerror;
    private javax.swing.JPasswordField jTcontraseña;
    private javax.swing.JTextField jTlogin;
    // End of variables declaration//GEN-END:variables

}
