📄 usersbean.java
字号:
package bean.users;
import java.io.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Hashtable;
import database.DBPoolManager;
public class UsersBean {
private ArrayList users;
private ArrayList roles;
public UsersBean() {
users = new ArrayList();
roles = new ArrayList();
}
public String ISOtoGB(String in){
String out = "";
if (in == null){
return "";
}
else{
try {
out = new String(in.getBytes("iso-8859-1"),"gb2312");
return out;
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return out;
}
public String GBtoISO(String in){
String out = "";
if (in == null){
return "";
}
else{
try {
out = new String(in.getBytes("gb2312"),"iso-8859-1");
return out;
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return out;
}
public ArrayList getUsers(String OrganID) {
users.clear();
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String s = null;
String sql = "select UserId,UserCode,UserName,UserPwd,ModifyDate,Remark from staff where USERFLAG='1' and OrganId="+OrganID;
Statement stmt = dbpool.conn.createStatement();
ResultSet rest = stmt.executeQuery(sql);
while (rest.next()) {
Hashtable ht = new Hashtable();
if (rest.getString("UserId") == null){
ht.put("UserId", "");
}
else{
s = rest.getString("UserId");
s = s.trim();
ht.put("UserId", s);
}
if (rest.getString("UserCode") == null){
ht.put("UserCode", "");
}
else{
s = rest.getString("UserCode");
s = s.trim();
ht.put("UserCode", s);
}
if (rest.getString("UserName") == null){
ht.put("UserName", "");
}
else{
s = rest.getString("UserName");
s = s.trim();
ht.put("UserName", s);
}
if (rest.getString("UserPwd") == null){
ht.put("UserPwd", "");
}
else{
s = rest.getString("UserPwd");
s = s.trim();
ht.put("UserPwd", s);
}
if (rest.getString("ModifyDate") == null){
ht.put("ModifyDate", "");
}
else{
s = rest.getString("ModifyDate");
s = s.trim();
ht.put("ModifyDate", s);
}
if (rest.getString("Remark") == null){
ht.put("Remark", "");
}
else{
s = rest.getString("Remark");
s = s.trim();
ht.put("Remark", s);
}
users.add(ht);
}
rest.close();
stmt.close();
} catch (SQLException ex) {
System.err.println("Get UsersBean SQLException: " + ex.toString());
} finally {
dbpool.freeConnection();
}
return this.users;
}
public ArrayList getUsersName(String usercode) {
users.clear();
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String s = null;
String sql = "select UserId , UserName from staff where UserCode = '"+ usercode + "'";
Statement stmt = dbpool.conn.createStatement();
ResultSet rest = stmt.executeQuery(sql);
if (rest.next()) {
Hashtable ht = new Hashtable();
if (rest.getString("UserId") == null){
ht.put("UserId", "");
}
else{
s = rest.getString("UserId");
s = s.trim();
ht.put("UserId", s);
}
if (rest.getString("UserName") == null){
ht.put("UserName", "");
}
else{
s = rest.getString("UserName");
s = s.trim();
ht.put("UserName", s);
}
users.add(ht);
}
rest.close();
stmt.close();
} catch (SQLException ex) {
System.err.println("Get UsersBean SQLException: " + ex.toString());
} finally {
dbpool.freeConnection();
}
return this.users;
}
public ArrayList getUsersByRole(String OrganID) {
users.clear();
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String s = null;
String sql = "select distinct a.UserId,a.UserCode,a.UserName,a.UserPwd,a.ModifyDate,a.Remark from staff a , staff_role b , manrole c ";
sql += " where a.USERFLAG='1' and a.OrganId="+OrganID ;
sql += " and a.userid = b.userid and b.roleid = c.roleid and ( c.rolecode = 'role_term_admi' or c.rolecode = 'role_term_stor' ) ";
Statement stmt = dbpool.conn.createStatement();
ResultSet rest = stmt.executeQuery(sql);
while (rest.next()) {
Hashtable ht = new Hashtable();
if (rest.getString("UserId") == null){
ht.put("UserId", "");
}
else{
s = rest.getString("UserId");
s = s.trim();
ht.put("UserId", s);
}
if (rest.getString("UserCode") == null){
ht.put("UserCode", "");
}
else{
s = rest.getString("UserCode");
s = s.trim();
ht.put("UserCode", s);
}
if (rest.getString("UserName") == null){
ht.put("UserName", "");
}
else{
s = rest.getString("UserName");
s = s.trim();
ht.put("UserName", s);
}
if (rest.getString("UserPwd") == null){
ht.put("UserPwd", "");
}
else{
s = rest.getString("UserPwd");
s = s.trim();
ht.put("UserPwd", s);
}
if (rest.getString("ModifyDate") == null){
ht.put("ModifyDate", "");
}
else{
s = rest.getString("ModifyDate");
s = s.trim();
ht.put("ModifyDate", s);
}
if (rest.getString("Remark") == null){
ht.put("Remark", "");
}
else{
s = rest.getString("Remark");
s = s.trim();
ht.put("Remark", s);
}
users.add(ht);
}
rest.close();
stmt.close();
} catch (SQLException ex) {
System.err.println("Get UsersBean SQLException: " + ex.toString());
} finally {
dbpool.freeConnection();
}
return this.users;
}
public ArrayList getUsers(String OrganID,String UserId) {
users.clear();
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String s = null;
String sql = "select a.UserId,a.UserCode,a.UserName,a.UserPwd, a.ModifyDate,a.Remark,b.OrganName, d.Purview from staff a, Organ b, staff_role c, manrole d where a.UserId=c.UserId and c.RoleId=d.RoleId and a.OrganId=b.OrganId and a.USERFLAG='1' and a.UserId="+UserId+" and a.OrganId="+OrganID;
Statement stmt = dbpool.conn.createStatement();
ResultSet rest = stmt.executeQuery(sql);
while (rest.next()) {
Hashtable ht = new Hashtable();
if (rest.getString("UserId") == null){
ht.put("UserId", "");
}
else{
s = rest.getString("UserId");
s = s.trim();
ht.put("UserId", s);
}
if (rest.getString("UserCode") == null){
ht.put("UserCode", "");
}
else{
s = rest.getString("UserCode");
s = s.trim();
ht.put("UserCode", s);
}
if (rest.getString("UserName") == null){
ht.put("UserName", "");
}
else{
s = rest.getString("UserName");
s = s.trim();
ht.put("UserName", s);
}
if (rest.getString("UserPwd") == null){
ht.put("UserPwd", "");
}
else{
s = rest.getString("UserPwd");
s = s.trim();
ht.put("UserPwd", s);
}
if (rest.getString("ModifyDate") == null){
ht.put("ModifyDate", "");
}
else{
s = rest.getString("ModifyDate");
s = s.trim();
ht.put("ModifyDate", s);
}
if (rest.getString("Remark") == null){
ht.put("Remark", "");
}
else{
s = rest.getString("Remark");
s = s.trim();
ht.put("Remark", s);
}
if (rest.getString("OrganName") == null){
ht.put("OrganName", "");
}
else{
s = rest.getString("OrganName");
s = s.trim();
ht.put("OrganName", s);
}
if (rest.getString("Purview") == null){
ht.put("Purview", "");
}
else{
s = rest.getString("Purview");
s = s.trim();
ht.put("Purview", s);
}
users.add(ht);
}
rest.close();
stmt.close();
} catch (SQLException ex) {
System.err.println("Get UsersBean SQLException: " + ex.toString());
} finally {
dbpool.freeConnection();
}
return this.users;
}
public ArrayList getUsers(String OrganID,int Page,int Lines) {
users.clear();
String s = null;
int i = 0;
int tp = 0;
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = "select UserId,UserCode,UserName,UserPwd,ModifyDate,Remark from staff where USERFLAG='1' and OrganId="+OrganID;
Statement stmt = dbpool.conn.createStatement();
ResultSet rest = stmt.executeQuery(sql);
while (rest.next()) {
Hashtable ht = new Hashtable();
tp= tp + 1;
if ((tp>Page*Lines)&&(i<Lines)){
i = i + 1;
if (rest.getString("UserId") == null){
ht.put("UserId", "");
}
else{
s = rest.getString("UserId");
s = s.trim();
ht.put("UserId", s);
}
if (rest.getString("UserCode") == null){
ht.put("UserCode", "");
}
else{
s = rest.getString("UserCode");
s = s.trim();
ht.put("UserCode", s);
}
if (rest.getString("UserName") == null){
ht.put("UserName", "");
}
else{
s = rest.getString("UserName");
s = s.trim();
ht.put("UserName", s);
}
if (rest.getString("UserPwd") == null){
ht.put("UserPwd", "");
}
else{
s = rest.getString("UserPwd");
s = s.trim();
ht.put("UserPwd", s);
}
if (rest.getString("ModifyDate") == null){
ht.put("ModifyDate", "");
}
else{
s = rest.getString("ModifyDate");
s = s.trim();
ht.put("ModifyDate", s);
}
if (rest.getString("Remark") == null){
ht.put("Remark", "");
}
else{
s = rest.getString("Remark");
s = s.trim();
ht.put("Remark", s);
}
users.add(ht);
}
}
rest.close();
stmt.close();
} catch (SQLException ex) {
System.err.println("Get UsersBean SQLException: " + ex.toString());
} finally {
dbpool.freeConnection();
}
return this.users;
}
public ArrayList getUserRoles(String UserId,int Page,int Lines) {
roles.clear();
String s = null;
int i = 0;
int tp = 0;
DBPoolManager dbpool = new DBPoolManager();
dbpool.getConnection();
try {
String sql = " select a.RoleID,a.RoleName,a.state from "+
"((select a.RoleID,a.RoleName,1 as state from ManRole a, staff_role b where a.RoleID=b.RoleID and b.UserId="+UserId+")"+
"union"+
"(select a.RoleID,a.RoleName,0 as state from ManRole a where a.RoleID not in ((select a.RoleID from ManRole a, staff_role b where a.RoleID=b.RoleID and b.UserId="+UserId+")))) a order by RoleID";
Statement stmt = dbpool.conn.createStatement();
ResultSet rest = stmt.executeQuery(sql);
while (rest.next()) {
Hashtable ht = new Hashtable();
tp= tp + 1;
if ((tp>Page*Lines)&&(i<Lines)){
i = i + 1;
if (rest.getString("RoleID") == null){
ht.put("RoleID", "");
}
else{
s = rest.getString("RoleID");
s = s.trim();
ht.put("RoleID", s);
}
if (rest.getString("RoleName") == null){
ht.put("RoleName", "");
}
else{
s = rest.getString("RoleName");
s = s.trim();
ht.put("RoleName", s);
}
if (rest.getString("state") == null){
ht.put("state", "");
}
else{
s = rest.getString("state");
s = s.trim();
ht.put("state", s);
}
roles.add(ht);
}
}
rest.close();
stmt.close();
} catch (SQLException ex) {
System.err.println("Get UsersBean SQLException: " + ex.toString());
} finally {
dbpool.freeConnection();
}
return this.roles;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -