Package carcel.controllers

Source Code of carcel.controllers.ControlAccesoController

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

import carcel.constant.CarcelConstants;
import carcel.views.PanelListener;
import carcel.customExceptions.UIValidateException;
import carcel.views.ControlAccesoView;
import carcel.views.WindowsCreator;
import conexion.base.EntityController;





import entidades.Usuario;
import entidades.UsuarioActualLogueado;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import javax.persistence.NoResultException;
import javax.swing.JOptionPane;

/**
*
* @author Administrador
*/
public class ControlAccesoController extends ControlAccesoView {
// Variables de la clase

    Usuario user;
    EntityController ec;
    List<Usuario> l1;
   
    PrincipalController pc;

    public ControlAccesoController() {
        ec = EntityController.getInstance();
        addButonsHandlers();



    }

    private void addButonsHandlers() {
        aceptarButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                // Declaro Variables

                try {
                    // Llamo para validar que no esten vacios los campos
                    validarDatos();

                    Usuario user = new Usuario();
                    user.setPassword(passText.getText());
                    user.setUsername(userText.getText());

                    String usuario = userText.getText();
                    String pass = passText.getText();

                    // Ya tengo los datos...
                    // Tengo que hacer la query ...
                    Usuario todos = (Usuario) ec.createQuery("select u from Usuario u where u.username = :usuario and u.password = :pass", Usuario.class).setParameter("usuario", usuario).setParameter("pass", pass).getSingleResult();


                    if ((todos.getPassword().equals(user.getPassword())) && (todos.getUsername().equals(user.getUsername()))) {
                            user.setUsername(userText.getText());
                            user.setPassword(passText.getText());
                            UsuarioActualLogueado.setUserLogueado(user);
                            pc = new PrincipalController(user);
                            pc.verificarPermisos();
                            pc.setVisible(true);
                            dispose();
                    } else {

                        validarDatos(userText.getText(), passText.getText());
                    }

                } catch (NoResultException exception) {
                    JOptionPane.showMessageDialog(ControlAccesoController.this, "Los datos ingresados no corresponden a un usuario válido.");

                } catch (UIValidateException ex) {
                    JOptionPane.showMessageDialog(ControlAccesoController.this, ex.getMessage());
                    //Logger.getLogger(ControlAccesoController.class.getName()).log(Level.SEVERE, null, ex);
                }



            }
        });
       
        cancelarButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
    }
}
TOP

Related Classes of carcel.controllers.ControlAccesoController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.