?? rightbean.java
字號:
{
boolean bool = false;
String right = "";
ResultSet rs = selectRecord("select CKQX from news.ZZ_BMB where BMBH =(select BMBH from news.ZZ_ZGB where ZGBH='"+uid+"')");
Statement stmt = null;
try{
if(rs.next())
right = rs.getString(1);
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
int t = right.indexOf(uid);
if(t!=-1)bool = true;
return bool;
}
/**文書權限*/
public boolean isRightSecretary()
{
boolean bool = false;
String right = "";
ResultSet rs = selectRecord("select WSZWBH from news.ZZ_BMB where BMBH =(select BMBH from news.ZZ_ZGB where ZGBH='"+uid+"')");
Statement stmt = null;
try{
if(rs.next())
right = rs.getString(1);
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
if(right!=null && right.equals(uid))bool = true;
return bool;
}
/**比較該Vector變量中莫一個變量權限名稱*/
public String getExist(Vector v,String s)
{
String str = "";
for(int i=0;i<v.size();i++)
{
String t = (String)v.get(i);
if(t.indexOf(s)!=-1)
{
int t1 = t.indexOf("<");
str = t.substring(t1+1,t.length()-1);
break;
}
}
return str;
}
/**檔案權限*/
//public Vector getRightArchives()檔案權限
//public Vector getRightPeriodical()期刊權限
//當前職工所在的部門編號(包括被分配職務后得到的職務部門編號)
public Vector getBMBHS()
{
Vector vect = new Vector();
String sql = " select BMBH from news.ZZ_ZGZWB where ZGBH='"+uid+"'";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
while(rs.next())
{
String bmbh = ds.toString(rs.getString(1));
String bmmc = db.toName("ZZ_BMB","BMBH","BMMC",bmbh);
Hashtable hash = new Hashtable();
hash.put("BMBH",bmbh);
hash.put("BMMC",bmmc);
vect.add(hash);
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
return vect;
}
public boolean isRightOrg(String lbid){//ZZ_FBXWB//部門新聞操作權限(根據orgmenu.id判斷)(uid,Orgid)
boolean isright=false;
ResultSet rst=selectRecord("select LB from news.ZZ_FBXWB where ZGBH='"+uid
+"' and BMBH='"+Orgid+"' and LB = 2");
Statement stmt = null;
try{
if(rst.next()){ isright=true;}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rst!=null)try{ stmt = rst.getStatement(); rst.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
return isright;
}
public boolean isRightPage(String dxbh,String whichtable,String sf,String cz){//版面權限
boolean isright=false;
ResultSet rst=selectRecord("select LB from news.ZZ_FBXWB where ZGBH='"+uid
+"' and LB = 1 and DXBH='"+ dxbh +"' and WHICHTABLE = '"+whichtable+"' and SF='"
+sf+"' and cz='"+cz+"'");
Statement stmt = null;
try{
if(rst.next()){ isright=true;}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rst!=null)try{ stmt = rst.getStatement(); rst.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
return isright;
}
/**取得模塊權限------------lbh-----------11-29*/
public String getRightModelbh()
{
String czqx = "",czqx1="";
String bmbh = "",bmbhchg="";
String zwbh = "";
String right = "";
String sql = "select BMBH,ZWBH,CZQX from news.ZZ_ZGZWB where ZGBH='"+uid+"'";
/*if(!uid.equals("1") && !Orgid.equals("-1"))
{
char bmsub;
int n=19;
for(n=19;n>=0;n--)
{
bmsub = Orgid.charAt(n);
if(bmsub!='0')
break;
}
if(n==-1) n=1;
sql += " and (BMBH='"+Orgid+"' or BMBH like '%"+Orgid.substring(0,n+1)+"%')";
}*/
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
while(rs.next())//取得職務表權限
{
czqx = ds.toString(rs.getString("CZQX"));
bmbh = ds.toString(rs.getString("BMBH"));
zwbh = ds.toString(rs.getString("ZWBH"));
if(!bmbh.equals("") && !zwbh.equals("")){
if(czqx.equals(""))//當職務表中權限為空時,去部門職務表權限
{
sql = "select CZQX from news.ZZ_ZWB where BMBH='"+bmbh+"' and ZWBH="+zwbh+" and ZWZT=0";
ResultSet rs_t = selectRecord(sql);
try{
if(rs_t.next())
czqx = ds.toString(rs_t.getString("CZQX"));
if(rs_t!=null)try{ stmt = rs_t.getStatement(); rs_t.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
if(czqx.equals(""))//當職務權限集合為空時查詢字典
{
rs_t = selectRecord("select ID from news.CODE_ANCZQXB where MRCZ=1 and SYZT=0");
while(rs_t.next())
{
czqx1 = rs_t.getString(1);
if(czqx.equals(""))
czqx = czqx1;
else
czqx = czqx+","+czqx1;
}
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs_t!=null)try{ stmt = rs_t.getStatement(); rs_t.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
}
if(!bmbhchg.equals("") && !bmbh.equals(bmbhchg))
{
right = right+"@"+bmbh+":"+czqx;
bmbhchg = bmbh;
continue;
}
if(right.equals("") && !czqx.equals(""))
right = bmbh+":"+czqx;
else if(!right.equals("") && !czqx.equals(""))
right = right+","+czqx;
bmbhchg = bmbh;
}
}
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
//////////////////////////////////////////////////////////////////////////////
if(right.equals(""))//當職務權限集合為空時查詢字典
{
bmbh = Orgid;
stmt = rs.getStatement();rs.close();stmt.close();
rs = selectRecord("select ID from news.CODE_ANCZQXB where MRCZ=1 and SYZT=0");
while(rs.next())
{
czqx = rs.getString(1);
if(!right.equals("") && !czqx.equals(""))
right = right+","+czqx;
if(right.equals("") && !czqx.equals(""))
right = bmbh+":"+czqx;
}
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
return right;
}
/**是否有模塊操作權限------------lbh-----------11-29*/
public boolean isRightModelbh(String strmkmc,String strbtnmc)
{
boolean bool = false;
/*原先每次取數據庫的代碼
ResultSet rs = selectRecord("select ID from news.CODE_ANCZQXB where MKMC='"+ds.toString(strmkmc)+"' and ANMC='"+ds.toString(strbtnmc)+"'");
String mkbh = "";
Statement stmt = null;
try{
if(rs.next())
mkbh = ds.toString(rs.getString("ID"));
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關閉聲明時statement出錯"+e);}
}
String rights = getRightModelbh();
String []ids = rights.split("@");
for(int i=0;i<ids.length;i++)
{
String []bmrt = ids[i].split(":");
char bmsub ;
int n=19;
for(n=19;n>=0;n--)
{
bmsub = bmrt[0].charAt(n);
if(bmsub!='0')
break;
}
//要setOrgid為當前部門
if(bmrt[0].equals(Orgid) || (bmrt[0].substring(0,n+1)).equals(Orgid.substring(0,n+1)))
{
String []rts = bmrt[1].split(",");
for(int j=0;j<rts.length;j++)
{
if(rts[j].equals(mkbh))
{
bool = true;
break;
}
}
}
}
*/
//////////////
//從靜態向量中取得權限記錄
if(PublicData.v_Buttons == null)
PublicData.rebuildButtonTable();
String strID = null;
String strRight = null;
Hashtable hash = null;
//得到該按鈕的ID
int k = PublicData.v_Buttons.size();
for(int i=0;i<k;i++){
hash = (Hashtable)PublicData.v_Buttons.get(i);
if(strmkmc.equals((String)hash.get("MKMC")) && strbtnmc.equals((String)hash.get("ANMC")))
{
strID = ","+(String)hash.get("ID")+",";
break;
}
}
//得到此人的所有權限
if(Orgid.equals("-1")){//不限制所在部門
if(PublicData.v_right==null)
PublicData.rebuildRightVector();
k = PublicData.v_right.size();
for(int i=0;i<k;i++){
if(uid.equals((String)PublicData.v_right.get(i))){
strRight = ","+(String)PublicData.v_right.get(++i)+",";
break;
}
}
}
else{//限制部門
if(PublicData.v_RightTable == null)
PublicData.rebuildRightTable();
k = PublicData.v_RightTable.size();
boolean b = false;
for(int i=0;i<k;i++){
hash = (Hashtable)PublicData.v_RightTable.get(i);
if(uid.equals((String)hash.get("ZGBH"))){
if(!b) b = true;
int n=19;
String bmrt = (String)hash.get("BMBH");
for(n=19;n>=0;n--)
{
if(bmrt.charAt(n)!='0')
break;
}
if(bmrt.equals(Orgid) || (bmrt.substring(0,n+1)).equals(Orgid.substring(0,n+1)))
{
String str = (String)hash.get("CZQX");
if(strRight==null)
strRight = str;
else
strRight += ","+str;
}
}
else if(b)
break;
}
if(strRight == null){
if(PublicData.s_RightDefault==null)
PublicData.rebuildRightDefault();
strRight = ","+PublicData.s_RightDefault+",";
}
else
strRight = ","+ds.strDistinct(strRight)+",";
}
//判斷權限
bool = (strRight.indexOf(strID)!=-1);
//////////////
return bool;
}
public static void main(String args[])
{
RightBean mb = new RightBean();
mb.setUID("1");
//判斷是否是管理員
boolean bool = mb.isAdmin();
//模塊權限用法:true/false
bool = mb.isRightMode("個人信息","修改個人信息");
//流程權限用法:true/false
bool = mb.isRightFlow("發郵件");
//系統配置參數
System.out.println(mb.isRightMode("部門列表","增加子部門"));
//System.out.println(mb.getConfValue("短消息保存時間"));
System.out.println("\r\n\r\nend");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -