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

📄 admin.java

📁 使用J2EE Struts开发的房地产信息咨询系统
💻 JAVA
字号:
package building;

import java.lang.*;
import java.util.*;
import java.sql.*;

import javax.sql.*;



public final class Admin {
	private int Id = 0 ;
	private String username = null ;
	private String password = null ;
	private String sex = null ;
	private int lev = 0 ;
	private String duty = null ;
	private String lastlogintime = null ;
	
	
	public Admin(){
		
	}
	
	/*
	 * 管理员Id set和get 方法
	 */
	public void setId(int Id){
		this.Id = Id ;
	}
	public int getId(){
		return(Id);
	}
	/*
	 * 管理员姓名(username) set和get方法
	 */
	public void setUsername(String username){
		this.username = username ;
	}
	public String getUsername(){
		return(username);
	}
	/*
	 * 管理员密码(password) set和get方法
	 */
	public void setPassword(String password){
		this.password = password ;
	}
	public String getPassword(){
		return(password);
	}
	/*
	 * 管理员性别(sex) set and get 方法 
	 */
	public void setSex(String sex){
		this.sex = sex ;
	}
	public String getSex(){
		return(sex);
	}
	/*
	 * 管理员的权限级别(lev) set and get方法
	 */
	public void setLev(int lev){
		this.lev = lev ;
	}
	public int getLev(){
		return(lev);
	}
	/*
	 * 管理员的职务(duty) set and get 方法
	 */
	public void setDuty(String duty){
		this.duty = duty ;
	}
	public String getDuty(){
		return (duty);
	}
	/*
	 * 管理员最后登陆时间(lastlogintime) set and get 方法 
	 */
	public void setLastlogintime(String lastlogintime){
		this.lastlogintime = lastlogintime ;
	}
	public String getLastlogintime(){
		return (lastlogintime);
	}
	
	
	/**
	 * 验证用户身份
	 */
	public static boolean checkAdmin(DB db,String adminName,String password)
	throws SQLException
	{
		String strSql = null;
		ResultSet rs = null;
		
		strSql = "select * from Admin where username='" + adminName
			 + "' and password='" + password + "'";
		rs = db.OpenSql(strSql);
		
		if (rs.next())
		{
			//用户存在,验证成功
			return(true);
		}//End of if
		else
		{
			//拥护不存在,验证失败
			return(false);
		}//End of else
	}//End of checkAdmin
	
	
	/**
	 * 按照管理员姓名查找其相关信息
	 */
	public static Admin getAdminInfo(DB db,String adminName)
	throws SQLException
	{
		String strSql = null;
		ResultSet rs = null;
		
		strSql = "select * from Admin where username='" + adminName + "'";
		rs = db.OpenSql(strSql);
		
		if (rs.next())
		{
			//查找到相关信息
			Admin admin = new Admin();
			
			admin.setId(rs.getInt("id"));
			admin.setUsername(rs.getString("username"));
			admin.setSex(rs.getString("sex"));
			admin.setLev(rs.getInt("lev"));
			admin.setDuty(rs.getString("duty"));
			admin.setLastlogintime(rs.getString("lastlogintime"));
			
			return(admin);
		}//End of if
		
		//没有找到相关信息
		return(null);
	}//End of getAdminInfo
	
	
	/**
	 * 根据管理员的姓名来更新其密码
	 */
	public static boolean updatePsw(DB db,String adminName,String newPsw)
	throws SQLException
	{
		String strSql = null;
		
		strSql = "update Admin set "
			+ "password='" + newPsw
			+ "' where username='" + adminName
			+ "'";
		
		if ( db.ExecSql(strSql) == 0 )
		{
			//更新失败
			return(false);
		}//End of if
		else
		{
			//更新成功
			return(true);
		}//End of else
	}//End of updatePsw
	
	
	
	/**
	 * 添加新的管理员
	 */
	public boolean addNewAdmin(DB db)
	throws SQLException
	{
		String strSql = null;
		ResultSet rs = null;
		int iMax = 0;
		
		//查找最大的ID号
		strSql = "select Max(id) from Admin";
		rs = db.OpenSql(strSql);
		
		if (rs.next())
		{
			iMax = rs.getInt(1);
			iMax++;
		}//End of if
		else
		{
			iMax = 1;
		}//End of else
		
		strSql = "insert into Admin values("
			+ iMax + ",'"
			+ username + "','"
			+ password + "','"
			+ sex + "',"
			+ lev + ",'"
			+ duty + "','"
			+ ChinaTime.getTime() + "')";
		
		if ( db.ExecSql(strSql) == 0 )
		{
			//添加失败
			return(false);
		}//End of if
		else
		{
			//添加成功
			return(true);
		}//End of else
	}//End of addNewAdmin
	
	
	/**
	 * 拥有最高权限的管理员可以查看所有管理员的资料
	 */
	public static Vector getAllInfo(DB db)
	throws SQLException
	{
		String strSql = null;
		ResultSet rs = null;
		Vector adminList = new Vector();
		
		strSql = "exec SELECT_ADMIN_ALL";//存储过程
		rs = db.OpenSql(strSql);

		while (rs.next())
		{
			Admin admin = new Admin();
			
			admin.setId(rs.getInt("id"));
			admin.setUsername(rs.getString("username"));
			admin.setPassword("");
			admin.setSex(rs.getString("sex"));
			admin.setLev(rs.getInt("lev"));
			admin.setDuty(rs.getString("duty"));
			admin.setLastlogintime(rs.getString("lastlogintime"));
			
			adminList.add(admin);
		}//End of while
		
		return(adminList);
	}//End of getAllInfo
	
	
	/**
	 * 删除管理员帐户,此操作只能是拥有最高权限的管理员进行操作
	 */
	public static boolean deleteAdmin(DB db,int adminId)
	throws SQLException
	{
		String strSql = null;
		
		strSql = "delete from Admin where id=" + adminId;
		
		if ( db.ExecSql(strSql) == 0 )
		{
			//删除操作失败
			return(false);
		}//End of if
		else
		{
			//删除操作成功
			return(true);
		}//End of esle
	}//End of deleteAdmin
}//End of class Admin

⌨️ 快捷键说明

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