/** 获得组内所有的用户 */
 public User[] getUsers(String twhere) {
   String strSql;
   try {
     strSql = "select strUserId,strMobile,strName from " + strTableName + "  ".concat(twhere);
     ResultSet rs = db.executeRollQuery(strSql);
     if (rs.last()) {
       int total = rs.getRow();
       rs.beforeFirst();
       User[] users = new User[total];
       int i = 0;
       while (rs.next()) {
         users[i] =
             new User(
                 rs.getString("strUserId"), rs.getString("strMobile"), rs.getString("strName"));
         i++;
       }
       rs.close();
       return users;
     } else {
       rs.close();
       return null;
     }
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
 // ����û�?
 public boolean addUnitUser(String strUserId, String[] arryUnitId) {
   String strSql = "";
   try {
     // ����Ϣд����ݿ�?
     strSql =
         "INSERT INTO "
             + strTableName2
             + "  (strUserId, strUnitId, intSort, strCreator, dtCreatTime) VALUES (?,?,?,?,str_to_date(?,'%Y-%m-%d %T'))";
     if (arryUnitId != null && arryUnitId.length > 0)
       for (int i = 0; i < arryUnitId.length; i++) {
         db.prepareStatement(strSql);
         db.setString(1, strUserId);
         db.setString(2, arryUnitId[i]);
         db.setInt(3, creatSort(arryUnitId[i])); // intSort
         db.setString(4, globa.loginName);
         db.setString(5, Format.getDateTime());
         db.executeUpdate();
       }
     return true;
   } catch (Exception e) {
     System.out.println("增加单位用户映射时出错!!");
     e.printStackTrace();
     return false;
   }
 }
 // 生成同一个单位上报单位的用户名
 public String creatUserId(String tStrUnitId) {
   ResultSet rs = null;
   String tStrUserId = "";
   try {
     Unit unit0 = new Unit(globa, false).show(" WHERE strId='" + tStrUnitId + "'");
     //            if(unit0.getIntUnitType()!=2)
     //                    return "";
     // System.out.println("SELECT Max(strUserId)  FROM " + strTableName + " WHERE  strUnitId='" +
     // tStrUnitId + "'");
     rs =
         db.executeQuery(
             "SELECT Max(strUserId)  FROM "
                 + strTableName
                 + " WHERE  strUnitId='"
                 + tStrUnitId
                 + "'");
     if (rs != null && rs.next()) {
       tStrUserId = rs.getString(1);
     }
     rs.close();
     rs = null;
     if (tStrUserId == null || tStrUserId.equals("")) {
       tStrUserId = unit0.getStrUnitCode() + "00";
     } else {
       tStrUserId = String.valueOf(Long.parseLong(tStrUserId) + 1);
     }
     return tStrUserId;
   } catch (Exception ee) {
     ee.printStackTrace();
     return "";
   }
 }
  // 列表记录集
  public Vector<User> list(String where, int startRow, int rowCount) {
    Vector<User> beans = new Vector<User>();
    try {
      String sql = "SELECT *  FROM  " + strTableName + " ";
      if (where.length() > 0) sql = String.valueOf(sql) + String.valueOf(where);
      Statement s =
          db.getConnection()
              .createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
      if (startRow != 0 && rowCount != 0) s.setMaxRows((startRow + rowCount) - 1);

      ResultSet rs = s.executeQuery(sql);
      if (rs != null && rs.next()) {
        if (startRow != 0 && rowCount != 0) rs.absolute(startRow);
        do {
          User theBean = new User();
          theBean = load(rs, false);
          beans.addElement(theBean);
        } while (rs.next());
      }
      rs.close();
      s.close();
    } catch (Exception ee) {
      ee.printStackTrace();
    }
    return beans;
  }
 // ɾ删除部门用户部门联系表中的一条数据
 public boolean delUnitUser(String where) {
   try {
     String sql = "DELETE FROM " + strTableName2 + "  ".concat(where);
     db.executeUpdate(sql);
     return true;
   } catch (Exception ee) {
     ee.printStackTrace();
     return false;
   }
 }
 // ɾ删除该用户的权限
 public boolean delRight(String where) {
   try {
     String sql = "DELETE FROM " + strTableName3 + "  ".concat(where);
     System.err.println(sql + "========+++++++");
     db.executeUpdate(sql);
     return true;
   } catch (Exception ee) {
     ee.printStackTrace();
     return false;
   }
 }
 // 判断用户信息是否冲突
 public void bCheckAccount(String tStrAccount) throws UserUnitIdException, SQLException {
   String strSql =
       "select strUserId  from " + strTableName + "   where strUserId='" + tStrAccount + "'";
   try {
     ResultSet rs = db.executeQuery(strSql);
     if (rs.next()) {
       globa.closeCon();
       throw new UserUnitIdException("已经存在'" + tStrAccount + "' 用户", "请输入其他用户名");
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 // 记录集转化为对象
 public User load2(ResultSet rs, boolean isView) {
   User theBean = new User();
   try {
     theBean.setStrId(rs.getString(1));
     theBean.setStrUserId(rs.getString(2));
     theBean.setStrName(rs.getString(3));
     theBean.setStrCaNO(rs.getString(4));
     theBean.setStrUnitId(rs.getString(5));
   } catch (Exception e) {
     e.printStackTrace();
   }
   return theBean;
 }
 // 获得制定用户所属的单位
 public HashMap unitUser(String tField, String tWhere) {
   HashMap result = new HashMap();
   String strSql = "SELECT " + tField + " FROM  " + strTableName2 + " ".concat(tWhere);
   try {
     ResultSet rs = db.executeQuery(strSql);
     while (rs.next()) {
       result.put(rs.getString(1), "true");
     }
     rs.close();
   } catch (Exception ee) {
     ee.printStackTrace();
   }
   return result;
 }
 // 列表记录集
 public String retVal(String strField, String where) {
   String val = "''";
   try {
     String sql = "SELECT " + strField + "  FROM  " + strTableName2 + "  ".concat(where);
     ResultSet rs = db.executeQuery(sql);
     while (rs != null && rs.next()) {
       val = val + ",'" + rs.getString(1) + "'";
     }
     rs.close();
   } catch (Exception ee) {
     ee.printStackTrace();
   }
   return val;
 }
 // 修改strCssType
 public boolean setCss(String tCss) {
   try {
     String strSql =
         "update "
             + strTableName
             + "  set strCssType='"
             + tCss
             + "' where strUserId='"
             + globa.loginName
             + "'";
     db.executeUpdate(strSql);
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
 // 修改密码
 public boolean doSetPwd(String tStrUserId, ServletContext application, HttpSession session) {
   try {
     String sql =
         "UPDATE " + strTableName + " SET strPWD=?,intState=? ,intError=0 WHERE  strUserId=? ";
     db.prepareStatement(sql);
     db.setString(1, MD5.getMD5ofString(strPWD));
     db.setInt(2, Constants.U_STATE_ON);
     db.setString(3, tStrUserId);
     db.executeUpdate();
     // �޸��û���������
     Globa.logger0(
         "修改用户密码", globa.loginName, globa.loginIp, sql, "用户管理", globa.userSession.getStrDepart());
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
 // 查询符合条件的记录总数
 public int getCount(String where) {
   int count = 0;
   try {
     String sql = "SELECT count(strId) FROM " + strTableName + "  ";
     if (where.length() > 0) {
       where = where.toLowerCase();
       if (where.indexOf("order") > 0) where = where.substring(0, where.lastIndexOf("order"));
       sql = String.valueOf(sql) + String.valueOf(where);
     }
     ResultSet rs = db.executeQuery(sql);
     if (rs.next()) count = rs.getInt(1);
     rs.close();
     return count;
   } catch (Exception ee) {
     ee.printStackTrace();
     return count;
   }
 }
 // 获得制定用户所属的单位
 public HashMap unitUser(String tWhere) {
   HashMap result = new HashMap();
   System.err.println(
       tWhere + "++++++++++_________________----------------------------==========");
   String strSql =
       "SELECT b.strUserId,b.strId FROM sys_unitUser a LEFT JOIN sys_user b ON a.strUserId=b.strUserId   "
           .concat(tWhere);
   try {
     ResultSet rs = db.executeQuery(strSql);
     while (rs != null && rs.next()) {
       // System.err.println(rs.getString(1)+rs.getString(2)+":DDDDDDDDDDDDDDD");
       result.put(rs.getString(1), rs.getString(2));
     }
     rs.close();
   } catch (Exception ee) {
     ee.printStackTrace();
   }
   return result;
 }
 // 修改领导密码用户密码
 public boolean setPassword(String pwd) {
   try {
     String strSql =
         "update "
             + strTableName
             + "  set strDepart='"
             + Format.enPass(pwd)
             + "' where strUserId='"
             + globa.loginName
             + "'";
     db.executeUpdate(strSql);
     UserSession userSession = globa.userSession;
     userSession.setStrPWD(pwd);
     globa.session.setAttribute(com.ejoysoft.common.Constants.USER_KEY, userSession);
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
 // 用户 认证֤
 public boolean authUser(String oldPwd) {
   String pwd = (new MD5().getMD5ofStr(oldPwd));
   String strSql =
       "SELECT  *  FROM  "
           + strTableName
           + "  WHERE strUserId='"
           + globa.loginName
           + "' and strPWD='"
           + pwd
           + "'";
   try {
     ResultSet rs = db.executeQuery(strSql);
     if (rs != null && rs.next()) {
       return true;
     }
     return false;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
 // 获得制定用户所属的单位
 public String[] arryUnitUser(String tWhere) {
   String[] result = null;
   try {
     String strSql = "SELECT count(*) FROM  " + strTableName2 + " ".concat(tWhere);
     ResultSet rs = db.executeQuery(strSql);
     int iLen = 0;
     if (rs.next()) iLen = rs.getInt(1);
     result = new String[iLen];
     strSql = "SELECT strUnitId FROM  " + strTableName2 + " ".concat(tWhere);
     rs = db.executeQuery(strSql);
     int i = 0;
     while (rs.next()) {
       result[i] = rs.getString(1);
       i++;
     }
     rs.close();
   } catch (Exception ee) {
     ee.printStackTrace();
   }
   return result;
 }
  // 记录集转化为对象
  public User load(ResultSet rs, boolean isView) {
    User theBean = new User();
    try {
      theBean.setStrId(rs.getString("strId"));
      theBean.setStrUserId(rs.getString("strUserId"));
      theBean.setStrPWD(rs.getString("strPWD"));
      theBean.setStrName(rs.getString("strName"));
      theBean.setIntError(rs.getInt("intError"));
      theBean.setIntState(rs.getInt("intState"));
      theBean.setdBirthday(rs.getString("dBirthday"));
      theBean.setStrSex(rs.getString("strSex"));
      theBean.setStrIntro(rs.getString("strIntro"));
      theBean.setIntType(rs.getInt("intType"));
      theBean.setStrUnitId(rs.getString("strUnitId"));
      theBean.setStrUnitCode(rs.getString("strUnitCode"));
      theBean.setStrNation(rs.getString("strNation"));
      theBean.setStrMobile(rs.getString("strMobile"));
      theBean.setStrEmail(rs.getString("strEmail"));
      theBean.setStrMsnQQ(rs.getString("strMsnQQ"));
      theBean.setStrOPhone(rs.getString("strOPhone"));
      theBean.setStrHPhone(rs.getString("strHPhone"));
      theBean.setStrDuty(rs.getString("strDuty"));
      theBean.setStrStation(rs.getString("strStation"));
      theBean.setIntLoginNum(rs.getInt("intLoginNum"));
      theBean.setdLatestLoginTime(rs.getString("dLatestLoginTime"));
      theBean.setfOnlineTime(rs.getFloat("fOnlineTime"));
      theBean.setStrCaNO(rs.getString("strCaNO"));
      theBean.setStrDepart(rs.getString("strDepart"));
      theBean.setStrCssType(rs.getString("strCssType"));
      theBean.setStrLinkAdd(rs.getString("strLinkAdd"));
      theBean.setStrCreator(rs.getString("strCreator"));
      theBean.setDtCreatTime(rs.getString("dtCreatTime"));
      theBean.setIntUserType(rs.getInt("intUserType"));

    } catch (Exception e) {
      e.printStackTrace();
    }
    return theBean;
  }
 // 生成同一个单位下的下级单位(组)的 排序号
 public int creatSort(String tStrUnitId) {
   ResultSet rs = null;
   int tIntSort = 0;
   try {
     rs =
         db.executeQuery(
             "SELECT  Max(intSort)  FROM "
                 + strTableName2
                 + " WHERE  strUnitId='"
                 + tStrUnitId
                 + "' ");
     if (rs != null && rs.next()) {
       tIntSort = rs.getInt(1);
     }
     rs.close();
     rs = null;
     return tIntSort + 1;
   } catch (Exception ee) {
     ee.printStackTrace();
     return 0;
   }
 }
 // ɾ��
 public boolean delete(String where, String strId) {
   try {
     String strUserId = "";
     String where2 = " where strId = '" + strId + "'";
     String sql2 = "select strUserId from  " + strTableName + " ".concat(where2);
     ResultSet rs = db.executeQuery(sql2);
     if (rs != null && rs.next()) {
       strUserId = rs.getString("strUserId");
     }
     String sql = "DELETE FROM " + strTableName + "  ".concat(where);
     db.executeUpdate(sql);
     // ɾ���û�ӳ����?
     String where3 = "where strUserId =  '" + strUserId + "'";
     String where4 = "where strUserId =  '" + strId + "'";
     delUnitUser(where3);
     delRight(where4);
     Globa.logger0("删除用户信息", globa.loginName, globa.loginIp, sql, "用户管理", globa.unitCode);
     return true;
   } catch (Exception ee) {
     ee.printStackTrace();
     return false;
   }
 }
  // 增加用户
  public boolean add(String strUserId) {
    String strSql = "";
    strId = UID.getID();
    try {
      // 把用户信息写入数据库
      strSql =
          "INSERT INTO "
              + strTableName
              + "  (strId, strUserId, strPWD, strName, intError, intState, dBirthday, strSex, strIntro,intType, strUnitId, strUnitCode,"
              + " strNation, strMobile, strEmail, strMsnQQ,strOPhone, strHPhone, strDuty, strStation, intLoginNum, dLatestLoginTime,fOnlineTime, strCaNO, "
              + "strDepart, strCssType,  strLinkAdd, strCreator, dtCreatTime,intUserType) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,str_to_date(?,'%Y-%m-%d %T'),?,?,?,?,?,?,str_to_date(?,'%Y-%m-%d %T'),?)";
      db.prepareStatement(strSql);
      db.setString(1, strId);
      db.setString(2, strUserId.replaceAll(" ", ""));
      db.setString(3, MD5.getMD5ofString(Constants.resetPass)); // strPWD
      db.setString(4, strName);
      db.setInt(5, 0);
      db.setInt(6, 0);
      db.setString(7, dBirthday);
      db.setString(8, strSex);
      db.setString(9, strIntro);
      db.setInt(10, intType);
      db.setString(11, strUnitId);
      db.setString(
          12,
          ""); // strUnitCode                  new Unit(globa, false).retFieldValue("strUnitCode",
               // strUnitId)
      db.setString(13, strNation);
      db.setString(14, strMobile);
      db.setString(15, strEmail);
      db.setString(16, strMsnQQ);
      db.setString(17, strOPhone);
      db.setString(18, strHPhone);
      db.setString(19, strDuty);
      db.setString(20, strStation);
      db.setInt(21, intLoginNum);
      db.setString(22, Format.getDateTime());
      db.setDouble(23, 0);
      db.setString(24, strCaNO);
      db.setString(25, strDepart);
      db.setString(26, strCssType);
      db.setString(27, strLinkAdd);
      db.setString(28, globa.loginName);
      db.setString(29, Format.getDateTime());
      db.setInt(30, intUserType);

      if (db.executeUpdate() > 0) {
        Globa.logger0(
            "增加用户信息",
            globa.loginName,
            globa.loginIp,
            strSql,
            "用户管理",
            globa.userSession.getStrDepart());
        return true;
      } else return false;
    } catch (Exception e) {
      System.out.println("增加用户信息时出错!!");
      e.printStackTrace();
      return false;
    }
  }