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

📄 menuchildbean.java

📁 在系统开发过程中用到了javabean和jsp技术
💻 JAVA
字号:
/**********************************************************
Version 1.0
Date:2003-10-21
Description:菜单维护表:列表查询、单条信息查询、增加记录、修改记录、删除记录
Other:
Variable List:
1.int strID //菜单唯一编号
2.int strParentID //父菜单编号

Function List:
1.public MenuBean()//构造函数
2.public void setID(String o)//设置菜单唯一编号
2.public void setParentID(String o)//设置父菜单编号

4.public Vector getData()//取得菜单维护表所有记录
5.public Hashtable getOneData()//取得一条记录的信息
6.public boolean getOneData(String a,String b,String c)//判断是否有满足条件的记录 true:有,false:无
7.public Vector getData(String a,String b,String c)//取得菜单维护表中满足条件的所有记录
public Vector changeData(String a,String b,String c)//修改菜单中的须修改的记录

7.public int addMenu(Hashtable hash)//增加菜单维护表数据记录
8.public int modMenu(Hashtable hash)//修改菜单维护表数据记录
9.public int delMenu()//删除菜单维护表数据记录
  public Hashtable getID3() //取得记录的三级菜单

History:

***********************************************************/
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 MenuChildBean extends ParentBean
{
	int strID=-1;//菜单唯一编号
	int strParentID=-1; //父菜单编号

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

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

	public Hashtable getID3() //取得记录的三级菜单
	{
		Hashtable ht = new Hashtable();
		Hashtable hash = (Hashtable)getOneData();
		String strthis = (String)hash.get("ISTHIS");
		String strparent = (String)hash.get("IDPARENT");
		if(strthis.equals("1"))
		{
			ht.put("ISID3","no");
			return ht;
		}
		else
		{
			ht.put("ISID3","yes");
			String sql = "select * from news.menu where id="+strparent;
			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));
				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 boolean getData() //取得一条记录的信息
	{
		Hashtable ht = new Hashtable();
		String sql = "";

		sql = "select * from news.menuchild where isthis=0 and idparent="+strParentID+"";

		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
			if(rs.next())
				return false;
		}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 true;
	}

	public Hashtable getOneData() //取得一条记录的信息
	{
		Hashtable ht = new Hashtable();
		String sql = "";

		sql = "select * from news.menuchild where ID="+strID+"";

		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 buildTree()  {
		
		Vector vt = new Vector();

		String sql =
			" Select * from news.MENUCHILD "
				+ " Where IDPARENT="+strParentID
				+ " and ISTHIS=0 order by ID ";
		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
			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);
				buildSubTree(root);
				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);}		
		}
		return vt;
	}

	//迭代生成树
	private void buildSubTree(DefaultMutableTreeNode rootNode)
		 {
		String sql = "";
		String ParentId = (String) ((Hashtable) rootNode.getUserObject()).get("ID");
		DefaultMutableTreeNode root = rootNode;
		DefaultMutableTreeNode treeNode;

		//选出rootNode的子节点		
		sql = " Select * from news.MENUCHILD "
				+ " Where IDPARENT="+ParentId
				+ " and ISTHIS=1 order by ID ";
		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);
			}
			treeNode = new DefaultMutableTreeNode(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) //增加菜单维护表数据记录
	{
		String sql = "";		
		int intMax = db.makeID("MENUCHILD","ID","","",true);
		String strParent = ds.toString((String)hash.get("IDPARENT"));
		String strBmname = ds.toGBK((String)hash.get("MENUCHILD"));
		String strIsthis = ds.toString((String)hash.get("ISTHIS"));

		Vector vect =new Vector();
		vect.add("MENUCHILD");
		vect.add(addVector("ID",String.valueOf(intMax),"NUM"));
		vect.add(addVector("IDPARENT",strParent,"NUM"));
		vect.add(addVector("MENUCHILD",strBmname,"CHAR"));
		vect.add(addVector("ISTHIS",strIsthis,"NUM"));
		
		return insertRecord(vect);

	}
	
	
	public int modMenu(Hashtable hash) //修改菜单维护表数据记录
	{
		Vector vect = new Vector();
		String strParent = ds.toString((String)hash.get("IDPARENT"));
		String strBmname = ds.toGBK((String)hash.get("MENUCHILD"));
		String strIsthis = ds.toString((String)hash.get("ISTHIS"));
        
		vect.add("MENUCHILD");
		vect.add(addVector("IDPARENT",strParent,"NUM"));
		vect.add(addVector("MENUCHILD",strBmname,"CHAR"));
		vect.add(addVector("ISTHIS",strIsthis,"NUM"));
		vect.add("ID="+strID+"");
		
		return updateRecord(vect);
	}

	public int delMenu() //删除菜单维护表数据记录
	{
		String sql = "";
		sql = "select * from news.menuchild where idparent="+strID+" and isthis=1";

		ResultSet rs = selectRecord(sql);
		Statement stmt = null;
		try{
		if(rs.next())
		{
			return 2;
		}
		else
		{ 
			sql = "delete menuchild where id="+strID;
			return deleteRecord(sql);
		}
		}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 -1;
	}
	
	public static void main(String args[]) 
	{
		
		MenuChildBean mcb = new MenuChildBean();
		mcb.setID(1);
		System.out.println("begin\r\n\r\n");
		System.out.println(mcb.getID3()+"\r\n\r\n");

        
		
		System.out.println("\r\n\r\nend");
	}
}

⌨️ 快捷键说明

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