📄 sharesubprogram.java
字号:
*@param number 该书的编号
*@return 如果是,返回true
*@return 如果不是,返回false
*/
public static boolean bookLend(String ISBN,String number) throws SQLException {
boolean lend = true;
String conditions[] = {"ISBN"};
ResultSet reserchwhetherwin;
DataBase result = new DataBase();
reserchwhetherwin=result.search("loan",conditions,"number='" + number + "' and ISBN = '" + ISBN + "'");
lend = reserchwhetherwin.next();
reserchwhetherwin.close();
result.closeConnection();
return lend;
}
/**
*该方法判断所给信息的书籍是否已经过了归还期限
*@param ISBN 需要查询状态的书籍的ISBN号
*@param number 该书的编号
*@return 如果是,返回true
*@return 如果不是,返回false
*/
public static boolean bookOverdue(String ISBN,String number) throws SQLException {
boolean over = false;
String conditions[] = {"deadline"};
ResultSet reserchwhetherwin;
DataBase result = new DataBase();
java.util.Date now = new java.util.Date();
DateFormat d = DateFormat.getDateInstance();
String str = d.format(now);
String deadLine;
/**
*str写入了系统现在时间
*/
reserchwhetherwin = result.search("loan",conditions,"number='" + number + "' and ISBN = '" + ISBN + "'");
if (reserchwhetherwin.next()){
deadLine = reserchwhetherwin.getString(1);
String dateNow [] = str.split("-");
String dateDead [] = deadLine.split("-");
if (Integer.parseInt(dateNow[0]) > Integer.parseInt(dateDead[0]))
over = true;
else if (Integer.parseInt(dateNow[0]) == Integer.parseInt(dateDead[0]) &&
Integer.parseInt(dateNow[1]) > Integer.parseInt(dateDead[1]))
over = true;
else if (Integer.parseInt(dateNow[0]) == Integer.parseInt(dateDead[0]) &&
Integer.parseInt(dateNow[1]) == Integer.parseInt(dateDead[1]) &&
Integer.parseInt(dateNow[1]) > Integer.parseInt(dateDead[1]))
over = true;
}
reserchwhetherwin.close();
result.closeConnection();
return over;
}
/**
*该方法判断readerID所对应的读者是否存在欠费情况
*@param readerID 要查询欠费情况的读者的读者证号
*@return 如果是,返回true
*@return 如果不是,返回false
*/
public static boolean readerOweMoney(String readerID) throws SQLException {
boolean arrearage = true;
String conditions[] = {"fine"};
ResultSet reserchwhetherwin;
DataBase result = new DataBase();
reserchwhetherwin=result.search("reader",conditions,"reader_ID='" + readerID + "'");
if (reserchwhetherwin.next())
{
float temp = reserchwhetherwin.getFloat("fine");
arrearage = temp > 0;
}
/**
*对于查找结果进行比较
*/
reserchwhetherwin.close();
result.closeConnection();
return arrearage;
}
/**
*该方法判断readerID所对应的读者是否存在欠书情况
*@param readerID 要查询欠书情况的读者的读者证号
*@return 如果是,返回true
*@return 如果不是,返回false
*/
public static boolean readerOweBook(String readerID) throws SQLException {
boolean arrearage = true;
String conditions[] = {"ISBN","deadline"};
ResultSet reserchwhetherwin;
DataBase result = new DataBase();
reserchwhetherwin = result.search("loan",conditions,"reader_ID='" + readerID + "'");
arrearage = reserchwhetherwin.next();
reserchwhetherwin.close();
result.closeConnection();
return arrearage;
}
/**
*该方法计算欠费的值
*@param ISBN 要计算的借阅信息的书籍ISBN号
*@param number 要计算的借阅信息的书籍编号
*@return 返回具体欠费值
*/
public static float fineCount(String ISBN,String number) throws SQLException {
float arrearage = 0;
java.util.Date now = new java.util.Date();
DateFormat d = DateFormat.getDateInstance();
String str = d.format(now);
/**
*str写入了系统现在时间
*/
String conditions[] = {"ISBN","deadline"};
ResultSet reserchwhetherwin;
DataBase result = new DataBase();
String a = "";
int year1,month1,day1;
int year2,month2,day2;
reserchwhetherwin = result.search("loan",conditions,"number='" + number + "' and ISBN = '" + ISBN + "'");
if (reserchwhetherwin.next())
a = reserchwhetherwin.getString("deadline");
else
return arrearage;
String aaa[]=a.split("-");
String bbb[]=str.split("-");
year1 = Integer.parseInt(bbb[0]);
month1 = Integer.parseInt(bbb[1]);
day1 = Integer.parseInt(bbb[2]);
year2 = Integer.parseInt(aaa[0]);
month2 = Integer.parseInt(aaa[1]);
day2 = Integer.parseInt(aaa[2]);
SystemParameter addm = new SystemParameter();
float i = Float.parseFloat(addm.getFineNumber());
arrearage = ((year1 - year2) * 365 + (month1 - month2) * 30 + (day1 - day2)) * i;
if(arrearage <= 0)
arrearage = 0;
reserchwhetherwin.close();
result.closeConnection();
return arrearage;
}
/**
*该方法分析检索书籍的关键字,以此创造where语句
*@param request[] 检索时的关键字数组
*@return 经过解析后的where语句
*/
public static String analyseRequest(String request[]){
int sign = 0;
String result[] = {"","","","",""};
if (request[0] != null && !(request[0].equals(""))){
String name[] = request[0].split(" ");
int length = name.length;
for (int count = 0;count < length;count++){
if (sign == 1)
result[0] = result[0].concat("and name like '%" + name[count] + "% '");
else{
result[0] = result[0].concat("name like '%" + name[count] + "%' ");
sign = 1;}
}
}
if (request[1] != null && !(request[1].equals("")))
if (sign == 1)
result[1] = "and publish like '%" + request[1] + "%' ";
else{
result[1] = "publish like '%" + request[1] + "%' ";
sign = 1;}
if (request[2] != null && !(request[2].equals("")))
if (sign == 1)
result[2] = "and author like '%" + request[2] + "%' ";
else{
result[2] = "author like '%" + request[2] + "%' ";
sign = 1;}
if (request[3] != null && !(request[3].equals("")))
if (sign == 1)
result[3] = "and year = '" + request[3] + "' ";
else{
result[3] = "year = '" + request[3] + "' ";
sign = 1;}
if (request[4] != null && !(request[4].equals("")))
if (sign == 1)
result[4] = "and ISBN like '%" + request[4] + "%' ";
else{
result[4] = "ISBN like '%" + request[4] + "%' ";
sign = 1;}
return result[0].concat(result[1].concat(result[2].concat(result[3].concat(result[4]))));
}
/**
*该方法实现了查询某个ID是否否存在于意见表中
*@param ID 要查询的ID
*@return 如果存在,返回true
*@return 如果不存在,返回false
*/
public static boolean IDExistInAdvice(String ID) throws SQLException{
boolean exist = false;
String [] s= {"*"};
DataBase db = new DataBase();
ResultSet rs = db.search("advise",s,"ID = '" + ID + "'");
exist = rs.next();
rs.close();
db.closeConnection();
return exist;
}
/**
*该方法实现了查询某个ID是否存在于荐购表中
*@param ID 要查询的ID
*@return 如果存在,返回true
*@return 如果不存在,返回false
*/
public static boolean IDExistInRecommend(String ID) throws SQLException{
boolean exist = false;
String [] s= {"*"};
DataBase db = new DataBase();
ResultSet rs = db.search("recommend",s,"ID = '" + ID + "'");
exist = rs.next();
rs.close();
db.closeConnection();
return exist;
}
/**
*该方法实现了判断某本书籍的编号是否过于大
*@param ISBN 要查询的书籍的ISBN号
*@param number 要查询的书籍的编号
*@return 如果是,返回true
*@return 如果不是,返回false
*/
public static boolean numberIsTooLarge(String ISBN,String number) throws SQLException{
boolean over = true;
String []s = {"total_number"};
DataBase db = new DataBase();
ResultSet rs = db.search("book",s,"ISBN = '" + ISBN + "'");
if (rs.next()){
int totalNumber = rs.getInt(1);
if (totalNumber >= (Integer.valueOf(number).intValue()))
over = false;
}
return over;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -