?? roleoperate.java
字號:
package com.ICT.AFC.user.beans;
import java.sql.ResultSet;
import com.ICT.AFC.DB.DB;
import java.util.ArrayList;
/**
* <p>Title:角色類相關操作 </p>
* <p>Description:權限類相關操作,包括部門插入、修改、刪除。 </p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: 電子所AFC事業部</p>
* @author 梅曉峰
* @version 1.0
*/
public class RoleOperate {
public RoleOperate() {
}
/**
* 添加新角色信息方法
* @param db DB
* @param department Department
* @throws Exception
* @return boolean
*/
public static boolean AddRole(DB db, Role role) throws
Exception {
ResultSet rs;
int roleid = role.getRoleId();
String roleremark = role.getRoleRemark();
String rolename = role.getRoleName();
String sqlstr =
"insert into M_ROLE(ROLEID,ROLENAME,ROLEREMARK) values("
+ roleid + ",'"
+ rolename + "','"
+ roleremark +"')";
if (db.ExecSql(sqlstr) == 0) {
return false;
}
else {
return true;
}
}
public static boolean AddRoleRight(DB db, Role role) throws
Exception {
int roleid = role.getRoleId();
String rightid = role.getRightId();
String sqlstr =
"insert into M_ROLE_RIGHT(ROLEID,RIGHTID) values("
+ roleid + ",'"
+ rightid + "')";
if (db.ExecSql(sqlstr) == 0) {
return false;
}
else {
return true;
}
}
/**
* 查找角色信息方法
* @param db DB
* @param department Department
* @throws Exception
* @return boolean
*/
public static ArrayList SearchRole(DB db) throws
Exception {
ResultSet rs;
ArrayList RoleList = new ArrayList();
/////////////////
String sqlstr = "select distinct(roleid) from V_ROLE";
String sql2 = "";
rs = db.OpenSql(sqlstr);
ResultSet rs2;
String rightNames = "";
while (rs.next()) {
sql2 = "select * from v_role where roleid = " + rs.getInt(1);
rs2 = db.OpenSql(sql2);
rightNames = "";
Role role = new Role();
while (rs2.next()) {
role.setRoleId(rs2.getInt("ROLEID"));
role.setRoleName(rs2.getString("ROLENAME"));
role.setRoleRemark(rs2.getString("ROLEREMARK"));
role.setRightId(rs2.getString("RIGHTID"));
rightNames = rightNames + " " + rs2.getString("rightName");
role.setRightName(rightNames);
}
RoleList.add(role);
}
///////////
return RoleList;
}
/**
* 角色編號加1方法
* @param db DB
* @param department Department
* @throws Exception
* @return boolean
*/
public static int SearchRoleID(DB db) throws Exception {
int no;
ResultSet rs;
String strSql = null;
strSql = "select Max(ROLEID) from M_ROLE";
rs = db.OpenSql(strSql);
if (rs.next()) {
no = rs.getInt(1) + 1;
}
else {
no = 1;
}
return no;
}
/**
* 查找某權限是否存在方法
* @param db DB
* @param department Department
* @throws Exception
* @return boolean
*/
public static boolean SearchRightID(DB db, String rightid) throws Exception {
ResultSet rs;
String strSql = null;
strSql = "select RIGHTID from V_ROLE where RIGHTID='" + rightid + "'";
rs = db.OpenSql(strSql);
if (rs.next()) {
return true;
}
else {
return false;
}
}
/**
* 根據角色編號查找角色信息方法
* @param db DB
* @param department Department
* @throws Exception
* @return boolean
*/
public static Role SearchRoleByID(DB db, String roleid) throws Exception {
ResultSet rs;
String strSql = null;
strSql = "select * from V_ROLE where ROLEID=" + roleid;
rs = db.OpenSql(strSql);
Role role = new Role();
if (rs.next()) {
role.setRoleId(rs.getInt("ROLEID"));
role.setRoleName(rs.getString("ROLENAME"));
role.setRoleRemark(rs.getString("ROLEREMARK"));
role.setRightId(rs.getString("RIGHTID"));
}
return role;
}
/**
* 刪除指定角色方法
* @param db DB
* @param department Department
* @throws Exception
* @return boolean
*/
public static boolean deleteRole(DB db, int roleID) throws Exception {
String strSql = null;
strSql = "delete M_Role where ROLEID=" + roleID;
if (db.ExecSql(strSql) == 0) {
return false;
}
else {
return true;
}
}
/**
* 修改角色信息方法
* @param db DB
* @param department Department
* @throws Exception
* @return boolean
*/
public static boolean updateRole(DB db, Role role) throws
Exception {
ResultSet rs;
int roleid = role.getRoleId();
String rightid = role.getRightId();
String strSql = null;
String roleremark = role.getRoleRemark();
String rolename = role.getRoleName();
strSql = "update M_ROLE set ROLENAME=" + rolename +
",ROLEEMARK='" + roleremark + "'" + ",RIGHTID='" + rightid +
"'" + " where ROLEID=" + roleid;
if (db.ExecSql(strSql) == 0) {
return false;
}
else {
return true;
}
}
public static boolean deleteRoleRight(DB db, int roleID) throws Exception {
String strSql = null;
strSql = "delete M_Role_RIGHT where ROLEID=" + roleID;
if (db.ExecSql(strSql) == 0) {
return false;
}
else {
return true;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -