?? returninfoupdate.java
字號:
package bookmanager;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class returnInfoUpdate
extends JFrame {
ResultSet rs; //定義結果集
private DBManager db = new DBManager(); //定義數據庫操作對象
XYLayout xYLayout1 = new XYLayout();
JLabel jLabel8 = new JLabel();
JLabel jLabel4 = new JLabel();
JTextField jTextbookname = new JTextField();
JTextField jTextborrowdate = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel3 = new JLabel();
JButton jButtonupdate = new JButton();
JLabel jLabel2 = new JLabel();
JButton jButtonexit = new JButton();
JTextField jTextcomment = new JTextField();
JButton jButtondicision = new JButton();
JButton jButtonClear = new JButton();
JTextField jTextstudentname = new JTextField();
JTextField jTextreturndate = new JTextField();
JLabel jLabel5 = new JLabel();
public returnInfoUpdate() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
returnInfoUpdate returnInfoUpdate = new returnInfoUpdate();
}
private void jbInit() throws Exception {
jTextstudentname.setFont(new java.awt.Font("Dialog", 0, 16));
jTextstudentname.setText("");
jButtonClear.setFont(new java.awt.Font("Dialog", 0, 16));
jButtonClear.setText("清空");
jButtonClear.addMouseListener(new
returnInfoUpdate_jButtonClear_mouseAdapter(this));
jButtondicision.setFont(new java.awt.Font("Dialog", 0, 16));
jButtondicision.setText("確定");
jButtondicision.addMouseListener(new
returnInfoUpdate_jButtondicision_mouseAdapter(this));
jTextcomment.setFont(new java.awt.Font("Dialog", 0, 16));
jTextcomment.setText("");
jButtonexit.setFont(new java.awt.Font("Dialog", 0, 16));
jButtonexit.setText("退出");
jButtonexit.addMouseListener(new returnInfoUpdate_jButtonexit_mouseAdapter(this));
jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel2.setText("書名");
jButtonupdate.setFont(new java.awt.Font("Dialog", 0, 16));
jButtonupdate.setText("更新");
jButtonupdate.addMouseListener(new
returnInfoUpdate_jButtonupdate_mouseAdapter(this));
jLabel3.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel3.setText("借閱日期");
jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel1.setRequestFocusEnabled(true);
jLabel1.setText("借閱者姓名");
jTextborrowdate.setFont(new java.awt.Font("Dialog", 0, 16));
jTextborrowdate.setText("");
jTextbookname.setFont(new java.awt.Font("Dialog", 0, 16));
jTextbookname.setText("");
jLabel4.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel4.setText("備注");
jLabel8.setText("輸入借閱者姓名或書名點擊確定,將調出此書相關信息");
jLabel8.setFont(new java.awt.Font("Dialog", 0, 16));
this.getContentPane().setLayout(xYLayout1);
jTextreturndate.setFont(new java.awt.Font("Dialog", 0, 16));
jTextreturndate.setText("");
jLabel5.setFont(new java.awt.Font("Dialog", 0, 16));
jLabel5.setText("還書日期");
xYLayout1.setWidth(478);
xYLayout1.setHeight(368);
this.setTitle("書籍還入信息修改");
this.getContentPane().add(jTextborrowdate,
new XYConstraints(201, 161, 153, -1));
this.getContentPane().add(jLabel1, new XYConstraints(74, 60, 88, 33));
this.getContentPane().add(jButtonupdate, new XYConstraints(229, 312, 74, 27));
this.getContentPane().add(jButtonexit, new XYConstraints(303, 312, 75, 28));
this.getContentPane().add(jButtondicision,
new XYConstraints(163, 312, -1, 28));
this.getContentPane().add(jButtonClear, new XYConstraints(96, 312, 66, 28));
this.getContentPane().add(jTextstudentname,
new XYConstraints(202, 64, 150, 26));
this.getContentPane().add(jTextcomment, new XYConstraints(202, 246, 154, -1));
this.getContentPane().add(jLabel4, new XYConstraints(73, 257, 63, 29));
this.getContentPane().add(jLabel5, new XYConstraints(71, 210, 87, 29));
this.getContentPane().add(jLabel8, new XYConstraints(15, 13, 435, 25));
this.getContentPane().add(jTextbookname,
new XYConstraints(201, 112, 154, 23));
this.getContentPane().add(jLabel2, new XYConstraints(73, 106, 89, 35));
this.getContentPane().add(jLabel3, new XYConstraints(70, 162, 87, 29));
this.getContentPane().add(jTextreturndate,
new XYConstraints(203, 204, 153, -1));
}
void jButtonexit_mouseClicked(MouseEvent e) {
this.dispose();
}
void jButtonupdate_mouseClicked(MouseEvent e) {
String strSQL;
strSQL = "update BookBorrow set ";
strSQL = strSQL + " Borrowdate='" + jTextborrowdate.getText().trim() + "',";
strSQL = strSQL + " Returndate='" + jTextreturndate.getText().trim() + "',";
strSQL = strSQL + " Comment='" + jTextcomment.getText().trim() + "'";
strSQL = strSQL + " where Studentname='" + jTextstudentname.getText().trim() +
"'";
strSQL = strSQL + " and Bookname='" + jTextbookname.getText().trim() + "'";
//由數據庫操作對象執行數據庫操作,并返回操作成功失敗的提示信息
if (db.executeSql(strSQL)) {
JOptionPane.showMessageDialog(null, "成功更新!");
}
else {
JOptionPane.showMessageDialog(null, " 更新失敗,請重新操作!");
}
}
void jButtondicision_mouseClicked(MouseEvent e) {
String sql;
//定義變量,用來判斷是否是第一個查詢條件
boolean isfirst = true;
sql = "select * from BookBorrow ";
//如果款型的查詢條件不為空
if (jTextstudentname.getText().trim().length() == 0) {}
else {
sql = sql + " where Studentname='" + jTextstudentname.getText().trim() +
"'";
isfirst = false;
}
//如果顏色的查詢條件不為空
if (jTextbookname.getText().trim().length() == 0) {}
else { //如果是第一個查詢條件
if (isfirst)
sql = sql + " where Bookname='" + jTextbookname.getText().trim() + "'";
//如果是第二個查詢條件
else
sql = sql + " and Bookname='" + jTextbookname.getText().trim() + "'";
}
//執行數據庫的查詢操作
rs = db.getResult(sql);
try {
//判斷返回的結果集是否為空,若不為空顯示第一條記錄
if (!rs.equals(null)) {
rs.first();
jTextstudentname.setText(rs.getString("Studentname"));
jTextbookname.setText(rs.getString("Bookname"));
jTextborrowdate.setText(rs.getString("Borrowdate"));
jTextreturndate.setText(rs.getString("Returndate"));
jTextcomment.setText(rs.getString("Comment"));
}
else {
JOptionPane.showMessageDialog(null, "無次紀錄!");
}
} //若出現異常,彈出警告對話框
catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "發生錯誤!");
}
}
void jButtonClear_mouseClicked(MouseEvent e) {
jTextstudentname.setText("");
jTextbookname.setText("");
jTextborrowdate.setText("");
jTextreturndate.setText("");
jTextcomment.setText("");
}
}
class returnInfoUpdate_jButtonexit_mouseAdapter
extends java.awt.event.MouseAdapter {
returnInfoUpdate adaptee;
returnInfoUpdate_jButtonexit_mouseAdapter(returnInfoUpdate adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButtonexit_mouseClicked(e);
}
}
class returnInfoUpdate_jButtonupdate_mouseAdapter
extends java.awt.event.MouseAdapter {
returnInfoUpdate adaptee;
returnInfoUpdate_jButtonupdate_mouseAdapter(returnInfoUpdate adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButtonupdate_mouseClicked(e);
}
}
class returnInfoUpdate_jButtondicision_mouseAdapter
extends java.awt.event.MouseAdapter {
returnInfoUpdate adaptee;
returnInfoUpdate_jButtondicision_mouseAdapter(returnInfoUpdate adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButtondicision_mouseClicked(e);
}
}
class returnInfoUpdate_jButtonClear_mouseAdapter
extends java.awt.event.MouseAdapter {
returnInfoUpdate adaptee;
returnInfoUpdate_jButtonClear_mouseAdapter(returnInfoUpdate adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButtonClear_mouseClicked(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -