Exemplo n.º 1
0
 public static String escapeBadSqlPatternChars(String s) {
   StringBuffer sb = new StringBuffer(s);
   for (int i = 0, len = sb.length(); i < len; ++i)
     if (sb.charAt(i) == '\'') {
       sb.insert(i, '\'');
       ++len;
       i += 2;
     }
   return sb.toString();
 }
 // returns column list: column-id, column-id ...
 private String getColumnLists(String tableName) {
   List<String> colNames = (List<String>) tableCols.get(tableName);
   StringBuffer aStr = new StringBuffer("  ");
   for (int i = 0; i < colNames.size(); i++) {
     if (SQLTest.random.nextBoolean()) {
       aStr.append(colNames.get(i) + ", ");
     }
   }
   if (aStr.charAt(aStr.length() - 2) == ',') {
     aStr.deleteCharAt(aStr.length() - 2);
   }
   aStr.deleteCharAt(0); // delete the leading space
   if (aStr.length() != 1) {
     aStr.insert(1, '(');
     aStr.append(')');
   } // has column
   return aStr.toString();
 }
Exemplo n.º 3
0
  /**
   * Modifies the DO within its table. Performs recursive commit/delete on referenced DOs; all
   * operations occur within a single transaction to allow rollback in the event of error. Only the
   * creator of the transaction releases it.
   *
   * @param dbt The transaction object to use for this operation.
   * @param delete True if doing a delete, otherwise doing insert/update.
   * @exception com.lutris.appserver.server.sql.DatabaseManagerException if a Transaction can not be
   *     created.
   * @exception RefAssertionException thrown by okTo method.
   * @exception java.sql.SQLException if any SQL errors occur.
   */
  protected void modifyDO(DBTransaction dbt, boolean delete)
      throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException,
          DBRowUpdateException, QueryException {
    boolean ownTransaction = false;
    try {
      if (null == dbt) {
        DatabaseManager dbm = Enhydra.getDatabaseManager();
        dbt = dbm.createTransaction(); // create a transaction
        ownTransaction = true;
      }
      if (null == dbt)
        throw new DatabaseManagerException("DatabaseManager.createTransaction returned null.");
      if (delete) {
        // Code to perform cascading deletes is generated here
        // if cascading deletes are not supported by the database.

        // The following line keeps the compiler happy
        // when the CASCADING_DELETES tag is empty.
        if (false) throw new QueryException("XXX");
      } else {
        // commit referenced DOs.
        jobmatch.data.CandidateDO Candidate_DO = DO.getCandidate();
        if (null != Candidate_DO) {
          if (Candidate_DO.isLoaded()) {
            okToCommitCandidate(Candidate_DO);
            jobmatch.data.CandidateBDO b = jobmatch.data.CandidateBDO.createExisting(Candidate_DO);
            b.commit(dbt);
          } else {
            // since the referenced DO is not loaded,
            // it cannot be dirty, so there is no need to commit it.
          }
        } else {
          if (!false)
            throw new RefAssertionException(
                "Cannot commit EmployerCandidateBDO ( "
                    + toString()
                    + " ) because Candidate is not allowed to be null.");
        }
        jobmatch.data.EmployerDO Employer_DO = DO.getEmployer();
        if (null != Employer_DO) {
          if (Employer_DO.isLoaded()) {
            okToCommitEmployer(Employer_DO);
            jobmatch.data.EmployerBDO b = jobmatch.data.EmployerBDO.createExisting(Employer_DO);
            b.commit(dbt);
          } else {
            // since the referenced DO is not loaded,
            // it cannot be dirty, so there is no need to commit it.
          }
        } else {
          if (!false)
            throw new RefAssertionException(
                "Cannot commit EmployerCandidateBDO ( "
                    + toString()
                    + " ) because Employer is not allowed to be null.");
        }
      }
      if (false) {
        // This throw is here to keep the compiler happy
        // in the case of a DO that does not refer to other DOs.
        // In that case, the above delete/commit code blocks will be empty
        // and throw nothing.
        throw new DataObjectException("foo");
      }
      if (delete) {
        dbt.delete(DO);
      } else {
        if (DO.isLoaded()) dbt.insert(DO); // dbt.insert() handles insertions and updates
      }
      if (ownTransaction) {
        dbt.commit(); // commit the transaction
      }
    } catch (DataObjectException doe) {
      throw doe;
    } catch (SQLException sqle) {
      StringBuffer message = new StringBuffer("Failed to insert/update DO: ");
      message.append(sqle.getMessage());

      // rollback, if necessary
      if (ownTransaction) {
        try {
          dbt.rollback();
        } catch (SQLException sqle2) {
          message.insert(0, "\n");
          message.insert(0, sqle2.getMessage());
          message.insert(0, "Rollback failed: ");
        }
      }
      throw new SQLException(message.toString());
    } finally {
      // release the transaction, if any
      if (ownTransaction) {
        dbt.release();
      }
    }
  }
  /**
   * 按条件查询多条数据
   *
   * @param conditions 查询条件
   * @param pageNo 页号
   * @param rowsPerPage 每页的行数
   * @return Collection
   * @throws Exception
   */
  public Collection findByConditions(String conditions, int pageNo, int rowsPerPage)
      throws Exception {
    StringBuffer buffer = new StringBuffer(200);
    // 拼SQL语句
    buffer.append("SELECT ");
    buffer.append("LineCode,");
    buffer.append("StatMonth,");
    buffer.append("PowerClass,");
    buffer.append("ElectricQuantity,");
    buffer.append("PointerQuantity,");
    buffer.append("SanXiaFee,");
    buffer.append("Surcharge,");
    buffer.append("SumFee,");
    buffer.append("ValidStatus,");
    buffer.append("Flag,");
    buffer.append("Remark,");
    buffer.append("TransLoss,");
    buffer.append("LineLoss,");
    buffer.append("UnPointerQuantity,");
    buffer.append("RateCode,");
    buffer.append("AdjustRate,");
    buffer.append("FarmUseScale,");
    buffer.append("FarmUsePrice,");
    buffer.append("FarmUseQuantity,");
    buffer.append("FarmUseFee,");
    buffer.append("ProductScale,");
    buffer.append("ProductPrice,");
    buffer.append("ProductQuantity,");
    buffer.append("ProductFee,");
    buffer.append("DenizenScale,");
    buffer.append("DenizenPrice,");
    buffer.append("DenizenQuantity,");
    buffer.append("DenizenFee,");
    buffer.append("UnDenizenScale,");
    buffer.append("UnDenizenPrice,");
    buffer.append("UnDenizenQuantity,");
    buffer.append("UnDenizenFee,");
    buffer.append("IndustryScale,");
    buffer.append("IndustryPrice,");
    buffer.append("IndustryQuantity,");
    buffer.append("IndustryFee,");
    buffer.append("BizScale,");
    buffer.append("BizPrice,");
    buffer.append("BizQuantity,");
    buffer.append("BizFee,");
    buffer.append("PowerRateFee,");
    buffer.append("UpCompany,");
    buffer.append("PowerFee,");
    buffer.append("InputDate,");
    buffer.append("Kv,");
    buffer.append("Wholesaletype,");
    buffer.append("WorkNum,");
    buffer.append("UnWorkNum,");
    buffer.append("OtherSurcharge,");
    buffer.append("DifferenceQuantity,");
    buffer.append("UnTransLoss,");
    buffer.append("UnLineLoss ");
    buffer.append("FROM LwWholeSaleSummary WHERE ");
    buffer.append(conditions);
    boolean supportPaging = false; // 数据库是否支持分页
    if (pageNo > 0) {
      // 对Oracle优化
      if (dbManager
          .getConnection()
          .getMetaData()
          .getDatabaseProductName()
          .equalsIgnoreCase("Oracle")) {
        buffer.insert(0, "SELECT * FROM ( SELECT row_.*, rownum rownum_ FROM (");
        buffer.append(
            ") row_ WHERE rownum <= "
                + rowsPerPage * pageNo
                + ") WHERE rownum_ > "
                + rowsPerPage * (pageNo - 1));
        supportPaging = true;
      } else if (dbManager
          .getConnection()
          .getMetaData()
          .getDatabaseProductName()
          .equalsIgnoreCase("DB2")) {
        String sql = buffer.toString();
        buffer.setLength(0);
        buffer.append("select * from ( select rownumber() over(");
        int orderByIndex = sql.toLowerCase().indexOf("order by");
        if (orderByIndex > 0) {
          buffer.append(sql.substring(orderByIndex));
        }
        buffer.append(") as rownumber_,");
        buffer.append(sql.substring(6));
        buffer.append(" ) as temp_ where rownumber_");
        buffer.append(
            " between " + (rowsPerPage * (pageNo - 1) + 1) + " and " + rowsPerPage * pageNo);
        supportPaging = true;
      }
    }
    if (logger.isDebugEnabled()) {
      logger.debug(buffer.toString());
    }
    ResultSet resultSet = dbManager.executeQuery(buffer.toString());
    int count = 0;
    if (supportPaging == false && pageNo > 1) {
      dbManager.locate(resultSet, rowsPerPage * (pageNo - 1));
    }

    // 定义返回结果集合
    Collection collection = new ArrayList(rowsPerPage);
    LwWholeSaleSummaryDto lwWholeSaleSummaryDto = null;
    while (resultSet.next()) {
      if (supportPaging == false && pageNo > 0) {
        count++;
        if (count > rowsPerPage) {
          break;
        }
      }

      lwWholeSaleSummaryDto = new LwWholeSaleSummaryDto();
      lwWholeSaleSummaryDto.setLineCode(dbManager.getString(resultSet, "LineCode"));
      lwWholeSaleSummaryDto.setStatMonth(dbManager.getString(resultSet, "StatMonth"));
      lwWholeSaleSummaryDto.setPowerClass(dbManager.getString(resultSet, "PowerClass"));
      lwWholeSaleSummaryDto.setElectricQuantity(dbManager.getDouble(resultSet, "ElectricQuantity"));
      lwWholeSaleSummaryDto.setPointerQuantity(dbManager.getDouble(resultSet, "PointerQuantity"));
      lwWholeSaleSummaryDto.setSanXiaFee(dbManager.getDouble(resultSet, "SanXiaFee"));
      lwWholeSaleSummaryDto.setSurcharge(dbManager.getDouble(resultSet, "Surcharge"));
      lwWholeSaleSummaryDto.setSumFee(dbManager.getDouble(resultSet, "SumFee"));
      lwWholeSaleSummaryDto.setValidStatus(dbManager.getString(resultSet, "ValidStatus"));
      lwWholeSaleSummaryDto.setFlag(dbManager.getString(resultSet, "Flag"));
      lwWholeSaleSummaryDto.setRemark(dbManager.getString(resultSet, "Remark"));
      lwWholeSaleSummaryDto.setTransLoss(dbManager.getDouble(resultSet, "TransLoss"));
      lwWholeSaleSummaryDto.setLineLoss(dbManager.getDouble(resultSet, "LineLoss"));
      lwWholeSaleSummaryDto.setUnPointerQuantity(
          dbManager.getDouble(resultSet, "UnPointerQuantity"));
      lwWholeSaleSummaryDto.setRateCode(dbManager.getDouble(resultSet, "RateCode"));
      lwWholeSaleSummaryDto.setAdjustRate(dbManager.getDouble(resultSet, "AdjustRate"));
      lwWholeSaleSummaryDto.setFarmUseScale(dbManager.getDouble(resultSet, "FarmUseScale"));
      lwWholeSaleSummaryDto.setFarmUsePrice(dbManager.getDouble(resultSet, "FarmUsePrice"));
      lwWholeSaleSummaryDto.setFarmUseQuantity(dbManager.getDouble(resultSet, "FarmUseQuantity"));
      lwWholeSaleSummaryDto.setFarmUseFee(dbManager.getDouble(resultSet, "FarmUseFee"));
      lwWholeSaleSummaryDto.setProductScale(dbManager.getDouble(resultSet, "ProductScale"));
      lwWholeSaleSummaryDto.setProductPrice(dbManager.getDouble(resultSet, "ProductPrice"));
      lwWholeSaleSummaryDto.setProductQuantity(dbManager.getDouble(resultSet, "ProductQuantity"));
      lwWholeSaleSummaryDto.setProductFee(dbManager.getDouble(resultSet, "ProductFee"));
      lwWholeSaleSummaryDto.setDenizenScale(dbManager.getDouble(resultSet, "DenizenScale"));
      lwWholeSaleSummaryDto.setDenizenPrice(dbManager.getDouble(resultSet, "DenizenPrice"));
      lwWholeSaleSummaryDto.setDenizenQuantity(dbManager.getDouble(resultSet, "DenizenQuantity"));
      lwWholeSaleSummaryDto.setDenizenFee(dbManager.getDouble(resultSet, "DenizenFee"));
      lwWholeSaleSummaryDto.setUnDenizenScale(dbManager.getDouble(resultSet, "UnDenizenScale"));
      lwWholeSaleSummaryDto.setUnDenizenPrice(dbManager.getDouble(resultSet, "UnDenizenPrice"));
      lwWholeSaleSummaryDto.setUnDenizenQuantity(
          dbManager.getDouble(resultSet, "UnDenizenQuantity"));
      lwWholeSaleSummaryDto.setUnDenizenFee(dbManager.getDouble(resultSet, "UnDenizenFee"));
      lwWholeSaleSummaryDto.setIndustryScale(dbManager.getDouble(resultSet, "IndustryScale"));
      lwWholeSaleSummaryDto.setIndustryPrice(dbManager.getDouble(resultSet, "IndustryPrice"));
      lwWholeSaleSummaryDto.setIndustryQuantity(dbManager.getDouble(resultSet, "IndustryQuantity"));
      lwWholeSaleSummaryDto.setIndustryFee(dbManager.getDouble(resultSet, "IndustryFee"));
      lwWholeSaleSummaryDto.setBizScale(dbManager.getDouble(resultSet, "BizScale"));
      lwWholeSaleSummaryDto.setBizPrice(dbManager.getDouble(resultSet, "BizPrice"));
      lwWholeSaleSummaryDto.setBizQuantity(dbManager.getDouble(resultSet, "BizQuantity"));
      lwWholeSaleSummaryDto.setBizFee(dbManager.getDouble(resultSet, "BizFee"));
      lwWholeSaleSummaryDto.setPowerRateFee(dbManager.getDouble(resultSet, "PowerRateFee"));
      lwWholeSaleSummaryDto.setUpCompany(dbManager.getString(resultSet, "UpCompany"));
      lwWholeSaleSummaryDto.setPowerFee(dbManager.getDouble(resultSet, "PowerFee"));
      lwWholeSaleSummaryDto.setInputDate(dbManager.getString(resultSet, "InputDate"));
      lwWholeSaleSummaryDto.setKv(dbManager.getString(resultSet, "Kv"));
      lwWholeSaleSummaryDto.setWholesaletype(dbManager.getString(resultSet, "Wholesaletype"));
      lwWholeSaleSummaryDto.setWorkNum(dbManager.getDouble(resultSet, "WorkNum"));
      lwWholeSaleSummaryDto.setUnWorkNum(dbManager.getDouble(resultSet, "UnWorkNum"));
      lwWholeSaleSummaryDto.setOtherSurcharge(dbManager.getDouble(resultSet, "OtherSurcharge"));
      lwWholeSaleSummaryDto.setDifferenceQuantity(
          dbManager.getString(resultSet, "DifferenceQuantity"));
      lwWholeSaleSummaryDto.setUnTransLoss(dbManager.getDouble(resultSet, "UnTransLoss"));
      lwWholeSaleSummaryDto.setUnLineLoss(dbManager.getDouble(resultSet, "UnLineLoss"));
      collection.add(lwWholeSaleSummaryDto);
    }
    resultSet.close();
    return collection;
  }
Exemplo n.º 5
0
  /**
   * Modifies the DO within its table. Performs recursive commit/delete on referenced DOs; all
   * operations occur within a single transaction to allow rollback in the event of error. Only the
   * creator of the transaction releases it.
   *
   * @param dbt The transaction object to use for this operation.
   * @param delete True if doing a delete, otherwise doing insert/update.
   * @exception com.lutris.appserver.server.sql.DatabaseManagerException if a Transaction can not be
   *     created.
   * @exception RefAssertionException thrown by okTo method.
   * @exception java.sql.SQLException if any SQL errors occur.
   */
  protected void modifyDO(DBTransaction dbt, boolean delete)
      throws SQLException, DatabaseManagerException, DataObjectException, RefAssertionException,
          DBRowUpdateException, QueryException {
    boolean ownTransaction = false;
    try {
      if (null == dbt) {
        DatabaseManager dbm = Enhydra.getDatabaseManager();
        dbt = dbm.createTransaction(); // create a transaction
        ownTransaction = true;
      }
      if (null == dbt)
        throw new DatabaseManagerException("DatabaseManager.createTransaction returned null.");
      if (delete) {
        // Code to perform cascading deletes is generated here
        // if cascading deletes are not supported by the database.

        {
          // perform cascading delete on referring table
          jobmatch.data.CompanyBDO[] a = getCompanyBDOArray();
          for (int i = 0; i < a.length; i++) {
            a[i].delete(dbt);
          }
        }

        // The following line keeps the compiler happy
        // when the CASCADING_DELETES tag is empty.
        if (false) throw new QueryException("XXX");
      } else {
        // commit referenced DOs.

      }
      if (false) {
        // This throw is here to keep the compiler happy
        // in the case of a DO that does not refer to other DOs.
        // In that case, the above delete/commit code blocks will be empty
        // and throw nothing.
        throw new DataObjectException("foo");
      }
      if (delete) {
        dbt.delete(DO);
      } else {
        if (DO.isLoaded()) dbt.insert(DO); // dbt.insert() handles insertions and updates
      }
      if (ownTransaction) {
        dbt.commit(); // commit the transaction
      }
    } catch (DataObjectException doe) {
      throw doe;
    } catch (SQLException sqle) {
      StringBuffer message = new StringBuffer("Failed to insert/update DO: ");
      message.append(sqle.getMessage());

      // rollback, if necessary
      if (ownTransaction) {
        try {
          dbt.rollback();
        } catch (SQLException sqle2) {
          message.insert(0, "\n");
          message.insert(0, sqle2.getMessage());
          message.insert(0, "Rollback failed: ");
        }
      }
      throw new SQLException(message.toString());
    } finally {
      // release the transaction, if any
      if (ownTransaction) {
        dbt.release();
      }
    }
  }
Exemplo n.º 6
0
  /**
   * 按条件查询多条数据
   *
   * @param conditions 查询条件
   * @param pageNo 页号
   * @param rowsPerPage 每页的行数
   * @return Collection
   * @throws Exception
   */
  public Collection findByConditions(String conditions, int pageNo, int rowsPerPage)
      throws Exception {
    StringBuffer buffer = new StringBuffer(200);
    // 拼SQL语句
    buffer.append("SELECT ");
    buffer.append("LineCode,");
    buffer.append("R,");
    buffer.append("LineLong,");
    buffer.append("Volt,");
    buffer.append("T,");
    buffer.append("ValidStatus,");
    buffer.append("Flag,");
    buffer.append("Remark ");
    buffer.append("FROM LineLoss WHERE ");
    buffer.append(conditions);
    boolean supportPaging = false; // 数据库是否支持分页
    if (pageNo > 0) {
      // 对Oracle优化
      if (dbManager
          .getConnection()
          .getMetaData()
          .getDatabaseProductName()
          .equalsIgnoreCase("Oracle")) {
        buffer.insert(0, "SELECT * FROM ( SELECT row_.*, rownum rownum_ FROM (");
        buffer.append(
            ") row_ WHERE rownum <= "
                + rowsPerPage * pageNo
                + ") WHERE rownum_ > "
                + rowsPerPage * (pageNo - 1));
        supportPaging = true;
      } else if (dbManager
          .getConnection()
          .getMetaData()
          .getDatabaseProductName()
          .equalsIgnoreCase("DB2")) {
        String sql = buffer.toString();
        buffer.setLength(0);
        buffer.append("select * from ( select rownumber() over(");
        int orderByIndex = sql.toLowerCase().indexOf("order by");
        if (orderByIndex > 0) {
          buffer.append(sql.substring(orderByIndex));
        }
        buffer.append(") as rownumber_,");
        buffer.append(sql.substring(6));
        buffer.append(" ) as temp_ where rownumber_");
        buffer.append(
            " between " + (rowsPerPage * (pageNo - 1) + 1) + " and " + rowsPerPage * pageNo);
        supportPaging = true;
      }
    }
    if (logger.isDebugEnabled()) {
      logger.debug(buffer.toString());
    }
    ResultSet resultSet = dbManager.executeQuery(buffer.toString());
    int count = 0;
    if (supportPaging == false && pageNo > 1) {
      dbManager.locate(resultSet, rowsPerPage * (pageNo - 1));
    }

    // 定义返回结果集合
    Collection collection = new ArrayList(rowsPerPage);
    LineLossDto lineLossDto = null;
    while (resultSet.next()) {
      if (supportPaging == false && pageNo > 0) {
        count++;
        if (count > rowsPerPage) {
          break;
        }
      }

      lineLossDto = new LineLossDto();
      lineLossDto.setLineCode(dbManager.getString(resultSet, "LineCode"));
      lineLossDto.setR(dbManager.getDouble(resultSet, "R"));
      lineLossDto.setLineLong(dbManager.getDouble(resultSet, "LineLong"));
      lineLossDto.setVolt(dbManager.getDouble(resultSet, "Volt"));
      lineLossDto.setT(dbManager.getDouble(resultSet, "T"));
      lineLossDto.setValidStatus(dbManager.getString(resultSet, "ValidStatus"));
      lineLossDto.setFlag(dbManager.getString(resultSet, "Flag"));
      lineLossDto.setRemark(dbManager.getString(resultSet, "Remark"));
      collection.add(lineLossDto);
    }
    resultSet.close();
    return collection;
  }
Exemplo n.º 7
0
  /**
   * 按条件查询多条数据
   *
   * @param conditions 查询条件
   * @param pageNo 页号
   * @param rowsPerPage 每页的行数
   * @return Collection
   * @throws Exception
   */
  public Collection findByConditions(String conditions, int pageNo, int rowsPerPage)
      throws Exception {
    StringBuffer buffer = new StringBuffer(200);
    // 拼SQL语句
    buffer.append("SELECT ");
    buffer.append("UserNo,");
    buffer.append("UserName,");
    buffer.append("Address,");
    buffer.append("ReadDate,");
    buffer.append("StatMonth,");
    buffer.append("ThisWorkNum,");
    buffer.append("MidWorkNum,");
    buffer.append("LastWorkNum,");
    buffer.append("Rate,");
    buffer.append("ReadQuantity,");
    buffer.append("ExcepQuantity,");
    buffer.append("ChgAmmeterQuantity,");
    buffer.append("CompensateQuantity,");
    buffer.append("AppendCalQuantity,");
    buffer.append("TranferLossQuantity,");
    buffer.append("PeoplePrice,");
    buffer.append("NotPeoplePrice,");
    buffer.append("FarmPrice,");
    buffer.append("ProducePrice,");
    buffer.append("BusinessPrice,");
    buffer.append("Voltlevel,");
    buffer.append("IndustryPrice,");
    buffer.append("ValidStatus,");
    buffer.append("Flag,");
    buffer.append("Remark,");
    buffer.append("InputDate ");
    buffer.append("FROM LwTownIndicator WHERE ");
    buffer.append(conditions);
    boolean supportPaging = false; // 数据库是否支持分页
    if (pageNo > 0) {
      // 对Oracle优化
      if (dbManager
          .getConnection()
          .getMetaData()
          .getDatabaseProductName()
          .equalsIgnoreCase("Oracle")) {
        buffer.insert(0, "SELECT * FROM ( SELECT row_.*, rownum rownum_ FROM (");
        buffer.append(
            ") row_ WHERE rownum <= "
                + rowsPerPage * pageNo
                + ") WHERE rownum_ > "
                + rowsPerPage * (pageNo - 1));
        supportPaging = true;
      } else if (dbManager
          .getConnection()
          .getMetaData()
          .getDatabaseProductName()
          .equalsIgnoreCase("DB2")) {
        String sql = buffer.toString();
        buffer.setLength(0);
        buffer.append("select * from ( select rownumber() over(");
        int orderByIndex = sql.toLowerCase().indexOf("order by");
        if (orderByIndex > 0) {
          buffer.append(sql.substring(orderByIndex));
        }
        buffer.append(") as rownumber_,");
        buffer.append(sql.substring(6));
        buffer.append(" ) as temp_ where rownumber_");
        buffer.append(
            " between " + (rowsPerPage * (pageNo - 1) + 1) + " and " + rowsPerPage * pageNo);
        supportPaging = true;
      }
    }
    if (true) {
      logger.debug(buffer.toString());
    }
    ResultSet resultSet = dbManager.executeQuery(buffer.toString());
    int count = 0;
    if (supportPaging == false && pageNo > 1) {
      dbManager.locate(resultSet, rowsPerPage * (pageNo - 1));
    }

    // 定义返回结果集合
    Collection collection = new ArrayList(rowsPerPage);
    LwTownIndicatorDto lwTownIndicatorDto = null;
    while (resultSet.next()) {
      if (supportPaging == false && pageNo > 0) {
        count++;
        if (count > rowsPerPage) {
          break;
        }
      }

      lwTownIndicatorDto = new LwTownIndicatorDto();
      lwTownIndicatorDto.setUserNo(dbManager.getString(resultSet, "UserNo"));
      lwTownIndicatorDto.setUserName(dbManager.getString(resultSet, "UserName"));
      lwTownIndicatorDto.setAddress(dbManager.getString(resultSet, "Address"));
      lwTownIndicatorDto.setReadDate(dbManager.getString(resultSet, "ReadDate"));
      lwTownIndicatorDto.setStatMonth(dbManager.getString(resultSet, "StatMonth"));
      lwTownIndicatorDto.setThisWorkNum(dbManager.getDouble(resultSet, "ThisWorkNum"));
      lwTownIndicatorDto.setMidWorkNum(dbManager.getDouble(resultSet, "MidWorkNum"));
      lwTownIndicatorDto.setLastWorkNum(dbManager.getDouble(resultSet, "LastWorkNum"));
      lwTownIndicatorDto.setRate(dbManager.getDouble(resultSet, "Rate"));
      lwTownIndicatorDto.setReadQuantity(dbManager.getDouble(resultSet, "ReadQuantity"));
      lwTownIndicatorDto.setExcepQuantity(dbManager.getDouble(resultSet, "ExcepQuantity"));
      lwTownIndicatorDto.setChgAmmeterQuantity(
          dbManager.getDouble(resultSet, "ChgAmmeterQuantity"));
      lwTownIndicatorDto.setCompensateQuantity(
          dbManager.getDouble(resultSet, "CompensateQuantity"));
      lwTownIndicatorDto.setAppendCalQuantity(dbManager.getLong(resultSet, "AppendCalQuantity"));
      lwTownIndicatorDto.setTranferLossQuantity(
          dbManager.getLong(resultSet, "TranferLossQuantity"));
      lwTownIndicatorDto.setPeoplePrice(dbManager.getDouble(resultSet, "PeoplePrice"));
      lwTownIndicatorDto.setNotPeoplePrice(dbManager.getDouble(resultSet, "NotPeoplePrice"));
      lwTownIndicatorDto.setFarmPrice(dbManager.getDouble(resultSet, "FarmPrice"));
      lwTownIndicatorDto.setProducePrice(dbManager.getDouble(resultSet, "ProducePrice"));
      lwTownIndicatorDto.setBusinessPrice(dbManager.getDouble(resultSet, "BusinessPrice"));
      lwTownIndicatorDto.setVoltlevel(dbManager.getInt(resultSet, "Voltlevel"));
      lwTownIndicatorDto.setIndustryPrice(dbManager.getDouble(resultSet, "IndustryPrice"));
      lwTownIndicatorDto.setValidStatus(dbManager.getString(resultSet, "ValidStatus"));
      lwTownIndicatorDto.setFlag(dbManager.getString(resultSet, "Flag"));
      lwTownIndicatorDto.setRemark(dbManager.getString(resultSet, "Remark"));
      lwTownIndicatorDto.setInputDate(dbManager.getString(resultSet, "InputDate"));
      collection.add(lwTownIndicatorDto);
    }
    resultSet.close();
    return collection;
  }
  public void actionPerformed(ActionEvent ae) {
    AbstractButton jlab = null;
    if ((count > 7)) {
      JOptionPane.showMessageDialog(
          jlab, "UnSuccessful Submit", "Error", JOptionPane.ERROR_MESSAGE);

    } else if ((count == 0)) {
      AbstractButton jlab1 = null;

      JOptionPane.showMessageDialog(
          jlab1, "UnSuccessful Submit", "Error", JOptionPane.ERROR_MESSAGE);

    } else if ((ae.getActionCommand().equals("Submit"))) {
      AbstractButton jlab2 = null;

      System.out.println("Submitted");
      // JOptionPane.showMessageDialog(jlab1, "Successfully Submitted.");

      JOptionPane.showMessageDialog(
          jlab2, "Submited Successfully!" + "\n" + "Choices are:  " + choices);
      String nameofuser;

      // change username with passed parameter here

      nameofuser = arg;
      System.out.println("Username:"******"select * from user where username= '******'";

      try {
        pst = con.prepareStatement(sql);
        rs = pst.executeQuery();
        if (rs.next()) {
          this.hide();

          allowedchoices.insert(0, rs.getString(9));
          threshold = rs.getFloat(7);
        }

        int i;
        StringBuffer temp;
        temp = new StringBuffer("-------");

        for (i = 0; i < 7; i++) {
          if (allowedchoices.charAt(i) != choices.charAt(i)) {

            temp.setCharAt(i, choices.charAt(i));
          }
        }

        double risk = 0.0;
        for (i = 0; i < 7; i++) {
          switch (temp.charAt(i)) {
            case 'r':
              risk = risk + 0.15;
              break;
            case 'c':
              risk = risk + 0.0;
              break;
            case 'a':
              risk = risk + 0.20;
              break;
            case 'u':
              risk = risk + 0.0;
              break;
            case 'd':
              risk = risk + 0.5;
              break;
            case 'p':
              risk = risk + 0.3;
              break;
            case 'e':
              risk = risk + 0.25;
              break;
          }
        }
        System.out.println("Current Risk Value: " + risk);
        System.out.println(
            "PREMISSION ALLOWED(BY DEFAULT):" + allowedchoices + "THRESHOLD:" + threshold);

        if (threshold < risk) {
          con = ClientConnect.ConnectDB();
          String sql1 =
              "update user set accountstatus = '" + 0 + "' where username= '******'";
          JOptionPane.showMessageDialog(
              jlab1,
              "Account Has Been Disabled! \n \t Contact Administrator!",
              "Error",
              JOptionPane.ERROR_MESSAGE);
          Statement stmt = con.createStatement();
          stmt.execute(sql1.toString());
          stmt.close();
        } else {
          GUIFRfetch gf = new GUIFRfetch();
        }

      } catch (SQLException | HeadlessException e) {
        JOptionPane.showMessageDialog(null, e);
      }
    }
  }