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

📄 roleoperate.java

📁 完整的合同管理信息系统
💻 JAVA
字号:
package com.ICT.AFC.user.beans;

import java.sql.ResultSet;
import com.ICT.AFC.DB.DB;
import java.util.ArrayList;

/**
 * <p>Title:角色类相关操作 </p>
 * <p>Description:权限类相关操作,包括部门插入、修改、删除。 </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: 电子所AFC事业部</p>
 * @author 梅晓峰
 * @version 1.0
 */

public class RoleOperate {
  public RoleOperate() {
  }

  /**
   * 添加新角色信息方法
   * @param db DB
   * @param department Department
   * @throws Exception
   * @return boolean
   */

  public static boolean AddRole(DB db, Role role) throws
      Exception {
    ResultSet rs;
    int roleid = role.getRoleId();


    String roleremark = role.getRoleRemark();
    String rolename = role.getRoleName();
    String sqlstr =
        "insert into M_ROLE(ROLEID,ROLENAME,ROLEREMARK) values("
        + roleid + ",'"
        + rolename + "','"
        + roleremark +"')";


    if (db.ExecSql(sqlstr) == 0) {

      return false;
    }
    else {
      return true;
    }

  }
  public static boolean AddRoleRight(DB db, Role role) throws
        Exception {
      int roleid = role.getRoleId();
      String rightid = role.getRightId();

      String sqlstr =
          "insert into M_ROLE_RIGHT(ROLEID,RIGHTID) values("
          + roleid + ",'"
          + rightid + "')";

      if (db.ExecSql(sqlstr) == 0) {

        return false;
      }
      else {
        return true;
      }

    }

  /**
   * 查找角色信息方法
   * @param db DB
   * @param department Department
   * @throws Exception
   * @return boolean
   */

  public static ArrayList SearchRole(DB db) throws
      Exception {
    ResultSet rs;
    ArrayList RoleList = new ArrayList();

    /////////////////
    String sqlstr = "select distinct(roleid)  from V_ROLE";
    String sql2 = "";
    rs = db.OpenSql(sqlstr);
    ResultSet rs2;
    String rightNames = "";

    while (rs.next()) {
      sql2 = "select * from v_role where roleid = " + rs.getInt(1);
      rs2 = db.OpenSql(sql2);
      rightNames = "";
      Role role = new Role();
      while (rs2.next()) {
        role.setRoleId(rs2.getInt("ROLEID"));
        role.setRoleName(rs2.getString("ROLENAME"));
        role.setRoleRemark(rs2.getString("ROLEREMARK"));
        role.setRightId(rs2.getString("RIGHTID"));
        rightNames = rightNames + " " + rs2.getString("rightName");
        role.setRightName(rightNames);

      }
      RoleList.add(role);
    }

    ///////////
    return RoleList;
  }

  /**
   * 角色编号加1方法
   * @param db DB
   * @param department Department
   * @throws Exception
   * @return boolean
   */

  public static int SearchRoleID(DB db) throws Exception {
    int no;
    ResultSet rs;
    String strSql = null;

    strSql = "select Max(ROLEID) from M_ROLE";
    rs = db.OpenSql(strSql);
    if (rs.next()) {

      no = rs.getInt(1) + 1;
    }
    else {
      no = 1;
    }
    return no;
  }

  /**
   * 查找某权限是否存在方法
   * @param db DB
   * @param department Department
   * @throws Exception
   * @return boolean
   */

  public static boolean SearchRightID(DB db, String rightid) throws Exception {

    ResultSet rs;
    String strSql = null;

    strSql = "select RIGHTID from V_ROLE where RIGHTID='" + rightid + "'";
    rs = db.OpenSql(strSql);
    if (rs.next()) {

      return true;
    }
    else {
      return false;
    }

  }

  /**
   * 根据角色编号查找角色信息方法
   * @param db DB
   * @param department Department
   * @throws Exception
   * @return boolean
   */

  public static Role SearchRoleByID(DB db, String roleid) throws Exception {

    ResultSet rs;
    String strSql = null;

    strSql = "select * from V_ROLE where ROLEID=" + roleid;
    rs = db.OpenSql(strSql);
    Role role = new Role();
    if (rs.next()) {
      role.setRoleId(rs.getInt("ROLEID"));
      role.setRoleName(rs.getString("ROLENAME"));
      role.setRoleRemark(rs.getString("ROLEREMARK"));
      role.setRightId(rs.getString("RIGHTID"));
    }
    return role;
  }

  /**
   * 删除指定角色方法
   * @param db DB
   * @param department Department
   * @throws Exception
   * @return boolean
   */

  public static boolean deleteRole(DB db, int roleID) throws Exception {

    String strSql = null;

    strSql = "delete M_Role where ROLEID=" + roleID;

    if (db.ExecSql(strSql) == 0) {

      return false;

    }
    else {

      return true;
    }
  }

  /**
   * 修改角色信息方法
   * @param db DB
   * @param department Department
   * @throws Exception
   * @return boolean
   */

  public static boolean updateRole(DB db, Role role) throws
      Exception {
    ResultSet rs;
    int roleid = role.getRoleId();
    String rightid = role.getRightId();
    String strSql = null;
    String roleremark = role.getRoleRemark();
    String rolename = role.getRoleName();

    strSql = "update M_ROLE set ROLENAME=" + rolename +
        ",ROLEEMARK='" + roleremark + "'" + ",RIGHTID='" + rightid +
        "'" + " where ROLEID=" + roleid;

    if (db.ExecSql(strSql) == 0) {
      return false;
    }
    else {
      return true;
    }

  }
  public static boolean deleteRoleRight(DB db, int roleID) throws Exception {

    String strSql = null;

    strSql = "delete M_Role_RIGHT where ROLEID=" + roleID;

    if (db.ExecSql(strSql) == 0) {

      return false;

    }
    else {

      return true;
    }
  }


}

⌨️ 快捷键说明

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