示例#1
0
  public String onDelete() {
    try {
      Session session = getSession();
      Long id = 0l;
      if (role.getId() > 0) {
        id = role.getId();
      } else if (getRequest().getParameter("id") != null) {
        id = Long.parseLong(getRequest().getParameter("id"));
      }
      if (id != null && id > 0) {
        Roles temp = new Roles();
        temp = (Roles) session.get(Roles.class, id);
        session.delete(temp);
        session.flush();
      }

      jsonDataGrid.setLabel("SUCCESS");
      jsonDataGrid.setCustomInfo("Delete Thành Công!");
      if (getRequest().getParameter("id") == null) {
        role = new Roles();
        onSearch();
      }
    } catch (Exception ex) {
      jsonDataGrid.setLabel("ERROR");
      jsonDataGrid.setCustomInfo(ex.getMessage());
    }
    return "jsonDataGrid";
  }
示例#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";
  }
示例#3
0
 public String onActive() {
   try {
     Session session = getSession();
     if (getRequest().getParameter("id") != null && getRequest().getParameter("active") != null) {
       Roles temp = new Roles();
       temp = (Roles) session.get(Roles.class, Long.parseLong(getRequest().getParameter("id")));
       if ("Y".equals(getRequest().getParameter("active"))) {
         temp.setIsactive("N");
       } else {
         temp.setIsactive("Y");
       }
       session.update(temp);
       session.flush();
     }
     jsonDataGrid.setLabel("SUCCESS");
     jsonDataGrid.setCustomInfo("Cập Nhật Trạng Thái Thành Công!");
     //            onSearch();
   } catch (Exception ex) {
     jsonDataGrid.setLabel("ERROR");
     jsonDataGrid.setCustomInfo(ex.getMessage());
   }
   return "jsonDataGrid";
 }
示例#4
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;
  }
示例#5
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";
 }
示例#6
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);
    }
  }