圖書館系統(6)
阿新 • • 發佈:2020-12-28
技術標籤:作業
這是管理員部分
管理員主要有以下幾種功能:
登入:管理員登入
圖書管理:查詢,新增圖書
讀者管理 :新增學生,修改學生資訊
圖書分類管理:新增分類,修改分類資訊
圖書借閱資訊:確認還書,延期
圖書歸還資訊:借出和歸還時間
管理員管理:返回登入頁面
熱門推薦:推薦借閱最多的圖書
最佳讀者:借閱量最多的讀者
讀者反饋:學生反饋的意見的解決
1.在com.rain.bean包中新增AdminBean.java:管理員的資訊表
package com.rain.bean;
public class AdminBean {
/**
* 使用者的資料表的bean
*/
private int aid;// id
private int status;// 用來判斷是管理員還是讀者,讀者的值為1,管理員為2
private String username;// 賬號
private String name;// 姓名
private String password;// 密碼
private String email;// 郵箱
private String phone;// 手機號
private int times;//借閱量
private int lend_num;// 可借閱天數
private int max_num;// 最大可借數
public int getAid() {
return aid;
}
public void setAid(int aid) {
this.aid = aid;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public int getTimes() {
return times;
}
public void setTimes(int times) {
this.times = times;
}
public int getLend_num() {
return lend_num;
}
public void setLend_num(int lend_num) {
this.lend_num = lend_num;
}
public int getMax_num() {
return max_num;
}
public void setMax_num(int max_num) {
this.max_num = max_num;
}
}
2.在com.rain.dao包中新增三個java:
1.AdminDao.java:驗證使用者戶資訊
package com.rain.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.rain.bean.AdminBean;
import com.rain.bean.BookBean;
import com.rain.util.DBUtil;
/**
* 有關讀者賬號的連線資料庫操作,登入驗證,註冊,修改賬號,修改密碼
*/
public class AdminDao {
/**
* 登入驗證功能,傳入使用者名稱和密碼,在資料庫中查詢,如果找到了,返回true,沒找到則返回false
*
* @param username
* @param password
* @return
*/
public boolean Login_verify(String username, String password) {
Connection conn = DBUtil.getConnectDb();
PreparedStatement stm = null;
ResultSet rs = null;
String sql = "select * from admin where username='" + username + " 'and password='" + password + "'";
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
if (rs.next()) {
return true;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return false;
}
/**
* 註冊賬號的函式,傳入賬號,密碼,姓名,郵箱,手機號,借閱天數,可借閱數
*/
public void Register(String username, String password, String name, String email, String phone, int lend_num,
int max_num) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "insert into admin(status,username,password,name,email,phone,lend_num,max_num) values(?,?,?,?,?,?,?,?)";
int rs = 0;
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, 1);
stm.setString(2, username);
stm.setString(3, password);
stm.setString(4, name);
stm.setString(5, email);
stm.setString(6, phone);
stm.setInt(7, lend_num);
stm.setInt(8, max_num);
rs = stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 新增管理員賬號,傳入賬號,密碼,姓名,郵箱,手機號
*
*/
public void Register2(String username, String password, String name, String email, String phone) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "insert into admin(status,username,password,name,email,phone) values(?,?,?,?,?,?)";
int rs = 0;
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, 2);
stm.setString(2, username);
stm.setString(3, password);
stm.setString(4, name);
stm.setString(5, email);
stm.setString(6, phone);
rs = stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 根據傳入的賬號,密碼,來查詢對應的讀者資訊,返回一個AdminBean型別,
*
*/
public AdminBean getAdminInfo(String username, String password) {
// TODO Auto-generated method stub
AdminBean adminbean = new AdminBean();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from admin where username= '"+username+"' and password= '"+password+"'";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
if (rs.next()) {
adminbean.setAid(rs.getInt("aid"));
adminbean.setUsername(rs.getString("username"));
adminbean.setName(rs.getString("name"));
adminbean.setPassword(rs.getString("password"));
adminbean.setEmail(rs.getString("email"));
adminbean.setPhone(rs.getString("phone"));
adminbean.setTimes(rs.getInt("times"));
adminbean.setStatus(rs.getInt("status"));
adminbean.setLend_num(rs.getInt("lend_num"));
adminbean.setMax_num(rs.getInt("max_num"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return adminbean;
}
/**
* 獲取全部使用者的資訊,其中sql語句中的status=1,表示只查詢讀者,不顯示管理員的
*
*/
public ArrayList<AdminBean> get_ListInfo() {
ArrayList<AdminBean> tag_Array = new ArrayList<AdminBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from admin where status=1";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
AdminBean adminbean = new AdminBean();
adminbean.setAid(rs.getInt("aid"));
adminbean.setUsername(rs.getString("username"));
adminbean.setName(rs.getString("name"));
adminbean.setPassword(rs.getString("password"));
adminbean.setEmail(rs.getString("email"));
adminbean.setPhone(rs.getString("phone"));
adminbean.setTimes(rs.getInt("times"));
adminbean.setStatus(rs.getInt("status"));
adminbean.setLend_num(rs.getInt("lend_num"));
adminbean.setMax_num(rs.getInt("max_num"));
tag_Array.add(adminbean);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
/**
* 獲取全部使用者的資訊,其中sql語句中的status=2,表示只查詢管理員,不顯示讀者的
*
* @return
*/
public ArrayList<AdminBean> get_ListInfo2() {
ArrayList<AdminBean> tag_Array = new ArrayList<AdminBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from admin where status=2";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
AdminBean adminbean = new AdminBean();
adminbean.setAid(rs.getInt("aid"));
adminbean.setUsername(rs.getString("username"));
adminbean.setName(rs.getString("name"));
adminbean.setPassword(rs.getString("password"));
adminbean.setEmail(rs.getString("email"));
adminbean.setPhone(rs.getString("phone"));
adminbean.setTimes(rs.getInt("times"));
adminbean.setStatus(rs.getInt("status"));
tag_Array.add(adminbean);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
/**
* 獲取全部使用者的資訊並排序,其中sql語句中的status=1,表示只查詢讀者,不顯示管理員的
*
* @return
*/
public ArrayList<AdminBean> get_ListInfo3() {
ArrayList<AdminBean> tag_Array = new ArrayList<AdminBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from admin where status=1 order by times desc";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
AdminBean adminbean = new AdminBean();
adminbean.setAid(rs.getInt("aid"));
adminbean.setUsername(rs.getString("username"));
adminbean.setName(rs.getString("name"));
adminbean.setPassword(rs.getString("password"));
adminbean.setEmail(rs.getString("email"));
adminbean.setPhone(rs.getString("phone"));
adminbean.setTimes(rs.getInt("times"));
adminbean.setStatus(rs.getInt("status"));
adminbean.setLend_num(rs.getInt("lend_num"));
adminbean.setMax_num(rs.getInt("max_num"));
tag_Array.add(adminbean);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
/**
* 根據傳入的aid,查詢到對應的讀者的全部資訊,返回一個AdminBean型別的資料
*
* @param aid
* @return
*/
public AdminBean get_AidInfo(int aid) {
AdminBean adminbean = new AdminBean();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from admin where aid=" + aid;
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
if (rs.next()) {
adminbean.setAid(rs.getInt("aid"));
adminbean.setUsername(rs.getString("username"));
adminbean.setName(rs.getString("name"));
adminbean.setPassword(rs.getString("password"));
adminbean.setEmail(rs.getString("email"));
adminbean.setPhone(rs.getString("phone"));
adminbean.setTimes(rs.getInt("times"));
adminbean.setStatus(rs.getInt("status"));
adminbean.setLend_num(rs.getInt("lend_num"));
adminbean.setMax_num(rs.getInt("max_num"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return adminbean;
}
/**
* 根據傳入的aid,查詢到對應的讀者的全部資訊,返回一個AdminBean型別的資料,與上一個相似,只是aid的型別為String
*
* @param aid
* @return
*/
public AdminBean get_AidInfo2(String aid) {
AdminBean adminbean = new AdminBean();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from admin where aid=" + aid;
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
if (rs.next()) {
adminbean.setAid(rs.getInt("aid"));
adminbean.setUsername(rs.getString("username"));
adminbean.setName(rs.getString("name"));
adminbean.setPassword(rs.getString("password"));
adminbean.setEmail(rs.getString("email"));
adminbean.setPhone(rs.getString("phone"));
adminbean.setTimes(rs.getInt("times"));
adminbean.setStatus(rs.getInt("status"));
adminbean.setLend_num(rs.getInt("lend_num"));
adminbean.setMax_num(rs.getInt("max_num"));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return adminbean;
}
/**
* 修改讀者的資訊
*/
public void updateUser(int aid, String username, String password, String name, String email, String phone,
int lend_num, int max_num) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "update admin set username=?,name=?,email=?,phone=?,password=?,lend_num=?,max_num=? where aid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setString(1, username);
stm.setString(2, name);
stm.setString(3, email);
stm.setString(4, phone);
stm.setString(5, password);
stm.setInt(6, lend_num);
stm.setInt(7, max_num);
stm.setInt(8, aid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 修改管理員的資訊
*/
public void updateAdmin(int aid, String username, String password, String name, String email, String phone) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "update admin set username=?,name=?,email=?,phone=?,password=? where aid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setString(1, username);
stm.setString(2, name);
stm.setString(3, email);
stm.setString(4, phone);
stm.setString(5, password);
stm.setInt(6, aid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 刪除使用者的資訊,根據傳入的aid作為條件
*
* @param aid
*/
public void deleteUser(int aid) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "delete from admin where aid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, aid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 刪除管理員的資訊,根據傳入的aid作為條件
*
* @param aid
*/
public void deleteAdmin(int aid) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "delete from admin where aid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, aid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 查詢使用者,根據輸入的名稱,使用like進行模糊查詢,然後返回一個ArrayList陣列型別
*
* @param name
* @return
*/
public ArrayList<AdminBean> getLikeList(String name) {
// TODO Auto-generated method stub
ArrayList<AdminBean> tag_Array = new ArrayList<AdminBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from admin where name like '%" + name + "%' or username like '%" + name + "%' or aid like '%" + name + "%'";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
AdminBean tag = new AdminBean();
tag.setAid(rs.getInt("aid"));
tag.setStatus(rs.getInt("status"));
tag.setUsername(rs.getString("username"));
tag.setName(rs.getString("name"));
tag.setPassword(rs.getString("password"));
tag.setEmail(rs.getString("email"));
tag.setPhone(rs.getString("phone"));
tag.setTimes(rs.getInt("times"));
tag.setLend_num(rs.getInt("lend_num"));
tag.setMax_num(rs.getInt("max_num"));
tag_Array.add(tag);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
}
2.ProblemDao.java:反饋的解決
package com.rain.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.rain.bean.AdminBean;
import com.rain.bean.ProblemBean;
import com.rain.util.DBUtil;
public class ProblemDao {
/**
* 獲取所有反饋問題的資訊,返回陣列形式
*
* @return
*/
public ArrayList<ProblemBean> get_ListInfo() {
ArrayList<ProblemBean> tag_Array = new ArrayList<ProblemBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from problem";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
ProblemBean tag = new ProblemBean();
tag.setPid(rs.getInt("pid"));
tag.setAid(rs.getInt("aid"));
tag.setName(rs.getString("name"));
tag.setPage(rs.getString("page"));
tag.setBody(rs.getString("body"));
tag.setPhone(rs.getString("phone"));
tag.setStatus(rs.getString("status"));
tag_Array.add(tag);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
/**
* 獲取所有反饋問題的資訊,返回陣列形式
*
* @return
*/
public ArrayList<ProblemBean> get_ListInfo2(String aid) {
ArrayList<ProblemBean> tag_Array = new ArrayList<ProblemBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from problem where aid=" + aid;
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
ProblemBean tag = new ProblemBean();
tag.setPid(rs.getInt("pid"));
tag.setAid(rs.getInt("aid"));
tag.setName(rs.getString("name"));
tag.setPage(rs.getString("page"));
tag.setBody(rs.getString("body"));
tag.setPhone(rs.getString("phone"));
tag.setStatus(rs.getString("status"));
tag_Array.add(tag);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
/**
* 新增一個反饋問題
*
* @param adminbean
* @param name
* @param page
* @param body
* @param phone
*/
public void addProblem(AdminBean adminbean, String name, String page, String body, String phone) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "insert into problem(aid,name,page,body,phone) values(?,?,?,?,?)";
int rs = 0;
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, adminbean.getAid());
stm.setString(2, name);
stm.setString(3, page);
stm.setString(4, body);
stm.setString(5, phone);
rs = stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 刪除一個反饋問題
*
* @param pid
*/
public void deleteProblem(int pid) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "delete from problem where pid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, pid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 修改反饋問題的狀態
*
* @param pid
* @param status
*/
public void updateProblem(int pid, String status) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "update problem set status=? where pid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setString(1, status);
stm.setInt(2, pid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 查詢反饋問題,根據輸入的名稱,使用like進行模糊查詢,然後返回一個ArrayList陣列型別
*
* @param name
* @return
*/
public ArrayList<ProblemBean> getLikeList(String name) {
// TODO Auto-generated method stub
ArrayList<ProblemBean> tag_Array = new ArrayList<ProblemBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from problem where name like '%" + name + "%' or page like '%" + name
+ "%' or body like '%" + name + "%' or status like '%" + name + "%'";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
ProblemBean tag = new ProblemBean();
tag.setPid(rs.getInt("pid"));
tag.setAid(rs.getInt("aid"));
tag.setName(rs.getString("name"));
tag.setPage(rs.getString("page"));
tag.setBody(rs.getString("body"));
tag.setPhone(rs.getString("phone"));
tag.setStatus(rs.getString("status"));
tag_Array.add(tag);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
}
3.TypeDao.java:圖書分類的修改
package com.rain.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.rain.bean.TypeBean;
import com.rain.util.DBUtil;
/**
* 圖書分類的類
*/
public class TypeDao {
/**
* 獲取所有圖書型別的資訊,返回陣列形式
*
* @return
*/
public ArrayList<TypeBean> get_ListInfo() {
ArrayList<TypeBean> tag_Array = new ArrayList<TypeBean>();
Connection conn = DBUtil.getConnectDb();
String sql = "select * from booktype";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while (rs.next()) {
TypeBean tag = new TypeBean();
tag.setTid(rs.getInt("tid"));
tag.setName(rs.getString("name"));
tag_Array.add(tag);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
DBUtil.CloseDB(rs, stm, conn);
}
return tag_Array;
}
/**
* 修改圖書分類的資訊
*
* @param tid
* @param name
*/
public void updateTypeBook(int tid, String name) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "update booktype set name=? where tid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setString(1, name);
stm.setInt(2, tid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 新增一個圖書分類
*
* @param name
*/
public void addBookType(String name) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "insert into booktype(name) values(?)";
int rs = 0;
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setString(1, name);
;
rs = stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 刪除一個圖書分類
*
* @param tid
*/
public void deleteBookType(int tid) {
// TODO Auto-generated method stub
Connection conn = DBUtil.getConnectDb();
String sql = "delete from booktype where tid=?";
PreparedStatement stm = null;
try {
stm = conn.prepareStatement(sql);
stm.setInt(1, tid);
stm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(uid);
}
}
3.新增一個包:com.rain.servlet:用於實現管理員的各種功能(由於過多省略了)