diff --git a/.idea/libraries/mysql_connector_j_8_4_0__2_.xml b/.idea/libraries/mysql_connector_j_8_4_0__2_.xml deleted file mode 100644 index eba3bbc..0000000 --- a/.idea/libraries/mysql_connector_j_8_4_0__2_.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__3_.xml b/.idea/libraries/mysql_connector_j_8_4_0__3_.xml deleted file mode 100644 index 0f3206f..0000000 --- a/.idea/libraries/mysql_connector_j_8_4_0__3_.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__4_.xml b/.idea/libraries/mysql_connector_j_8_4_0__4_.xml deleted file mode 100644 index f696bd6..0000000 --- a/.idea/libraries/mysql_connector_j_8_4_0__4_.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__5_.xml b/.idea/libraries/mysql_connector_j_8_4_0__5_.xml deleted file mode 100644 index 76ca74a..0000000 --- a/.idea/libraries/mysql_connector_j_8_4_0__5_.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/mysql_connector_j_8_4_0__6_.xml b/.idea/libraries/mysql_connector_j_8_4_0__6_.xml deleted file mode 100644 index df57474..0000000 --- a/.idea/libraries/mysql_connector_j_8_4_0__6_.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/src/com/msksbr/MainFrm/MainFrm.java b/src/com/msksbr/MainFrm/MainFrm.java index 4a61bae..cf5e8bd 100644 --- a/src/com/msksbr/MainFrm/MainFrm.java +++ b/src/com/msksbr/MainFrm/MainFrm.java @@ -31,7 +31,6 @@ public class MainFrm extends JFrame { setJMenuBar(menuBar); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(960, 720); - setVisible(true); String countData = "本馆共藏书" + getCount("books") + "本,共记录学生信息" + getCount("students") + "条,已借阅" + getCount("rents") + "本书,人均借阅" + (double) getCount("rents") / getCount("students") + "本"; countMessage.setText(countData); @@ -45,6 +44,7 @@ public class MainFrm extends JFrame { setLocation(); initDialogs(); + setVisible(true); } diff --git a/src/com/msksbr/MainFrm/MenuBar.java b/src/com/msksbr/MainFrm/MenuBar.java index 164aca6..9f90c05 100644 --- a/src/com/msksbr/MainFrm/MenuBar.java +++ b/src/com/msksbr/MainFrm/MenuBar.java @@ -1,6 +1,7 @@ package com.msksbr.MainFrm; import com.msksbr.MainFrm.MenuItemDiaog.Adder.BookAdder; +import com.msksbr.MainFrm.MenuItemDiaog.Adder.RentAdder; import com.msksbr.MainFrm.MenuItemDiaog.Adder.StudentAdder; import com.msksbr.MainFrm.MenuItemDiaog.AuthorDIalog; import com.msksbr.MainFrm.MenuItemDiaog.SearchDIalog; @@ -62,6 +63,11 @@ public class MenuBar extends JMenuBar { } }); JMenuItem rentAdd = new JMenuItem("添加借阅信息"); + rentAdd.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new RentAdder(); + } + }); addMenu.add(bookAdd); addMenu.add(studentAdd); addMenu.add(rentAdd); diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/RentAdder.form b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/RentAdder.form new file mode 100644 index 0000000..34686a9 --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/RentAdder.form @@ -0,0 +1,104 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/RentAdder.java b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/RentAdder.java new file mode 100644 index 0000000..2b4734a --- /dev/null +++ b/src/com/msksbr/MainFrm/MenuItemDiaog/Adder/RentAdder.java @@ -0,0 +1,93 @@ +package com.msksbr.MainFrm.MenuItemDiaog.Adder; + +import com.msksbr.LoginFrm.ScreenSize; +import com.msksbr.SQL.Connector; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class RentAdder extends JDialog { + private JPanel contentPane; + private JButton buttonOK; + private JTextField bIDField; + private JTextField sIDField; + private int bID; + private int sID; + private Connector bConnector; + private Connector sConnector; + private String bookSearchSQL; + private String studentSearchSQL; + private String updateSQL; + private ResultSet bIDResult; + private ResultSet sIDResult; + + public RentAdder() { + try { + bConnector = new Connector(); + sConnector = new Connector(); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } catch (SQLException e) { + throw new RuntimeException(e); + } + setContentPane(contentPane); + setModal(true); + getRootPane().setDefaultButton(buttonOK); + setTitle("添加借阅信息"); + + buttonOK.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + onOK(); + } + }); + pack(); + setResizable(false); + setLocation(); + setVisible(true); + } + + private void onOK() { + // 在此处添加您的代码 + try { + this.bID = Integer.valueOf(bIDField.getText()); + this.sID = Integer.valueOf(sIDField.getText()); + searchSQLMaker(); + updateSQLMaker(); + bIDResult = bConnector.executeQuery(bookSearchSQL); + sIDResult = sConnector.executeQuery(studentSearchSQL); + if (!bIDResult.next()) { + JOptionPane.showMessageDialog(this, "未找到该书信息", "错误", JOptionPane.WARNING_MESSAGE); + } else if (!sIDResult.next()) { + JOptionPane.showMessageDialog(this, "未找到学生信息", "错误", JOptionPane.WARNING_MESSAGE); + } else { + if (bIDResult.getInt("borrowed_by") == 0) { + bConnector.executeUpdate(updateSQL); + } else { + JOptionPane.showMessageDialog(this, "该书已借出", "错误", JOptionPane.WARNING_MESSAGE); + } + } + } catch (NumberFormatException e) { + JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE); + } catch (SQLException e) { + throw new RuntimeException(e); + } + + dispose(); + } + + public void setLocation() { + setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2); + } + + private void searchSQLMaker() { + this.bookSearchSQL = "SELECT * FROM books WHERE book_id =" + this.bID + ";"; + this.studentSearchSQL = "SELECT * FROM students WHERE student_id =" + this.sID + ";"; + } + + private void updateSQLMaker() { + this.updateSQL = "UPDATE books SET borrowed_by = " + this.sID + " WHERE book_id =" + this.bID + ";"; + } +}