?? frreturn.java
字號:
package mybook.book;
import java.awt.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.Font;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import mydbc.dbc.DBC;
import java.sql.ResultSet;
import java.sql.*;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2008</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
//該類用于還書登記
public class FrReturn extends JFrame {
public FrReturn() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
setSize(new Dimension(295, 263));
this.setTitle("還書登記");
lblBid.setText("所借書編號:");
lblBid.setBounds(new Rectangle(46, 91, 83, 15));
lblReturn.setFont(new java.awt.Font("宋體", Font.BOLD, 20));
lblReturn.setText("還書登記");
lblReturn.setBounds(new Rectangle(90, 21, 114, 49));
btnSubmit.setBounds(new Rectangle(51, 196, 81, 23));
btnSubmit.setText("提交");
btnSubmit.addActionListener(new FrReturn_btnSubmit_actionAdapter(this));
btnCancel.setBounds(new Rectangle(159, 196, 81, 23));
btnCancel.setText("取消");
btnCancel.addActionListener(new FrReturn_jButton2_actionAdapter(this));
this.getContentPane().add(lblBid);
txtUid.setBounds(new Rectangle(137, 136, 76, 20));
txtBid.setBounds(new Rectangle(137, 87, 76, 20));
this.getContentPane().add(txtBid);
this.getContentPane().add(txtUid);
this.getContentPane().add(lblUid);
this.getContentPane().add(lblReturn);
this.getContentPane().add(btnSubmit);
this.getContentPane().add(btnCancel);
lblUid.setText("借書人編號:");
lblUid.setBounds(new Rectangle(46, 138, 86, 15));
}
JLabel lblBid = new JLabel();
JLabel lblUid = new JLabel();
JTextField txtBid = new JTextField();
JTextField txtUid = new JTextField();
JLabel lblReturn = new JLabel();
JButton btnSubmit = new JButton();
JButton btnCancel = new JButton();
//該方法用于退出當前Frame
public void jButton2_actionPerformed(ActionEvent e) {
this.setVisible(false);
}
//該方法用于還書
public void btnSubmit_actionPerformed(ActionEvent e) {
//欄位判斷
if (txtUid.getText().equals("") || txtBid.getText().equals("")) {
javax.swing.JOptionPane.showMessageDialog(this, "各欄位不能為空!請重新輸入。");
return;
} else {
//判斷是否為數字型
try {
Integer.parseInt(txtUid.getText());
Integer.parseInt(txtBid.getText());
} catch (NumberFormatException ex) {
javax.swing.JOptionPane.showMessageDialog(this,
"編號只能為數字!請重新輸入。");
return;
}
//判斷數據庫中是否有該讀者的結束記錄
DBC dbc = DBC.getInstance();
String state = "";
String time = "";
ResultSet rs = dbc.executeQuery(
"SELECT TOP 1 * FROM OutBooks WHERE Obid = " +
Integer.parseInt(txtBid.getText()) + "AND Ouid=" +
Integer.parseInt(txtUid.getText()) +
"ORDER BY Obotime DESC");
try {
rs.next();
time = rs.getString("Obotime");
state = rs.getString("Obstate");
} catch (SQLException ex1) {
javax.swing.JOptionPane.showMessageDialog(this, "該讀者未租借過此書!");
return;
}
if (state.equals("是")) {
javax.swing.JOptionPane.showMessageDialog(this,
"還書失敗,該讀者已經還過此書!");
return;
} else {
//開始還書操作
if (dbc.executeUpdate(
"UPDATE OutBooks SET Obstate='是',Obkeep='否' WHERE Obid = " +
Integer.parseInt(txtBid.getText()) + " AND Ouid = " +
Integer.parseInt(txtUid.getText()) + "AND Obotime = '" +
time + "'") &&
dbc.
executeUpdate(
"UPDATE Users SET Uyue=Uyue+(SELECT Bprice FROM Books WHERE Bid = " +
Integer.parseInt(txtBid.getText()) +
") WHERE Uid = " +
Integer.parseInt(txtUid.getText())) &&
dbc.
executeUpdate(
"UPDATE Books SET Bsum=Bsum+1 WHERE Bid =" +
Integer.parseInt(txtBid.getText()))) {
javax.swing.JOptionPane.showMessageDialog(this, "還書成功!");
} else {
javax.swing.JOptionPane.showMessageDialog(this,
"還書失?。≌堉卦?。");
}
}
}
}
}
class FrReturn_btnSubmit_actionAdapter implements ActionListener {
private FrReturn adaptee;
FrReturn_btnSubmit_actionAdapter(FrReturn adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnSubmit_actionPerformed(e);
}
}
class FrReturn_jButton2_actionAdapter implements ActionListener {
private FrReturn adaptee;
FrReturn_jButton2_actionAdapter(FrReturn adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -