📄 menubean.java
字号:
package oa.bean;
import java.util.*;
import java.sql.*;
import oa.main.*;
import javax.mail.internet.NewsAddress;
import javax.swing.tree.DefaultMutableTreeNode;
public class MenuBean extends ParentBean {
int strID = -1;//菜单唯一编号
String uid = "-1";
public void setID(int o)//设置菜单唯一编号
{
strID = o;
}
public void setUID(String u) {
uid = u;
}
public Vector getstyle()//取得可用的版面风格
{
Vector vt = new Vector();
String sql = "";
sql = "select * from news.code_zdb where syzt=0 and zdmc='版面风格'";
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);
}
vt.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 vt;
}
public String toname()//取得一条记录的中文路径
{
String name = "";
Hashtable hash = (Hashtable) getOneData();
String id1 = (String) hash.get("ID1");
String id2 = (String) hash.get("ID2");
String id3 = (String) hash.get("ID3");
if (id2.equals("0")) {
name = (String) hash.get("MENU1");
}
if (id3.equals("0") && !id2.equals("0")) {
name = (String) hash.get("MENU1") + "\\"
+ (String) hash.get("MENU2");
}
if (!id3.equals("0")) {
name = (String) hash.get("MENU1") + "\\"
+ (String) hash.get("MENU2") + "\\"
+ (String) hash.get("MENU3");
}
return name;
}
public Hashtable getID1()//取得一条记录的一级菜单
{
Hashtable ht = new Hashtable();
Hashtable hash = (Hashtable) getOneData();
String strid2 = (String) hash.get("ID2");
if (strid2.equals("0")) {
return hash;
}
String strid1 = (String) hash.get("ID1");
String sql = "select * from news.menu where id1=" + strid1
+ " and id2=0";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try {
//取得列数和列名
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while (rs.next()) {
for (int i = 1; i <= cols; i++) {
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
ht.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("关闭记录集rs时出错" + e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out.println("关闭声明时statement出错" + e);
}
}
return ht;
}
public Hashtable getID2()//取得一条记录的二级菜单
{
Hashtable ht = new Hashtable();
Hashtable hash = (Hashtable) getOneData();
String strid1 = (String) hash.get("ID1");
String strid2 = (String) hash.get("ID2");
String strid3 = (String) hash.get("ID3");
if (strid2.equals("0")) {
ht.put("ISID2", "no");
return ht;
}
ht.put("ISID2", "yes");
if (!strid2.equals("0") && strid3.equals("0")) {
hash.put("ISID2", "yes");
return hash;
} else {
String sql = "select * from news.menu where id1=" + strid1
+ " and id2=" + strid2 + " and id3=0";
ResultSet rs = selectRecord(sql);
Statement stmt = null;
try {
//取得列数和列名
ResultSetMetaData rsmd = rs.getMetaData();
int cols = rsmd.getColumnCount();
while (rs.next()) {
for (int i = 1; i <= cols; i++) {
String field = ds.toString(rsmd.getColumnName(i));
String value = ds.toString(rs.getString(i));
ht.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("关闭记录集rs时出错" + e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out.println("关闭声明时statement出错" + e);
}
}
}
return ht;
}
public Vector getData()//取得菜单维护表所有记录select B.id,B.id1,B.id2,B.id3 from
// news.menu a,news.menu b where a.id='290' and
// b.id1=a.id1 and (b.id2=a.id2 and a.id2<>0 or
// a.id2=0) and (b.id3=a.id3 and a.id3<>0 or a.id3=0)
// and b.zt=0 order by b.id1,b.id2,b.id3
{
Vector vect = new Vector();
String sql = "select * from news.menu order by id1,id2,id3";
String sqllr = "select xm,dxbh,news.menu.id1,news.menu.id2,news.menu.id3,news.menu.zt from news.zz_fbxwb,news.zz_zgb,news.menu where sf='1' and news.zz_zgb.zgbh<>'1' and news.zz_fbxwb.zgbh=news.zz_zgb.zgbh and news.zz_fbxwb.dxbh=news.menu.id order by id1,id2,id3,news.zz_zgb.bmbh,news.zz_zgb.jbxh";
String sqlcz1 = "select xm,dxbh,news.menu.id1,news.menu.id2,news.menu.id3,news.menu.zt from news.zz_fbxwb,news.zz_zgb,news.menu where sf='2' and news.zz_zgb.zgbh<>'1' and cz='1' and news.zz_fbxwb.zgbh=news.zz_zgb.zgbh and news.zz_fbxwb.dxbh=news.menu.id order by id1,id2,id3,news.zz_zgb.bmbh,news.zz_zgb.jbxh";
String sqlcz2 = "select xm,dxbh,news.menu.id1,news.menu.id2,news.menu.id3,news.menu.zt from news.zz_fbxwb,news.zz_zgb,news.menu where sf='2' and news.zz_zgb.zgbh<>'1' and cz='2' and news.zz_fbxwb.zgbh=news.zz_zgb.zgbh and news.zz_fbxwb.dxbh=news.menu.id order by id1,id2,id3,news.zz_zgb.bmbh,news.zz_zgb.jbxh";
String sqlcz3 = "select xm,dxbh,news.menu.id1,news.menu.id2,news.menu.id3,news.menu.zt from news.zz_fbxwb,news.zz_zgb,news.menu where sf='2' and news.zz_zgb.zgbh<>'1' and cz='3' and news.zz_fbxwb.zgbh=news.zz_zgb.zgbh and news.zz_fbxwb.dxbh=news.menu.id order by id1,id2,id3,news.zz_zgb.bmbh,news.zz_zgb.jbxh";
String sqlcz0 = "select xm,dxbh,news.menu.id1,news.menu.id2,news.menu.id3,news.menu.zt from news.zz_fbxwb,news.zz_zgb,news.menu where sf='2' and news.zz_zgb.zgbh<>'1' and cz='0' and news.zz_fbxwb.zgbh=news.zz_zgb.zgbh and news.zz_fbxwb.dxbh=news.menu.id order by id1,id2,id3,news.zz_zgb.bmbh,news.zz_zgb.jbxh";
String sqlnum = "select c.id,count(news.article.id) from news.article,news.menu c where menuid in(select distinct B.id from news.menu a,news.menu b where a.id=c.id and b.id1=a.id1 and (b.id2=a.id2 and a.id2<>0 or a.id2=0) and (b.id3=a.id3 and a.id3<>0 or a.id3=0) and b.zt=0 and a.zt=0) and news.article.ifshow='1' group by c.id";
if (!uid.equals("-1")) {
String str = getbmqx(uid);
if (str.equals(""))
str = "0";
sql = "select * from news.menu where id in (" + str
+ ") order by id1,id2,id3";
}
ResultSet rs = selectRecord(sql);
ResultSet rslr = selectRecord(sqllr);
ResultSet rscz0 = selectRecord(sqlcz0);
ResultSet rscz1 = selectRecord(sqlcz1);
ResultSet rscz2 = selectRecord(sqlcz2);
ResultSet rscz3 = selectRecord(sqlcz3);
ResultSet rsnum = selectRecord(sqlnum);
Vector vlr = new Vector(), vshow = new Vector(), vgood = new Vector(), vhead = new Vector(), vimg = new Vector(), vnum = new Vector();
Statement stmt = null;
try {
while (rslr.next()) {
Hashtable hash = new Hashtable();
hash.put("XM", rslr.getString("XM"));
hash.put("ID", rslr.getString("DXBH"));
vlr.add(hash);
}
while (rscz0.next()) {
Hashtable hash = new Hashtable();
hash.put("XM", rscz0.getString("XM"));
hash.put("ID", rscz0.getString("DXBH"));
vshow.add(hash);
}
while (rscz1.next()) {
Hashtable hash = new Hashtable();
hash.put("XM", rscz1.getString("XM"));
hash.put("ID", rscz1.getString("DXBH"));
vgood.add(hash);
}
while (rscz2.next()) {
Hashtable hash = new Hashtable();
hash.put("XM", rscz2.getString("XM"));
hash.put("ID", rscz2.getString("DXBH"));
vhead.add(hash);
}
while (rscz3.next()) {
Hashtable hash = new Hashtable();
hash.put("XM", rscz3.getString("XM"));
hash.put("ID", rscz3.getString("DXBH"));
vimg.add(hash);
}
while (rsnum.next()) {
Hashtable hash = new Hashtable();
hash.put("ID", rsnum.getString(1));
hash.put("COUNT", rsnum.getString(2));
vnum.add(hash);
}
//取得列数和列名
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));
if (field.equals("ADMIN")) {
String lr = "", img = "", good = "", head = "", show = "", num = "";
String id = (String) hash.get("ID");
for (int j = 0; j < vlr.size(); j++) {
if (((Hashtable) vlr.get(j)).get("ID").equals(id))
if (lr.equals(""))
lr = (String) ((Hashtable) vlr.get(j))
.get("XM");
else
lr += ","
+ (String) ((Hashtable) vlr.get(j))
.get("XM");
}
for (int j = 0; j < vshow.size(); j++) {
if (((Hashtable) vshow.get(j)).get("ID").equals(id))
if (show.equals(""))
show = (String) ((Hashtable) vshow.get(j))
.get("XM");
else
show += ","
+ (String) ((Hashtable) vshow
.get(j)).get("XM");
}
for (int j = 0; j < vgood.size(); j++) {
if (((Hashtable) vgood.get(j)).get("ID").equals(id))
if (good.equals(""))
good = (String) ((Hashtable) vgood.get(j))
.get("XM");
else
good += ","
+ (String) ((Hashtable) vgood
.get(j)).get("XM");
}
for (int j = 0; j < vhead.size(); j++) {
if (((Hashtable) vhead.get(j)).get("ID").equals(id))
if (head.equals(""))
head = (String) ((Hashtable) vhead.get(j))
.get("XM");
else
head += ","
+ (String) ((Hashtable) vhead
.get(j)).get("XM");
}
for (int j = 0; j < vimg.size(); j++) {
if (((Hashtable) vimg.get(j)).get("ID").equals(id))
if (img.equals(""))
img = (String) ((Hashtable) vimg.get(j))
.get("XM");
else
img += ","
+ (String) ((Hashtable) vimg.get(j))
.get("XM");
}
for (int j = 0; j < vnum.size(); j++) {
if (((Hashtable) vnum.get(j)).get("ID").equals(id))
num = (String) ((Hashtable) vnum.get(j))
.get("COUNT");
}
hash.put("LR", lr);
hash.put("IMG", img);
hash.put("GOOD", good);
hash.put("HEAD", head);
hash.put("SHOW", show);
hash.put("COUNT", num);
} else
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("关闭记录集rs时出错" + e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out.println("关闭声明时statement出错" + e);
}
if (rslr != null)
try {
stmt = rslr.getStatement();
rslr.close();
} catch (Exception e) {
System.out.println("关闭记录集rs时出错" + e);
}
if (stmt != null)
try {
stmt.close();
} catch (Exception e) {
System.out.println("关闭声明时statement出错" + e);
}
if (rscz0 != null)
try {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -