软件工程课程设计实验报告--图书馆管理系统 下载本文

public static boolean doBorrow(int bid,int uid,int lid) throws NamingException, SQLException{

Lib_Book_Dal bookD = new Lib_Book_Dal();

Book_LibInfo_Dal blD = new Book_LibInfo_Dal();

Lib_Borrow_Log_Dal logD = new Lib_Borrow_Log_Dal(); User_Brrow_Dal ubD = new User_Brrow_Dal(); Lib_User_Dal userD = new Lib_User_Dal(); Isbn_Lib_Dal ilD = new Isbn_Lib_Dal();

User_Brrow uB = new User_Brrow();

//Book_LibInfo bl = new Book_LibInfo(); Lib_Book book = new Lib_Book(); Lib_User user = new Lib_User();

Lib_Borrow_Log log = new Lib_Borrow_Log(); Isbn_Lib il = new Isbn_Lib();

//得到用户借阅总和记录 uB = ubD.queryById(uid);

//如果超期 则返回false 表示借书失败 if(uB.getUb_is_overdue()==1){ return false;} //得到书目

String ISBN = blD.getISBN(bid); book = bookD.queryById(ISBN); int bookType = book.getType_id(); //借阅量

short sum = uB.getUs_sum();//总

short chi = uB.getUb_c_num();//中文书 short fre = uB.getUb_f_num();//外文书 short nw = uB.getUb_n_num();//新书

//得到用户,验证是否在该用户类型规定的可借范围内 user = userD.queryById(uid); switch(user.getU_type_id()){

case 0:return false;//如果是管理员 不能借书

case1:if(chi==5&&fre==1&&nw==1&&sum==7){return false;}break;//本科生 case2:if(chi==12&&fre==3&&nw==1&&sum==16){return false;}break;//教师 case3:if(chi==10&&fre==2&&nw==1&&sum==13){return false;}break;//研究生

case4:if(chi==12&&fre==3&&nw==1&&sum==16){return false;}break;//博士 case5:if(chi==7&&fre==1&&nw==1&&sum==9){return false;}break;//非教师} //增加该书的借书记录 并初始化 log.setBl_is_overdue((short)0); log.setBl_renew((short)0);

log.setBl_state((short)0); log.setBook_id(bid); log.setU_id(uid);

logD.inserBorrowLog(log);//插入 //减少该书库存剩余量

il = ilD.queryById(book.getIsbn(), lid); il.setIl_rest((short)(il.getIl_rest()-1)); //增加其某种书的借阅量 switch(bookType){

case 1:uB.setUb_c_num((short)(uB.getUb_c_num()+1));break; case 2:uB.setUb_f_num((short)(uB.getUb_f_num()+1));break; case 3:uB.setUb_n_num((short)(uB.getUb_n_num()+1));break} uB.setUs_sum((short)(uB.getUs_sum()+1)); ubD.update_User_Brrow(uB);//更新借阅量 return true;} /**

* 为用户办理还书手续 * @param bid * @param uid * @param lid * @return

* @throws NamingException * @throws SQLException */

public static boolean doBack(int bid,int uid,int lid) throws NamingException, SQLException{

Lib_Book_Dal bookD = new Lib_Book_Dal();

Book_LibInfo_Dal blD = new Book_LibInfo_Dal();

Lib_Borrow_Log_Dal logD = new Lib_Borrow_Log_Dal(); User_Brrow_Dal ubD = new User_Brrow_Dal(); Isbn_Lib_Dal ilD = new Isbn_Lib_Dal(); User_Brrow uB = new User_Brrow(); Lib_Book book = new Lib_Book();

Lib_Borrow_Log log = new Lib_Borrow_Log(); Isbn_Lib il = new Isbn_Lib(); //得到用户借阅总和记录 uB = ubD.queryById(uid);

//如果超期 则需检查还了这本书之后 是否无超期 if(uB.getUb_is_overdue()==1){ //检查该书还书之后是否无超期

//如果是 则设该读者为无超期状态uB.setUb_is_overdue((short)0); return false; } //得到书目 和书本类型

String ISBN = blD.getISBN(bid); book = bookD.queryById(ISBN); int bookType = book.getType_id(); //查找该用户最近对该书的借书记录 log = logD.queryLastLog(bid, uid); if(log == null){return false;}

logD.updateState(log.getBl_id(),1);//设置该借书记录为已还state=1

//增加该书库存剩余量

il = ilD.queryById(book.getIsbn(), lid); il.setIl_rest((short)(il.getIl_rest()+1)); //减少其对某种书的借阅量 switch(bookType){

case 1:uB.setUb_c_num((short)(uB.getUb_c_num()-1));break; case 2:uB.setUb_f_num((short)(uB.getUb_f_num()-1));break; case 3:uB.setUb_n_num((short)(uB.getUb_n_num()-1));break; }

uB.setUs_sum((short)(uB.getUs_sum()-1)); ubD.update_User_Brrow(uB);//更新借阅量

return true;} /**

* 得到用户借书记录 * @param uid * @return

* @throws NamingException * @throws SQLException

*/public static List getUserBorrowLog(int uid) throws NamingException, SQLException{

Lib_Borrow_Log_Dal logD = new Lib_Borrow_Log_Dal(); return logD.queryHistory(uid, (short)2); }}

用户业务类:

public class User_Bll {

private Lib_User_Dal userDal; private Lib_Book_Dal bookDal; private Book_LibInfo_Dal bookLib;

private Lib_Borrow_Log_Dal borrowHistory;

public User_Bll() throws NamingException, SQLException{ userDal = new Lib_User_Dal(); bookDal = new Lib_Book_Dal();} public boolean regist(Lib_User user){ return userDal.insert_User(user);}

//修改密码public boolean modifyPsw(Lib_User user){

return userDal.update_User(user);}

//修改其他信息public boolean modifyMess(Lib_User user){ return userDal.update_User(user);} //根据ISBN查询书目

public List queryBook(String ISBN) throws SQLException{ return bookLib.searchByISBN(ISBN);} //根据ISBN查询书目

public List queryBook(String ISBN,String name,String author,String publisher,int typeid) throws SQLException{

return bookDal.queryCondition(ISBN,name, author, publisher, typeid);} //查询所有借阅历史

public List queryBorrowHistory(int uid,short state) throws SQLException{return borrowHistory.queryHistory(uid, state);}}

登录业务类:

public class Login_Bll {

private Lib_User_Dal userDal;

public Login_Bll() throws NamingException, SQLException{ userDal = new Lib_User_Dal();} public boolean isExistUser(int uid){ if (userDal.queryById(uid)==null) return false; else

return true;}

public Lib_User islogin(int uid,String psw){ try {

Lib_User_Dal userD = new Lib_User_Dal(); Lib_User user = new Lib_User(); user = userD.queryById(uid); if(psw.equals(user.getU_psw())){ return user; }else{

return null;}

} catch (NamingException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace();} return null;}

public boolean isAdmin(Lib_User user){ if(user.getU_type_id()==0){ return true; }else{

return false; }}}