⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orgmenubean.java

📁 这是一个很好用的软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

package oa.bean;

import java.util.*;
import java.sql.*;
import oa.main.*;
import javax.swing.tree.DefaultMutableTreeNode;

public class OrgMenuBean extends ParentBean {

	int strID = -1;//当前类唯一编号

	int strParentID = -1;//父类编号

	String strOrgID = "";

	public void setID(int o)//设置菜单唯一编号
	{
		strID = o;
	}

	public void setParentID(int o)//设置父菜单编号
	{
		strParentID = o;
	}

	public void setOrgID(String o)//设置父菜单编号
	{
		strOrgID = o;
	}

	//根据职部门编号生成其子树并返回根节点
	public DefaultMutableTreeNode buildTree(String orgid) {
		String sql = "";
		sql = "select * from news.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("运行时出错:" + 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);
				}
		}
		DefaultMutableTreeNode root = new DefaultMutableTreeNode(hash);//建立树根
		//System.out.println("部门信息"+hash);

		//开始建立类树
		String DepartNo = "";
		String strPBH = "0";
		DepartNo = (String) ((Hashtable) root.getUserObject()).get("BMBH");

		sql = "select * from news.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("运行时出错:" + 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);
				}
		}
		return root;
	}

	//迭代生成树
	private void buildSubTree(DefaultMutableTreeNode rootNode) {
		String sql = "";
		String DepartNo = "";
		DefaultMutableTreeNode root = rootNode;
		DefaultMutableTreeNode treeNode;

		//选出rootNode的子节点
		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 news.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("运行时出错:" + 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);
				}
		}
	}

	//新增子类信息
	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 news.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("运行时出错:" + 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 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 news.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("运行时出错:" + 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);
				}
		}
		//被修改名称
		if (!stroName.equals(strName)) {
			sql = "select * from news.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("运行时出错:" + 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 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 news.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("运行时出错:" + 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);
				}
		}
		sql = "select count(id) from news.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("运行时出错:" + 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 (article_num != 0) {
			return article_num;
		}
		if (isChild(strOrgID, strid))
			return -5;
		intJBXH = Integer.parseInt(strJBXH);
		sql = "update news.orgmenu set JBXH = JBXH-1 where BMBH = '" + strOrgID
				+ "' and PBH=" + strParentID + " and JBXH>" + intJBXH + "";
		deleteRecord(sql);

		sql = "delete from news.orgmenu where BH = " + strID + "";
		return deleteRecord(sql);
	}

	//取得所有下一级类信息
	public Vector getAllDownCs(String id) {
		Vector vect = new Vector();
		return vect;
	}

	//新增的时候设置级别序号
	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;
	}

	//修改的时候设置级别序号
	public int setJBXH(String id, String orgid, String pid, String strJBXH) {
		if (pid.equals(""))
			pid = "0";
		ResultSet rs1 = selectRecord("select JBXH from news.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("运行时出错:" + 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);
				}
		}
		///////////////
		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;
	}

	//根据编号取得名称
	public String toName(String id) {
		String sql = "";
		String name = "";
		if (id.equals(""))
			return name;

		sql = "select mc from news.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("运行时出错:" + 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 name;
	}

	//取得某一条信息
	public Hashtable getOneData(String id) {
		Hashtable hash = new Hashtable();
		String sql = "";

		sql = "select * from news.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));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -