示例#1
0
  public boolean getIsShowRec(String areaID, String userName) throws BusinessException {
    boolean returnBln = false;

    Connection myConn = DAOFactory.getInstance().getConnection();
    Statement statement = null;
    try {
      statement = myConn.createStatement();
      String tempSql =
          "select IS_DISPLAY_REC from AS_DESKTOP "
              + "where AREA_ID='"
              + areaID
              + "' and USER_ID='"
              + userName
              + "'";
      ResultSet rs = statement.executeQuery(tempSql);
      if (rs.next()) {
        String tempStr = rs.getString("IS_DISPLAY_REC");
        returnBln = tempStr == null ? false : tempStr.equalsIgnoreCase("y");
      } else {
        throw new BusinessException("数据库中没有,区域号:" + areaID + "   用户名:" + userName + " 的信息!");
      }

    } catch (SQLException ex) {
      throw new RuntimeException("DeskTopBean类的areaNametoID方法:在桌面的区域中" + "加入部件时,SQL语句执行错误!");
    } finally {
      DBHelper.closeConnection(myConn, statement, null);
    }
    return returnBln;
  }
示例#2
0
 public static String getKeyStringFromDB() {
   String sql = " select value from as_info where key = ? ";
   if (DAOFactory.getWhichFactory() == DAOFactory.MSSQL) {
     sql = " select value from as_info where [key] = ? ";
   }
   return (String) DBHelper.queryOneValue(sql, new Object[] {LICENSE_KEY});
 }
示例#3
0
  public String getie5menu() {
    StringBuffer sb = new StringBuffer();

    sb.append(
        "<div id=\"ie5menu\" class=\"rightKeyMenu\" onMouseover=\"highlightie5()\" onMouseout=\"lowlightie5()\">");
    sb.append(
        "<div id=\"ie5new\" class=\"menuitems\" onclick=\"gotoNewPage()\">&nbsp;&nbsp;新窗口打开</div>");
    sb.append("      <hr>");
    // sb.append(" <div id=\"ie5add\" class=\"menuitems\"
    // onclick=\"addToFavorite()\">&nbsp;&nbsp;加入收藏夹</div>");
    // sb.append("<div id=\"ie5del\" class=\"menuitems\"
    // onclick=\"delFromFavorite()\">&nbsp;&nbsp;从收藏夹删除</div>");
    Connection conn = null;
    Statement statement = null;
    ResultSet rs = null;
    int i = 0;
    try {
      StringBuffer sql = new StringBuffer();
      sql.append("select DISTINCT AREA_ID,AREA_NAME,AREA_INDEX from AS_DESKTOP where USER_ID= '");
      sql.append(this.userID);
      sql.append("'");
      sql.append(" order by AREA_INDEX");
      conn = DAOFactory.getInstance().getConnection();

      statement = conn.createStatement();
      rs = statement.executeQuery(sql.toString());

      while (rs.next()) {
        sb.append(
            "         <div id=\"ie5add"
                + i
                + "\" class=\"menuitems\" onclick=\"addToA()\">&nbsp;&nbsp;");
        sb.append("加入");
        sb.append(rs.getString("AREA_NAME"));
        sb.append("</div>");
        i++;
        if (i == 4) {
          break;
        }
      }
    } catch (SQLException ex) {
      throw new RuntimeException("DeskTopBean类的getIe5menu方法:" + "SQL语句执行错误!" + ex.toString());
    } finally {
      DBHelper.closeConnection(conn, statement, rs);
    }
    sb.append("  </div>");

    return sb.toString();
  }
示例#4
0
 public static String getDBServerURL() {
   Connection conn = null;
   try {
     conn = DAOFactory.getInstance().getConnection();
     if (conn != null) {
       DatabaseMetaData meta = conn.getMetaData();
       return (meta.getURL() + ":" + meta.getUserName()).toUpperCase();
     }
   } catch (SQLException e) {
     e.printStackTrace();
   } finally {
     DBHelper.closeConnection(conn);
   }
   return "";
 }
示例#5
0
  /** 修改口令 */
  public boolean changePasswd() {
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    java.util.Date currDate = new java.util.Date();
    String nowtime = formatter.format(currDate);

    String sqlStr = null;
    PreparedStatement pst = null;

    if (userId != null && !userId.equals("")) {
      Connection conn = DAOFactory.getInstance().getConnection();
      try {
        boolean autoCommit = conn.getAutoCommit();
        conn.setAutoCommit(false);

        sqlStr = " update AS_USER set PASSWD = ? ,MODI_TIME = ? where USER_ID = ? ";
        pst = conn.prepareStatement(sqlStr);

        int i = 1;
        pst.setString(i++, newPassword);
        pst.setString(i++, nowtime);
        pst.setString(i++, userId);

        int infectedRows = pst.executeUpdate();
        if (infectedRows > 1) {
          conn.rollback();
          conn.setAutoCommit(autoCommit);
          log.error(sqlStr);
          // System.out.println("非法修改口令,请系统管理员检查系统日志(rolling.log)。");
          return false;
        }

        conn.commit();
        conn.setAutoCommit(autoCommit);

        return true;
      } catch (SQLException se) {
        throw new RuntimeException("类SavePasswordAction方法changePasswd()出错:" + se.getMessage());
      } finally {
        DBHelper.closeConnection(conn, pst, null);
      }
    }
    return false;
  }
示例#6
0
  /**
   * 验证口令
   *
   * @return flag boolean变量
   */
  public boolean checkPasswd() {
    boolean flag = false;
    String sqlStr = null;
    ResultSet rs = null;
    PreparedStatement pst = null;
    sqlStr = "select PASSWD from AS_USER where USER_ID = ?";

    if (userId != null && oldPassword != null) {
      Connection conn = DAOFactory.getInstance().getConnection();
      try {
        pst = conn.prepareStatement(sqlStr);
        int i = 1;
        pst.setString(i++, userId);

        rs = pst.executeQuery();
        if (rs.next()) {
          String p = rs.getString(1);
          if (p != null && p.equals("")) {
            p = null;
          }
          if (oldPassword != null && oldPassword.equals("")) {
            oldPassword = null;
          }
          if (p == null) {
            if (oldPassword == null) {
              flag = true;
            }
          } else {
            if (oldPassword != null && p.equals(oldPassword)) {
              flag = true;
            }
          }
        }
      } catch (SQLException se) {
        throw new RuntimeException("类SavPasswordAction方法checkPasswd()出错:" + se.getMessage());
      } finally {
        DBHelper.closeConnection(conn, pst, rs);
      }
    }
    return flag;
  }
示例#7
0
  public void init() {

    Connection conn = null;
    Statement statement = null;
    ResultSet rs = null;
    int i = 0;
    StringBuffer sql = new StringBuffer();
    StringBuffer insertSql = new StringBuffer();
    try {
      DesktopArea desktopArea;
      sql.append("select DISTINCT AREA_ID, AREA_INDEX, DISPLAY_AMOUNT, ");
      sql.append("IS_DISPLAY_REC from AS_DESKTOP where USER_ID='");
      sql.append(this.getUserID());
      sql.append("' order by AREA_INDEX ");
      conn = DAOFactory.getInstance().getConnection();

      statement = conn.createStatement();
      rs = statement.executeQuery(sql.toString());
      while (rs.next()) {
        boolean tempBln = rs.getString("IS_DISPLAY_REC").equalsIgnoreCase("Y");
        desktopArea =
            DesktopArea.getInstanceFromDB(rs.getString("AREA_ID"), this.request, this.getUserID());
        desktopArea.setDisplayAmount(rs.getInt("DISPLAY_AMOUNT"));
        desktopArea.setIsDisplayRec(tempBln);
        this.deskTopAreas.put(new Integer(i + 1), desktopArea);
        i++;
        if (i == 4) {
          break;
        }
      }
      if (i == 0) {
        insertSql.append(
            "insert into AS_DESKTOP (AREA_ID, USER_ID,AREA_NAME,  AREA_INDEX, AREA_IMG) ");
        insertSql.append("SELECT AREA_ID,'");
        insertSql.append(this.getUserID());
        insertSql.append("', AREA_NAME, AREA_INDEX, AREA_IMG ");
        insertSql.append("FROM AS_DESKTOP WHERE USER_ID='sa'");
        if (statement.executeUpdate(insertSql.toString()) > 0) {
          rs = statement.executeQuery(sql.toString());
          while (rs.next()) {
            desktopArea =
                DesktopArea.getInstanceFromDB(
                    rs.getString("AREA_ID"), this.request, this.getUserID());
            this.deskTopAreas.put(new Integer(i + 1), desktopArea);
            i++;
            if (i == 4) {
              break;
            }
          }
        }
      }
    } catch (SQLException ex) {
      if (i == 0) {
        System.out.println(insertSql);
      } else {
        System.out.println(sql);
      }
      ex.printStackTrace();
      log.error(ex);
      throw new RuntimeException("DeskTopBean类的init方法:" + "SQL语句执行错误!", ex);
    } catch (BusinessException ex) {
      log.error(ex);
      throw new RuntimeException("DeskTopBean类的init方法:" + "出现业务异常!", ex);
    } finally {
      DBHelper.closeConnection(conn, statement, rs);
    }
  }
示例#8
0
  public String doExecute() {
    String cond = condition;
    String searCond = this.searchCond;
    if (!type.equalsIgnoreCase(ADVANCED_SEARCH) && !type.equalsIgnoreCase(ADVANCED_PAGINATION)) {
      if (searCond != null && !searCond.equals("")) {
        if (cond.equals("")) {
          cond = searCond;
        } else {
          cond += ";" + searCond;
        }
      }
    }

    Map paramsMap = new HashMap();
    DBHelper.parseParamsSimpleForSql(cond, paramsMap);

    if (userid == null) userid = (String) paramsMap.get("userid");

    // System.out.println("######################################################");
    // System.out.println("userId:" + userid);
    String userNumLimCondition = "";

    if (masterTableName != null
        && masterTableName.length() > 0
        && masterCompoName != null
        && masterCompoName.length() > 0) {
      if (masterTableName.equals(MetaManager.getCompoMeta(masterCompoName).getMasterTable())) {
        String realFieldName = request.getParameter("realFieldName");
        List realFieldNameList = java.util.Arrays.asList(realFieldName.split(","));

        TableMeta tableMeta = MetaManager.getTableMeta(masterTableName);
        if (masterSelectField != null && masterSelectField.length() > 0) {
          String[] sTemp = masterSelectField.split(",");
          for (int i = 0; i < sTemp.length; i++) {
            Field field = tableMeta.getField(sTemp[i]);
            if (field == null
                || !realFieldNameList.contains(
                    field.getRefField())) { // 主表选择字段对应的外部实体字段与外部实体的实际选择字段比较
              continue;
            }
            if (!field.isSave()) { // 非保存字段,查询此外部实体对应的其他保存字段的数值权限
              List fields = ((Foreign) tableMeta.getForeign(field.getRefName())).getFields();
              for (int j = 0; j < fields.size(); j++) {
                Field tField = (Field) fields.get(i);
                String fieldName = tField.getName();
                if (sTemp[i].equals(fieldName) || !tField.isSave()) continue;

                String refFieldName = tField.getRefField();

                String iCond = getListUserLimCondition(refFieldName, fieldName);
                if (iCond != null && iCond.length() > 0) {
                  if (userNumLimCondition.length() > 0) {
                    userNumLimCondition += " and " + iCond;
                  } else {
                    userNumLimCondition = iCond;
                  }
                }
              }
            } else { // 保存字段,添加数值权限
              String iCond = getListUserLimCondition(field.getRefField(), sTemp[i]);
              if (iCond != null && iCond.length() > 0) {
                if (userNumLimCondition.length() > 0) {
                  userNumLimCondition += " and " + iCond;
                } else {
                  userNumLimCondition = iCond;
                }
              }
            }
          }
        }
      }
    }

    String quotUserNumLim =
        RightUtil.getUserNumLimCondition(
            ServletActionContext.getRequest(), userid, "fquote", componame, null, null);
    // System.out.println("svCoCode:" + SessionUtils.getAttribute(request, "svCoCode"));
    // System.out.println("quotUserNumLim:" + quotUserNumLim);
    if (userNumLimCondition != null && userNumLimCondition.length() > 0) {
      if (quotUserNumLim != null && quotUserNumLim.length() > 0) {
        userNumLimCondition += " and ";
        userNumLimCondition += quotUserNumLim;
      }
    } else {
      if (quotUserNumLim != null && quotUserNumLim.length() > 0) {
        userNumLimCondition = quotUserNumLim;
      }
    }

    if (type.equalsIgnoreCase(ADVANCED_SEARCH)
        || type.equalsIgnoreCase(ADVANCED_PAGINATION)) { // 搜索类型为高级搜索时,将搜索条件附加上;
      if (userNumLimCondition != null && userNumLimCondition.length() > 0)
        userNumLimCondition += " and ";
      searCond = searCond.replaceAll(";", " and "); // 将;替换为and
      userNumLimCondition += searCond;
    }
    provider.setUserNumLimCondition(userNumLimCondition);

    // System.out.println("userNumLimCondition:" + userNumLimCondition);

    int pageIndex = Pub.calcPageIndex(currentpage, direction, pagesize, totalcount);
    if (pageIndex <= 0) pageIndex = 1;
    int rowmin = (pageIndex - 1) * pagesize + 1;
    int rowmax = pageIndex * pagesize;

    Datum datum = null;
    if (isFromSql && (sqlid == null || sqlid.length() == 0)) { // sqlid为空直接查询表
      DBSupport support = (DBSupport) ApplusContext.getBean("dbSupport");
      List newParams = new ArrayList();

      String matchCond = (String) paramsMap.get("matchCond"); // 仅添加搜索框的条件
      paramsMap = new HashMap();

      if (matchCond != null) {
        List saveFieldNames = MetaManager.getTableMeta(tablename).getSaveFieldNames();
        for (int i = 0; i < saveFieldNames.size(); i++)
          paramsMap.put(saveFieldNames.get(i), matchCond);
      }

      String sql = support.wrapSqlByTableName(tablename, paramsMap, newParams);

      if (matchCond != null) {
        sql = sql.replaceAll("[=]", "like");
        sql = sql.replaceAll("and", "or");
      }

      StringBuffer orderStr = new StringBuffer(""); // 排序和年度
      TableMeta tableMeta = MetaManager.getTableMeta(tablename);
      List keyFieldNames = tableMeta.getKeyFieldNames();
      if (keyFieldNames != null) {
        orderStr.append(" order by ");
        for (int i = 0; i < keyFieldNames.size(); i++) {
          orderStr.append(keyFieldNames.get(i) + ",");
          if ("ND".equalsIgnoreCase((String) keyFieldNames.get(i))) {
            sql =
                support.wrapSqlByCondtion(sql, "ND=" + SessionUtils.getAttribute(request, "svNd"));
          }
        }
      }

      if (orderStr.toString().endsWith(",")) {
        sql += orderStr.substring(0, orderStr.length() - 1);
      }

      if (totalcount < 0)
        totalcount = provider.getTotalCount(support.wrapSqlForCount(sql), newParams);
      if (totalcount <= 0) { // 没有数据
        return SUCCESS;
      }

      // System.out.println("sql:" + sql);
      paramsMap.put("rownum", rowmax + "");
      paramsMap.put("rn", rowmin + "");
      newParams.add(rowmax + "");
      newParams.add(rowmin + "");
      if (userNumLimCondition != null && userNumLimCondition.length() > 0) {
        sql = support.wrapSqlByCondtion(sql, userNumLimCondition);
      }
      sql = support.wrapPaginationSql(sql);
      datum =
          provider.getPaginationData(
              pageIndex, totalcount, pagesize, tablename, sql, newParams, false);
    } else {
      if (totalcount < 0) { // 取总条数
        totalcount = provider.getTotalCount(sqlid, paramsMap);
      }
      if (totalcount <= 0) { // 没有数据
        return SUCCESS;
      }

      paramsMap.put("rownum", rowmax + "");
      paramsMap.put("rn", rowmin + "");

      // 取分页数据
      datum =
          provider.getPaginationData(
              pageIndex, totalcount, pagesize, tablename, sqlid, paramsMap, false);
    }

    int totalPage = totalcount % pagesize == 0 ? totalcount / pagesize : totalcount / pagesize + 1;
    StringBuffer sb = new StringBuffer();
    sb.append("<?xml version=\"1.0\" encoding=\"GBK\"?>\n");
    List data = datum.getData();
    if (data != null) {
      sb.append(
          "<delta totalCount=\""
              + totalcount
              + "\" totalPage=\""
              + totalPage
              + "\" currentPage=\""
              + pageIndex
              + "\" pageSize=\""
              + pagesize
              + "\">\n");
      for (int i = 0; i < data.size(); i++) {
        sb.append("<entity name=\"null\">\n");
        Map map = (Map) data.get(i);
        Set entrySet = map.entrySet();
        Iterator itera = entrySet.iterator();
        while (itera.hasNext()) {
          Entry entry = (Entry) itera.next();
          sb.append("<field name=\"");
          sb.append(entry.getKey());
          sb.append("\" value=\"");
          sb.append(
              entry.getValue() == null
                  ? ""
                  : XMLTools.getValidStringForXML(entry.getValue().toString()));
          sb.append("\"/>\n");
        }
        sb.append("</entity>\n");
      }
      sb.append("</delta>\n");
    }

    // System.out.println("######################################################");

    resultstring = sb.toString();
    return SUCCESS;
  }