Compare commits

...

11 Commits

Author SHA1 Message Date
msksbr d876ba1e3b test 2025-05-03 18:23:47 +08:00
msksbr ef9ebbaddd SQL语句的bug都修完了 2024-12-23 20:39:26 +08:00
msksbr 1d90d8b6c4 迁移成功 2024-12-23 19:38:50 +08:00
msksbr 11c97cb958 实验十六 2024-12-04 17:28:06 +08:00
msksbr bea3ef3e43 实验十五 2024-12-04 16:49:23 +08:00
msksbr 6d6af4dbf1 实验十四 2024-11-28 00:37:53 +08:00
msksbr ea0131ce37 实验十三 2024-11-19 22:49:45 +08:00
msksbr 773a387d5f 实验十二 2024-11-13 01:21:35 +08:00
msksbr 8f53666563 实验十一 2024-11-13 00:49:07 +08:00
msksbr aa938c2a7a 实验二 2024-11-10 16:39:49 +08:00
msksbr eae0489af6 修复实验一check box 2024-11-10 16:33:02 +08:00
62 changed files with 3309 additions and 8 deletions
+5
View File
@@ -16,3 +16,8 @@ bin-release/
# Project files, i.e. `.project`, `.actionScriptProperties` and `.flexProperties`
# should NOT be excluded as they contain compiler settings and other important
# information for Eclipse / Flash Builder.
# JetBrains
*/.idea/
*.iml
TermFinalHomework/out/
+15 -1
View File
@@ -12,7 +12,7 @@
- [实验一](实验一.md)
- ~~实验二 敬请期待~~
- [实验二](实验二.sql)
- [实验三](实验三.sql)
@@ -30,6 +30,20 @@
- [实验十](实验十.sql)
- [实验十一](实验十一.sql)
- [实验十二](实验十二.sql)
- [实验十三](实验十三.sql)
- [实验十四](实验十四.sql)
- [实验十五](实验十五.md)
- [实验十六](实验十六.md)
- [大作业](TermFinalHomework/)
### 课后作业📖
[课后作业](课后作业/)
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
+107
View File
@@ -0,0 +1,107 @@
/*
Navicat Premium Data Transfer
Source Server : SQL Server
Source Server Type : SQL Server
Source Server Version : 15004410
Source Host : sqlmsksbr.com:1433
Source Catalog : book
Source Schema : dbo
Target Server Type : SQL Server
Target Server Version : 15004410
File Encoding : 65001
Date: 23/12/2024 22:04:15
*/
-- ----------------------------
-- Table structure for books
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[books]') AND type IN ('U'))
DROP TABLE [dbo].[books]
GO
CREATE TABLE [dbo].[books] (
[book_name] nvarchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[book_type] nvarchar(255) COLLATE Chinese_PRC_CI_AS NULL,
[book_id] int NOT NULL,
[borrowed_by] int NULL,
[ISBN] nvarchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL
)
GO
ALTER TABLE [dbo].[books] SET (LOCK_ESCALATION = TABLE)
GO
-- ----------------------------
-- Table structure for students
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[students]') AND type IN ('U'))
DROP TABLE [dbo].[students]
GO
CREATE TABLE [dbo].[students] (
[student_name] nvarchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[student_id] int NOT NULL,
[student_class] nvarchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[student_gender] nvarchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL
)
GO
ALTER TABLE [dbo].[students] SET (LOCK_ESCALATION = TABLE)
GO
-- ----------------------------
-- Table structure for users
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[users]') AND type IN ('U'))
DROP TABLE [dbo].[users]
GO
CREATE TABLE [dbo].[users] (
[username] nvarchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[password] nvarchar(255) COLLATE Chinese_PRC_CI_AS NOT NULL
)
GO
ALTER TABLE [dbo].[users] SET (LOCK_ESCALATION = TABLE)
GO
-- ----------------------------
-- View structure for rents
-- ----------------------------
IF EXISTS (SELECT * FROM sys.all_objects WHERE object_id = OBJECT_ID(N'[dbo].[rents]') AND type IN ('V'))
DROP VIEW [dbo].[rents]
GO
CREATE VIEW [dbo].[rents] AS SELECT students.*,books.*
FROM students
JOIN books
on students.student_id=books.borrowed_by
GO
-- ----------------------------
-- Indexes structure for table books
-- ----------------------------
CREATE NONCLUSTERED INDEX [b_id_index]
ON [dbo].[books] (
[book_id] ASC
)
GO
-- ----------------------------
-- Indexes structure for table students
-- ----------------------------
CREATE NONCLUSTERED INDEX [s_id_index]
ON [dbo].[students] (
[student_id] ASC
)
GO
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.LoginFrm.LoginFrm">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="74" y="20" width="446" height="204"/>
</constraints>
<properties>
<font name="PingFang SC"/>
</properties>
<border type="none"/>
<children>
<grid id="1e979" binding="titlePanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="North"/>
<properties/>
<border type="none"/>
<children>
<component id="4318d" class="javax.swing.JLabel" binding="titleLabel">
<constraints/>
<properties>
<font name="PingFang SC" size="36" style="1"/>
<text value="登录"/>
</properties>
</component>
</children>
</grid>
<grid id="a0f72" binding="bodyPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<grid id="40c81" binding="labelPanel" 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>
<grid id="a09bf" binding="uLabelPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="2">
<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="c9cc0" class="javax.swing.JLabel" binding="uLabel">
<constraints/>
<properties>
<font name="PingFang SC" size="18" style="1"/>
<text value="用户名:"/>
</properties>
</component>
</children>
</grid>
<grid id="29291" binding="pLabelPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="2">
<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="dada" class="javax.swing.JLabel" binding="pLabel">
<constraints/>
<properties>
<font name="PingFang SC" size="18" style="1"/>
<horizontalAlignment value="10"/>
<text value="密码:"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="8481c" binding="fieldPanel" 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="4d39" 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="fc448" class="javax.swing.JTextField" binding="uField">
<constraints/>
<properties>
<font name="PingFang SC" style="1"/>
</properties>
</component>
</children>
</grid>
<grid id="f1071" 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="5fc4f" class="javax.swing.JPasswordField" binding="pField">
<constraints/>
<properties>
<font name="PingFang SC" style="1"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
<grid id="2e911" binding="bottomPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<component id="fbf4e" class="javax.swing.JButton" binding="commitButton">
<constraints/>
<properties>
<font name="PingFang SC" size="18" style="1"/>
<text value="登录"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,124 @@
package com.msksbr.LoginFrm;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.msksbr.MainFrm.MainFrm;
import com.msksbr.SQL.Connector;
import com.msksbr.images.EasterEgg;
public class LoginFrm extends JFrame {
private final Connector connector;
private final LoginMessangeExpection loginMessangeExpection;
private JPanel panel1;
private JPanel titlePanel;
private JLabel titleLabel;
private JPanel bodyPanel;
private JPanel bottomPanel;
private JButton commitButton;
private JPanel labelPanel;
private JPanel fieldPanel;
private JPanel uLabelPanel;
private JPanel pLabelPanel;
private JLabel uLabel;
private JLabel pLabel;
private JTextField uField;
private JPasswordField pField;
private String username;
private String password;
public LoginFrm() {
loginMessangeExpection = new LoginMessangeExpection();
setIconImage(new ImageIcon("src/com/msksbr/images/mainicon.png").getImage());
try {
connector = new Connector();
} catch (ClassNotFoundException | SQLException e) {
throw new RuntimeException(e);
}
setTitle("登录到图书管理系统");
setContentPane(panel1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
setSize(400, 250);
setResizable(false);
Dimension fieldDimension = new Dimension(250, 30);
this.uField.setPreferredSize(fieldDimension);
this.pField.setPreferredSize(fieldDimension);
this.pField.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
loginMessangeEntered();
}
}
});
this.commitButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
this.commitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
loginMessangeEntered();
}
});
setLocation();
setDialogLocation();
}
private void setLocation() {
ScreenSize screenSize = new ScreenSize();
setLocation(screenSize.width / 2 - getWidth() / 2, screenSize.height / 2 - getHeight() / 2);
}
private void setDialogLocation() {
loginMessangeExpection.setLocation(getX() + getWidth() / 4, getY() + getHeight() / 4);
}
private void loginMessangeEntered() {
username = uField.getText();
password = new String(pField.getPassword());
Boolean ISMessageTrue = isLoginMessageTrue();
if (ISMessageTrue) {
dispose();
try {
new MainFrm();
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
loginMessangeExpection.setVisible(true);
}
}
private Boolean isLoginMessageTrue() {
if (username.equals("java") && password.equals("beans")) {
new EasterEgg();
return false;
} else {
try {
ResultSet resultSet = connector.executeQuery("SELECT * FROM users WHERE username = '" + username + "'");
if (resultSet != null && resultSet.next()) { // 检查结果集是否不为空
if (resultSet.getString("password").equals(password)) {
return true;
}
}
return false;
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.LoginFrm.LoginMessangeExpection">
<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="248" y="54" width="236" height="131"/>
</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>
<font name="PingFang SC" size="14" style="1"/>
<text value="确认"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" layout-manager="GridBagLayout">
<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="42fcc" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
<gridbag weightx="1.0" weighty="0.0"/>
</constraints>
<properties>
<font name="PingFang SC" size="14" style="1"/>
<text value="用户名或密码错误"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,51 @@
package com.msksbr.LoginFrm;
import javax.swing.*;
import java.awt.event.*;
public class LoginMessangeExpection extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
public LoginMessangeExpection() {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
setResizable(false);
setSize(200, 150);
setTitle("登录失败");
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
onCancel();
}
});
// 点击 X 时调用 onCancel()
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
onCancel();
}
});
// 遇到 ESCAPE 时调用 onCancel()
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void onOK() {
// 在此处添加您的代码
dispose();
}
private void onCancel() {
// 必要时在此处添加您的代码
dispose();
}
}
@@ -0,0 +1,15 @@
package com.msksbr.LoginFrm;
import java.awt.*;
public class ScreenSize {
public int width;
public int height;
public Dimension screenSize;
public ScreenSize() {
screenSize = Toolkit.getDefaultToolkit().getScreenSize();
width = screenSize.width;
height = screenSize.height;
}
}
@@ -0,0 +1,4 @@
Manifest-Version: 1.0
Main-Class: com.msksbr.Main.Main
Class-Path: mysql-connector-j-8.4.0.jar flatlaf-3.2.jar
@@ -0,0 +1,13 @@
package com.msksbr.Main;
import com.formdev.flatlaf.FlatDarculaLaf;
import com.msksbr.LoginFrm.LoginFrm;
public class Main {
public static void main(String[] args) {
FlatDarculaLaf.install();
new LoginFrm();
}
}
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MainFrm">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="742" height="409"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="3e1f8" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="North"/>
<properties/>
<border type="none"/>
<children/>
</grid>
<grid id="a9381" binding="tablePanel" layout-manager="GridBagLayout">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="b90f2" class="javax.swing.JLabel" binding="backLabel">
<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"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
<grid id="4f963" binding="bottomPanel" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="2">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,73 @@
package com.msksbr.MainFrm;
import javax.swing.*;
import com.msksbr.LoginFrm.ScreenSize;
import com.msksbr.SQL.Connector;
import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.sql.SQLException;
public class MainFrm extends JFrame {
private Connector connector;
private JPanel panel1;
private JPanel tablePanel;
private JPanel bottomPanel;
private JLabel backLabel;
private JLabel countMessage = new JLabel();
private MenuBar menuBar;
public MainFrm() throws SQLException, ClassNotFoundException {
setIconImage(new ImageIcon("src/com/msksbr/images/mainicon.png").getImage());
connector = new Connector();
setTitle("图书管理系统");
setContentPane(panel1);
pack();
menuBar = new MenuBar();
setJMenuBar(menuBar);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(960, 720);
String countData = "本馆共藏书" + getCount("books") + "本,共记录学生信息" + getCount("students") + "条,已借阅" + getCount("rents") + "本书,人均借阅" + (double) getCount("rents") / getCount("students") + "";
countMessage.setText(countData);
bottomPanel.add(countMessage);
ImageIcon imageIcon = new ImageIcon("src/com/msksbr/images/backGround.png");
imageIcon.setImage(imageIcon.getImage().getScaledInstance(250, 250, 0));
backLabel.setIcon(imageIcon);
setMinimumSize(new Dimension(960, 720));
setLocation();
initDialogs();
setVisible(true);
}
private void setLocation() {
ScreenSize screenSize = new ScreenSize();
setLocation(screenSize.width / 2 - getWidth() / 2, screenSize.height / 2 - getHeight() / 2);
}
private void initDialogs() {
menuBar.exitItem.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
);
}
private int getCount(String table) throws SQLException {
ResultSet rs = connector.executeQuery("SELECT COUNT(*) AS bookCount FROM " + table + ";");
rs.next();
return rs.getInt("bookCount");
}
}
@@ -0,0 +1,139 @@
package com.msksbr.MainFrm;
import com.msksbr.MainFrm.MenuItemDiaog.*;
import com.msksbr.MainFrm.MenuItemDiaog.Adder.BookAdder;
import com.msksbr.MainFrm.MenuItemDiaog.Adder.RentAdder;
import com.msksbr.MainFrm.MenuItemDiaog.Adder.StudentAdder;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MenuBar extends JMenuBar {
public JMenuItem exitItem;
protected com.msksbr.MainFrm.MenuItemDiaog.aboutDIalog aboutDIalog;
protected AuthorDIalog authorDIalog;
public MenuBar() {
// “文件“菜单
JMenu fileMenu = new JMenu("文件");
exitItem = new JMenuItem("退出");
fileMenu.add(exitItem);
// ”查询“菜单
JMenu searchMenu = new JMenu("查询");
JMenuItem bookSearch = new JMenuItem("查询图书信息");
bookSearch.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new SearchDIalog("books");
}
}
);
JMenuItem studentSearch = new JMenuItem("查询学生信息");
studentSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new SearchDIalog("students");
}
});
JMenuItem rentSearch = new JMenuItem("查询借阅信息");
rentSearch.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new SearchDIalog("rents");
}
});
searchMenu.add(bookSearch);
searchMenu.add(studentSearch);
searchMenu.add(rentSearch);
// ”添加“菜单
JMenu addMenu = new JMenu("添加");
JMenuItem bookAdd = new JMenuItem("添加图书信息");
bookAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new BookAdder();
}
});
JMenuItem studentAdd = new JMenuItem("添加学生信息");
studentAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new StudentAdder();
}
});
JMenuItem rentAdd = new JMenuItem("添加借阅信息");
rentAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new RentAdder();
}
});
addMenu.add(bookAdd);
addMenu.add(studentAdd);
addMenu.add(rentAdd);
// ”删除“菜单
JMenu removeMenu = new JMenu("删除");
JMenuItem bookRemove = new JMenuItem("删除图书信息");
bookRemove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Remover("books");
}
});
JMenuItem studentRemove = new JMenuItem("删除学生信息");
studentRemove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Remover("students");
}
});
JMenuItem rentRemove = new JMenuItem("删除借阅信息");
rentRemove.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new Remover("rents");
}
});
removeMenu.add(bookRemove);
removeMenu.add(studentRemove);
removeMenu.add(rentRemove);
// ”关于“菜单
JMenu aboutMenu = new JMenu("关于");
JMenuItem about = new JMenuItem("关于软件");
aboutDIalog = new aboutDIalog();
about.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
aboutDIalog.setVisible(true);
}
});
JMenuItem author = new JMenuItem("作者");
authorDIalog = new AuthorDIalog();
author.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
authorDIalog.setVisible(true);
}
});
JMenuItem MITLicense = new JMenuItem("MIT许可证");
MITLicense.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new MITDialog();
}
});
JMenuItem thanksItem = new JMenuItem("鸣谢");
thanksItem.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
new AcademyThanksDialog();
}
}
);
aboutMenu.add(about);
aboutMenu.add(author);
aboutMenu.add(MITLicense);
aboutMenu.add(thanksItem);
//将菜单加入菜单栏
add(fileMenu);
add(searchMenu);
add(addMenu);
add(removeMenu);
add(aboutMenu);
}
}
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.AcademyThanksDialog">
<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="BorderLayout" hgap="0" vgap="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 border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
<constraints/>
<properties>
<text value="OK"/>
</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="75e6c" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<component id="bd601" class="javax.swing.JLabel">
<constraints/>
<properties>
<text value="新疆理工学院"/>
</properties>
</component>
</children>
</grid>
<grid id="51315" layout-manager="GridBagLayout">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="78840" class="javax.swing.JLabel" binding="imageLabel">
<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"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,41 @@
package com.msksbr.MainFrm.MenuItemDiaog;
import com.msksbr.LoginFrm.ScreenSize;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AcademyThanksDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JLabel imageLabel;
public AcademyThanksDialog() {
setTitle("鸣谢");
setContentPane(contentPane);
setModal(false);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
imageLabel.setIcon(new ImageIcon("src/com/msksbr/images/academy_logo.png"));
pack();
setResizable(false);
setLocation();
setAlwaysOnTop(true);
setVisible(true);
}
private void onOK() {
// 在此处添加您的代码
dispose();
}
public void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
}
@@ -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) AS 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);
}
}
}
@@ -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 + ";";
}
}
@@ -0,0 +1,166 @@
<?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.StudentAdder">
<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="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>
<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="5c571" 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="8e179" class="javax.swing.JLabel">
<constraints border-constraint="West"/>
<properties>
<text value="姓名:"/>
</properties>
</component>
<grid id="19f7f" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="e5161" class="javax.swing.JTextField" binding="textField1" default-binding="true">
<constraints/>
<properties>
<columns value="15"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="4197b" 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="a91a6" class="javax.swing.JLabel">
<constraints border-constraint="West"/>
<properties>
<text value="学号:"/>
</properties>
</component>
<grid id="6cf70" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="32fcc" class="javax.swing.JTextField" binding="IDField">
<constraints/>
<properties>
<columns value="15"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="d8df3" 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="adb15" class="javax.swing.JLabel">
<constraints border-constraint="West"/>
<properties>
<text value="班级:"/>
</properties>
</component>
<grid id="cd800" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="e20a7" class="javax.swing.JTextField" binding="textField3" default-binding="true">
<constraints/>
<properties>
<columns value="15"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="9af6b" 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="bd9ba" class="javax.swing.JLabel">
<constraints border-constraint="West"/>
<properties>
<text value="性别:"/>
</properties>
</component>
<grid id="d4804" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="8ce32" class="javax.swing.JRadioButton" binding="maleRadioButton">
<constraints/>
<properties>
<text value="男"/>
</properties>
</component>
<component id="27c62" class="javax.swing.JRadioButton" binding="femaleRadioButton">
<constraints/>
<properties>
<text value="女"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,97 @@
package com.msksbr.MainFrm.MenuItemDiaog.Adder;
import com.msksbr.LoginFrm.ScreenSize;
import com.msksbr.SQL.Connector;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
public class StudentAdder extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JTextField textField1;
private JTextField IDField;
private JTextField textField3;
private JRadioButton maleRadioButton;
private JRadioButton femaleRadioButton;
private Connector connector;
private String sName;
private int sID;
private String sClass;
private String sGender;
private ButtonGroup genderGroup;
private String sql;
public StudentAdder() {
try {
connector = new Connector();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
genderGroup = new ButtonGroup();
genderGroup.add(maleRadioButton);
genderGroup.add(femaleRadioButton);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
try {
sID = getStudentMaxID() + 1;
IDField.setText(String.valueOf(sID));
} catch (SQLException e) {
throw new RuntimeException(e);
}
IDField.setEditable(false);
setTitle("添加学生信息");
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
setSize(new Dimension(260, 265));
setResizable(false);
pack();
setLocation();
setVisible(true);
}
public void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
private void onOK() {
// 在此处添加您的代码
sName = textField1.getText();
sClass = textField3.getText();
sGender = maleRadioButton.isSelected() ? "" : "";
sql = "INSERT INTO students (student_name,student_id,student_class,student_gender) VALUES ('" + sName + "'," + sID + ",'" + sClass + "','" + sGender + "');";
commit2SQL();
dispose();
}
private void commit2SQL() {
try {
connector.executeUpdate(sql);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public int getStudentMaxID() throws SQLException {
ResultSet rs = connector.executeQuery("SELECT MAX(student_id) AS max_student_id FROM students;");
rs.next();
return rs.getInt("max_student_id");
}
}
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.AuthorDIalog">
<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="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="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="fe414" 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="56d70" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<component id="1c1ff" class="javax.swing.JLabel">
<constraints/>
<properties>
<font name="PingFang SC" size="14"/>
<text value="https://gitee.com/msksbr"/>
</properties>
</component>
</children>
</grid>
<grid id="da859" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<grid id="1727d" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<component id="a162d" class="javax.swing.JLabel">
<constraints/>
<properties>
<font name="PingFang SC" size="16" style="1"/>
<text value="御坂昴"/>
</properties>
</component>
</children>
</grid>
<grid id="e09f1" binding="iconPanel" layout-manager="GridBagLayout">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,38 @@
package com.msksbr.MainFrm.MenuItemDiaog;
import com.msksbr.LoginFrm.ScreenSize;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class AuthorDIalog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JPanel iconPanel;
public AuthorDIalog() {
setContentPane(contentPane);
setModal(false);
getRootPane().setDefaultButton(buttonOK);
setVisible(false);
JLabel authorLabel = new JLabel();
authorLabel.setIcon(new ImageIcon("src/com/msksbr/images/AuthorProfile.jpg"));
iconPanel.add(authorLabel);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
setTitle("作者");
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
}
});
setResizable(false);
setAlwaysOnTop(true);
pack();
setLocation();
}
public void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
}
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.MITDialog">
<grid id="cbd77" binding="contentPane" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="48" y="54" width="436" height="366"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="e3588" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="North"/>
<properties/>
<border type="none"/>
<children>
<component id="a6e23" class="javax.swing.JLabel">
<constraints/>
<properties>
<text value="本项目已在gitee.com开源"/>
</properties>
</component>
</children>
</grid>
<grid id="94766" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<grid id="9538f" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="Center"/>
<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="f0964" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="802af" class="javax.swing.JTextPane" binding="MITPane">
<constraints border-constraint="Center"/>
<properties>
<text value=""/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,64 @@
package com.msksbr.MainFrm.MenuItemDiaog;
import com.msksbr.LoginFrm.ScreenSize;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MITDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JTextPane MITPane;
public MITDialog() {
setTitle("开源信息");
MITPane.setEditable(false);
MITPane.setText("MIT License\n" +
"\n" +
"Copyright (c) 2024 御坂昴\n" +
"\n" +
"Permission is hereby granted, free of charge, to any person obtaining a copy\n" +
"of this software and associated documentation files (the \"Software\"), to deal\n" +
"in the Software without restriction, including without limitation the rights\n" +
"to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n" +
"copies of the Software, and to permit persons to whom the Software is\n" +
"furnished to do so, subject to the following conditions:\n" +
"\n" +
"The above copyright notice and this permission notice shall be included in all\n" +
"copies or substantial portions of the Software.\n" +
"\n" +
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n" +
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n" +
"FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n" +
"AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n" +
"LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n" +
"OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" +
"SOFTWARE.\n");
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
setModal(false);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
pack();
setResizable(false);
setLocation();
setAlwaysOnTop(true);
setVisible(true);
}
private void onOK() {
// 在此处添加您的代码
dispose();
}
public void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
}
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.Remover">
<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>
<component id="1b7c" class="javax.swing.JLabel" binding="idLable">
<constraints border-constraint="West"/>
<properties>
<text value=""/>
</properties>
</component>
<grid id="8147a" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="19c5" class="javax.swing.JTextField" binding="idField">
<constraints/>
<properties>
<columns value="15"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,106 @@
package com.msksbr.MainFrm.MenuItemDiaog;
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 Remover extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JLabel idLable;
private JTextField idField;
private String table;
private String Searchsql;
private String searchSQL;
private String deleteSQL;
private String searchErrMsg;
private int id;
private Connector searchConnector;
private Connector deleteConnector;
public Remover(String table) {
try {
searchConnector = new Connector();
deleteConnector = new Connector();
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
this.table = table;
if (table.equals("books")) {
setTitle("删除图书信息");
idLable.setText("请输入书号:");
searchErrMsg = "未找到该图书信息";
} else if (table.equals("students")) {
setTitle("删除学生信息");
idLable.setText("请输入学号:");
searchErrMsg = "未找到该学生信息";
} else if (table.equals("rents")) {
setTitle("删除借阅信息");
idLable.setText("请输入书号:");
searchErrMsg = "未找到该借阅信息";
}
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
pack();
setResizable(false);
setLocation();
setVisible(true);
}
private void onOK() {
// 在此处添加您的代码
try {
this.id = Integer.valueOf(idField.getText());
searchSQLMaker();
deleteSQLMaker();
ResultSet rs = searchConnector.executeQuery(searchSQL);
if (rs.next()) {
deleteConnector.executeUpdate(deleteSQL);
} else {
JOptionPane.showMessageDialog(this, searchErrMsg, "错误", JOptionPane.WARNING_MESSAGE);
}
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
} catch (SQLException e) {
throw new RuntimeException(e);
}
dispose();
}
private void searchSQLMaker() {
if (table.equals("books")) {
searchSQL = "select * from " + table + " where book_id=" + id + ";";
} else if (table.equals("students")) {
searchSQL = "select * from " + table + " where student_id=" + id + ";";
} else if (table.equals("rents")) {
searchSQL = "select * from " + table + " where book_id=" + id + ";";
}
}
private void deleteSQLMaker() {
if (table.equals("books")) {
deleteSQL = "delete from " + table + " where book_id=" + id + ";";
} else if (table.equals("students")) {
deleteSQL = "delete from " + table + " where student_id=" + id + ";";
} else if (table.equals("rents")) {
deleteSQL = "UPDATE books SET borrowed_by = null WHERE book_id=" + id + ";";
}
}
public void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
}
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.SearchDIalog">
<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="8f9fb" layout-manager="GridBagLayout">
<constraints border-constraint="West"/>
<properties/>
<border type="none"/>
<children>
<component id="a8662" class="javax.swing.JLabel" binding="messageLabel">
<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"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="请输入学号:"/>
</properties>
</component>
<hspacer id="c8446">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</hspacer>
<vspacer id="36605">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</vspacer>
</children>
</grid>
<grid id="87c34" layout-manager="GridBagLayout">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="90640" class="javax.swing.JTextField" binding="idFIeld">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<columns value="10"/>
</properties>
</component>
<hspacer id="a6bdf">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</hspacer>
<vspacer id="ceec6">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</vspacer>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,116 @@
package com.msksbr.MainFrm.MenuItemDiaog;
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.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
public class SearchDIalog extends JDialog {
public JLabel messageLabel;
protected int idInt;
private JPanel contentPane;
private JButton buttonOK;
private JTextField idFIeld;
private String table;
public SearchDIalog(String table) {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
if (table.equals("books")) {
this.table = "books";
this.setTitle("查询图书信息");
messageLabel.setText("请输入书号:");
} else if (table.equals("students")) {
this.table = "students";
this.setTitle("查询学生信息");
messageLabel.setText("请输入学号:");
} else if (table.equals("rents")) {
this.table = "rents";
this.setTitle("查询借阅信息");
messageLabel.setText("请输入书号:");
}
setListener();
pack();
setLocation();
setVisible(true);
}
private void setListener() {
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
idFIeld.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
onOK();
}
}
});
}
private void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
private void onOK() {
ResultSet rs = SQLExe();
String message = "";
try {
if (rs != null && rs.next()) {
String title = "";
if (table.equals("books")) {
message = "书名:\t" + rs.getString("book_name") + "\n类别:\t" + rs.getString("book_type") + "\n书号:\t" + rs.getInt("book_id") + "\nISBN\t" + rs.getString("ISBN");
title = "图书信息";
} else if (table.equals("students")) {
message = "学生姓名:\t" + rs.getString("student_name") + "\n学号:\t" + rs.getInt("student_id") + "\n班级:\t" + rs.getString("student_class") + "\n性别:\t" + rs.getString("student_gender");
title = "学生信息";
} else if (table.equals("rents")) {
message = "学生姓名:\t" + rs.getString("student_name") + "\n学号:\t" + rs.getInt("student_id") + "\n班级:\t" + rs.getString("student_class") + "\n性别:\t" + rs.getString("student_gender") + "\n书名:\t" + rs.getString("book_name") + "\n书号:\t" + rs.getInt("book_id") + "\n类别:\t" + rs.getString("book_type") + "\nISBN\t" + rs.getString("ISBN");
title = "借阅信息";
}
new showMessae(message, title);
} else {
JOptionPane.showMessageDialog(this, "未找到", "未找到", JOptionPane.WARNING_MESSAGE);
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
private ResultSet SQLExe() {
ResultSet rs = null;
try {
idInt = Integer.valueOf(idFIeld.getText());
Connector connector = new Connector();
rs = connector.executeQuery(SQLExeMaker(table));
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "请输入一个整数", "错误", JOptionPane.ERROR_MESSAGE);
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
return rs;
}
private String SQLExeMaker(String table) {
if (table.equals("books")) {
return "SELECT * FROM books WHERE book_id = " + idInt + ";";
} else if (table.equals("students")) {
return "SELECT * FROM students WHERE student_id = " + idInt + ";";
} else if (table.equals("rents")) {
return "SELECT * FROM rents WHERE book_id = " + idInt + ";";
} else {
return null;
}
}
}
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.aboutDIalog">
<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="f8413" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<component id="48047" class="javax.swing.JLabel">
<constraints/>
<properties>
<font name="PingFang SC" size="14"/>
<text value="https://gitee.com/msksbr/system-homework-in-the-library"/>
</properties>
</component>
</children>
</grid>
<grid id="bae5e" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<grid id="b98e5" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<component id="58e29" class="javax.swing.JLabel">
<constraints/>
<properties>
<font name="PingFang SC" size="16" style="1"/>
<text value="图书管理系统 Demo"/>
</properties>
</component>
</children>
</grid>
<grid id="d8804" binding="iconPanel" layout-manager="GridBagLayout">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children/>
</grid>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,44 @@
package com.msksbr.MainFrm.MenuItemDiaog;
import com.msksbr.LoginFrm.ScreenSize;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class aboutDIalog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JPanel iconPanel;
public aboutDIalog() {
setTitle("关于图书管理系统");
setVisible(false);
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
setResizable(false);
JLabel iconLabel = new JLabel();
iconLabel.setIcon(new ImageIcon("src/com/msksbr/images/logo_128.png"));
iconPanel.add(iconLabel);
setModal(false);
setAlwaysOnTop(true);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
pack();
setLocation();
}
private void onOK() {
// 在此处添加您的代码
dispose();
}
public void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
}
@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.MainFrm.MenuItemDiaog.showMessae">
<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="OK"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<grid id="e3588" 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="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="165c3" layout-manager="GridBagLayout">
<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="b32d2" class="javax.swing.JTextPane" binding="textPane1" default-binding="true">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false">
<preferred-size width="150" height="50"/>
</grid>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value="text"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,41 @@
package com.msksbr.MainFrm.MenuItemDiaog;
import com.msksbr.LoginFrm.ScreenSize;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class showMessae extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JTextPane textPane1;
public showMessae(String message, String title) {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
this.textPane1.setText(message);
this.setTitle(title);
textPane1.setEditable(false);
pack();
setResizable(false);
setCenterLocation();
setVisible(true);
}
public void setCenterLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
private void onOK() {
// 在此处添加您的代码
dispose();
}
}
@@ -0,0 +1,30 @@
package com.msksbr.SQL;
import java.sql.*;
public class Connector {
private Connection conn;
private Statement stmt;
private String url="sqlmsksbr.com";
private Integer port=1433;
private String username="sa";
private String password="nothx";
private String database="book";
private Boolean encrypted=false;
private String loginURL=new UserInfo(url,port,database,username,password,encrypted).GetUserInfo();
public Connector() throws ClassNotFoundException, SQLException {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection(loginURL);
stmt = conn.createStatement();
}
public ResultSet executeQuery(String query) throws SQLException {
return stmt.executeQuery(query);
}
public int executeUpdate(String query) throws SQLException {
return stmt.executeUpdate(query);
}
}
@@ -0,0 +1,31 @@
package com.msksbr.SQL;
public class UserInfo {
private String url;
private Integer port;
private String database;
private String username;
private String password;
private Boolean encrypted;
public UserInfo(String url, Integer port, String database, String username, String password,boolean encrypted) {
this.url = url;
this.port = port;
this.database = database;
this.username = username;
this.password = password;
this.encrypted = encrypted;
}
public String GetUserInfo(){
String LoginURL;
LoginURL = "jdbc:sqlserver://";
LoginURL=LoginURL+url;
LoginURL=LoginURL+":"+port.toString();
LoginURL=LoginURL+";databaseName="+database;
LoginURL=LoginURL+";user="+username;
LoginURL=LoginURL+";password="+password;
LoginURL=LoginURL+";encrypt="+encrypted.toString().toLowerCase();
return LoginURL;
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.msksbr.images.EasterEgg">
<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="FlowLayout" hgap="5" vgap="5" flow-align="1">
<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="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="Coding!"/>
</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="3b48b" layout-manager="FlowLayout" hgap="5" vgap="5" flow-align="1">
<constraints border-constraint="South"/>
<properties/>
<border type="none"/>
<children>
<component id="76717" class="javax.swing.JLabel">
<constraints/>
<properties>
<font size="14" style="1"/>
<text value="Coding with JavaBeans!"/>
</properties>
</component>
</children>
</grid>
<grid id="283b1" layout-manager="GridBagLayout">
<constraints border-constraint="Center"/>
<properties/>
<border type="none"/>
<children>
<component id="9b6a4" class="javax.swing.JLabel" binding="imageLable">
<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"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
<properties>
<text value=""/>
</properties>
</component>
<hspacer id="29912">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</hspacer>
<vspacer id="5cc54">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>
</constraints>
</vspacer>
</children>
</grid>
</children>
</grid>
</children>
</grid>
</form>
@@ -0,0 +1,41 @@
package com.msksbr.images;
import com.msksbr.LoginFrm.ScreenSize;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class EasterEgg extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JLabel imageLable;
public EasterEgg() {
setTitle("Easter Egg!");
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
imageLable.setIcon(new ImageIcon("src/com/msksbr/images/BuzzBeans.png"));
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
pack();
setResizable(false);
setLocation();
setVisible(true);
}
private void onOK() {
// 在此处添加您的代码
dispose();
}
public void setLocation() {
setLocation(new ScreenSize().width / 2 - getWidth() / 2, new ScreenSize().height / 2 - getHeight() / 2);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 199 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

+3 -6
View File
@@ -111,14 +111,12 @@
<tr>
<td>主文件</td>
<td>
</td>
<td>
🟩
</td>
<td>
🟩
</td>
<td></td>
</tr>
<tr>
<td>最大尺寸</td>
@@ -157,7 +155,6 @@
</td>
</tr>
</table>
### 实现
其他**略**,只介绍如何增加文件
+1 -1
View File
@@ -42,7 +42,7 @@ CREATE TABLE 课程表
VARCHAR(10) CHECK( IN('公共基础','专业基础','专业选修','任意选修')),
FOREIGN KEY() REFERENCES ()
);
--5 选课表
-- 5 选课表
CREATE TABLE (
VARCHAR(8),
VARCHAR(8),
+43
View File
@@ -0,0 +1,43 @@
-- 1.用户账号管理。
-- 1)利用Transact-SQL 创建。
-- 创建SQL Server 认证登录名
CREATE LOGIN [] WITH PASSWORD = '密码';
-- 创建数据库用户并将其关联到登录名
USE [];
CREATE USER [] FOR LOGIN [];
-- (2)查看用户账号。在“对象资源管理器”中,展开“安全性”文件夹下的“登录名”,可查看已创建的用户账号。
-- 查询已创建的用户账号
USE [];
SELECT name FROM sys.database_principals WHERE
type_desc = 'SQL_USER';
-- (3)修改用户账号。对于需要修改的登录名,右击选择“属性”,在打开的对话框中修改用户信息,如密码、默认数据库等。
-- 修改用户名
ALTER LOGIN [] WITH NAME = [];
-- 修改用户账号密码
ALTER LOGIN [] WITH PASSWORD = '新密码';
-- 修改用户账号的默认数据库
ALTER LOGIN [] WITH DEFAULT_DATABASE = [];
-- 2.设置用户权限。
-- (1)确定需要设置权限的用户账号。
-- 2)使用
USE []
-- 选择目标数据库。
-- 3)使用
GRANTDENYREVOKE
-- 命令来分配、拒绝或移除权限。
-- 授予用户SELECT 权限
USE [];
GRANT SELECT ON [] TO [];
-- 撤销用户SELECT 权限
USE [];
REVOKE SELECT ON [] FROM [];
-- 3.角色管理
-- 1)创建角色。
-- (1)使用USE [数据库名]选择目标数据库。
-- 2)使用CREATE ROLE [角色名]创建新角色。
-- 创建数据库角色
USE [];
CREATE ROLE [];
-- 删除数据库角色
USE [];
DROP ROLE [];
+49
View File
@@ -0,0 +1,49 @@
-- (1)对于学生管理数据库给出的学生表结构,定义一个名为female的变量,并在SELECT 语句中使用它找出女学生的编号和姓名
DECLARE @female TABLE(
VARCHAR(8),
VARCHAR(10)
);
INSERT INTO @female(,)
SELECT , FROM ;
SELECT * FROM @female;
-- (2)定义一个变量,用于获取编号为20231212的学生的生源地,并将该生源地的学生编号和姓名显示出来
DECLARE @origin VARCHAR(6);
SET @origin =(
SELECT FROM WHERE ='12'
); -- 这里没有编号是20231212的学生
SELECT AS , FROM
WHERE = @origin;
-- (3)使用CASE语句对教师表按所在院系进行分类
SELECT *
,CASE
WHEN 1 THEN (SELECT . FROM WHERE =1)
WHEN 2 THEN (SELECT . FROM WHERE =2)
WHEN 3 THEN (SELECT . FROM WHERE =3)
WHEN 4 THEN (SELECT . FROM WHERE =4)
WHEN 5 THEN (SELECT . FROM WHERE =5)
WHEN 6 THEN (SELECT . FROM WHERE =6)
WHEN 7 THEN (SELECT . FROM WHERE =7)
WHEN 8 THEN (SELECT . FROM WHERE =8)
WHEN 9 THEN (SELECT . FROM WHERE =9)
WHEN 10 THEN (SELECT . FROM WHERE =10)
ELSE '未知'
END AS
FROM ;
-- (4)使用循环控制语句计算10!
DECLARE @i INT = 1;
DECLARE @j INT = 1;
WHILE @i<10 BEGIN
SET @i = @i+1
SET @j = @j*@i;
END
SELECT @j;
+112
View File
@@ -0,0 +1,112 @@
USE ;
-- (1)为选课表分别建立插入和更新触发器,如果当前学生累计不及格门数达到5则给出警示信息。
-- 插入触发器
CREATE TRIGGER
ON
AFTER INSERT
AS
BEGIN
SET NOCOUNT ON;
CREATE TABLE # (
VARCHAR(8),
INT
);
INSERT INTO #(, )
SELECT
i.,
COUNT(*) AS
FROM
AS q
INNER JOIN INSERTED AS i ON q. = i.
WHERE
q. < 60
GROUP BY
i.
HAVING
COUNT(*) >= 5;
IF EXISTS (SELECT 1 FROM #)
BEGIN
DECLARE @ NVARCHAR(MAX);
SELECT @ = STRING_AGG(
CONCAT('警示: 学号 ', , ' 的累计不及格门数已达到 ', , ' 门!'),
CHAR(13) + CHAR(10)
)
FROM #;
RAISERROR (@, 16, 1);
ROLLBACK TRANSACTION;
END
DROP TABLE #;
END;
-- 更新触发器
CREATE TRIGGER
ON
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
CREATE TABLE # (
VARCHAR(8),
INT
);
INSERT INTO #(, )
SELECT
i.,
COUNT(*) AS
FROM
AS q
INNER JOIN INSERTED AS i ON q. = i.
WHERE
q. < 60
GROUP BY
i.
HAVING
COUNT(*) >= 5;
IF EXISTS (SELECT 1 FROM #)
BEGIN
DECLARE @ NVARCHAR(MAX);
SELECT @ = STRING_AGG(
CONCAT('警示: 学号 ', , ' 的累计不及格门数已达到 ', , ' 门!'),
CHAR(13) + CHAR(10)
)
FROM #;
RAISERROR (@, 16, 1);
ROLLBACK TRANSACTION;
END
DROP TABLE #;
END;
-- (2)为课程表分别建立插入和更新触发器来建立约束规则:“专业基础”课的教师必须为“教授”或“副教授”,如果不满足约束则拒绝操作,并给出错误信息。
-- 插入触发器
CREATE TRIGGER _插入 ON
AFTER INSERT
AS
BEGIN
IF EXISTS (
SELECT *
FROM INSERTED
JOIN ON INSERTED.=.
WHERE (. != '教授' AND . != '副教授')AND INSERTED.='专业基础'
)
BEGIN
RAISERROR ('教授专业基础课的教师必须为教授或副教授',16,1);
ROLLBACK TRANSACTION;
END;
END;
-- 更新触发器
CREATE TRIGGER _更新 ON
AFTER UPDATE
AS
BEGIN
IF EXISTS (
SELECT *
FROM INSERTED
JOIN ON INSERTED.=.
WHERE (. != '教授' AND . != '副教授')AND INSERTED.='专业基础'
)
BEGIN
RAISERROR ('教授专业基础课的教师必须为教授或副教授',16,1);
ROLLBACK TRANSACTION;
END;
END;
+39
View File
@@ -0,0 +1,39 @@
-- 用SQL 语言定义学生表、课程表和选课表,要求完成以下完整性约束条件:
CREATE DATABASE new_学生管理;
USE new_学生管理;
-- 1)定义每个表的主码。
-- 2)定义参照完整性。
-- (3)定义课程的学分不超过4学分。
CREATE TABLE (
VARCHAR(64),
VARCHAR(3) CHECK( IN('','')), -- 参照完整性
PRIMARY KEY() -- 定义主码
);
CREATE TABLE (
VARCHAR(64),
SMALLINT CHECK( <=4), --设置学分不超过四分
PRIMARY KEY() -- 定义主码
);
CREATE TABLE (
VARCHAR(64),
VARCHAR(64)
PRIMARY KEY(), -- 定义主码
FOREIGN KEY () REFERENCES ()
)
-- (4)显示说明当操作违反实体完整性、参照完整性和用户定义的完整性约束条件时,如何进行处理?
-- 实体完整性
INSERT INTO ()
VALUES
('1'),
('1');
-- 参照完整性
INSERT INTO () VALUES('1');
INSERT INTO (,) VALUES
('1','2');
+51
View File
@@ -0,0 +1,51 @@
# 实验十五🧪
## 题目一
### 原题
利用向导为`学生管理`数据库生成一个`完全备份`
### 分析
- 要求:备份
- 备份类型:完全备份
### 实现
1. 打开SSMS,点击备份
<img src="F:\git\database-system-homework\img\实验十五\image-20241204163120483.png" alt="image-20241204163120483" style="zoom:50%;" />
2. 选择完全备份
<img src="F:\git\database-system-homework\img\实验十五\image-20241204163319192.png" alt="image-20241204163319192" style="zoom:50%;" />
3. 确定
## 题目二
### 原题
`张三`同学的名字改为:`张兵`,然后`执行恢复`,将数据库恢复到修改“张三”同学姓名之前的状态
### 分析
- 任务:修改条目、执行恢复
- 修改条目:`张三`->`张兵`
### 实现
1. 修改`张三`的名字为`张兵`
```sql
UPDATE 学生表
SET 姓名='张兵'
WHERE 姓名='张三';
```
2. 执行恢复
<img src="F:\git\database-system-homework\img\实验十五\image-20241204164336221.png" alt="image-20241204164336221" style="zoom:50%;" />
<img src="F:\git\database-system-homework\img\实验十五\image-20241204164409979.png" alt="image-20241204164409979" style="zoom:50%;" />
+95
View File
@@ -0,0 +1,95 @@
# 实验十六🧪
## 1. 安装数据库管理系统
### 实验步骤
1. 下载SQL Server安装程序。
2. 运行安装程序并按照向导完成安装。
3. 配置SQL Server服务,确保其可以正常启动。
4. 打开SQL Server Management Studio (SSMS) 并连接到本地服务器以验证安装。
### 实验结果
- SQL Server安装成功,SSMS能够成功连接到本地服务器。
## 2. 创建数据库和数据表
### 实验步骤
1. 打开SSMS并连接到SQL Server实例。
2. 创建一个新的数据库,例如使用T-SQL命令:
```sql
CREATE DATABASE mydatabase;
GO
```
3. 在新创建的数据库中创建数据表,例如使用T-SQL命令:
```sql
USE mydatabase;
GO
CREATE TABLE users (
id INT IDENTITY(1,1) PRIMARY KEY,
username NVARCHAR(255) NOT NULL,
password NVARCHAR(255) NOT NULL
);
GO
```
### 实验结果
- 数据库`mydatabase`创建成功。
- 数据表`users`创建成功,包含`id`、`username`和`password`字段。
## 3. 插入数据到数据表中
### 实验步骤:
1. 连接到`mydatabase`数据库。
2. 向`users`表中插入数据,例如:
```sql
INSERT INTO users (username, password) VALUES ('user1', 'password1');
GO
```
### 实验
- 数据成功插入,通过查询`SELECT * FROM users;`可以查看到新插入的数据。
## 4. 进行数据库备份
### 实验步骤
1. 在SSMS中,找到数据库,右键选择“任务” -> “备份...”。
2. 在备份向导中,设置备份文件的位置和名称,完成备份。
### 实验结果
- 数据库备份成功,备份文件已生成在指定位置。
## 5. 修改数据表中的数据
### 实验步骤
1. 连接到`mydatabase`数据库。
2. 更新`users`表中的数据,例如:
```sql
UPDATE users SET username = 'user1_updated' WHERE id = 1;
GO
```
### 实验结果
- 数据更新成功,通过查询可以验证`username`字段已更新。
## 6. 使用备份进行数据库恢复
### 实验步骤
1. 在SSMS中,找到服务器实例,右键选择“任务” -> “还原...”。
2. 在还原向导中,选择之前备份的数据库文件进行还原。
### 实验结果
- 数据库恢复成功,所有数据和结构与备份前一致。
## 7. 进行开发操作,如查询、更新、删除数据等
### 实验步骤
1. 连接到`mydatabase`数据库。
2. 执行各种T-SQL操作,如查询、更新和删除数据:
- 查询:`SELECT * FROM users;`
- 更新:`UPDATE users SET password = 'newpassword' WHERE id = 1;`
- 删除:`DELETE FROM users WHERE id = 1;`
### 实验结果
- 查询结果返回所有用户数据。
- 更新操作成功,密码字段更新。
- 删除操作成功,指定用户被删除。
+37
View File
@@ -0,0 +1,37 @@
-- 建立如下的存储过程(基于前面实验建立的表和插入的数据,并为每个存储过程设计返回的状态值):
-- 1.按要求设计完成如下功能的存储过程。
-- (1)查询平均分数在x到y范围内的学生信息。 该存储过程有两个参数:要求查询的学生信息包括学号、姓名、院系名称和平均成绩。
CREATE PROCEDURE quire_stu_between
@x INT,
@y INT
AS
BEGIN
SELECT ., ., ., .
FROM
JOIN ON . = .
WHERE . BETWEEN @x AND @y;
END;
-- (2)更新操作,以学号、课程编号和考试成绩作参数更新指定学生和课程的考试成绩,并返回该学生的平均成绩。
CREATE PROCEDURE update_stu_grade
@ VARCHAR(8),
@ VARCHAR(8),
@ SMALLINT
AS
BEGIN
UPDATE
SET =@
WHERE =@ AND =@;
SELECT FROM
WHERE =@;
END;
-- 2.在客户端以存储过程和输入SQL语句的方式分别执行相同的查询或操作,比较使用和不使用存储过程的区别。
-- 使用存储过程
EXEC quire_stu_between @x=85,@y=90;
-- 使用SQL查询
SELECT ., ., ., .
FROM
JOIN ON . = .
WHERE . BETWEEN 85 AND 90;