Exemplo n.º 1
0
 @Override
 public List<Rol> verTodo() {
   Session session = HibernateUtil.getSessionFactory().openSession();
   session.beginTransaction();
   Criteria criteria = session.createCriteria(Rol.class);
   //        String hql="from Rol";
   //        Query query=session.createQuery(hql);
   List<Rol> listaRol = (List<Rol>) criteria.list();
   session.close();
   return listaRol;
 }
Exemplo n.º 2
0
  public static List<Detallecompra> detallecompr(Session session) {
    session = null;
    Query query = null;
    try {

      session = HibernateUtil.getSessionFactory().openSession();
      String hql = "from Detallecompra as dc ORDER BY dc.compra.idcompra DESC ";
      query = session.createQuery(hql);

      return query.list();
    } catch (Exception e) {
    } finally {
      session.close();
    }
    return null;
  }
Exemplo n.º 3
0
  public String login() {
    this.session = null;
    this.transaction = null;

    try {
      DaoUsuario daoUsuario = new DaoUsuario();

      this.session = HibernateUtil.getSessionFactory().openSession();
      this.transaction = this.session.beginTransaction();

      Usuario usuarioConsulta = daoUsuario.getByNombreUsuario(this.session, this.usuario);
      // int rol = usuarioConsulta.getRol().getId();

      if (usuarioConsulta != null && usuarioConsulta.getEstado() != false) {
        if (usuarioConsulta.getContrasenia().equals(EncryptMD5.encriptaEnMD5(this.contrasenia))) {
          // if(rol==1){
          HttpSession httpSession =
              (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
          httpSession.setAttribute("usuario", this.usuario);
          httpSession.setAttribute("rol", usuarioConsulta.getRol().getId());
          this.rol = usuarioConsulta.getRol().getId();

          if (this.rol == 1) {
            RequestContext.getCurrentInstance()
                .execute(
                    "mostrarMenu('liParametros,liUsuario,liPropietarios,liAuxiliar,liInformes')");
          } else if (this.rol == 2) {
            RequestContext.getCurrentInstance().execute("mostrarMenu('liAuxiliar')");
          } else if (this.rol == 3) {
            RequestContext.getCurrentInstance().execute("mostrarMenu('liPropietarios')");
          }

          return "principal";
        }
      }

      this.transaction.commit();

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_ERROR,
                  "Error de acceso ",
                  " Usuario o contraseña incorrecto"));
      this.usuario = null;
      this.contrasenia = null;

      return "/index";

    } catch (Exception ex) {
      if (this.transaction != null) {
        this.transaction.rollback();
      }

      FacesContext.getCurrentInstance()
          .addMessage(
              null,
              new FacesMessage(
                  FacesMessage.SEVERITY_FATAL,
                  "Error fatal",
                  ex.getMessage() + " Contacte al administrador"));

      return null;
    } finally {
      if (this.transaction != null) {
        this.session.close();
      }
    }
  }