⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 returnbook.java~1~

📁 教材管理系统
💻 JAVA~1~
字号:
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 returnBook
    extends JFrame {
  //定义结果集
  ResultSet rs;
  // 定义数据库操作对象
  private DBManager db = new DBManager();

  XYLayout xYLayout1 = new XYLayout();
  JLabel jLabel4 = new JLabel();
  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();
  JComboBox jComboBoxbookname = new JComboBox();

  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));
    jLabel4.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel4.setText("备注");
    this.getContentPane().setLayout(xYLayout1);
    xYLayout1.setWidth(497);
    xYLayout1.setHeight(306);
    this.setTitle("书籍还入");
    this.addWindowListener(new returnBook_this_windowAdapter(this));
    this.getContentPane().add(jTextstudentname,
                              new XYConstraints(204, 32, 134, 26));
    this.getContentPane().add(jLabel4, new XYConstraints(79, 184, 63, 29));
    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));
    this.getContentPane().add(jComboBoxbookname,
                              new XYConstraints(203, 80, 142, 26));
  }

  void jButtonCancel_mouseClicked(MouseEvent e) {
    this.dispose();
  }

//清空所有文本框
  void jButtonReset_mouseClicked(MouseEvent e) {
    jTextstudentname.setText("");
    jComboBoxbookname.setSelectedItem("");
    jTextreturndate.setText("");
    jTextcomment.setText("");

  }

  void jButtonOk_mouseClicked(MouseEvent e) {
    String strSQL;
    //借阅者姓名是否为空
    if (jTextstudentname.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(null, "借阅者姓名不许为空!");
      return;
    }
    //书名是否为空
    if (jComboBoxbookname.getSelectedItem().toString().trim().equals("")) {
      JOptionPane.showMessageDialog(null, "书名不许为空!");
      return;
    }
    //还阅日起是否为空
    if (jTextreturndate.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(null, "还阅日起不许为空!");
      return;
    }
    //检验是否此人借的此书
    strSQL = "select * from BookBorrow where Studentname='" +
        jTextstudentname.getText().trim() + "'";
    strSQL = strSQL + " and Bookname='" +
        jComboBoxbookname.getSelectedItem().toString().trim() + "'";
    rs = db.getResult(strSQL);
    boolean isexist = false;
    try {
      isexist = rs.first();
    }
    catch (SQLException ex1) {
    }
    //若用户名不存在,提示警告信息提醒用户从新输入
    if (!isexist) {
      JOptionPane.showMessageDialog(null,
                                    jTextstudentname.getText().trim() + " 同学并未借得!<" +
                                    jComboBoxbookname.getSelectedItem().
                                    toString().trim() + ">请确认!");
      return;
    }

    //生成更新sql语句
    strSQL = "update  BookBorrow set Returndate='" + jTextreturndate.getText() +
        "',";
    strSQL = strSQL + "  Comment='" + jTextcomment.getText() + "'";
    strSQL = strSQL + " where Studentname='" + jTextstudentname.getText() + "'";
    strSQL = strSQL + " and Bookname='" +
        jComboBoxbookname.getSelectedItem().toString().trim() + "'";
    //由数据库操作对象执行数据库操作,并返回操作成功失败的提示信息
    if (db.executeSql(strSQL)) {
      JOptionPane.showMessageDialog(null, "操作成功!");
    }
    else {
      JOptionPane.showMessageDialog(null, "此借书者不存在!请确认!");
    }

  }

  void this_windowOpened(WindowEvent e) {
    String strSQL = "";
    strSQL = "select bookname from Books  ";
    rs = db.getResult(strSQL);
    boolean isexist = false;
    try {
      isexist = rs.first();
    }
    catch (SQLException ex1) {
    }
    //若用户名不存在,提示警告信息提醒用户从新输入
    if (!isexist) {
      JOptionPane.showMessageDialog(null,
                                    "书库中没有书目,请确认!");
      return;
    }
    else {
      try {
        rs.beforeFirst();
        while (rs.next()) {
          jComboBoxbookname.addItem(rs.getString("Bookname"));
        }
      }
      catch (SQLException ex) {
      }

    }

  }
}

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);
  }
}

class returnBook_this_windowAdapter
    extends java.awt.event.WindowAdapter {
  returnBook adaptee;

  returnBook_this_windowAdapter(returnBook adaptee) {
    this.adaptee = adaptee;
  }

  public void windowOpened(WindowEvent e) {
    adaptee.this_windowOpened(e);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -