package bookmanager; import javax.swing.*; import com.borland.jbcl.layout.*; import java.awt.*; import java.awt.event.*; import java.sql.*; /** * Title: * Description: * Copyright: Copyright (c) 2003 * Company: * @author not attributable * @version 1.0 */ public class returnBook extends JFrame { //定义结果集 ResultSet rs; // 定义数据库操作对象 private DBManager db =new DBManager(); XYLayout xYLayout1 = new XYLayout(); JLabel jLabel4 = new JLabel(); JTextField jTextbookname = new JTextField(); JButton jButtonCancel = new JButton(); JButton jButtonOk = new JButton(); JLabel jLabel1 = new JLabel(); JLabel jLabel3 = new JLabel(); JButton jButtonReset = new JButton(); JTextField jTextreturndate = new JTextField(); JLabel jLabel2 = new JLabel(); JTextField jTextcomment = new JTextField(); JTextField jTextstudentname = new JTextField(); public returnBook() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } public static void main(String[] args) { returnBook returnBook = new returnBook(); } private void jbInit() throws Exception { jTextstudentname.setText(""); jTextstudentname.setFont(new java.awt.Font("Dialog", 0, 16)); jTextcomment.setText(""); jTextcomment.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel2.setText("书名"); jTextreturndate.setText(""); jTextreturndate.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonReset.setText("清空"); jButtonReset.addMouseListener(new returnBook_jButtonReset_mouseAdapter(this)); jButtonReset.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonReset.setEnabled(true); 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("还书者姓名"); jButtonOk.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonOk.setText("确定"); jButtonOk.addMouseListener(new returnBook_jButtonOk_mouseAdapter(this)); jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16)); jButtonCancel.addMouseListener(new returnBook_jButtonCancel_mouseAdapter(this)); jButtonCancel.setText("退出"); jButtonCancel.addMouseListener(new returnBook_jButtonCancel_mouseAdapter(this)); jTextbookname.setText(""); jTextbookname.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setFont(new java.awt.Font("Dialog", 0, 16)); jLabel4.setText("备注"); this.getContentPane().setLayout(xYLayout1); xYLayout1.setWidth(497); xYLayout1.setHeight(306); this.getContentPane().add(jTextstudentname, new XYConstraints(204, 32, 134, 26)); this.getContentPane().add(jLabel4, new XYConstraints(79, 184, 63, 29)); this.getContentPane().add(jTextbookname, new XYConstraints(200, 82, 154, 30)); this.getContentPane().add(jButtonCancel, new XYConstraints(334, 229, 100, 36)); this.getContentPane().add(jButtonOk, new XYConstraints(208, 230, 101, 36)); this.getContentPane().add(jLabel3, new XYConstraints(79, 136, 87, 29)); this.getContentPane().add(jButtonReset, new XYConstraints(57, 233, 104, 32)); this.getContentPane().add(jTextreturndate, new XYConstraints(202, 131, 137, -1)); this.getContentPane().add(jLabel2, new XYConstraints(82, 79, 89, 35)); this.getContentPane().add(jTextcomment, new XYConstraints(206, 187, 137, -1)); this.getContentPane().add(jLabel1, new XYConstraints(80, 29, 88, 33)); } void jButtonCancel_mouseClicked(MouseEvent e) { this.dispose(); } //清空所有文本框 void jButtonReset_mouseClicked(MouseEvent e) { jTextstudentname.setText(""); jTextbookname.setText(""); jTextreturndate.setText(""); jTextcomment.setText(""); } void jButtonOk_mouseClicked(MouseEvent e) { String strSQL ; //借阅者姓名是否为空 if(jTextstudentname.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"借阅者姓名不许为空!"); return;} //书名是否为空 if(jTextbookname.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"书名不许为空!"); return;} //还阅日起是否为空 if(jTextreturndate.getText().trim().equals("")) {JOptionPane.showMessageDialog(null,"还阅日起不许为空!"); return;} //检验是否此人借的此书 strSQL="select * from BookBorrow where username='"+jTextFieldusername.getText().trim() +"' and password='"+jPasswordold.getText().trim()+"'"; rs=db.getResult(strSQL) ; boolean isexist=false; try { isexist = rs.first(); } catch (SQLException ex1) { } //若用户名不存在,提示警告信息提醒用户从新输入 if(!isexist) {JOptionPane.showMessageDialog(null,"用户名不存在,或原密码不正确!"); return; } //生成更新sql语句 strSQL="update BookBorrow set returndate='"+jTextreturndate.getText()+"',"; strSQL=strSQL+" comment='"+jTextcomment.getText() +"'"; strSQL=strSQL+" where studentname='"+jTextstudentname.getText() +"'"; strSQL=strSQL+" and bookname='"+jTextbookname.getText() +"'"; //由数据库操作对象执行数据库操作,并返回操作成功失败的提示信息 if(db.executeSql(strSQL) ){ JOptionPane.showMessageDialog(null,"操作成功!"); } else { JOptionPane.showMessageDialog(null,"此借书者不存在!请确认!"); } } } class returnBook_jButtonCancel_mouseAdapter extends java.awt.event.MouseAdapter { returnBook adaptee; returnBook_jButtonCancel_mouseAdapter(returnBook adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonCancel_mouseClicked(e); } } class returnBook_jButtonReset_mouseAdapter extends java.awt.event.MouseAdapter { returnBook adaptee; returnBook_jButtonReset_mouseAdapter(returnBook adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonReset_mouseClicked(e); } } class returnBook_jButtonOk_mouseAdapter extends java.awt.event.MouseAdapter { returnBook adaptee; returnBook_jButtonOk_mouseAdapter(returnBook adaptee) { this.adaptee = adaptee; } public void mouseClicked(MouseEvent e) { adaptee.jButtonOk_mouseClicked(e); } }