做完添加借阅信息功能

This commit is contained in:
2024-06-27 11:20:16 +08:00
parent 10f5bc629e
commit a894cd09a3
9 changed files with 204 additions and 46 deletions
-9
View File
@@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="mysql-connector-j-8.4.0 (2)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.4.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
-9
View File
@@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="mysql-connector-j-8.4.0 (3)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.4.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
-9
View File
@@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="mysql-connector-j-8.4.0 (4)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.4.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
-9
View File
@@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="mysql-connector-j-8.4.0 (5)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.4.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
-9
View File
@@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="mysql-connector-j-8.4.0 (6)">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/mysql-connector-j-8.4.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
+1 -1
View File
@@ -31,7 +31,6 @@ public class MainFrm extends JFrame {
setJMenuBar(menuBar); setJMenuBar(menuBar);
setDefaultCloseOperation(EXIT_ON_CLOSE); setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(960, 720); setSize(960, 720);
setVisible(true);
String countData = "本馆共藏书" + getCount("books") + "本,共记录学生信息" + getCount("students") + "条,已借阅" + getCount("rents") + "本书,人均借阅" + (double) getCount("rents") / getCount("students") + ""; String countData = "本馆共藏书" + getCount("books") + "本,共记录学生信息" + getCount("students") + "条,已借阅" + getCount("rents") + "本书,人均借阅" + (double) getCount("rents") / getCount("students") + "";
countMessage.setText(countData); countMessage.setText(countData);
@@ -45,6 +44,7 @@ public class MainFrm extends JFrame {
setLocation(); setLocation();
initDialogs(); initDialogs();
setVisible(true);
} }
+6
View File
@@ -1,6 +1,7 @@
package com.msksbr.MainFrm; package com.msksbr.MainFrm;
import com.msksbr.MainFrm.MenuItemDiaog.Adder.BookAdder; 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.Adder.StudentAdder;
import com.msksbr.MainFrm.MenuItemDiaog.AuthorDIalog; import com.msksbr.MainFrm.MenuItemDiaog.AuthorDIalog;
import com.msksbr.MainFrm.MenuItemDiaog.SearchDIalog; import com.msksbr.MainFrm.MenuItemDiaog.SearchDIalog;
@@ -62,6 +63,11 @@ public class MenuBar extends JMenuBar {
} }
}); });
JMenuItem rentAdd = new JMenuItem("添加借阅信息"); JMenuItem rentAdd = new JMenuItem("添加借阅信息");
rentAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new RentAdder();
}
});
addMenu.add(bookAdd); addMenu.add(bookAdd);
addMenu.add(studentAdd); addMenu.add(studentAdd);
addMenu.add(rentAdd); addMenu.add(rentAdd);
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.Adder.RentAdder">
<grid id="cbd77" binding="contentPane" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="54" y="54" width="264" height="145"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="94766" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints/>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="添加"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<grid id="e3beb" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="West"/>
<properties/>
<border type="none"/>
<children>
<component id="9c1af" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="请输入书号:"/>
</properties>
</component>
<component id="c9df7" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="请输入学号:"/>
</properties>
</component>
</children>
</grid>
<grid id="10667" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<grid id="60ed0" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="5f80a" class="javax.swing.JTextField" binding="bIDField">
<constraints/>
<properties>
<columns value="15"/>
</properties>
</component>
</children>
</grid>
<grid id="d1af9" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="26f68" class="javax.swing.JTextField" binding="sIDField">
<constraints/>
<properties>
<columns value="15"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -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 + ";";
}
}