Example #1
0
  public String onUpdate() {
    try {
      Session session = getSession();
      Long id = pattern.getId();
      if (id != null && id > 0) {
        Pattern temp = new Pattern();
        temp = (Pattern) session.get(Pattern.class, id);
        temp.setType(pattern.getType());
        temp.setPattern(pattern.getPattern());
        temp.setValue(pattern.getValue());
        temp.setPriority(pattern.getPriority());
        temp.setUseFor(pattern.getUseFor());
        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";
  }
Example #2
0
  public String onDelete() {
    try {
      Session session = getSession();
      Long id = 0l;
      if (pattern.getId() > 0) {
        id = pattern.getId();
      } else if (getRequest().getParameter("id") != null) {
        id = Long.parseLong(getRequest().getParameter("id"));
      }
      if (id != null && id > 0) {
        Pattern temp = new Pattern();
        temp = (Pattern) session.get(Pattern.class, id);
        session.delete(temp);
        session.flush();
      }

      jsonDataGrid.setLabel("SUCCESS");
      jsonDataGrid.setCustomInfo("Delete Thành Công!");
      if (getRequest().getParameter("id") == null) {
        pattern = new Pattern();
        onSearch();
      }

    } catch (Exception ex) {
      jsonDataGrid.setLabel("ERROR");
      jsonDataGrid.setCustomInfo(ex.getMessage());
    }
    return "jsonDataGrid";
  }
Example #3
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";
  }
Example #4
0
  public void setMaxResult() {
    try {
      StringBuilder sql = new StringBuilder("select count(*) from Pattern where 1=1 ");
      ArrayList param = new ArrayList();

      if (pattern != null) {

        if (pattern.getType() != null && !"".equals(pattern.getType())) {
          sql.append(" AND type = ? ");
          param.add(pattern.getType());
        }
        if (pattern.getPattern() != null && !"".equals(pattern.getPattern())) {
          sql.append(" AND pattern = ? ");
          param.add(pattern.getPattern());
        }
        if (pattern.getValue() != null && !"".equals(pattern.getValue())) {
          sql.append(" AND value = ? ");
          param.add(pattern.getValue());
        }
        if (pattern.getPriority() != null) {
          sql.append(" AND priority = ? ");
          param.add(pattern.getPriority());
        }
        if (pattern.getUseFor() != null && !"".equals(pattern.getUseFor())) {
          sql.append(" AND usefor = ? ");
          param.add(pattern.getUseFor());
        }
        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);
    }
  }
Example #5
0
  public String onSearch() {
    try {
      //            UserToken userToken = (UserToken)
      // getRequest().getSession().getAttribute("userToken");
      if (getRequest().getSession().getAttribute("isactive") != null) {
        isactive = getRequest().getSession().getAttribute("isactive").toString();
        getRequest().getSession().removeAttribute("isactive");
      }
      setMaxResult();
      List<Pattern> lstResult = new ArrayList<Pattern>();
      lstResult = takePatterns();
      jsonDataGrid.setItems(lstResult);

    } catch (Exception ex) {
      jsonDataGrid.setLabel("ERROR");
      jsonDataGrid.setCustomInfo(ex.getMessage());
    }
    return "jsonDataGrid";
  }
  public void setMaxResult() {
    try {
      String sql = takeSQL("count");

      SQLQuery query = getSession().createSQLQuery(sql.toString());
      for (int i = 0; i < param.size(); i++) {
        query.setParameter(i, param.get(i));
      }

      List lst = query.list();
      Integer countRecord = (Integer) lst.get(0);
      if (String.valueOf(count).length() >= 6) {
        count = countRecord.intValue();
      }
      jsonDataGrid.setTotalRows(countRecord.intValue());
    } catch (Exception ex) {
      jsonDataGrid.setTotalRows(0);
      ex.printStackTrace();
    }
  }
Example #7
0
 public String onInsert() {
   try {
     Session session = getSession();
     HashMap<String, Object> map = new HashMap<String, Object>();
     map.put("type", pattern.getType());
     map.put("pattern", pattern.getPattern());
     map.put("value", pattern.getValue());
     List checks = findByProperty(Pattern.class, map);
     if (checks != null && checks.size() > 0) {
       jsonDataGrid.setLabel("ERROR");
       jsonDataGrid.setCustomInfo("Đã tồn tại bộ giá trị trên!");
     } else {
       if (pattern.getIsactive() == null) pattern.setIsactive('Y');
       Date date = new Date();
       pattern.setCreateDate(date);
       pattern.setLastUpdate(date);
       session.save(pattern);
       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";
 }
Example #8
0
 public String onActive() {
   try {
     Session session = getSession();
     if (getRequest().getParameter("id") != null && getRequest().getParameter("active") != null) {
       Pattern temp = new Pattern();
       temp =
           (Pattern) session.get(Pattern.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!");
   } catch (Exception ex) {
     jsonDataGrid.setLabel("ERROR");
     jsonDataGrid.setCustomInfo(ex.getMessage());
   }
   return "jsonDataGrid";
 }
  public String onSearch() {
    try {
      //            UserToken userToken = (UserToken)
      // getRequest().getSession().getAttribute("userToken");
      setMaxResult();
      List<Tablet> lstResult = new ArrayList<Tablet>();
      lstResult = takeTablets();

      jsonDataGrid.setItems(lstResult);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return "jsonDataGrid";
  }
Example #10
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";
 }