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

📄 function.java

📁 图书管管理系统是基于JAVA的 很好的
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                appraiseSuccess=1;
        }
        else if (db.insert("review", "'" + ISBN + "','" + str[4] + "','" + str[3] + "','" + str[2] + "','" + str[1] + "','" + str[0] + "'"))
            appraiseSuccess = 1;
        
        rs.close();
        db.closeConnection();
        return appraiseSuccess;
    }
    
    /**
     *该方法实现了书籍借阅的功能
     *@param readerID 请求借阅书籍的读者的读者证号
     *@param ISBN 要借阅的书籍的ISBN号
     *@param number 要借阅的书籍的编号
     *@return 如果读者readerID未找到,返回-6
     *@return 如果读者有欠费情况,无法借阅,返回-5
     *@return 如果ISBN不存在,返回-4
     *@return 如果number越界,返回-3
     *@return 如果要借阅的书籍已是借出状态,无法借阅,返回-2
     *@return 如果读者已达可借上限,无法借阅,返回-1
     *@return 如果插入失败,返回0
     *@return 如果插入成功,返回1
     */
    public static int lendBook(String readerID,String ISBN,String number)throws SQLException{
        int lendSuccess = 0;
        int lendNumber = 0;
        DataBase db = new DataBase();
        SystemParameter addm = new SystemParameter();
        String []now = Filter.getDate().split("-");
        int year = Integer.parseInt(now[0]);
        int month = Integer.parseInt(now[1]);
        int date = Integer.parseInt(now[2]);
        
        year += Integer.parseInt(addm.getLendTerm()) / 12;
        month += Integer.parseInt(addm.getLendTerm()) % 12;
        if (month > 12){
            year += 1;
            month %= 12;
        }
        String formatdate = year + "-" + month + "-" + date;
        if (!ShareSubprogram.readerExist(readerID))
            lendSuccess = -6;
        else if (ShareSubprogram.readerOweMoney(readerID))
            lendSuccess = -5;
        else if (!ShareSubprogram.bookExist(ISBN))
            lendSuccess = -4;
        else if (ShareSubprogram.numberIsTooLarge(ISBN,number))
            lendSuccess = -3;
        else if (ShareSubprogram.bookLend(ISBN,number))
            lendSuccess = -2;
        else if (!ShareSubprogram.loanEnabled(readerID))
            lendSuccess = -1;
        else{
            String [] s = {"lend_number"};
            ResultSet rs = db.search("book",s,"ISBN = '" + ISBN + "'");
            
            if(rs.next())
                lendNumber = Integer.parseInt(rs.getString("lend_number")) + 1;
            if (db.insert("loan", "'" + ISBN + "','" + number + "','" + readerID + "','F','" + formatdate + "'") &&
                    db.update("book","lend_number='" + String.valueOf(lendNumber) + "'","ISBN='" + ISBN + "'"))
                lendSuccess=1;
            
           rs.close();
        }
        
        db.closeConnection();
        return lendSuccess;
    }
    
    /**
     *该方法实现了书籍归还的功能,同时自动更新罚金信息
     *@param ISBN 要归还的书籍的ISBN号
     *@param number 要归还的书籍的编号
     *@return 如果要归还的书籍已是归还状态,无法归还,返回-1
     *@return 如果删除失败,返回0
     *@return 如果删除成功,返回1
     */
    public static int returnBook(String ISBN,String number)throws SQLException{
        int returnSuccess = 0;
        int lendNumber = 0;
        float fine = 0;
        String readerID = "";
        DataBase db = new DataBase();
        
        if(! ShareSubprogram.bookLend(ISBN,number))
            returnSuccess = -1;
        else{ 
            String attr[] = {"reader_ID"};
            String where = "ISBN='" + ISBN + "'and number='" + number + "'";
            ResultSet rs = db.search("loan",attr,where);
            if(rs.next())
                readerID = rs.getString("reader_ID");
            
            String [] s = {"lend_number"};
            ResultSet sr = db.search("book",s,"ISBN='" + ISBN + "'");
            if(sr.next())
                lendNumber = Integer.parseInt(sr.getString("lend_number")) - 1;
            
            String [] x = {"fine"};
            ResultSet sx = db.search("reader",x,"reader_ID='" + readerID + "'");
            if(sx.next())
                fine = Float.parseFloat(sx.getString("fine")) + ShareSubprogram.fineCount(ISBN,number);
            
            if (db.update("reader","fine='" + fine + "'","reader_ID='" + readerID + "'") &&
                    db.update("book","lend_number='" + String.valueOf(lendNumber) + "'","ISBN='" + ISBN + "'") &&
                    db.delete("loan","number='" + number + "'and ISBN='" + ISBN + "'"))
                returnSuccess = 1;
            
            rs.close();
            sr.close();
            sx.close();
        }
        
        db.closeConnection();
        return returnSuccess;
    }
    
    /**
     *该方法实现了删除新书表中过期信息的功能
     *@return 如果删除失败,返回0
     *@return 如果删除成功,返回1
     */
    public static int updateNewBook()throws SQLException{
        int updataSuccess = 0;
        DataBase db = new DataBase();
        Calendar c = Calendar.getInstance();   
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int date = c.get(Calendar.DATE);
        String formatdate = year + "-" + month + "-" + date;
      
        month = month + 1;
        if (month < 7){
            year = year - 1;
            month = month + 6;}
        else
            month = month - 6;
        if(db.delete("newbook","date<'" + formatdate + "'"))
            updataSuccess = 1;
        
        db.closeConnection();
        return updataSuccess; 
    }
    
    /**
     *该方法实现了读者荐购的功能
     *@param ISBN 被荐购的书籍的ISBN号
     *@param bookName 书名
     *@param publish 出版社
     *@param author 作者
     *@param year 出版年份          
     *@return 如果插入失败,返回0
     *@return 如果插入成功,返回1
     */
    public static int readerSuggest(String ISBN,String bookName,
            String publish,String author,String year)throws SQLException{
        int addSuccess = 0;
        DataBase db = new DataBase();
        Calendar c = Calendar.getInstance();   
        int year1 = c.get(Calendar.YEAR);   
        int month = c.get(Calendar.MONTH);   
        int date = c.get(Calendar.DATE); 
        String str;
        
        month = month + 1;
        str = year1 + "-" + month + "-" + date;
        if (db.insert("recommend", "NULL,'" + ISBN + "','" + bookName + "','" + author + "','" + year + "','" + publish + "','" + str + "'"))
            addSuccess=1;
        
        db.closeConnection();
        return addSuccess;
    }
    
    /**
     *该方法实现了意见簿的功能
     *@param readerName 提出意见的读者的姓名
     *@param content 提出的意见的具体内容
     *@param email 该读者的Eamil地址
     *@return 如果插入失败,返回0
     *@return 如果插入成功,返回1
     */  
    public static int readerIdea(String readerName,String content,String email)throws SQLException{  
        int addSuccess = 0;
        DataBase db = new DataBase();
        Calendar c = Calendar.getInstance();   
        int year = c.get(Calendar.YEAR);   
        int month = c.get(Calendar.MONTH);   
        int date = c.get(Calendar.DATE); 
        String str;
        
        month = month + 1;
        str = year + "-" + month + "-" + date;
        if (db.insert("advise", "NULL,'" + readerName + "','" + str + "','" + content + "','" + email + "'"))
                addSuccess=1;
        
        db.closeConnection();
        return addSuccess;
    }
    
    /**
     *该方法实现了读者帐户的添加
     *@param readerID 该读者的读者证号
     *@param userName 用户名
     *@param password 密码
     *@param ID 身份证号
     *@param readerName 姓名
     *@param sex 性别
     *@param birthday 生日
     *@param email 电子邮箱
     *@param phoneNumber 联系方式
     *@param address 通信地址
     *@return 如果该readerID已存在于表中,返回-2
     *@return 如果该userName已存在于表中,返回-1
     *@return 如果插入失败,返回0
     *@return 如果插入成功,返回1
     */  
    public static int addReader(String readerID,String userName,String password,
            String ID,String readerName,String sex,String birthday,String email,
            String phoneNumber,String address)throws SQLException{  
        int addSuccess = 0;
        DataBase db = new DataBase();
        
        if (ShareSubprogram.readerExist(readerID))
            return -2;
        else if (ShareSubprogram.readerUserNameExist(userName))
            return -1;
        else if (db.insert("reader","'" + readerID + "','" + userName + "','" + Filter.toMd5(password) +
                "','" + ID + "','" + readerName + "','" + sex + "','" + birthday + "','" + email + "','" +
                phoneNumber + "','" + address + "','0'"))
            addSuccess = 1;
        
        db.closeConnection();
        return addSuccess;
    }
    
    /**
     *该方法实现了读者帐户的更新
     *@param readerID 该读者的读者证号
     *@param userName 更新后的用户名
     *@param password 更新后的密码
     *@param ID 更新后的身份证号
     *@param readerName 更新后的姓名
     *@param sex 更新后的性别
     *@param birthday 更新后的生日
     *@param email 更新后的电子邮箱
     *@param phoneNumber 更新后的联系方式
     *@param address 更新后的通信地址
     *@return 如果该readerID不存在,返回-1
     *@return 如果更新失败,返回0
     *@return 如果更新成功,返回1
     */
    public static int updateReader(String readerID,String userName,String password,
            String ID,String readerName,String sex,String birthday,String email,
            String phoneNumber,String address,String fine)throws SQLException{
        int updataSuccess = 0;
        DataBase db = new DataBase();
        String [] info = {"","","","","","","","","","",""};
        
        if (!ShareSubprogram.readerExist(readerID))
               updataSuccess = -1;
        else{
            if (readerID.compareTo("") != 0)
                info[0] = "reader_ID='" + readerID + "'";
            if (userName.compareTo("") != 0)
                info[1] = ",user_name='" + userName + "'";
            if (password.compareTo("") != 0)
                info[2] = ",password='" + Filter.toMd5(password) + "'";
            if (ID.compareTo("") != 0)
                info[3] = ",ID='" + ID + "'";
            if (readerName.compareTo("") != 0)
                info[4] = ",name='" + readerName + "'";
            if (sex.compareTo("") != 0)
                info[5] = ",sex='" + sex + "'";
            if (birthday.compareTo("") != 0)
                info[6] = ",birthday='" + birthday + "'";
            if (email.compareTo("") != 0)
                info[7] = ",email='" + email + "'";
            if (phoneNumber.compareTo("") != 0)
                info[8] = ",phone_number='" + phoneNumber + "'";
            if (address.compareTo("") != 0)
                info[9] = ",address='" + address + "'";
            if (fine.compareTo("") != 0)
                info[10] = ",fine='" + fine + "'";
            if (db.update("reader",info[0] + info[1] + info[2] + info[3] + info[4] + info[5] + info[6] + info[7] +
                       info[8] + info[9] + info[10],"reader_ID='" + readerID + "'"))
                updataSuccess = 1;
        }
        
        db.closeConnection();
        return updataSuccess;
    }
    
    /**
     *该方法实现了读者帐户的删除
     *@param readerID 请求注销帐号的读者的读者证号
     *@return 如果该readerID不存在,返回-3
     *@return 如果该读者还有欠书情况,返回-2
     *@return 如果该读者还有欠费情况,返回-1
     *@return 如果删除失败,返回0
     *@return 如果删除成功,返回1
     */
    public static int deleteReader(String readerID)throws SQLException{    
        int deleteSuccess = 0;
        DataBase db = new DataBase();
       
        if (!ShareSubprogram.readerExist(readerID))
            deleteSuccess = -3;
        else if (ShareSubprogram.readerOweBook(readerID))
            deleteSuccess = -2;
        else if (ShareSubprogram.readerOweMoney(readerID))
            deleteSuccess = -1;
        else if (db.delete("reader","reader_ID='" + readerID + "'"))
            deleteSuccess = 1;
        
        db.closeConnection();
        return deleteSuccess;
    }
    
    /**
     *该方法实现了读者荐购的删除
     *@param ID 请求注销帐号
     *@return 如果该ID不存在,返回-1
     *@return 如果删除失败,返回0
     *@return 如果删除成功,返回1
     */ 
    public static int deleteReaderSuggest(String ID)throws SQLException{
        int deleteSuccess = 0;

⌨️ 快捷键说明

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