
package vistas;

import bbuvajava.Caja;
import bbuvajava.Empleado;
import bbuvajava.Sucursal;


public class jfrmCreacionEmpleado extends javax.swing.JFrame {

    Sucursal Auxsuc;
    Boolean op=false;
    public jfrmCreacionEmpleado(Sucursal suc) {
        Auxsuc=suc;
        initComponents();
    }

    @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();
        jtxtdnidirector = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jtxtlogin = new javax.swing.JTextField();
        jbIdentificarse = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        jtxtdninuevo = new javax.swing.JTextField();
        jtxtloginnuevo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jtxtnombrenuevo = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtxtnumcaja = new javax.swing.JTextField();
        jbValidar = new javax.swing.JButton();

        jLabel1.setText("CREACION DE EMPLEADOS");

        jLabel2.setText("dni director");

        jtxtdnidirector.setText("48944102");

        jLabel3.setText("login");

        jLabel4.setForeground(new java.awt.Color(255, 0, 0));
        jLabel4.setText("*ATENCION= esta operación solo puede autorizarla el director");

        jtxtlogin.setText("12345");

        jbIdentificarse.setText("Identificarse");
        jbIdentificarse.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbIdentificarseActionPerformed(evt);
            }
        });

        jLabel5.setText("dni nuevo empleado");

        jLabel6.setText("login nuevo empleado");

        jLabel7.setText("nombre");

        jLabel8.setText("numcaja");

        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(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(26, 26, 26)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addComponent(jbValidar, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)
                                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                                .addComponent(jtxtdnidirector, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel3)
                                                .addGap(31, 31, 31)
                                                .addComponent(jtxtlogin, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(20, 20, 20)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(108, 108, 108)
                                .addComponent(jbIdentificarse, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jtxtdninuevo, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jtxtnumcaja)
                                    .addComponent(jtxtnombrenuevo)
                                    .addComponent(jtxtloginnuevo))))))
                .addGap(39, 39, 39))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtxtdnidirector, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jtxtlogin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbIdentificarse)
                .addGap(21, 21, 21)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jtxtdninuevo, 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(jLabel6)
                    .addComponent(jtxtloginnuevo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtnombrenuevo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jtxtnumcaja, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jbValidar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

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

    private void jbIdentificarseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbIdentificarseActionPerformed
        String dnidirector=jtxtdnidirector.getText();
        if(Auxsuc.getEmpleado(dnidirector)==null||Auxsuc.getEmpleado(dnidirector).getDirector()==false)
            jtxtdnidirector.setText("ERROR ");
        else{
            jtxtdnidirector.setText("OK");
            op=true;
        }
    }//GEN-LAST:event_jbIdentificarseActionPerformed

    private void jbValidarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbValidarActionPerformed
        if(op==false){
            jtxtdnidirector.setText("Identificar");
            jtxtlogin.setText("Identificarse");
        }
        else{
            String dninuevo=jtxtdninuevo.getText();
            String loginnuevo=jtxtloginnuevo.getText();
            String nomnuevo=jtxtnombrenuevo.getText();
            String numcaja=jtxtnumcaja.getText();
        
            if(Auxsuc.getEmpleado(dninuevo)!=null)
                jtxtdninuevo.setText("ese empleado ya existe");
            else{
                Empleado e=new Empleado();
                e.setDni(dninuevo);
                e.setLogin(Integer.parseInt(loginnuevo));
                e.setNombre(nomnuevo);
    
	            int numero=Integer.parseInt(numcaja);
                if(Auxsuc.getCaja(numero)!=null){
                    jtxtnumcaja.setText("caja ya asignada");
                }
                else{
                Caja aux=Auxsuc.asignarCajanueva((numero));
                Auxsuc.nuevoEmpleado(e, aux);
                jtxtnumcaja.setText("HECHO");
                jtxtdninuevo.setText("hecho");
                }
            }
        }
    }//GEN-LAST:event_jbValidarActionPerformed

    
    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    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.JButton jbIdentificarse;
    private javax.swing.JButton jbValidar;
    private javax.swing.JTextField jtxtdnidirector;
    private javax.swing.JTextField jtxtdninuevo;
    private javax.swing.JTextField jtxtlogin;
    private javax.swing.JTextField jtxtloginnuevo;
    private javax.swing.JTextField jtxtnombrenuevo;
    private javax.swing.JTextField jtxtnumcaja;
    // End of variables declaration//GEN-END:variables

}
