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

📄 usertoroesdao.java

📁 oa rar it is the jsp
💻 JAVA
字号:
package com.accp.oa.dao.imple;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import com.accp.oa.bean.User_Roes;
import com.accp.oa.common.Constants;
import com.accp.oa.common.DbUtil;
import com.accp.oa.dao.inface.*;

/*
 * 此DAO用于处理人员和
 * 相应角色的相关数据
 * 的操作
 */
public class UserToRoesDAO implements BaseDAO{

	/*
	 * 添加新的人员和角色的关系
	 * @see com.accp.oa.dao.inface.BaseDAO#add(java.lang.Object)
	 */
	public boolean add(Object user_roes) {
		User_Roes userRoes = (User_Roes)user_roes;
		boolean success = false;
		Connection con = null;
		PreparedStatement stmt = null;
		try{
			con = DbUtil.connectToDB();
			stmt = con.prepareStatement(Constants.ADD_USER_ROES);
			stmt.setInt(1, userRoes.getPerId());
			stmt.setInt(2, userRoes.getRoesId());
            if(stmt.executeUpdate() > 0){
            	success = true;
            }
			
		}catch(Exception ex){
			return false;
		}finally{
			try{
				stmt.close();
				con.close();
			}catch(Exception ex){
				
			}
		}
		return success;
	}

	public boolean delete(Object obj) {
		return false;
	}

	/*
	 * 删除人员的角色
	 * @see com.accp.oa.dao.inface.BaseDAO#delete(int)
	 */
	public boolean delete(int perId) {
		Connection con = null;
		PreparedStatement stmt = null;
		try{
			con = TransDAO.getConnection();
			stmt = con.prepareStatement(Constants.DELETE_USER_ROES);
			stmt.setInt(1, perId);
           stmt.executeUpdate();
		}catch(Exception ex){
			
			return false;
		}finally{
			try{
				stmt.close();
			}catch(Exception ex){
				
			}
		}
		return true;
	}

	public boolean delete(String ag0) {
		return false;
	}

	public Object search(Object obj) {
		return null;
	}

	/*
	 * 此方法用于检验传入的角色是否被使用
	 * @see com.accp.oa.dao.inface.BaseDAO#search(java.lang.String, java.lang.String)
	 */
	public int search(String roesId, String roesName) {
		int success = 0;
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try{
			con = DbUtil.connectToDB();
			stmt = con.prepareStatement(Constants.SEARCH_ALL_BYROESID);
			stmt.setInt(1, Integer.parseInt(roesId));
			rs = stmt.executeQuery();
			if(rs.next()){
				success = 1;
			}
		}catch(Exception ex){
			return 0;
		}finally{
			try{
				rs.close();
				stmt.close();
				con.close();
			}catch(Exception ex){
				
			}
		}
		return success;
	}

	public Object search(int id) {
		return null;
	}

	public ArrayList search(String age0) {
		return null;
	}

	public ArrayList search(int ag0, int age1) {
		return null;
	}

	/*
	 * 实现此方法用于查询
	 * 出以授有角色的人员
	 * 的角色信息
	 * @see com.accp.oa.dao.inface.BaseDAO#search()
	 */
	public ArrayList search() {
		ArrayList users_roess = new ArrayList();
		Connection con = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		try{
			con = DbUtil.connectToDB();
			stmt = con.prepareStatement(Constants.SEARCH_USER_ROES);
			rs = stmt.executeQuery();
			while(rs.next()){
				User_Roes userAndRoes = new User_Roes();
				userAndRoes.setPerId(rs.getInt(1));
				userAndRoes.setUsername(rs.getString(2));
				userAndRoes.setRoesId(rs.getInt(3));
				userAndRoes.setRoesname(rs.getString(4));
				users_roess.add(userAndRoes);
			}
		}catch(Exception ex){
			return null;
		}finally{
			try{
				rs.close();
				stmt.close();
				con.close();
			}catch(Exception ex){
				
			}
		}
		return users_roess;
	}

	/*
	 * 此方法用于修改用户的角色
	 * @see com.accp.oa.dao.inface.BaseDAO#update(java.lang.Object)
	 */
	public boolean update(Object user_roes) {
		User_Roes userRoes = (User_Roes)user_roes;
		boolean success = false;
		Connection con = null;
		PreparedStatement stmt = null;
		try{
			con = DbUtil.connectToDB();
			stmt = con.prepareStatement(Constants.UPDATE_USER_ROES);
			stmt.setInt(1, userRoes.getRoesId());
			stmt.setInt(2, userRoes.getPerId());
			
            if(stmt.executeUpdate() > 0){
            	success = true;
            }
			
		}catch(Exception ex){
			return false;
		}finally{
			try{
				stmt.close();
				con.close();
			}catch(Exception ex){
				
			}
		}
		return success;
	}

}

⌨️ 快捷键说明

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