?? orgmenubean.java
字號:
Hashtable hash = new Hashtable();
String sql = "";
sql = "select * from orgmenu where BH = "+id+"";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
if(rs.next())
{
for(int i=1;i<=cols;i++)
{
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field,value);
}
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
return hash;
}
//取得部門名稱
public String getOrgName(String id)
{
String sql = "";
String name = "";
sql = "select BMMC from zz_bmb where BMBH = '"+id+"'";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
if(rs.next())
{
name = ds.toString(rs.getString("BMMC"));
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
return name;
}
//判斷是否有子類
public boolean isChild(String orgid,String pid)
{
String sql ="";
boolean b = false;
sql ="select * from orgmenu where BMBH = '"+orgid+"' and PBH = "+pid+"";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
if(rs.next())
b = true;
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
return b;
}
//取得當(dāng)前子類位置
public String getDetailPath(String orgid,String id)
{
String path = "";
String sql = "";
path = getOrgName(orgid);
if(id.equals("")) return path;
String spath = "";
while(!id.equals("0"))
{
sql = "select * from orgmenu where bh = "+id+"";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
if(rs.next())
{
spath +=ds.toString(rs.getString("MC"))+",";
id = ds.toString(rs.getString("PBH"));
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
}
String strpath[] = spath.split(",");
for(int i=strpath.length-1;i>=0;i--)
{
path+=">>"+strpath[i];
}
return path;
}
//初始化數(shù)據(jù)-----------------------------------------------------------------------------
public void initialMenu()
{
String sql="";
sql = "select BMBH from ZZ_BMB where BMBH like '%0000000000000000'";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
String strName[] = new String[3];
strName[0] ="綜合信息";
strName[1] ="公告通知";
strName[2] ="規(guī)章制度";
while(rs.next())
{
String strOrgid = "";
strOrgid = ds.toString(rs.getString("BMBH"));
for(int i=0;i<3;i++)
{
Hashtable hash =new Hashtable();
hash.put("PBH","0");
hash.put("BMBH",strOrgid);
hash.put("MC",strName[i]);
hash.put("JBXH","0");
addMenu(hash);
}
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
}
public void initialMenu(String strBMBH)
{
String sql="";
String strName[] = new String[3];
strName[0] ="綜合信息";
strName[1] ="公告通知";
strName[2] ="規(guī)章制度";
String strOrgid = ds.toString(strBMBH);
for(int i=0;i<3;i++)
{
Hashtable hash =new Hashtable();
hash.put("PBH","0");
hash.put("BMBH",strOrgid);
hash.put("MC",strName[i]);
hash.put("JBXH","0");
addMenu(hash);
}
}
//取得所有信息
public Vector getClass(String id)
{
Vector vect = new Vector();
return vect;
}
//取得上一級父類信息
public Hashtable getUpCs(String id)
{
Hashtable hash = new Hashtable();
ResultSet rs = selectRecord("SELECT * FROM ORGMENU WHERE BH in (SELECT BH FROM ORGMENU WHERE BH ="+ id +")");
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
if(rs.next()){
for(int i=1;i<=cols;i++)
{
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field,value);
}
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
return hash;
}
//取得下一級類信息
public Vector getDownCs(String id)
{
Vector vect = new Vector();
ResultSet rs = selectRecord("SELECT * FROM ORGMENU WHERE PBH=" + id + " order by JBXH");
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while(rs.next()){
Hashtable hash = new Hashtable();
for(int i=1;i<=cols;i++)
{
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field,value);
}
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("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
return vect;
}
public String getID1()//取得一級類別名稱
{
String str = "";
int pbh=strID;
Statement stmt = null;
while(pbh!=0){
ResultSet rs = selectRecord("SELECT PBH,MC FROM ORGMENU WHERE BH=" + pbh);
try{
if(rs.next()){
str = rs.getString("MC");
pbh = rs.getInt("PBH");
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
}
return str;
}
public int getPBH()
{
int str=0;
int pbh=strID;
Statement stmt = null;
ResultSet rs = null;
while(pbh!=0){
rs = selectRecord("SELECT PBH,BH FROM ORGMENU WHERE BH=" + pbh);
try{
if(rs.next()){
str = rs.getInt("BH");
pbh = rs.getInt("PBH");
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
}
return str;
}
public String getPathWithoutOrg()//取得當(dāng)前子類位置(不含部門名稱)
{
String path = "";
String sql = "";
if(strID==0) return path;
ResultSet rs = null;
Statement stmt = null;
while(strID!=0)
{
sql = "select * from orgmenu where bh = "+strID+"";
rs = selectRecord(sql);
try{
if(rs.next())
{
path +=ds.toString(rs.getString("MC"))+",";
strID = rs.getInt("PBH");
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
}
String strpath[] = path.split(",");
path="";
for(int i=strpath.length-1;i>=0;i--)
{
path+=strpath[i]+"\\";
}
path = path.substring(0,path.length()-1);
return path;
}
public Vector getData(String orgid)//根據(jù)部門編號取得此部門下的所有子類的樹形結(jié)構(gòu)
{
Vector vect = new Vector();
String sql = "select * from orgmenu where PBH=0 and BMBH='"+orgid+"' order by jbxh";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while(rs.next())
{
Hashtable hash = new Hashtable();
for(int i=1;i<=cols;i++)
{
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
hash.put(field,value);
}
vect.add(hash);
Vector v = new Vector();
sql = "select * from orgmenu where PBH="+rs.getInt("BH") + " order by jbxh";
ResultSet rs1 = selectRecord(sql);
try{
ResultSetMetaData rsmd1 = rs1.getMetaData();
int cols1 = rsmd1.getColumnCount();
while(rs1.next())
{
Hashtable hash1 = new Hashtable();
for(int i=1;i<=cols1;i++)
{
String field = ds.toString(rsmd1.getColumnName(i));
String value = ds.toString(rs1.getString(i));
hash1.put(field,value);
}
v.add(hash1);
}
vect.add(v);
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null)try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
}
if(vect.size()==0 && !orgid.equals("")){
initialMenu(orgid);
vect=getData(orgid);
}
}catch(Exception e){System.out.println("運行時出錯:"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時出錯"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時statement出錯"+e);}
}
return vect;
}
public static void main(String args[])
{
OrgMenuBean omb = new OrgMenuBean();
System.out.println("begin\r\n\r\n");
Hashtable hash = new Hashtable();
//hash.put("BH","5");
hash.put("PBH","4");
hash.put("BMBH","00020000000000000000");
hash.put("MC","防毒殺毒");
hash.put("JBXH","1");
omb.setID(3);
omb.setParentID(0);
//omb.setOrgID("00020000000000000000");
//omb.delMenu();
//omb.addMenu(hash);
//System.out.println(omb.buildTree("00010000000000000000").getDepth());
//System.out.println(omb.getDetailPath("8"));
System.out.println("\r\n\r\nend");
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -