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

📄 departmentbean.java

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			}
			int cols = rsmd.getColumnCount();
			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("DepartmentBean.buildTree(String)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("DepartmentBean.buildTree(String)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.buildTree(String)关闭声明时statement出错"+e);}		
		}
		DefaultMutableTreeNode root = new DefaultMutableTreeNode(hash);
		buildSubTree(root);
		return root;
	}

	public DefaultMutableTreeNode buildMyTree(String sql){
		ResultSet rs = selectRecord(sql);
		Hashtable hash = new Hashtable();
		Statement stmt = null;
		try{
			ResultSetMetaData rsmd = rs.getMetaData();
			//		结果集为空时返回
			if (!(rs.next())) {
				//System.err.println("数据表错误:根为空。");
				return null;
			}
			int cols = rsmd.getColumnCount();
			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("DepartmentBean.buildMyTree(String)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("DepartmentBean.buildMyTree(String)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.buildMyTree(String)关闭声明时statement出错"+e);}		
		}
		DefaultMutableTreeNode root = new DefaultMutableTreeNode(hash);
		buildSubTree(root);
		return root;
	}

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

		//选出rootNode的子节点
		DepartNo = (String) ((Hashtable) rootNode.getUserObject()).get("BMBH");
		sql =
			" Select BMBH,BMFBH,BMMC,JBXH from ZZ_BMB "
				+ " Where BMFBH='"
				+ DepartNo
				+ "' "
				+ " and BMZT=0  order by JBXH ";
		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("DepartmentBean.buildSubTree(root)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("DepartmentBean.buildSubTree(root)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.buildSubTree(root)关闭声明时statement出错"+e);}		
		}
	}


		//得到当前部门所有的职务名称
	public Vector getOrgDutys()
	{
		Vector vt = new Vector();
		String sql = "";
		sql = " select ZWBH,ZWMC from ZZ_ZWB where BMBH='"+ depNo +"' and ZWZT=0 order by JBXH ";
		ResultSet rs = selectRecord(sql);
		Hashtable ht = new Hashtable();
		Statement stmt = null;
		try{
			while (rs.next()) 
			{
				String zwNO   = ds.toString(rs.getString(1));
				String zwName = ds.toString(rs.getString(2));
				ht = new Hashtable();
				ht.put("ZWBH", zwNO);
				ht.put("ZWMC", zwName);
				vt.add(ht);
			}
		}catch(Exception e){System.out.println("DepartmentBean.getOrgDutys()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("DepartmentBean.getOrgDutys()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.getOrgDutys()关闭声明时statement出错"+e);}		
		}
		return vt;
	}

	//查询某部门职务信息
	public Vector getArr()
	{
		String sql = " select * from ZZ_ZWB where BMBH='"+ depNo + "' order by JBXH,ZWBH";
		ResultSet rs = selectRecord(sql);
		Vector vt = new Vector();
		Statement stmt = null;
		try{
			ResultSetMetaData rsmd = rs.getMetaData();
			int cols = rsmd.getColumnCount();
			int recsum = 0;
			while (rs.next())
			{
				recsum++;
				for(int i=1;i<=cols;i++)
				{
					Hashtable ht = new Hashtable();
					String field = ds.toString(rsmd.getColumnName(i));				
					String value = ds.toString(rs.getString(i));
					ht.put(field,value);
					vt.add(ht);
				}
			}
			vt.add(new Integer(recsum));
		}catch(Exception e){System.out.println("DepartmentBean.getArr()运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("DepartmentBean.getArr()关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.getArr()关闭声明时statement出错"+e);}		
		}
		return vt;
	}

	//生成新增纪录的'部门编号'
	private String makeNewNo(String fatherNo){

		String bmNo = "", maxNo = "00000000000000000000";
		long lbmNo = -1, lmaxNo = -1;
		String sql = "select BMBH from ZZ_BMB where BMFBH=" + fatherNo;
		ResultSet rs = db.QuerySQL(sql);
		boolean flg = false;

		Statement stmt = null;
		try{
			while (rs.next()) { //取得本部门最大编号
				bmNo = ds.toString(rs.getString("BMBH"));
				lbmNo = Long.parseLong(bmNo);
				if (lbmNo > lmaxNo) {
					lmaxNo = lbmNo;
					maxNo = bmNo;
				}
				flg = true;
			}
		}catch(Exception e){System.out.println("DepartmentBean.makeNewNo(String)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("DepartmentBean.makeNewNo(String)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.makeNewNo(String)关闭声明时statement出错"+e);}		
		}

		//生成加1的20位编号
		int index = -1;
		String strchar = "";
		String newNo = "";
		int subno = -1;
		if (flg) {
			for (int i = 19; i > 1; i--) {
				char data[] = { maxNo.charAt(i)};
				strchar = new String(data);
				if (!strchar.equals("0")) {
					index = i;
					flg = true;
					break;
				}
			}
			if (index % 2 == 0) {
				newNo = maxNo.substring(0, index);
				newNo =
					newNo.concat(
						String.valueOf(
							Integer.parseInt(maxNo.substring(index, index + 2))
								+ 1));
				newNo = newNo.concat(maxNo.substring(index + 2));
			}
			if (index % 2 != 0) {
				newNo = maxNo.substring(0, index - 1);
				subno =
					Integer.parseInt(maxNo.substring(index - 1, index + 1)) + 1;
				if (subno < 10) //单个位数在前面加0
					newNo = newNo + "0" + String.valueOf(subno);
				else
					newNo = newNo + String.valueOf(subno);
				newNo = newNo.concat(maxNo.substring(index + 1));
			}
		} else {
			maxNo = fatherNo;
			if (maxNo.equals("00000000000000000000")) {
				newNo = "00010000000000000000";
			} else {
				for (int i = 19; i > 1; i--) {
					char data[] = { maxNo.charAt(i)};
					strchar = new String(data);
					if (!strchar.equals("0")) {
						index = i;
						break;
					}
				}
				if (index % 2 == 0) {
					index += 3;
				} else {
					index += 2;
				}
				if (index % 2 == 0) {
					newNo = maxNo.substring(0, index);
					newNo =
						newNo.concat(
							String.valueOf(
								Integer.parseInt(
									maxNo.substring(index, index + 2))
									+ 1));
					newNo = newNo.concat(maxNo.substring(index + 2));
				}
				if (index % 2 != 0) {
					newNo = maxNo.substring(0, index - 1);
					subno =
						Integer.parseInt(maxNo.substring(index - 1, index + 1))
							+ 1;
					if (subno < 10) //单个位数在前面加0
						newNo = newNo + "0" + String.valueOf(subno);
					else
						newNo = newNo + String.valueOf(subno);
					newNo = newNo.concat(maxNo.substring(index + 1));
				}
			}

		}
		return newNo;
	}
	public int addRec(Hashtable ht,boolean rebuild){
		String fatherNo = ds.toString((String) ht.get("BMFBH"));
		String bmName = ds.toString((String) ht.get("BMMC"));
		String jbNo = ds.toString((String) ht.get("JBXH"));
		String bossNo = ds.toString((String) ht.get("TZWBH"));
	//	String admin = ds.toString((String) ht.get("GLYZWBH"));
	//	String ws = ds.toString((String) ht.get("WSZWBH"));
		//String ckqx = ds.toString((String) ht.get("CKQX"));

		String newNo = makeNewNo(fatherNo);
		String sqlno =
			"select ZWBH from ZZ_ZWB where BMBH='"
				+ fatherNo
				+ "' and ZWMC='"
				+ bossNo
				+ "'";
		ResultSet rs = selectRecord(sqlno);
		Statement stmt = null;
		try{
			if (rs.next()) {
				bossNo = ds.toString(rs.getString("ZWBH"));
			}
		}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("epartmentBean.addRec(Hashtable)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("epartmentBean.addRec(Hashtable)关闭声明时statement出错"+e);}		
		}
		if (bossNo.equals("") || bossNo == null)
			bossNo = "-1";
		//检验同意部门下部门名称是否已经存在
		ResultSet rst =
			selectRecord(
				"select BMBH from ZZ_BMB where BMMC='"
					+ bmName
					+ "' and BMFBH='"
					+ fatherNo
					+ "' and BMZT=0");
					System.out.println(
				"select BMBH from ZZ_BMB where BMMC='"
					+ bmName
					+ "' and BMFBH='"
					+ fatherNo
					+ "' and BMZT=0");
		try{
			if (rst.next()){
			return 1;
			}
		}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)运行时出错:"+e);}
		finally{
			if(rst!=null)try{ stmt = rst.getStatement(); rst.close();}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)关闭声明时statement出错"+e);}		
		}
/////////////////
		int maxjbNo=makeID("ZZ_BMB","BMFBH","BMZT","JBXH",fatherNo,"0",false,true);
		int jbxh=0;
		if(!jbNo.equals(""))
			jbxh=Integer.parseInt(jbNo);
		if(jbxh==0||jbxh>maxjbNo)
			{ jbxh=maxjbNo;jbNo=""+jbxh;}
//////////////////////
		String sql="update ZZ_BMB set jbxh=jbxh+1 where BMFBH='"+ fatherNo	+ "' and BMZT=0 and JBXH >=" + jbxh ;
		deleteRecord(sql);
//////////////////////

		Vector sqlvt = new Vector();
		sqlvt.add("ZZ_BMB");
		sqlvt.add(addVector("BMBH", newNo, "CHAR"));
		sqlvt.add(addVector("BMFBH", fatherNo, "CHAR"));
		sqlvt.add(addVector("BMMC", bmName, "CHAR"));
		sqlvt.add(addVector("TZWBH", bossNo, "CHAR"));
		sqlvt.add(addVector("JBXH", jbNo, "CHAR"));
	//	sqlvt.add(addVector("GLYZWBH", admin, "CHAR"));
	//	sqlvt.add(addVector("WSZWBH", ws, "CHAR"));
		sqlvt.add(addVector("BMZT", "0", "NUM"));
		//sqlvt.add(addVector("CKQX",strMax,"CHAR"));
		insertRecord(sqlvt);
//////////////////////
		ResultSet rs1 = null;
		int i=0;
		rs = selectRecord("select XMMC from CODE_ZDB where ZDMC='默认职务' and SYZT=0 order by JBXH");
		try{
			while(rs.next())
			{
				int zwbh=makeID("ZZ_ZWB","BMBH","ZWBH",""+newNo,false);
				String zwmc=rs.getString("XMMC");
				String czqx = "";
				if(zwmc.equals("主管领导")){
					rs1 = selectRecord("select XMMC from CODE_ZDB where ZDMC='操作权限主管领导'");
					if(rs1.next())
						czqx = rs1.getString("XMMC");
				}
				else if(zwmc.equals("分管领导")){
					rs1 = selectRecord("select XMMC from CODE_ZDB where ZDMC='操作权限分管领导'");
					if(rs1.next())
						czqx = rs1.getString("XMMC");
				}
				sqlvt.clear();
				sqlvt.add("ZZ_ZWB");
				sqlvt.add(addVector("BMBH", newNo, "CHAR"));
				sqlvt.add(addVector("ZWBH", ""+zwbh, "NUM"));
				sqlvt.add(addVector("ZWMC", zwmc, "CHAR"));
				sqlvt.add(addVector("CZQX", czqx, "CHAR"));
	//			sqlvt.add(addVector("LCQX", "", "CHAR"));
	//			sqlvt.add(addVector("PZCS", "", "CHAR"));
				sqlvt.add(addVector("JBXH", ""+makeID("ZZ_ZWB","BMBH","JBXH",newNo,false), "NUM"));
				sqlvt.add(addVector("ZWZT", "0", "CHAR"));
				sqlvt.add(addVector("SFJC", "0", "NUM"));

				insertRecord(sqlvt);
			}
		}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)运行时出错:"+e);}
		finally{
			if(rs!=null)try{ stmt = rs.getStatement(); rs.close();}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)关闭记录集rs时出错"+e);}
			if(stmt!=null) try{stmt.close();}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)关闭声明时statement出错"+e);}		
			if(rs1!=null)try{ stmt = rs1.getStatement(); rs1.close();}catch(Exception e){System.out.println("DepartmentBean.addRec(Hashtable)关闭记录集rs时出错"+e);}

⌨️ 快捷键说明

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