📄 menubean.java
字号:
String sql="";
sql = "delete from ZZ_FBXWB where DXBH=" + strID + "";
int ii = deleteRecord(sql);
sql = "delete from menu where id = " + strID + "";
int jj = deleteRecord(sql);
return jj;
}
public Vector delMenu(String strID) //删除多条菜单数据记录
{
Vector vect = new Vector();
Vector vect1 = new Vector();
Vector vect2 = new Vector();
String sql="";
if(strID.equals(""))
return vect;
sql = "select count(id),menuid from article where menuid in("+strID+") group by menuid order by menuid";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
while(rs.next())
{
Hashtable hash = new Hashtable();
hash.put("COUNT",(String)rs.getString(1));
hash.put("MENUID",(String)rs.getString(2));
vect1.add(hash);
}
vect.add(vect1);
sql = "select * from menu where id in(select distinct menuid from article where menuid in ("+strID+")) order by id";
stmt = rs.getStatement(); rs.close(); stmt.close();
rs = selectRecord(sql);
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);
}
vect2.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);}
}
vect.add(vect2);
// sql="select menu.id from menu,article where not exists(select article.id from article where article.menuid=menu.id) and menu.id in("+strID+") group by menu.id";////////////修改未完成
sql="delete from menu where not exists(select article.id from article where article.menuid=menu.id) and menu.id in("+strID+")";
deleteRecord(sql);
sql="delete from zz_fbxwb where not exists(select article.id from article where article.menuid=dxbh) and dxbh in("+strID+")";
deleteRecord(sql);
return vect;
}
//生成树并返回根节点
public Vector buildTree()
{
Vector vt = new Vector();
MenuChildBean mcb = null;
String sql =
" Select * from MENU Where ID2=0 and ID3=0 order by ID1 ";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
mcb = new MenuChildBean();
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while(rs.next())
{
Hashtable hash = new Hashtable();
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);
}
DefaultMutableTreeNode root = new DefaultMutableTreeNode(hash);//生成根节点,一级版面
String ParentId = (String)hash.get("ID1");
sql = "select * from menu where id1="+Integer.parseInt(ParentId)+" and id2<>0 and id3=0 order by id2";
ResultSet rs1 = selectRecord(sql);
try{
ResultSetMetaData rsmd1 = rs1.getMetaData();
int cols1 = rsmd1.getColumnCount();
while(rs1.next())
{
Hashtable hash1 = new Hashtable();
hash1.clear();
for (int i1 = 1; i1 <= cols1; i1++)
{
String field1 = ds.toString(rsmd1.getColumnName(i1));
String value1 = ds.toString(rs1.getString(i1));
hash1.put(field1, value1);
}
DefaultMutableTreeNode root1 = new DefaultMutableTreeNode(hash1);//生成二级节点,二级版面
String ParentId1 = (String)hash1.get("ID2");
sql = "select * from menu where id1="+Integer.parseInt(ParentId)+" and id2="+Integer.parseInt(ParentId1)+" and id3<>0 order by id3";
ResultSet rs2 = selectRecord(sql);
try{
ResultSetMetaData rsmd2 = rs2.getMetaData();
int cols2 = rsmd2.getColumnCount();
while(rs2.next())
{
Hashtable hash2 = new Hashtable();
hash2.clear();
for (int i2 = 1; i2 <= cols2; i2++)
{
String field2 = ds.toString(rsmd2.getColumnName(i2));
String value2 = ds.toString(rs2.getString(i2));
hash2.put(field2, value2);
}
DefaultMutableTreeNode root2 = new DefaultMutableTreeNode(hash2);//生成三级节点,三级版面
String str = (String)hash2.get("ID");
mcb.setParentID(Integer.parseInt(str));
Vector child = mcb.buildTree();
if(child.size()!=0)
{
for(int a=0;a<child.size();a++)
{
DefaultMutableTreeNode root3 = (DefaultMutableTreeNode)child.get(a);
root2.add(root3);
}
}
root1.add(root2);
}
}catch(Exception e){System.out.println("运行时出错:"+e);}
finally{
if(rs2!=null)try{ stmt = rs2.getStatement(); rs2.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
}
}catch(Exception e){System.out.println("运行时出错:"+e);}
finally{
if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("关闭记录集rs时出错"+e);}
if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("关闭声明时statement出错"+e);}
}
vt.add(root);
}
}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(mcb!=null) mcb.closeConn();
}
return vt;
}
public DefaultMutableTreeNode buildMenuTree(String PersonNo){
//最多只能处理到4层节点
Vector vect = buildTree();
Hashtable ht = new Hashtable();
ht.put("ROOT", "ROOT");
DefaultMutableTreeNode root = new DefaultMutableTreeNode(ht);
for (int i = 0; i < vect.size(); i++) {
root.add((DefaultMutableTreeNode) vect.get(i));
}
//取得4级以下节点到vectMenuChild
String sql =
" Select DXBH From ZZ_FBXWB "
+ " Where ZGBH='"
+ PersonNo
+ "'"
+ " and WhichTable='2'"
+ " and LB='1'";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
Vector vectMenuChild = new Vector();
while (rs.next())
vectMenuChild.add(rs.getString("DXBH"));
//取得4级以上节点到vectMenu
sql =
" Select DXBH From ZZ_FBXWB "
+ " Where ZGBH='"
+ PersonNo
+ "'"
+ " and WhichTable='1'"
+ " and LB='1'";
stmt = rs.getStatement();
rs.close();
stmt.close();
rs = selectRecord(sql);
Vector vectMenu = new Vector();
while (rs.next())
vectMenu.add(rs.getString("DXBH"));
//开始剪枝
boolean canCut = true;
boolean cut = true;
while (canCut && root.getChildCount() > 0) {
canCut = false;
for (Enumeration e = root.preorderEnumeration();
e.hasMoreElements();
) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode) e.nextElement();
Hashtable hs = (Hashtable) (node.getUserObject());
String strParent = (String) hs.get("IDPARENT");
String strID = (String) hs.get("ID");
//处理4层以下的节点
if (strParent != null)
if (!vectMenuChild.contains(strID)) {
//检查这个节点的根路径上的节点是否有效
Object[] obj =
((DefaultMutableTreeNode) node.getParent())
.getUserObjectPath();
cut = true;
for (int i = 0; i < obj.length; i++) {
hs = (Hashtable) obj[i];
strID = ds.toString((String) hs.get("ID"));
if (vectMenu.contains(strID)) {
cut = false;
}
} //end for
if ((cut) && (node.isLeaf())) {
node.removeFromParent();
canCut = true;
}
} else {
Hashtable hst = (Hashtable) node.getUserObject();
hst.put("Enabled", "True");
} //end if
//处理4层以上节点
if (strParent == null)
if (!vectMenu.contains(strID)) {
//检查这个节点的根路径上的节点是否有效
Object[] obj = node.getUserObjectPath();
cut = true;
for (int i = 0; i < obj.length; i++) {
hs = (Hashtable) obj[i];
strID = ds.toString((String) hs.get("ID"));
if (vectMenu.contains(strID)) {
cut = false;
}
}
if ((cut) && (node.isLeaf())) {
node.removeFromParent();
canCut = true;
}
} else {
Hashtable hst = (Hashtable) node.getUserObject();
hst.put("Enabled", "True");
} //end if
} //end for
} //end while
}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 root;
}
public String getbmqx(String uid)//获得个人有管理员权限的所有版面
{
String showqx1 = "";//所有可审批的位于menu表中的版面
String imgqx1 = "";//所有可审批图片的位于menu表中的版面
String headqx1 = "";//所有可审批首页的位于menu表中的版面
String goodqx1 = "";//所有可审批焦点的位于menu表中的版面
Hashtable ht = new Hashtable();
String sql = "select dxbh,cz,whichtable from zz_fbxwb where zgbh='"+uid+"' and lb='1' and sf='2' ";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try{
while(rs.next())
{
String dxbh = ds.toString(rs.getString(1));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -