Skip to content

Commit

Permalink
Update Back.java
Browse files Browse the repository at this point in the history
  • Loading branch information
uboger authored Jan 16, 2021
1 parent 6c66096 commit d20eaef
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions Back.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ public class Back extends Frame {
*
*/
private static final long serialVersionUID = 7670129939284773294L;
Label bookidlb = new Label("图书编号"), readeridlb = new Label("读者编号");
Label bookidlb = new Label("图书编号"), readeridlb = new Label("读者编号");
TextField bookidtxt = new TextField(), readeridtxt = new TextField();
Button querybtn = new Button("查询"), borrowbtn = new Button("还书"),
closebtn = new Button("清除");
Button querybtn = new Button("查询"), borrowbtn = new Button("还书"),
closebtn = new Button("清除");
String SepLine = "--------------------------------------------------";
String[] sep = { "图书信息", "读者信息", "借阅信息" };
String[] sep = { "图书信息", "读者信息", "借阅信息" };
Label[] seplabel = new Label[3];
String[] optionname = { "书名:", "作者:", "出版社:", "出版时间:", "定价:", "存量:", "姓名:","类型:", "可借数:", "可借天数:", "借阅日期:","阅读天数:","还书日期" };
String[] optionname = { "书名:", "作者:", "出版社:", "出版时间:", "定价:", "存量:", "姓名:","类型:", "可借数:", "可借天数:", "借阅日期:","阅读天数:","还书日期" };
Label[] alloption = new Label[13];
Label[] showoption = new Label[13];

public Back() {
setTitle("图书归还");
setTitle("图书归还");
setLayout(null);
setSize(500, 470);
setResizable(false);
Expand All @@ -46,7 +46,7 @@ public Back() {
ly = ly + 30;
}
if (ly == 90 || ly == 210 || ly == 300) {
System.out.println(i);// /太奇怪了
System.out.println(i);// /太奇怪了
seplabel[i] = new Label(SepLine + sep[i] + SepLine);
seplabel[i].setBounds(20, ly, 440, 20);
add(seplabel[i]);
Expand Down Expand Up @@ -107,18 +107,18 @@ public void borrowActionPerformed(ActionEvent e) {
if (!bookid.equals("") && !readerid.equals("")) {
Date currentdate = new Date();
String borrowbackdate = showoption[12].getText();
String sql = "update borrow set back_date='"+borrowbackdate+"',if_back='是'";
sql=sql+"where book_id='"+bookid+"'and reader_id='"+readerid+"'and if_back='否'";
String sql = "update borrow set back_date='"+borrowbackdate+"',if_back='是'";
sql=sql+"where book_id='"+bookid+"'and reader_id='"+readerid+"'and if_back='否'";
String sql1 = "update book set stock='"
+ (Integer.parseInt(showoption[5].getText()) + 1) + "'"
+ "where id='" + bookid + "'";
int success = DbOp.executeUpdate(sql);
if (success == 1) {
DbOp.executeUpdate(sql1);
JOptionPane.showMessageDialog(null, "还书成功");
JOptionPane.showMessageDialog(null, "还书成功");

} else {
JOptionPane.showMessageDialog(null, "还书数据登记失败!");
JOptionPane.showMessageDialog(null, "还书数据登记失败!");
}
setInitialize();
}
Expand All @@ -128,14 +128,14 @@ public void queryActionPerformed(ActionEvent e) {
String bookid = bookidtxt.getText(), readerid = readeridtxt.getText();
if (!bookid.equals("") && !readerid.equals("")) {
} else {
JOptionPane.showMessageDialog(null, "图书编号和读者编号都不可以为空");
JOptionPane.showMessageDialog(null, "图书编号和读者编号都不可以为空");
setInitialize();
return;
}
Book book = BookSelect.SelectBookByID(bookid);
Reader reader = ReaderSelect.SelectReaderByID(readerid);
if (!IfBorrowBack.findBook(bookid, readerid)) {
JOptionPane.showMessageDialog(null,"查询不到该读者借阅这本书");
JOptionPane.showMessageDialog(null,"查询不到该读者借阅这本书");
setInitialize();
return;

Expand All @@ -154,7 +154,7 @@ public void queryActionPerformed(ActionEvent e) {
showoption[8].setText(String.valueOf(reader.getMax_num()));
showoption[9].setText(String.valueOf(reader.getDays_num()));
} else {
JOptionPane.showMessageDialog(null, "不存在该图书或该读者");
JOptionPane.showMessageDialog(null, "不存在该图书或该读者");
setInitialize();
return;

Expand All @@ -170,14 +170,14 @@ public void queryActionPerformed(ActionEvent e) {
bookidtxt.setEditable(false);
readeridtxt.setEditable(false);
}
public boolean IfLeapYear(int year) {// 是否闰年,用于计算时间差
public boolean IfLeapYear(int year) {// 是否闰年,用于计算时间差
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) {
return true;
}
return false;
}

public String getReaderBorrowDays(Date date1, Date date2) {// 计算时间差
public String getReaderBorrowDays(Date date1, Date date2) {// 计算时间差
String sum = "";
int year1 = 0, month1 = 0, day1 = 0;
int year2 = 0, month2 = 0, day2 = 0;
Expand Down Expand Up @@ -222,11 +222,11 @@ public void queryActionPerformed(ActionEvent e) {
sum = String.valueOf(count);
return sum;
}
public Date getBorrowDate(String bookid, String readerid) {// 获取读者借书日期
public Date getBorrowDate(String bookid, String readerid) {// 获取读者借书日期
String sql, mydate = "";
Date readerdate = new Date();
sql = "select * from borrow where book_id='" + bookid
+ "' and reader_id='" + readerid + "' and if_back='否'";
+ "' and reader_id='" + readerid + "' and if_back='否'";
ResultSet rs = DbOp.executeQuery(sql);
try {
if (rs.next()) {
Expand All @@ -236,9 +236,9 @@ public void queryActionPerformed(ActionEvent e) {
readerdate = sdf.parse(mydate);
DbOp.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "借书日期查询失败");
JOptionPane.showMessageDialog(null, "借书日期查询失败");
} catch (ParseException e2) {
JOptionPane.showMessageDialog(null, "借书日期异常");
JOptionPane.showMessageDialog(null, "借书日期异常");
}
return readerdate;
}
Expand All @@ -255,7 +255,7 @@ public void setInitialize() {
borrowbtn.setEnabled(false);
}

public static void main(String[] args){
public static void main(String[] args){
new Back();
}
}
}

0 comments on commit d20eaef

Please sign in to comment.