做完添加图书信息功能
This commit is contained in:
@@ -69,11 +69,4 @@ public class MainFrm extends JFrame {
|
|||||||
rs.next();
|
rs.next();
|
||||||
return rs.getInt("COUNT(*)");
|
return rs.getInt("COUNT(*)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getBookMaxID() throws SQLException {
|
|
||||||
ResultSet rs = connector.executeQuery("SELECT MAX(book_id) FROM books;");
|
|
||||||
rs.next();
|
|
||||||
return rs.getInt("MAX(book_id)");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.msksbr.MainFrm;
|
package com.msksbr.MainFrm;
|
||||||
|
|
||||||
|
import com.msksbr.MainFrm.MenuItemDiaog.Adder.BookAdder;
|
||||||
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;
|
||||||
@@ -49,6 +50,11 @@ public class MenuBar extends JMenuBar {
|
|||||||
// ”添加“菜单
|
// ”添加“菜单
|
||||||
JMenu addMenu = new JMenu("添加");
|
JMenu addMenu = new JMenu("添加");
|
||||||
JMenuItem bookAdd = new JMenuItem("添加图书信息");
|
JMenuItem bookAdd = new JMenuItem("添加图书信息");
|
||||||
|
bookAdd.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
new BookAdder();
|
||||||
|
}
|
||||||
|
});
|
||||||
JMenuItem studentAdd = new JMenuItem("添加学生信息");
|
JMenuItem studentAdd = new JMenuItem("添加学生信息");
|
||||||
studentAdd.addActionListener(new ActionListener() {
|
studentAdd.addActionListener(new ActionListener() {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|||||||
@@ -0,0 +1,183 @@
|
|||||||
|
<?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.BookAdder">
|
||||||
|
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||||
|
<margin top="10" left="10" bottom="10" right="10"/>
|
||||||
|
<constraints>
|
||||||
|
<xy x="48" y="54" width="436" height="297"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="94766" 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>
|
||||||
|
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||||
|
</constraints>
|
||||||
|
<properties/>
|
||||||
|
<border type="none"/>
|
||||||
|
<children>
|
||||||
|
<grid id="9538f" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
|
||||||
|
<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="e7465" class="javax.swing.JButton" binding="buttonOK">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<text value="添加"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="e3588" layout-manager="BorderLayout" hgap="0" vgap="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>
|
||||||
|
<grid id="c66f9" layout-manager="GridLayoutManager" row-count="4" 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>
|
||||||
|
<grid id="a5571" layout-manager="BorderLayout" hgap="0" vgap="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="eec5b" class="javax.swing.JLabel">
|
||||||
|
<constraints border-constraint="Center"/>
|
||||||
|
<properties>
|
||||||
|
<text value="书名:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="8fb87" layout-manager="BorderLayout" hgap="0" vgap="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="bca8" class="javax.swing.JLabel">
|
||||||
|
<constraints border-constraint="Center"/>
|
||||||
|
<properties>
|
||||||
|
<text value="类别:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="f4a54" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" 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="6fff7" class="javax.swing.JLabel">
|
||||||
|
<constraints border-constraint="Center"/>
|
||||||
|
<properties>
|
||||||
|
<text value="书号:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="5edf3" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" 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="4eb7a" class="javax.swing.JLabel">
|
||||||
|
<constraints border-constraint="Center"/>
|
||||||
|
<properties>
|
||||||
|
<text value="ISBN:"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="6ff4f" layout-manager="GridLayoutManager" row-count="4" 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="7a6bb" 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="7e1ba" class="javax.swing.JTextField" binding="textField1" default-binding="true">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<columns value="15"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="c22f4" 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="dd3f3" class="javax.swing.JTextField" binding="textField2" default-binding="true">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<columns value="15"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="20b32" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="2" 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="4c60f" class="javax.swing.JTextField" binding="IDField">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<columns value="15"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
<grid id="db2b1" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
|
||||||
|
<constraints>
|
||||||
|
<grid row="3" 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="7e531" class="javax.swing.JTextField" binding="textField4" default-binding="true">
|
||||||
|
<constraints/>
|
||||||
|
<properties>
|
||||||
|
<columns value="15"/>
|
||||||
|
</properties>
|
||||||
|
</component>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</children>
|
||||||
|
</grid>
|
||||||
|
</form>
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
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.awt.print.Book;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
public class BookAdder extends JDialog {
|
||||||
|
private JPanel contentPane;
|
||||||
|
private JButton buttonOK;
|
||||||
|
private JTextField textField1;
|
||||||
|
private JTextField textField2;
|
||||||
|
private JTextField IDField;
|
||||||
|
private JTextField textField4;
|
||||||
|
private Connector connector;
|
||||||
|
private int bID;
|
||||||
|
private String bName;
|
||||||
|
private String bType;
|
||||||
|
private String ISBN;
|
||||||
|
private String sql;
|
||||||
|
|
||||||
|
public BookAdder() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
connector = new Connector();
|
||||||
|
bID = getBookMaxID() + 1;
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
buttonOK.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
onOK();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IDField.setText(String.valueOf(bID));
|
||||||
|
IDField.setEditable(false);
|
||||||
|
|
||||||
|
setTitle("添加图书信息");
|
||||||
|
setContentPane(contentPane);
|
||||||
|
setModal(true);
|
||||||
|
getRootPane().setDefaultButton(buttonOK);
|
||||||
|
|
||||||
|
setResizable(false);
|
||||||
|
pack();
|
||||||
|
setLocation();
|
||||||
|
setVisible(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onOK() {
|
||||||
|
bName = textField1.getText();
|
||||||
|
bType = textField2.getText();
|
||||||
|
ISBN = textField4.getText();
|
||||||
|
sql = "INSERT INTO books (book_name,book_id,book_type,ISBN) VALUES ('" + bName + "'," + bID + ",'" + bType + "','" + ISBN + "');";
|
||||||
|
commit2SQL();
|
||||||
|
// 在此处添加您的代码
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getBookMaxID() throws SQLException {
|
||||||
|
ResultSet rs = connector.executeQuery("SELECT MAX(book_id) FROM books;");
|
||||||
|
rs.next();
|
||||||
|
return rs.getInt("MAX(book_id)");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation() {
|
||||||
|
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void commit2SQL() {
|
||||||
|
try {
|
||||||
|
connector.executeUpdate(sql);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -87,7 +87,6 @@ public class StudentAdder extends JDialog {
|
|||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getStudentMaxID() throws SQLException {
|
public int getStudentMaxID() throws SQLException {
|
||||||
|
|||||||
Reference in New Issue
Block a user