Ejemplo n.º 1
0
  public List<Roles> takeRoles() {
    List<Roles> lst = null;
    String sortType = null;
    try {
      Session session = getSession();
      if (sort != null) {
        if (sort.indexOf('-') != -1) {
          sortType = "asc";
          sort = sort.substring(1);
        } else {
          sortType = "desc";
        }
      }

      Criteria cri = session.createCriteria(Roles.class);

      if (role != null) {

        if (role.getValue() != null && !"".equals(role.getValue())) {
          cri.add(Restrictions.eq("value", role.getValue()));
        }
        if (role.getName() != null && !"".equals(role.getName())) {
          cri.add(Restrictions.eq("name", role.getName()));
        }

        if (isactive != null) {
          cri.add(Restrictions.eq("isactive", "Y"));
        } else {
          cri.add(Restrictions.eq("isactive", "N"));
        }
      }

      if (sort != null) {
        if (sortType != null && sortType.equals("asc")) {
          cri.addOrder(Order.asc(sort).ignoreCase());
        } else if (sortType != null && sortType.equals("desc")) {
          cri.addOrder(Order.desc(sort).ignoreCase());
        }
      } else {
        cri.addOrder(Order.desc("lastUpdate").ignoreCase());
      }
      if (startval >= 0) {
        cri.setFirstResult(startval);
      }
      if (count >= 0) {
        cri.setMaxResults(count);
      }
      lst = cri.list();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return lst;
  }
Ejemplo n.º 2
0
  public String onUpdate() {
    try {
      Session session = getSession();
      Long id = role.getId();
      if (id != null && id > 0) {
        Roles temp = new Roles();
        temp = (Roles) session.get(Roles.class, id);
        temp.setValue(role.getValue());
        temp.setName(role.getName());
        if (isactive != null) {
          temp.setIsactive("Y");
        } else {
          temp.setIsactive("N");
        }

        session.update(temp);
        session.flush();
      }
      jsonDataGrid.setLabel("SUCCESS");
      jsonDataGrid.setCustomInfo("Update Thành Công!");
      onSearch();
    } catch (Exception ex) {
      jsonDataGrid.setLabel("ERROR");
      jsonDataGrid.setCustomInfo(ex.getMessage());
    }
    return "jsonDataGrid";
  }
Ejemplo n.º 3
0
  public void setMaxResult() {
    try {
      StringBuilder sql = new StringBuilder("select count(*) from Roles where 1=1 ");
      ArrayList param = new ArrayList();

      if (role != null) {

        if (role.getValue() != null && !"".equals(role.getValue())) {
          sql.append(" AND value = ? ");
          param.add(role.getValue());
        }
        if (role.getName() != null && !"".equals(role.getName())) {
          sql.append(" AND name = ? ");
          param.add(role.getName());
        }

        if (isactive != null) {
          sql.append(" AND isactive = 'Y' ");
        } else {
          sql.append(" AND isactive = 'N' ");
        }
      }

      Query query = getSession().createQuery(sql.toString());
      for (int i = 0; i < param.size(); i++) {
        query.setParameter(i, param.get(i));
      }
      List lst = query.list();
      Long countRecord = (Long) lst.get(0);
      if (String.valueOf(count).length() >= 6) {
        count = countRecord.intValue();
      }
      jsonDataGrid.setTotalRows(countRecord.intValue());
    } catch (Exception ex) {
      jsonDataGrid.setTotalRows(0);
    }
  }
Ejemplo n.º 4
0
 public String onInsert() {
   try {
     Session session = getSession();
     HashMap<String, Object> map = new HashMap<String, Object>();
     map.put("value", role.getValue());
     List checks = findByProperty(Roles.class, map);
     if (checks != null && checks.size() > 0) {
       jsonDataGrid.setLabel("ERROR");
       jsonDataGrid.setCustomInfo("Đã tồn tại Role trên!");
     } else {
       session.save(role);
       session.flush();
       jsonDataGrid.setLabel("SUCCESS");
       jsonDataGrid.setCustomInfo("Insert Thành Công!");
     }
     onSearch();
   } catch (Exception ex) {
     jsonDataGrid.setLabel("ERROR");
     jsonDataGrid.setCustomInfo(ex.getMessage());
   }
   return "jsonDataGrid";
 }