📄 book_op.java~57~
字号:
package bookmanager;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* <p>Title: 图书管理</p>
*
* <p>Description: 大型软件实习项目</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: 武汉大学计算机学院</p>
*
* @author 王佳
* @version 1.0
*/
public class book_op {
private String bkid="";
private String bkname="";
private String edition="";
private String bkpublish="";
private String bkauthor="";
private String bdate="";
private String rdate="";
private String username="";
//private ResultSet rs1=null;
private String sql="";
private String printHtml="";
private String hold="";
private String authority="";
private String uid="";
//private ResultSet rs2=null;
public book_op() {
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public String borrowinfo(){
ResultSet rs1=null;
dbconnBean dbconn=new dbconnBean();
sql="SELECT bkid, bkname, edition, bkauthor, bkpublish, bdate, rdate, authority, hold FROM book_borrow WHERE (username = '"+username+"')";
rs1=dbconn.executeQuery(sql);
//System.out.println(sql);
printHtml="";
try {
printHtml = "<tr bgcolor=\"#FFFFFF\">"
+ " <th width=\"12%\" height=\"18\">图书编号</th>"
+ " <th width=\"12%\" height=\"18\">图书名</th>"
+ " <th width=\"12%\" height=\"18\">版次</th>"
+ " <th width=\"12%\" height=\"18\">作者</th>"
+ " <th width=\"12%\" height=\"18\">出版社</th>"
+ " <th width=\"12%\" height=\"18\">借书时间</th>"
+ " <th width=\"12%\" height=\"18\">理论归还时间</th>"
+ " <th width=\"12%\" height=\"18\">选择</th>"
+ " </tr>";
while (rs1.next()) {
this.hold = rs1.getString("hold");
this.authority = rs1.getString("authority");
printHtml += "<tr bgcolor=\"#FFFFFF\">"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkid") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkname") + "</td>"
+ "<td width=\"12%\" height=\"18\"> " +
rs1.getString("edition") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkauthor") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkpublish") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bdate").substring(0,10) + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("rdate").substring(0,10) + "</td>"
+
" <td width=\"12%\" height=\"18\" align=\"center\"><a href=\"book_op.jsp?tp=continue&bkid="+rs1.getString("bkid")+"\">续借</a><a href=\"book_op.jsp?tp=return&bkid="+rs1.getString("bkid")+"\">||还书</a></td>"
+ " </tr>";
}
} catch (SQLException ex) {
ex.printStackTrace();
}
return printHtml;
}
public boolean continueborrow(){
dbconnBean dbconn=new dbconnBean();
boolean a=false;
sql="";
sql="update borrow set rdate=rdate+30 where bkid="+bkid;
a=dbconn.executeUpdate(sql);
//System.out.println(sql);
//System.out.println("a= "+a);
return a;
}
public boolean returnbook(){
dbconnBean dbconn=new dbconnBean();
sql="delete from borrow where bkid="+bkid;
boolean a=false,b=false,c=false;
a=dbconn.executeUpdate(sql);
String sql1="update bookuser set hold=hold-1 where uid="+uid;
String sql2="update book set bborrow='no' where bkid="+bkid;
b=dbconn.executeUpdate(sql1);
c=dbconn.executeUpdate(sql2);
if(a&&b&&c)return true;
return false;
}
public boolean canborrow(){
dbconnBean dbconn=new dbconnBean();
sql="";
sql="INSERT INTO borrow (bkid, uid, bdate, rdate)VALUES ("+bkid+","+uid+", GETDATE(), GETDATE() + 30)";
if( dbconn.executeInsert(sql)){
sql="update bookuser set hold=hold+1 where uid="+uid;
if(dbconn.executeUpdate(sql)){
sql="update book set bborrow='yes' where bkid="+bkid;
if(dbconn.executeUpdate(sql)){
return true;
}
return false;
}
return false;
//sql="delete from borrow where
}
return false;
}
public String printbooking(){
ResultSet rs1=null;
dbconnBean dbconn1=new dbconnBean();
sql="";
printHtml="";
sql="select * from bk_bkclass where bborrow='no' and bkname= '"+bkname+"'";
rs1=null;
printHtml = "<tr bgcolor=\"#FFFFFF\">"
+ " <th width=\"12%\" height=\"18\">图书编号</th>"
+ " <th width=\"12%\" height=\"18\">图书名</th>"
+ " <th width=\"12%\" height=\"18\">版次</th>"
+ " <th width=\"12%\" height=\"18\">作者</th>"
+ " <th width=\"12%\" height=\"18\">出版社</th>"
+ " <th width=\"12%\" height=\"18\">出版日期</th>"
+ " <th width=\"12%\" height=\"18\">类别</th>"
+ " <th width=\"12%\" height=\"18\">选择</th>"
+ " </tr>";
try {
rs1=dbconn1.executeQuery(sql);
while(rs1.next()) {
printHtml += "<tr bgcolor=\"#FFFFFF\">"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkid") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkname") + "</td>"
+ "<td width=\"12%\" height=\"18\"> " +
rs1.getString("edition") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkauthor") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkpublish") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("pubdate")+ "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkcname") + "</td>"
+
" <td width=\"12%\" height=\"18\" align=\"center\"><a href=\"book_op.jsp?tp=confirm&bkid=" +
rs1.getString("bkid") + "\">预借</a></td>"
+ " </tr>";
//System.out.println("printbooking="+printHtml);
}
} catch (SQLException ex) {
System.out.println("12");
ex.printStackTrace();
}
return printHtml;
}
public String punishinfo(){
ResultSet rs1=null;
dbconnBean dbconn=new dbconnBean();
sql="SELECT bkid, bkname, edition, bkauthor, bkpublish, bdate, rdate, authority, hold,(DAY(GETDATE() - rdate)) as dat FROM book_borrow WHERE GETDATE()>rdate and (username = '"+username+"')";
System.out.println(uid+" "+sql);
rs1=dbconn.executeQuery(sql);
printHtml="";
try {
printHtml = "<tr bgcolor=\"#FFFFFF\">"
+ " <th width=\"12%\" height=\"18\">图书编号</th>"
+ " <th width=\"12%\" height=\"18\">图书名</th>"
+ " <th width=\"12%\" height=\"18\">版次</th>"
+ " <th width=\"12%\" height=\"18\">作者</th>"
+ " <th width=\"12%\" height=\"18\">出版社</th>"
+ " <th width=\"12%\" height=\"18\">借书时间</th>"
+ " <th width=\"12%\" height=\"18\">理论归还时间</th>"
+ " <th width=\"12%\" height=\"18\">罚金(逾期天数*0.1元)</th>"
+ " </tr>";
while (rs1.next()) {
this.hold = rs1.getString("hold");
this.authority = rs1.getString("authority");
printHtml += "<tr bgcolor=\"#FFFFFF\">"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkid") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkname") + "</td>"
+ "<td width=\"12%\" height=\"18\"> " +
rs1.getString("edition") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkauthor") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bkpublish") + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("bdate").substring(0,10) + "</td>"
+ " <td width=\"12%\" height=\"18\"> " +
rs1.getString("rdate").substring(0,10) + "</td>"
+
" <td width=\"12%\" height=\"18\" align=\"center\">"+rs1.getString("dat")+"</td>"
+ " </tr>";
}
System.out.println(printHtml);
} catch (SQLException ex) {
ex.printStackTrace();
}
return printHtml;
}
public static void main(String[] args) {
book_op book_op = new book_op();
}
public void setBkid(String bkid) {
this.bkid = bkid;
}
public void setBkname(String bkname) {
this.bkname = bkname;
}
public void setEdition(String edition) {
this.edition = edition;
}
public void setBkpublish(String bkpublish) {
this.bkpublish = bkpublish;
}
public void setBkauthor(String bkauthor) {
this.bkauthor = bkauthor;
}
public void setBdate(String bdate) {
this.bdate = bdate;
}
public void setRdate(String rdate) {
this.rdate = rdate;
}
public void setUsername(String username) {
this.username = username;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getBkid() {
return bkid;
}
public String getBkname() {
return bkname;
}
public String getEdition() {
return edition;
}
public String getBkpublish() {
return bkpublish;
}
public String getBkauthor() {
return bkauthor;
}
public String getBdate() {
return bdate;
}
public String getRdate() {
return rdate;
}
public String getUsername() {
return username;
}
public String getHold() {
return hold;
}
public String getAuthority() {
return authority;
}
public String getUid() {
return uid;
}
private void jbInit() throws Exception {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -