Пример #1
0
  public HashMap<String, Object> getAllData(
      String strpage, String strpagesize, String filter, String lang) {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    HashMap<String, Object> datas = null;
    ArrayList<HashMap<String, Object>> items = null;
    HashMap<String, Object> tmp = null;
    Singleton s = Singleton.getInstance();
    int cnt = 0;
    int page = 0;
    int pagesize = 0;
    int totalRow = 0;
    try {
      conn = this.dbobj.getConnection(ConnectionType.SYS);
      ps =
          conn.prepareStatement(
              this.cmd.getAllData(filter),
              ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_READ_ONLY);
      ps.setString(1, lang);
      rs = ps.executeQuery();
      items = new ArrayList<HashMap<String, Object>>();
      if (DCIString.isNullOrEmpty(strpage)) {
        page = 1;
      } else {
        page = Integer.parseInt(strpage);
      }
      if (DCIString.isNullOrEmpty(strpagesize)) {
        pagesize = APConstants.getDefaultpagesize();
      } else {
        pagesize = Integer.parseInt(strpagesize);
      }
      if (rs.next()) {
        rs.last();
        totalRow = rs.getRow();
        rs.beforeFirst();
        if ((page - 1) * pagesize <= totalRow) {
          if ((page - 1) * pagesize != 0) {
            rs.absolute((page - 1) * pagesize);
          }
          cnt = 1;
          while (rs.next()) {
            tmp = new HashMap<String, Object>();
            tmp.put("id", cnt);
            tmp.put("icon_id", rs.getString("icon_id"));
            tmp.put("icon_name", rs.getString("icon_name"));
            tmp.put("icon_show_name", s.getLanguage(lang, rs.getString("icon_name")));
            tmp.put("icon_map_key", rs.getString("icon_map_key"));
            tmp.put("icon_path", rs.getString("icon_path"));
            tmp.put("icon_type", rs.getString("icon_type"));
            tmp.put("icon_id_show", DCIString.Base64Encode(rs.getString("icon_id")));
            tmp.put(
                "icon_names",
                s.getLanguage("CHS", rs.getString("icon_name"))
                    + "$"
                    + s.getLanguage("CHT", rs.getString("icon_name")));
            items.add(tmp);
            cnt++;
            if (cnt > pagesize) {
              break;
            }
          }
        }
      } else {
        totalRow = 0;
      }

      datas = new HashMap<String, Object>();
      datas.put("items", items);
      datas.put("total", totalRow);

    } catch (Exception ex) {
      ex.printStackTrace();
    } finally {
      this.dbctrl.closeConnection(rs, ps, conn);
    }

    // System.out.println("execute getAllUserInfo");

    return datas;
  }
Пример #2
0
  public HashMap<String, Object> saveData(
      String formDatas, String mode, FileUploadBean file, String lang) {
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    HashMap<String, Object> datas = null;
    HashMap<String, Object> result = null;
    HashMap<String, Object> resultdata = null;
    String sql = null;
    boolean boolResult = false;
    String resultMsg = "";
    String newid = null;
    String filePath = null;
    String filename = null;
    String mapkey = null;
    String iconname = null;
    String[][] langValue = null;
    String[] langtmp = null;

    try {
      datas = DCIString.jsonTranToObjMap(formDatas); // new
      // ObjectMapper().readValue(formDatas,
      // HashMap.class);
      conn = this.dbobj.getConnection(ConnectionType.SYS);

      if (mode.equals("Add")) {
        sql = this.cmd.addData();
        newid = getMaxID(conn);
        if (file == null || file.getFile() == null) {
          throw new Exception("no file upload");
        } else {
          filename = file.getFile().getOriginalFilename();
          filename = newid + filename.substring(filename.lastIndexOf(46));
          filePath =
              new ConfigControl(false, null).getConfigXMLPath()
                  + File.separator
                  + APConstants.getUploadicondir()
                  + File.separator
                  + filename;
          if (new APPubMethods().saveUploadFile(filename, file)) {
            throw new Exception("save file fail");
          }
        }
        mapkey = getMaxKey(conn);
      } else {
        sql = this.cmd.updateData();
        newid = datas.get("icon_id").toString();
        filePath = datas.get("icon_path").toString();
        mapkey = datas.get("icon_map_key").toString();
      }

      if (datas.get("icon_name") == null
          || DCIString.isNullOrEmpty(datas.get("icon_name").toString())) {
        iconname = newid;
      } else {
        iconname = datas.get("icon_name").toString();
      }

      ps =
          conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);

      ps.setString(1, iconname);
      ps.setString(2, mapkey);
      ps.setString(3, filePath);
      ps.setString(4, datas.get("icon_type").toString());
      ps.setString(5, newid);
      ps.executeUpdate();

      langValue = new String[2][];

      if (datas.get("icon_names") == null
          || DCIString.isNullOrEmpty(datas.get("icon_names").toString())
          || datas.get("icon_names").toString().indexOf("$") == -1
          || datas.get("icon_names").toString().length() == 1) {
        langValue[0] = new String[] {"CHS", iconname, ""};
        langValue[1] = new String[] {"CHT", iconname, ""};
      } else {
        langtmp = datas.get("icon_names").toString().split("\\$");
        if (langtmp.length == 2) {
          langValue[0] =
              new String[] {"CHS", iconname, datas.get("icon_names").toString().split("\\$")[0]};
          langValue[1] =
              new String[] {"CHT", iconname, datas.get("icon_names").toString().split("\\$")[1]};
        } else {
          if (datas.get("icon_names").toString().startsWith("$")) {
            langValue[0] = new String[] {"CHS", iconname, ""};
            langValue[1] =
                new String[] {"CHT", iconname, datas.get("icon_names").toString().split("\\$")[1]};
          } else {
            langValue[0] =
                new String[] {"CHS", iconname, datas.get("icon_names").toString().split("\\$")[0]};
            langValue[1] = new String[] {"CHT", iconname, ""};
          }
        }
      }

      saveLangs(conn, langValue);
      resultdata = getAllData("1", "1", " and icon_id = '" + newid + "'", lang);

      boolResult = true;
    } catch (Exception ex) {
      ex.printStackTrace();
      boolResult = false;
      resultMsg = ex.getMessage();
    } finally {
      this.dbctrl.closeConnection(rs, ps, conn);
      result = new HashMap<String, Object>();
      result.put("success", boolResult);
      result.put("resultData", resultdata);
      result.put("errorMessage", resultMsg);
    }
    return result;
  }