Java 图书馆管理系统(附全代码) - 课程设计报告 下载本文

《数据库系统概论》课程报告

课题名称:小型图书管理系统

课题负责人名(学号):best

同组成员名单(角色):

指导教师: 评阅成绩: 评阅意见:

提交报告时间:2015年12月15日

课程名称:数据库系统概论

小型图书管理系统

计算机科学与技术专业

学生指导老师

[摘要] 随着计算机技术的飞速发展,利用计算机来获得和处理信息是当今信息管理的一大特点。伴随计算机硬件的快速发展,有关信息管理的软件——数据库系统软件也在迅猛发展着。图书馆是高等院校的重要组成部门,是教师和学生获取知识的重要场所。由于图书馆主要从事大量的图书资料的储存和流通。所以一直以来,计算机在图书馆的图书管理中得到了广泛的应用。本系统实现图书信息管理的系统化,规范化和自动化,以最大程度提高操作人员的办公效率。

关键词:JAVA、JDBC、SQL Server、数据库、图书馆管理

-1-

课程名称:数据库系统概论

一、实验题目:小型图书管理系统

二、实验的目的和要求:

完成一个小型图书管理系统,功能要求如下:

1) 能够通过书籍基本信息(包括:书号、书名、出版社、出版日期、作者、内容摘要)单个或以AND方式组合多个条件查询书籍信息;

2) 对于每一种书籍,除可查看其基本信息之外还可查看其总数以及目前在馆数量 3) 可增添新的书籍

4) 可删除已有书籍(如有读者借了该书籍尚未归还,则不允许删除)

5) 可修改书籍的基本信息

6) 能够通过读者基本信息(包括:证号、姓名、性别、系名、年级)单个或以AND方式组合多个条件查询读者信息

7) 对于每位读者除可查看其基本信息之外,还可查看其已借的书籍列表、数量、借还日期 8) 可增添新的读者

9) 可删除已有读者(如该读者有尚未归还的借书,则不允许删除) 10) 可修改读者的基本信息

-2-

课程名称:数据库系统概论

11) 可完成借还书籍的手续

12) 还书时如超期,应该显示超期天数

13) 借书时如果有超期的书没有还,则不允许借书

14) 可查询有哪些读者有超期的书没有还,列出这些读者的基本信息

三、实验的环境:

1、硬件环境:CPU:Intel(R) Core i5-3230 2.60GHz RAM:8GB

2、软件环境:操作系统:Windows 7 Ultimate SP1 编译软件:Eclipse Luna

Microsoft SQL Server 2014

四、系统ER图

-3-

课程名称:数据库系统概论

添加读者删除读者删除图书修改读者添加图书用户名密码权限修改图书拥有管理员编号书名编号姓名性别年级管理管理作者出版社读者借阅图书出版时间摘要总量系名超期时间应还时间借阅时间现存量 五、表结构定义(使用表格说明)

-4-

课程名称:数据库系统概论

-5-

课程名称:数据库系统概论

-6-

课程名称:数据库系统概论

六、系统功能模块

1) 能够通过书籍基本信息单个或组合多个条件查询书籍信息;

2) 对于每一种书籍,除可查看其基本信息之外还可查看其总数以

-7-

课程名称:数据库系统概论

及目前在馆数量 3) 可增添新的书籍

4) 可删除已有书籍(如有读者借了该书籍尚未归还,则不允许删除)

5) 可修改书籍的基本信息

6) 能够通过读者基本信息单个或组合多个条件查询读者信息 7) 对于每位读者除可查看其基本信息之外,还可查看其已借的书籍列表、数量、借还日期 8) 可增添新的读者

9) 可删除已有读者(如该读者有尚未归还的借书,则不允许删除) 10) 可修改读者的基本信息 11) 可完成借还书籍的手续

12) 还书时如超期,应该显示超期天数

13) 借书时如果有超期的书没有还,则不允许借书

14) 可查询有哪些读者有超期的书没有还,列出这些读者的基本信息

七、程序框架流程图

-8-

课程名称:数据库系统概论

登录主界面图书管理读者管理借阅列表增加书籍编辑书籍删除书籍组合查询借阅书籍归还书籍增加读者编辑读者删除读者组合查询详细信息详细信息

-9-

课程名称:数据库系统概论

九、程序运行结果

-10-

课程名称:数据库系统概论

-11-

课程名称:数据库系统概论

-12-

课程名称:数据库系统概论

-13-

课程名称:数据库系统概论

八、核心代码

AddBook.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;

import javax.swing.*;

-14-

课程名称:数据库系统概论

publicclassAddBookextends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();

JLabel bookNumber = new JLabel(\); JLabel bookName = new JLabel(\);

JLabel bookAuthor = new JLabel(\); JLabel press = new JLabel(\);

JLabel pressTime = new JLabel(\); JLabel bookAbstract = new JLabel(\); JLabel storage = new JLabel(\); JLabel remain = new JLabel(\);

JLabel remain1 = new JLabel(\); JTextFieldnumberField = newJTextField(); JTextFieldnameField = newJTextField(); JTextFieldauthorField = newJTextField(); JTextFieldpressField = newJTextField();

JTextFieldpressTimeField = newJTextField(); JTextFieldabstractField = newJTextField(); JTextFieldstorageField = newJTextField(); JButton cancel = new JButton(\);

JButton confirm = new JButton(\);

public AddBook() {

c.add(p1, BorderLayout.NORTH);

p1.setLayout(new GridLayout(9, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(bookName); p1.add(nameField); p1.add(bookAuthor); p1.add(authorField); p1.add(press);

p1.add(pressField); p1.add(pressTime);

p1.add(pressTimeField); p1.add(bookAbstract); p1.add(abstractField); p1.add(storage);

p1.add(storageField);

-15-

课程名称:数据库系统概论

p1.add(remain); p1.add(remain1); p1.add(cancel); p1.add(confirm);

cancel.addActionListener(this); confirm.addActionListener(this);

}

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose(); }

if (e.getSource() == confirm) { this.dispose();

BookInfo book = new BookInfo(numberField.getText(), nameField.getText(), authorField.getText(), pressField.getText(), pressTimeField.getText(),

abstractField.getText(), Integer.parseInt(storageField

.getText()),

Integer.parseInt(storageField.getText())); ArrayListstrArray = new ArrayList();

strArray = op.addBookJudgement(); intn = 0;

intreplicate = 0;

while (n< Integer.parseInt(strArray.get(0))) { n++; if

(numberField.getText().equals(strArray.get(n))) { replicate++; } }

if (replicate == 0) { op.saveBook(book);

JOptionPane.showMessageDialog(null, \a book successfully!\,

-16-

课程名称:数据库系统概论

\, JOptionPane.INFORMATION_MESSAGE); } else {

JOptionPane.showMessageDialog(null,

\book(number) has already existed!\, \,

JOptionPane.INFORMATION_MESSAGE); }

} } }

AddReader.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;

import javax.swing.*;

publicclassAddReaderextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();

JLabel readerNumber = new JLabel(\); JLabel readerName = new JLabel(\);

-17-

课程名称:数据库系统概论

JLabel sex = new JLabel(\);

JLabel dpt = new JLabel(\); JLabel grade = new JLabel(\);

JTextField numberField = new JTextField(); JTextField nameField = new JTextField(); JTextField sexField = new JTextField(); JTextField dptField = new JTextField(); JTextField gradeField = new JTextField(); JButton cancel = new JButton(\);

JButton confirm = new JButton(\);

public AddReader() {

c.add(p1, BorderLayout.NORTH);

p1.setLayout(new GridLayout(6, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); p1.add(readerName); p1.add(nameField); p1.add(sex);

p1.add(sexField); p1.add(dpt);

p1.add(dptField); p1.add(grade);

p1.add(gradeField); p1.add(cancel); p1.add(confirm);

cancel.addActionListener(this); confirm.addActionListener(this);

}

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose(); }

if (e.getSource() == confirm) { this.dispose();

ReaderInfo reader =

newReaderInfo(numberField.getText(),

-18-

课程名称:数据库系统概论

nameField.getText(), sexField.getText(), dptField.getText(),

Integer.parseInt(gradeField.getText())); ArrayListstrArray = new ArrayList();

strArray = op.addReaderJudgement(); intn = 0;

intreplicate = 0;

while (n< Integer.parseInt(strArray.get(0))) { n++; if

(numberField.getText().equals(strArray.get(n))) { replicate++; } }

if (replicate == 0) {

if (!sexField.getText().equals(\)

&& !sexField.getText().equals(\)) { JOptionPane

.showMessageDialog( null,

\input 'boy' or 'girl'!\,

\, JOptionPane.INFORMATION_MESSAGE); } else {

op.saveReader(reader);

JOptionPane.showMessageDialog(null, \!\, \,

JOptionPane.INFORMATION_MESSAGE); }

} else {

JOptionPane.showMessageDialog(null,

\existed!\, \,

JOptionPane.INFORMATION_MESSAGE); } }

-19-

课程名称:数据库系统概论

} }

BookDetails.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;

import javax.swing.*;

import javax.swing.table.DefaultTableModel;

publicclassBookDetailsextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel();

JLabel bookNumber = new JLabel(\); JLabel bookName = new JLabel(\); JLabel author = new JLabel(\); JLabel press = new JLabel(\);

JLabel pressTime = new JLabel(\); JLabel bookAbstract = new JLabel(\); JLabel storage = new JLabel(\); JLabel remain = new JLabel(\); JLabel numberField = new JLabel(); JLabel nameField = new JLabel(); JLabel authorField = new JLabel(); JLabel pressField = new JLabel();

JLabel pressTimeField = new JLabel();

-20-

课程名称:数据库系统概论

JLabel abstractField = new JLabel(); JLabel storageField = new JLabel(); JLabel remainField = new JLabel();

JButton cancel = new JButton(\);

JLabel details = new JLabel(\and reaturn details\); Object[] s = { \, \, \, \ };

Object[][] ob1 = new Object[7][4]; JTable table = new JTable(ob1, s);

JScrollPane scrollPane = new JScrollPane(table);

public BookDetails(String number) {

BookInfo book = new BookInfo(number); ob1 = op.borrowListForBook(number); for (inti = 0; i< 5; i++) {

DefaultTableModel books = new DefaultTableModel(ob1, s);

for (intn = 0; n< 7; n++) { for (intm = 0; m< 4; m++) { ob1[n][m] = this.ob1[n][m]; }

table.setModel(books); table.invalidate(); } }

ArrayListstrArray = new ArrayList(); strArray = op.outputBook(book); numberField.setText(number);

nameField.setText(strArray.get(1)); authorField.setText(strArray.get(2)); pressField.setText(strArray.get(3));

pressTimeField.setText(strArray.get(4)); abstractField.setText(strArray.get(5)); storageField.setText(strArray.get(6)); remainField.setText(strArray.get(7)); c.add(p1, BorderLayout.NORTH); c.add(p2, BorderLayout.CENTER); c.add(p3, BorderLayout.SOUTH);

p1.setLayout(new GridLayout(9, 2, 20, 10)); p1.add(bookNumber);

-21-

课程名称:数据库系统概论

p1.add(numberField); p1.add(bookName); p1.add(nameField); p1.add(author);

p1.add(authorField); p1.add(press);

p1.add(pressField); p1.add(pressTime);

p1.add(pressTimeField); p1.add(bookAbstract); p1.add(abstractField); p1.add(storage);

p1.add(storageField); p1.add(remain);

p1.add(remainField); p1.add(details);

scrollPane.setBounds(0, 0, 800, 300); p2.add(scrollPane); p3.add(cancel);

table.setPreferredScrollableViewportSize(new Dimension(400, 100));

cancel.addActionListener(this);

}

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose(); } } }

BookInfo.java

-22-

课程名称:数据库系统概论

publicclass BookInfo {

private String number, name, author, press, pressTime, bookAbstract;

privateinttotal, remain;

// default constructor public BookInfo() { }

public BookInfo(String number) { this.number = number; }

public BookInfo(String number, String name) { this.number = number; this.name = name; }

public BookInfo(String number, String name, String author, String press,

String pressTime, String bookAbstract, inttotal, intremain) {

this.number = number; this.name = name;

this.author = author; this.press = press;

this.pressTime = pressTime;

this.bookAbstract = bookAbstract; this.total = total; this.remain = remain; }

publicvoid setRemain(inti) { this.remain=i; }

public String getNumber() { returnnumber; }

public String getName() { returnname;

-23-

课程名称:数据库系统概论

}

public String getAuthor() { returnauthor; }

public String getPress() { returnpress; }

public String getPressTime() { returnpressTime; }

public String getBookAbstract() { returnbookAbstract; }

publicint getTotal() { returntotal; }

publicint getRemain() { returnremain; } }

BookRetrieval.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.Font;

import java.awt.GridLayout;

-24-

课程名称:数据库系统概论

import java.awt.event.*; import java.util.ArrayList;

import javax.swing.*;

import javax.swing.table.DefaultTableModel;

classBookRetrievalextends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p4 = new JPanel(); JPanel p5 = new JPanel();

JLabel bookNumber = new JLabel(\); JLabel bookName = new JLabel(\); JTextField number = new JTextField(); JTextField name = new JTextField();

JButton back = new JButton(\); JButton addBook = new JButton(\);

JButton deleteBook = new JButton(\); JButton editBook = new JButton(\);

JButton search = new JButton(\); JButton borrowBook = new JButton(\); JButton returnBook = new JButton(\); Font font1 = new Font(\, Font.BOLD, 20);

Object[] s = { \, \, \, \, \Time\,

\, \, \ }; Object[][] ob = new Object[40][8]; JTable table = new JTable(ob, s);

JScrollPane scrollPane = new JScrollPane(table);

public BookRetrieval() {

BookInfo book = new BookInfo(); ob = op.allBook(book);

for (inti = 0; i< 5; i++) {

DefaultTableModel books = new DefaultTableModel(ob, s);

for (intn = 0; n< 20; n++) { for (intm = 0; m< 8; m++) { ob[n][m] = this.ob[n][m];

-25-

课程名称:数据库系统概论

}

table.setModel(books); table.invalidate(); } }

c.add(p4, BorderLayout.NORTH); c.add(p1, BorderLayout.CENTER); c.add(p5, BorderLayout.SOUTH); search.setFont(font1);

p4.setLayout(new GridLayout(2, 4, 20, 10)); p4.add(back); p4.add(addBook); p4.add(editBook); p4.add(deleteBook); p4.add(borrowBook); p4.add(returnBook); p1.setLayout(null);

scrollPane.setBounds(0, 0, 800, 300); p1.add(scrollPane);

p5.setLayout(new GridLayout(5, 1, 0, 0)); p5.add(bookNumber); p5.add(number); p5.add(bookName); p5.add(name); p5.add(search);

table.setPreferredScrollableViewportSize(new Dimension(400, 300));

addBook.addActionListener(this); search.addActionListener(this); back.addActionListener(this);

deleteBook.addActionListener(this); editBook.addActionListener(this); borrowBook.addActionListener(this); returnBook.addActionListener(this); }

publicvoid actionPerformed(ActionEvent e) { if (e.getSource() == search) {

ArrayListstrArray = new ArrayList();

-26-

课程名称:数据库系统概论

strArray = op.addBookJudgement(); String s1 = number.getText(); String s2 = name.getText(); intn = 0;

intreplicate = 0;

while (n< Integer.parseInt(strArray.get(0))) { n++;

if (s1.equals(strArray.get(n))) { replicate++; } }

ArrayListstrArray1 = new ArrayList();

strArray1 = op.addBookJudgement1(); intn1 = 0;

intreplicate1 = 0;

while (n1< Integer.parseInt(strArray1.get(0))) { n1++;

if (s2.equals(strArray1.get(n1))) { replicate1++; } }

if (replicate == 0 &&replicate1 == 0) { JOptionPane.showMessageDialog(null,

\name!\,

\, JOptionPane.INFORMATION_MESSAGE);

} elseif (replicate != 0 || replicate1 != 0) { if (replicate == 0 &&replicate1 != 0) { BookInfo book = new BookInfo(s1, s2); String s = op.searchBookByName(book);

BookDetails f = new BookDetails(s); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(480, 470); f.setVisible(true);

-27-

课程名称:数据库系统概论

} elseif (replicate != 0) {

BookDetails f = new BookDetails(s1); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(480, 470); f.setVisible(true);

} }

}

if (e.getSource() == back) { this.dispose();

MyFrame f = new MyFrame(); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(580, 300); f.setVisible(true); }

if (e.getSource() == addBook) { AddBook f = new AddBook(); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(300, 400); f.setVisible(true); }

if (e.getSource() == deleteBook) { DeleteBook f = new DeleteBook(); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true);

-28-

课程名称:数据库系统概论

}

if (e.getSource() == borrowBook) { BorrowBook f = new BorrowBook(); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); }

if (e.getSource() == returnBook) { ReturnBook f = new ReturnBook(); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); }

if (e.getSource() == editBook) { SelectEdit f = new SelectEdit(); //

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(300, 200); f.setVisible(true); } } }

BorrowBook.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;

-29-

课程名称:数据库系统概论

import javax.swing.*;

publicclassBorrowBookextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();

JLabel bookNumber = new JLabel(\); JTextField numberField = new JTextField();

JLabel readerNumber = new JLabel(\); JTextField readerNumberField = new JTextField(); JButton cancel = new JButton(\); JButton borrow = new JButton(\);

public BorrowBook() {

c.add(p1, BorderLayout.NORTH);

p1.setLayout(new GridLayout(3, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(readerNumber);

p1.add(readerNumberField); p1.add(cancel); p1.add(borrow);

cancel.addActionListener(this); borrow.addActionListener(this); }

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose(); }

if (e.getSource() == borrow) {

String bookNumber = numberField.getText(); ArrayListstrArray = new ArrayList();

strArray = op.addBookJudgement(); intn = 0;

-30-

课程名称:数据库系统概论

intreplicate = 0;

while (n< Integer.parseInt(strArray.get(0))) { n++;

if (bookNumber.equals(strArray.get(n))) { replicate++; } }

String readerNumber = readerNumberField.getText(); ArrayListstrArray1 = new ArrayList();

strArray1 = op.addReaderJudgement(); intn1 = 0;

intreplicate1 = 0;

while (n1< Integer.parseInt(strArray1.get(0))) { n1++;

if (readerNumber.equals(strArray1.get(n1))) { replicate1++; } }

if (replicate == 0 || replicate1 == 0) { JOptionPane

.showMessageDialog( null, \input a correct book number and a reader number!\,

\, JOptionPane.INFORMATION_MESSAGE);

} else {

BookInfo book = new BookInfo(bookNumber);

ArrayLists = new ArrayList(); s = op.outputBook(book);

if (Integer.parseInt(s.get(7)) > 0) { ints1 =

op.reBorrowCheck(numberField.getText(),

readerNumberField.getText()); if (s1 == 1) { JOptionPane

-31-

课程名称:数据库系统概论

.showMessageDialog( null, \have borrowed this book, can not reborrow it!\,

\,

JOptionPane.INFORMATION_MESSAGE); } else {

longcurrentTime = System.currentTimeMillis(); if

(op.deadLineCheck(readerNumberField.getText(), currentTime) != 0) { JOptionPane

.showMessageDialog( null,

\deadline, please return these books first!\,

\,

JOptionPane.INFORMATION_MESSAGE); } else { BookInfo book1 = new BookInfo(s.get(0), s.get(1),

s.get(2), s.get(3), s.get(4), s.get(5),

Integer.parseInt(s.get(6)), Integer.parseInt(s.get(7)) - 1);

op.inputBook(book1); String borrowTime = Long.toString(System

.currentTimeMillis()); String deadline = Long.toString(System

.currentTimeMillis() + 2592000000l);

System.out.println(borrowTime); System.out.println(deadline);

op.insertBorrow(numberField.getText(),

-32-

课程名称:数据库系统概论

readerNumberField.getText(), borrowTime,

deadline); JOptionPane

.showMessageDialog( null,

\successfully, you have 30 days to enjoy this book!\, \,

JOptionPane.INFORMATION_MESSAGE); } }

} else {

JOptionPane.showMessageDialog(null, \, \,

JOptionPane.INFORMATION_MESSAGE); } }

this.dispose(); } } }

BorrowList.Java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; importjava.awt.Font; importjava.awt.GridLayout; import java.awt.event.*; importjava.util.ArrayList;

import javax.swing.*;

-33-

课程名称:数据库系统概论

import javax.swing.table.DefaultTableModel;

publicclassBorrowListextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane();

JPanel p1 = new JPanel(); JPanel p2 = new JPanel();

JButton back=new JButton(\); Object[] s = { \number\, \number\, \time\, \,\};

Object[][] ob = new Object[100][5]; JTable table = new JTable(ob, s);

JScrollPane scrollPane = new JScrollPane(table);

public BorrowList() {

// TODO Auto-generated constructor stub Object[][] ob1 = op.borrowList(); for (inti = 0; i< 5; i++) {

DefaultTableModel list = new DefaultTableModel(ob, s);

for (intn = 0; n< 100; n++) { for (intm = 0; m< 5; m++) { ob[n][m] = ob1[n][m]; }

table.setModel(list); table.invalidate(); } }

c.add(p1, BorderLayout.CENTER); c.add(p2,BorderLayout.SOUTH);

scrollPane.setBounds(0, 0, 800, 300); p1.add(scrollPane); p2.add(back);

table.setPreferredScrollableViewportSize(new Dimension(400, 400));

back.addActionListener(this); }

-34-

课程名称:数据库系统概论

publicvoid actionPerformed(ActionEvent e) { if (e.getSource() == back) { this.dispose();

MyFrame f = new MyFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(580, 300); f.setVisible(true); }

// TODO Auto-generated method stub } }

Date.java

import java.text.DateFormat;

import java.text.SimpleDateFormat;

publicclass Date { public Date(){ }

static String borrowTimeInterface(longtime) { SimpleDateFormat df = (SimpleDateFormat) DateFormat.getInstance();

df.applyPattern(\); String s = df.format(time); returns; } }

-35-

课程名称:数据库系统概论

DeleteBook.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*;

import javax.swing.*;

publicclassDeleteBookextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();

JLabel bookNumber = new JLabel(\); JTextField numberField = new JTextField(); JButton cancel = new JButton(\); JButton delete = new JButton(\);

public DeleteBook() {

c.add(p1, BorderLayout.NORTH);

p1.setLayout(new GridLayout(2, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField); p1.add(cancel); p1.add(delete);

cancel.addActionListener(this); delete.addActionListener(this); }

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose(); }

if (e.getSource() == delete) { BookInfo book = new BookInfo(numberField.getText()); this.dispose(); if (op.deleteBookCheck(numberField.getText()) != 0) {

-36-

课程名称:数据库系统概论

JOptionPane

.showMessageDialog( null,

\The book bas been borrowed!\,

\, JOptionPane.INFORMATION_MESSAGE);

} else {

if (op.deleteBook(book) == 1) {

JOptionPane.showMessageDialog(null,

\!\, \,

JOptionPane.INFORMATION_MESSAGE); } else {

JOptionPane

.showMessageDialog( null, \the book unsuccessfully. The book does not exist!\,

\, JOptionPane.INFORMATION_MESSAGE); }

}

} } }

DeleteReader.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*;

-37-

课程名称:数据库系统概论

import javax.swing.*;

publicclassDeleteReaderextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();

JLabel readerNumber = new JLabel(\); JTextField numberField = new JTextField(); JButton cancel = new JButton(\); JButton delete = new JButton(\);

public DeleteReader() {

c.add(p1, BorderLayout.NORTH);

p1.setLayout(new GridLayout(2, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); p1.add(cancel); p1.add(delete);

cancel.addActionListener(this); delete.addActionListener(this); }

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose(); }

if (e.getSource() == delete) { ReaderInfo reader = new ReaderInfo(numberField.getText()); this.dispose();

if (op.deleteReaderCheck(numberField.getText()) != 0) {

JOptionPane

.showMessageDialog( null,

\the reader unsuccessfully. Please return books first!\,

\,

-38-

课程名称:数据库系统概论

JOptionPane.INFORMATION_MESSAGE);

} else {

if (op.deleteReader(reader) == 1) { JOptionPane.showMessageDialog(null,

\!\, \,

JOptionPane.INFORMATION_MESSAGE); } else {

JOptionPane

.showMessageDialog( null,

%unsuccessfully. The reader does not exist!\, \, JOptionPane.INFORMATION_MESSAGE); } } } } }

EditBook.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;

import javax.swing.*;

publicclassEditBookextends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();

-39-

课程名称:数据库系统概论

JLabel bookNumber = new JLabel(\); JLabel bookName = new JLabel(\); JLabel author = new JLabel(\); JLabel press = new JLabel(\);

JLabel pressTime = new JLabel(\); JLabel bookAbstract = new JLabel(\); JLabel storage = new JLabel(\); JLabel remain = new JLabel(\);

JLabel remain1 = new JLabel(\); JLabel numberField = new JLabel();

JTextField nameField = new JTextField(); JTextField authorField = new JTextField(); JTextField pressField = new JTextField();

JTextField pressTimeField = new JTextField(); JTextField abstractField = new JTextField(); JTextField storageField = new JTextField(); JTextField temp1 = new JTextField(); JTextField temp2 = new JTextField(); JButton cancel = new JButton(\); JButton save = new JButton(\);

public EditBook(String number) {

BookInfo book = new BookInfo(number);

ArrayListstrArray = new ArrayList(); strArray = op.outputBook(book); numberField.setText(number);

nameField.setText(strArray.get(1)); authorField.setText(strArray.get(2)); pressField.setText(strArray.get(3));

pressTimeField.setText(strArray.get(4)); abstractField.setText(strArray.get(5)); storageField.setText(strArray.get(6)); temp1.setText(strArray.get(6)); temp2.setText(strArray.get(7));

c.add(p1, BorderLayout.NORTH);

p1.setLayout(new GridLayout(9, 2, 20, 10)); p1.add(bookNumber); p1.add(numberField);

-40-

课程名称:数据库系统概论

p1.add(bookName); p1.add(nameField); p1.add(author);

p1.add(authorField); p1.add(press);

p1.add(pressField); p1.add(pressTime);

p1.add(pressTimeField); p1.add(bookAbstract); p1.add(abstractField); p1.add(storage);

p1.add(storageField); p1.add(remain); p1.add(remain1); p1.add(cancel); p1.add(save);

cancel.addActionListener(this); save.addActionListener(this);

}

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose();

}

if (e.getSource() == save) {

inti = Integer.parseInt(storageField.getText()) - Integer.parseInt(temp1.getText()) + Integer.parseInt(temp2.getText());

BookInfo book = new BookInfo(numberField.getText(), nameField.getText(), authorField.getText(), pressField.getText(), pressTimeField.getText(),

abstractField.getText(), Integer.parseInt(storageField

.getText()), i); op.inputBook(book);

-41-

课程名称:数据库系统概论

JOptionPane.showMessageDialog(null, \successfully!\,

\, JOptionPane.INFORMATION_MESSAGE); this.dispose(); } } }

EditReader.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;

import javax.swing.*;

publicclassEditReaderextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel();

JLabel readerNumber = new JLabel(\); JLabel readerName = new JLabel(\); JLabel sex = new JLabel(\);

JLabel dpt = new JLabel(\); JLabel grade = new JLabel(\); JLabel numberField = new JLabel();

JTextField nameField = new JTextField(); JTextField sexField = new JTextField(); JTextField dptField = new JTextField(); JTextField gradeField = new JTextField(); JButton cancel = new JButton(\); JButton save = new JButton(\);

public EditReader(String number) {

-42-

课程名称:数据库系统概论

numberField.setText(number);

ReaderInfo reader = new ReaderInfo(number);

ArrayListstrArray = new ArrayList(); strArray = op.outputReader(reader); System.out.println(strArray); numberField.setText(number);

nameField.setText(strArray.get(1)); sexField.setText(strArray.get(2)); dptField.setText(strArray.get(3)); gradeField.setText(strArray.get(4));

c.add(p1, BorderLayout.NORTH);

p1.setLayout(new GridLayout(6, 2, 20, 10)); p1.add(readerNumber); p1.add(numberField); p1.add(readerName); p1.add(nameField); p1.add(sex);

p1.add(sexField); p1.add(dpt);

p1.add(dptField); p1.add(grade);

p1.add(gradeField); p1.add(cancel); p1.add(save);

cancel.addActionListener(this); save.addActionListener(this);

}

publicvoid actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if (e.getSource() == cancel) { this.dispose(); }

if (e.getSource() == save) { ReaderInfo reader =

newReaderInfo(numberField.getText(),

nameField.getText(), sexField.getText(), dptField.getText(),

-43-

课程名称:数据库系统概论

Integer.parseInt(gradeField.getText()));

if (!sexField.getText().equals(\)

&& !sexField.getText().equals(\)) { JOptionPane

.showMessageDialog( null,

\input 'boy' or 'girl'!\,

\, JOptionPane.INFORMATION_MESSAGE); } else {

op.inputReader(reader);

JOptionPane.showMessageDialog(null, \!\, \,

JOptionPane.INFORMATION_MESSAGE); this.dispose(); } }

} }

HomePage.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*;

import javax.swing.*;

import java.awt.Font;

publicclass HomePage { }

-44-

课程名称:数据库系统概论

classMyFrameextends JFrame implements ActionListener {

Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel();

JLabel welcome = new JLabel(\management system\);

JLabel space = new JLabel(\); JLabel space1 = new JLabel(\); JButtonbook = newJButton(\);

JButtonreader = newJButton(\); JButtonlist = newJButton(\); Font font1 = new Font(\, Font.BOLD, 20); Font font2 = new Font(\, Font.ITALIC, 20);

public MyFrame() {

c.add(p1, BorderLayout.CENTER); c.add(p2, BorderLayout.EAST); c.add(p3, BorderLayout.WEST); p2.add(space); p3.add(space1);

p1.setLayout(new GridLayout(4, 1, 50, 50)); p1.add(welcome); p1.add(book); p1.add(reader); p1.add(list);

welcome.setFont(font2); book.setFont(font1); reader.setFont(font1); list.setFont(font1);

list.addActionListener(this); book.addActionListener(this); reader.addActionListener(this); }

publicvoid actionPerformed(ActionEvent e) { if (e.getSource() == book) { this.dispose();

BookRetrieval page1 = new BookRetrieval();

-45-

课程名称:数据库系统概论

page1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); page1.setTitle(\); page1.setLocation(200, 100); page1.setSize(815, 600); page1.setVisible(true); }

if (e.getSource() == reader) { this.dispose();

ReaderRetrieval page2 = new ReaderRetrieval();

page2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); page2.setTitle(\); page2.setLocation(200, 100); page2.setSize(615, 600); page2.setVisible(true); }

if (e.getSource() == list) { this.dispose();

BorrowList page2 = new BorrowList();

page2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); page2.setTitle(\); page2.setLocation(200, 100); page2.setSize(495, 515); page2.setVisible(true); } } }

LogIn.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.GridLayout; import java.awt.event.*;

importjavax.management.openmbean.OpenDataException; import javax.swing.*;

-46-

课程名称:数据库系统概论

importjava.awt.Font;

publicclass LogIn {

publicstaticvoid main(String[] args) {

My f = new My();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(300, 150); f.setVisible(true); } }

classMyextends JFrame implements ActionListener { SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel();

JLabel userName = new JLabel(\); JLabel password = new JLabel(\); JTextField nameField = new JTextField();

JPasswordField passField = new JPasswordField(); JButton confirm = new JButton(\);

public My() {

c.add(p1, BorderLayout.CENTER); c.add(p2, BorderLayout.SOUTH);

p1.setLayout(new GridLayout(2, 2, 50, 10)); p1.add(userName); p1.add(nameField); p1.add(password); p1.add(passField); p2.add(confirm);

confirm.addActionListener(this); }

@Override

publicvoid actionPerformed(ActionEvent e) {

-47-

课程名称:数据库系统概论

if (e.getSource() == confirm) {

String name = nameField.getText(); String pass = passField.getText(); inti = op.logCheck(name, pass); if (i == 1) {

this.dispose();

MyFrame f = new MyFrame();

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setTitle(\); f.setLocation(300, 200); f.setSize(580, 300); f.setVisible(true); } else {

JOptionPane.showMessageDialog(null,

\password!\,

\, JOptionPane.INFORMATION_MESSAGE); }

}

// TODO Auto-generated method stub

} }

ReaderDetails.java

import java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.*; import java.util.ArrayList;

-48-

课程名称:数据库系统概论

import javax.swing.*;

import javax.swing.table.DefaultTableModel;

publicclassReaderDetailsextends JFrame implements ActionListener {

SQLOperation op = new SQLOperation(); Container c = getContentPane(); JPanel p1 = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel();

JLabel readerNumber = new JLabel(\); JLabel readerName = new JLabel(\); JLabel sex = new JLabel(\);

JLabel dpt = new JLabel(\); JLabel grade = new JLabel(\); JLabel numberField = new JLabel(); JLabel nameField = new JLabel(); JLabel sexField = new JLabel(); JLabel dptField = new JLabel(); JLabel gradeField = new JLabel();

JButton cancel = new JButton(\);

JLabel details = new JLabel(\and reaturn details\); Object[] s = { \, \, \, \ };

Object[][] ob1 = new Object[7][4]; JTable table = new JTable(ob1, s);

JScrollPane scrollPane = new JScrollPane(table);

public ReaderDetails(String number) {

ReaderInfo reader = new ReaderInfo(number);

ob1 = op.borrowListForReader(number); for (inti = 0; i< 5; i++) {

DefaultTableModel books = new DefaultTableModel(ob1, s);

for (intn = 0; n< 7; n++) { for (intm = 0; m< 4; m++) { ob1[n][m] = this.ob1[n][m];

-49-