?? orgmenubean.java
字號:
package oa.bean;
import java.text.*;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.sql.*;
import oa.main.*;
import javax.swing.tree.DefaultMutableTreeNode;
public class OrgMenuBean extends ParentBean
{
int strID=-1;//當(dāng)前類唯一編號
int strParentID=-1;//父類編號
String strOrgID="";
public void setID(int o)//設(shè)置菜單唯一編號
{
strID = o;
}
public void setParentID(int o)//設(shè)置父菜單編號
{
strParentID = o;
}
public void setOrgID(String o)//設(shè)置父菜單編號
{
strOrgID = o;
}
//根據(jù)職部門編號生成其子樹并返回根節(jié)點(diǎn)
public DefaultMutableTreeNode buildTree(String orgid)
{
String sql = "";
sql = "select * from ZZ_BMB where BMBH='"+orgid+"'";
Statement stmt = null;
Hashtable hash = new Hashtable();//存放部門信息
ResultSet rs = selectRecord(sql);
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
if(rs.next())
{
hash.clear();
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("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
DefaultMutableTreeNode root = new DefaultMutableTreeNode(hash);//建立樹根
//System.out.println("部門信息"+hash);
//開始建立類樹
String DepartNo = "";
String strPBH = "0";
DepartNo = (String)((Hashtable) root.getUserObject()).get("BMBH");
sql = "select * from orgmenu where BMBH = '"+DepartNo+"' and PBH = "+strPBH+" order by JBXH";
ResultSet rs1 = selectRecord(sql);
try{
ResultSetMetaData rsmd1 = rs1.getMetaData();
int cols1 = rsmd1.getColumnCount();
while(rs1.next())
{
Hashtable hash1 = new Hashtable();
hash1.clear();
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);
}
//System.out.println("一級類別信息"+hash1);
DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode(hash1);
root.add(treeNode);
buildSubTree(treeNode);
}
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
return root;
}
//迭代生成樹
private void buildSubTree(DefaultMutableTreeNode rootNode)
{
String sql = "";
String DepartNo = "";
DefaultMutableTreeNode root = rootNode;
DefaultMutableTreeNode treeNode;
//選出rootNode的子節(jié)點(diǎn)
DepartNo = (String)((Hashtable) rootNode.getUserObject()).get("BMBH");
String strPBH = (String)((Hashtable) rootNode.getUserObject()).get("BH");
//System.out.println("DepartNo="+DepartNo);
//System.out.println("strPBH="+strPBH);
sql ="select * from orgmenu where BMBH = '"+DepartNo+"' and PBH = "+strPBH+" order by JBXH";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
//System.out.println("dddddddddd");
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);
}
treeNode = new DefaultMutableTreeNode(hash);
//System.out.println("二級類別信息"+hash);
root.add(treeNode);
buildSubTree(treeNode);
}
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
}
//新增子類信息
public int addMenu(Hashtable hash)
{
int intMax = makeID("ORGMENU","BH","","",true);
String strParentId = ds.toString((String)hash.get("PBH"));
String strOrgId = ds.toString((String)hash.get("BMBH"));
String strName = ds.toString((String)hash.get("MC"));
String strJBXH = ds.toString((String)hash.get("JBXH"));
if(strParentId.equals("")) strParentId = "0";
String sql ="";
sql = "select * from ORGMENU where BMBH = '"+strOrgId+"' and PBH = "+strParentId+" and MC = '"+strName+"'";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
if(rs.next())
return 1;
}
catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null)try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明statement時(shí)出錯(cuò);錯(cuò)誤為:"+e);}
}
int intJBXH = setJBXH(strOrgId,strParentId,strJBXH);
Vector vect =new Vector();
vect.add("ORGMENU");
vect.add(addVector("BH",String.valueOf(intMax),"NUM"));
vect.add(addVector("PBH",strParentId,"NUM"));
vect.add(addVector("BMBH",strOrgId,"CHAR"));
vect.add(addVector("MC",strName,"CHAR"));
vect.add(addVector("JBXH",String.valueOf(intJBXH),"NUM"));
return insertRecord(vect);
}
//修改子類信息
public int updateMenu(Hashtable hash)
{
String strId = ds.toString((String)hash.get("BH"));
String strParentId = ds.toString((String)hash.get("PBH"));
String strOrgId = ds.toString((String)hash.get("BMBH"));
String strName = ds.toString((String)hash.get("MC"));
String strJBXH = ds.toString((String)hash.get("JBXH"));
String sql ="";
String stroName = "";
sql = "select MC from ORGMENU where BH = "+strId+"";
ResultSet rs1 = selectRecord(sql);
Statement stmt = null;
try{
if(rs1.next())
{
stroName = ds.toString(rs1.getString("MC"));
}
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
//被修改名稱
if(!stroName.equals(strName))
{
sql = "select * from ORGMENU where BMBH = '"+strOrgId+"' and PBH = "+strParentId+" and MC = '"+strName+"'";
ResultSet rs = selectRecord(sql);
try{
if(rs.next()){ return 1; }
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
}
int intJBXH = setJBXH(strId,strOrgId,strParentId,strJBXH);
Vector vect =new Vector();
vect.add("ORGMENU");
vect.add(addVector("MC",strName,"CHAR"));
vect.add(addVector("JBXH",String.valueOf(intJBXH),"NUM"));
vect.add("BH="+strId+"");
return updateRecord(vect);
}
//刪除子類信息
public int delMenu()
{
String sql = "";
String strJBXH = "0";
String strOrgID ="";
String strid ="";
ResultSet rs = null;
int intJBXH = Integer.parseInt(strJBXH);
sql = "select * from orgmenu where BH = "+strID+"";
rs = selectRecord(sql);
Statement stmt = null;
try{
if(rs.next())
{
strJBXH = ds.toString(rs.getString("JBXH"));
strOrgID = ds.toString(rs.getString("BMBH"));
strid = ds.toString(rs.getString("BH"));
}
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
sql = "select count(id) from article where article.organid='"+strOrgID+"' and article.wzlx="+strID+"";
rs = selectRecord(sql);
int article_num = 0;
try{
if(rs.next())
article_num = rs.getInt(1);
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
if(article_num!=0){
return article_num;
}
if(isChild(strOrgID,strid)) return -5;
intJBXH = Integer.parseInt(strJBXH);
sql = "update orgmenu set JBXH = JBXH-1 where BMBH = '"+strOrgID+"' and PBH="+strParentID+" and JBXH>"+intJBXH+"";
deleteRecord(sql);
sql = "delete from orgmenu where BH = "+strID+"";
return deleteRecord(sql);
}
//取得所有下一級類信息
public Vector getAllDownCs(String id)
{
Vector vect = new Vector();
return vect;
}
//新增的時(shí)候設(shè)置級別序號
public int setJBXH(String id,String pid,String jbxh)
{
int intJBXH = makeID("ORGMENU","BMBH","PBH","JBXH",id,pid,false,true);
if(jbxh.equals("")) jbxh = "0";
int intxh = Integer.parseInt(jbxh);
if(intxh>0&&intxh<intJBXH)
{
intJBXH = intxh;
String sql = "";
sql = "update orgmenu set JBXH=JBXH+1 where BMBH = '"+id+"' and PBH = "+pid+" and JBXH>="+intxh;
deleteRecord(sql);
}
return intJBXH;
}
//修改的時(shí)候設(shè)置級別序號
public int setJBXH(String id,String orgid,String pid,String strJBXH)
{
if(pid.equals(""))
pid = "0";
ResultSet rs1 = selectRecord("select JBXH from ORGMENU where BH=" + id);
int yjbxh=999;
Statement stmt = null;
try{
if(rs1.next())
yjbxh=Integer.parseInt(rs1.getString("JBXH"));
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
///////////////
int jbxh = Integer.parseInt(strJBXH);
int maxjbNo = makeID("ORGMENU","BMBH","PBH","JBXH",orgid,pid,false,true);
if(jbxh==0||jbxh>=maxjbNo)
jbxh=maxjbNo-1;
if(jbxh < yjbxh){
String sql1="update ORGMENU set JBXH=JBXH+1 where BMBH='"
+ orgid + "' and PBH = " + pid
+ " and JBXH >="
+ jbxh
+ " and JBXH<"
+ yjbxh;
deleteRecord(sql1);
}
else if(jbxh > yjbxh && yjbxh!=0){
String sql2="update ORGMENU set jbxh=jbxh-1 where BMBH='"
+ orgid + "' and PBH = " + pid
+ " and JBXH <="
+ jbxh
+ " and JBXH>"
+ yjbxh;
deleteRecord(sql2);
}
//////////////////////
return jbxh;
}
//根據(jù)編號取得名稱
public String toName(String id)
{
String sql ="";
String name = "";
if(id.equals("")) return name;
sql = "select mc from orgmenu where BH = "+id+"";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
if(rs.next())
name = ds.toString(rs.getString("MC"));
}catch(Exception e){System.out.println("運(yùn)行時(shí)出錯(cuò):"+e);}
finally{
if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("關(guān)閉記錄集rs時(shí)出錯(cuò)"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("關(guān)閉聲明時(shí)statement出錯(cuò)"+e);}
}
return name;
}
//取得某一條信息
public Hashtable getOneData(String id)
{
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -