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)); //Ôö¼ÓÆäijÖÖÊéµÄ½èÔÄÁ¿ 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)); //¼õÉÙÆä¶ÔijÖÖÊéµÄ½èÔÄÁ¿ 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
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; }}}