当前位置:   article > 正文

数据库课程设计(学生宿舍管理系统)附sql文件、源代码和Word模板_学生宿舍管理系统数据库设计

学生宿舍管理系统数据库设计

目录

一、功能要求

1、设计内容

2、学生宿舍管理系统主要功能

3、学生宿舍管理系统数据库表单(可以按照需求增、删、改)

二、系统需求分析

2.1 功能需求分析

2.2数据需求分析

2.3 业务规则及完整性约束分析

三、数据库概念结构设计

3.1 局部E-R图

四、 数据库物理结构设计

4.1创建数据库:

4.2创建Suguan表:

4.3创建qinshizhang表:

4.4创建student表:

4.5创建baoxun表:

4.6创建存储过程my

4.7另一种实现利用触发器实现当前时间

五、程序代码展示 

5.1登录界面

5.2寝室长 

 5.3宿管员

六、程序运行和数据库截图

六、源代码链接


一、功能要求

1、设计内容

设计一个学生宿舍管理系统,该系统的用户由寝室长和宿管员组成,不同的用户拥有不同的管理权限,各自完成各自的管理功能,首先是登录,登录的时候首先要判断用户的身份,合法的用户然后进入到系统主界面中,不同的用户看到不同的系统功能。

2、学生宿舍管理系统主要功能

(1)登录界面

(2)寝室长界面:寝室人员信息、保修操作、修改密码。

(3)管理员管理:查看学生住宿信息(按学号搜索、空白搜索全部)、管理学生住宿信息(添加学生住宿信息、删除学生住宿信息)、处理保修信息(修改处理状况)、管理学生账号(添加和删除)、修改密码。

3、学生宿舍管理系统数据库表单(可以按照需求增、删、改)

(1)寝室长信息表单:账号、密码

(2)宿管员信息表单:账号、密码

(3)报修信息表单:报修编号、寝楼、宿舍号、时间、问题、状况

(4)学生信息表单:学号、姓名、性别、专业、班级、宿舍号、寝楼、联系电话

二、系统需求分析

2.1 功能需求分析

首先,基本功能是登录。登录有两种身份:寝室长或宿管员。对于寝室长而言,系统中需要提供,寝室人员信息显示、报修功能、报修状态查看、修改密码的功能。对于管理员而言,系统需要提供查看学生住宿信息,管理学生住宿信息,处理报修,管理学生账号,修改密码的功能

1.1 系统功能模块图

2.2数据需求分析

寝室长登录需要对寝室长采集账号和密码;

寝室人员信息显示:在界面上显示寝室人员的全部信息,由宿管员界面添加学生信息采集;

报修操作需要对寝室长采集寝楼、宿舍号、时间、问题的信息;

修改密码需要采集原密码和新密码;

宿管员登录需要对宿管员采集用户名和用户密码;

查看学生住宿信息:开始显示全部学生的信息,通过搜索按钮需要输入对应的学号(模糊匹配)、输入空白则搜索全部学生信息;

管理学生住宿信息:添加需要对学生采集学号、姓名、性别、专业、班级、宿舍号、寝楼、联系电话,删除学生信息只需要提供学生的学号;

处理报修:需要采集处理序号,选择处理的状况;

管理学生账号:需要采集学生的账号和密码后可以选择删除还是添加;

修改密码需要采集原密码和新密码;

2.3 业务规则及完整性约束分析

寝室长(账号、密码)

学生(学号、姓名、性别、专业、班级、宿舍号、寝楼、联系电话)

报修信息(报修编号寝楼(外码)、宿舍号、时间、问题、状况)

宿管员(账号、密码)

三、数据库概念结构设计

3.1 局部E-R图

2.1寝室长实体E-R

2.2顾客实体E-R

2.3订单实体E-R

2.4菜单实体E-R

四、 数据库物理结构设计

4.1创建数据库:

CREATE database susheSystem;

4.2创建Suguan表:

  1. use susheSystem;
  2. create table Suguan(
  3.     Zhanghao CHAR(10PRIMARY KEY,
  4.     Mima CHAR(20) NOT null
  5. );

4.3创建qinshizhang表:

  1. create table qinshizhang(
  2.     Zhanghao1 CHAR(10PRIMARY KEY,
  3.     Mima1 CHAR(20) NOT null
  4. );

4.4创建student表:

  1. CREATE Table student(
  2.     Xuehao CHAR(20) PRIMARY KEY, #学号
  3.     Name CHAR(10) NOT NULL, #姓名
  4.     Sex CHAR(5) NOT NULL, #性别
  5.     Specialistion CHAR(10) NOT NULL,#专业
  6.     Class CHAR(10) NOT NULL,#班级
  7.     Dormitory CHAR(10) NOT NULL,#宿舍号
  8.     Qinlou CHAR(10) NOT NULL,#寝楼
  9.     Phone CHAR(20)#电话
  10. );

4.5创建baoxun表:

  1. CREATE TABLE baoxun(
  2.     Number1 int(2) NOT NULL AUTO_INCREMENT,#报修编号
  3.     Qinlou CHAR(10) NOT NULL,#寝楼
  4.     Dormitory CHAR(10) NOT NULL,#宿舍号
  5.     Time1 DATE ,#时间
  6.     Question char(100) NOT NULL,#问题
  7.     Situation char(10DEFAULT '等待处理',#状况
  8.     PRIMARY KEY (Number1) USING BTREE,
  9.     FOREIGN KEY (Qinlou) REFERENCES Suguan(zhanghao)
  10. );

4.6创建存储过程my

  1. delimiter $
  2. create procedure my()
  3. begin
  4.       alter table baoxun drop Number1;
  5. alter table baoxun add Number1 int(2) not null auto_increment primary key first;
  6. end $
  7. delimiter ;
  8. 设置定时事件
  9. show variables like '%event_sche%';-- 查看事件计划是否开启
  10. set global event_scheduler=1;
  11. create event on1  on schedule every 1 second do call my();-- 创建定时事务

4.7另一种实现利用触发器实现当前时间

  1. /*delimiter $
  2. create procedure my(in id int)
  3. begin
  4.       declare ti date default 0;
  5.       set ti=curdate();
  6.       update  baoxun set Time1=ti where  Number1=id;
  7. end $
  8. delimiter ;
  9. delimiter $
  10. create trigger my1 after insert on baoxun for each row
  11. begin
  12.       call my(new.Number1);
  13. end $
  14. delimiter ;
  15. drop trigger if exists my;
  16. delimiter $
  17. create trigger my2 after insert on baoxun for each row
  18. begin
  19.       declare ti date default 0;
  20.       set ti=curdate();
  21.       update  baoxun set Time1=ti where  Number1=new.Number1;
  22. end $
  23. delimiter ;
  24. INSERT INTO baoxun(Qinlou,Dormitory,Question) VALUES ('紫园一栋', '107','门坏了');
  25. */

五、程序代码展示 

5.1登录界面

  1. package 学生宿舍管理系统;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import javax.swing.JComboBox;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. @SuppressWarnings("serial")
  13. public class 登录界面 extends JFrame implements ActionListener{
  14. //添加输入框【用户名输入框】
  15. JTextField user1 = new JTextField(20);
  16. //定义两个静态变量,提共账号和密码
  17. public static String chaxu,pass1;
  18. String url = "jdbc:mysql://localhost:3306/sushesystem?useSSL=false&serverTimezone=UTC";
  19. //添加下拉单
  20. static JComboBox<Object> jc1 = new JComboBox<>();
  21. //主方法
  22. public static void main(String[] args) {
  23. 登录界面 a =new 登录界面();
  24. a.界面();
  25. }
  26. //定义界面方法
  27. public void 界面() {
  28. //创建主界面框架“登录”
  29. JFrame jFrame = new JFrame("登录");
  30. //设置窗口大小
  31. jFrame.setSize(900,507);
  32. //设置布局管理为null
  33. jFrame.setLayout(null);
  34. //添加标签{学生宿舍管理系统}
  35. //创建一个标签并命名
  36. JLabel textStudentManage = new JLabel("学生宿舍管理系统");
  37. //设置颜色
  38. textStudentManage.setForeground(new Color(0x0010FF));
  39. //设置字体、大小
  40. textStudentManage.setFont(new Font("微软雅黑", Font.PLAIN,30));
  41. //设置标签的绝对位置
  42. textStudentManage.setBounds(280,50,800,100);
  43. //向框架中添加组件
  44. jFrame.add(textStudentManage);
  45. //添加标签【用户名】
  46. JLabel textUser = new JLabel("用户名:");
  47. textUser.setForeground(new Color(0xFF0000));
  48. textUser.setFont(new Font("微软雅黑", Font.PLAIN,30));
  49. textUser.setBounds(200,140,200,100);
  50. jFrame.add(textUser);
  51. //添加输入框【用户名输入框】
  52. user1.setFont(new Font("微软雅黑", Font.PLAIN,18));
  53. user1.setSelectedTextColor(new Color(0xFF0000));
  54. user1.setBounds(330,170,280,40);
  55. jFrame.add(user1);
  56. //添加标签【密码】
  57. JLabel textPassword = new JLabel("密 码 :");
  58. textPassword.setForeground(new Color(0xFF0000));
  59. textPassword.setFont(new Font("微软雅黑", Font.PLAIN,30));
  60. textPassword.setBounds(200,200,200,100);
  61. jFrame.add(textPassword);
  62. //添加密码输入框【密码】
  63. JPasswordField password = new JPasswordField(20);
  64. password.setBounds(330,230,280,40);
  65. jFrame.add(password);
  66. //添加下拉单
  67. jc1.setBounds(380,280,150,30);
  68. jc1.addItem("宿管员");
  69. jc1.addItem("寝室长");
  70. jFrame.add(jc1);
  71. //添加按钮【登录】
  72. JButton jButton = new JButton("登录");
  73. jButton.setForeground(new Color(0x023BF6));
  74. jButton.setBackground(new Color(0x38FF00));
  75. jButton.setFont(new Font("微软雅黑", Font.PLAIN,20));
  76. jButton.setBorderPainted(false);
  77. jButton.setBounds(300,330,100,50);
  78. jFrame.add(jButton);
  79. //添加按钮【注册】
  80. JButton chongzhi = new JButton("重置");
  81. chongzhi.setForeground(new Color(0x0029FF));
  82. chongzhi.setBackground(new Color(0xECA871));
  83. chongzhi.setFont(new Font("微软雅黑", Font.PLAIN,20));
  84. chongzhi.setBorderPainted(false);
  85. chongzhi.setBounds(500,330,100,50);
  86. jFrame.add(chongzhi);
  87. //设置界面关闭,显示
  88. jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  89. jFrame.setResizable(false);//false设置窗口大小不可改变
  90. jFrame.setLocationRelativeTo(null);//将窗口置于屏幕的中央
  91. jFrame.setVisible(true);//设置可见
  92. chongzhi.addActionListener(new ActionListener(){//为重置按钮添加监听事件
  93. //同时清空name、password的数据
  94. public void actionPerformed(ActionEvent arg0) {
  95. user1.setText("");
  96. password.setText("");
  97. }
  98. });
  99. //设置登录按钮监听
  100. jButton.addActionListener(new ActionListener(){
  101. public void actionPerformed(ActionEvent arg0){
  102. //获取用户输入的密码和账号,并赋值给静态变量
  103. String name = user1.getText();
  104. chaxu = name;
  105. String pass = password.getText();
  106. pass1 = pass;
  107. //账号规范检测
  108. if (0 == name.length()) {
  109. JOptionPane.showMessageDialog(null, "账号不能为空");
  110. user1.grabFocus();
  111. return;
  112. }
  113. if (0 == pass.length()) {
  114. JOptionPane.showMessageDialog(null, "密码不可为空!");
  115. password.grabFocus();
  116. return;
  117. }
  118. //双界面登录判断
  119. if (jc1.getSelectedItem().toString().equals("宿管员")) {
  120. if (check(name, pass)) {
  121. JOptionPane.showMessageDialog(null, "登录成功");
  122. jFrame.dispose(); //关闭当前界面
  123. new 宿管员();
  124. } else
  125. JOptionPane.showMessageDialog(null, "密码错误");
  126. }
  127. if (jc1.getSelectedItem().toString().equals("寝室长")) {
  128. if (check(name, pass)) {
  129. JOptionPane.showMessageDialog(null, "登录成功");
  130. jFrame.dispose();
  131. new 寝室长();
  132. } else
  133. JOptionPane.showMessageDialog(null, "密码错误");
  134. }
  135. }
  136. });
  137. }
  138. //重写由继承actionlistener得到的方法
  139. @Override
  140. public void actionPerformed(ActionEvent e) {
  141. }
  142. //定义账号密码检查方法check,从数据库获取账号信息
  143. public static boolean check(String name, String password){
  144. try {
  145. //数据库加载
  146. Class.forName("com.mysql.cj.jdbc.Driver");
  147. System.out.println("Success loading Mysql Driver!");
  148. } catch (ClassNotFoundException e) {
  149. e.printStackTrace();
  150. }
  151. boolean result = false;
  152. try {
  153. //数据库信息定义和连接数据库
  154. String url = "jdbc:mysql://localhost:3306/sushesystem?useSSL=false&serverTimezone=UTC";
  155. String username = "root";
  156. String passwords = "yu1314520";
  157. Connection c = DriverManager.getConnection(url, username, passwords);
  158. if (c != null) {
  159. System.out.println("数据库连接成功!");
  160. } else {
  161. System.out.println("数据库连接失败!");
  162. }
  163. Statement s = c.createStatement();
  164. //上面的是为了建立数据而做驱动准备以及连接测试。
  165. //账号登录判断,通过改变数据库查询代码来读取相应的表并验证账号、密码
  166. if (jc1.getSelectedItem().toString().equals("宿管员")) { //当用户选择“超级管理员”身份登录时
  167. String sql = "select * from suguan " + "where Zhanghao = '" + name + "' and Mima = '" //查询
  168. + password + "'";
  169. ResultSet rs = s.executeQuery(sql);
  170. while (rs.next()) {
  171. if (rs.getString("Zhanghao").equals(name) && rs.getString("Mima").equals(password)) { //如果用户输入的用户名和密码都和数据库中信息对得上。
  172. result = true; //返回true
  173. } else {
  174. System.out.println(rs.getString("Zhanghao").equals(name));
  175. System.out.println(rs.getString("Mima").equals(password));
  176. return false;
  177. }
  178. }
  179. } else {
  180. if (jc1.getSelectedItem().toString().equals("寝室长")) { //当用户选择“供应商”身份登录时
  181. String sql = "select * from qinshizhang " + "where Zhanghao1 = '" + name + "' and Mima1 = '"
  182. + password + "'";
  183. ResultSet rs = s.executeQuery(sql);
  184. while (rs.next()) {
  185. if (rs.getString("Zhanghao1").equals(name)
  186. && rs.getString("Mima1").equals(password)) {
  187. result = true; // 如果用户名和密码都正确,那么就将result返回为true;
  188. } else {
  189. return false;
  190. }
  191. }
  192. }
  193. }
  194. c.close();
  195. }catch (SQLException e2) {
  196. e2.printStackTrace();
  197. }
  198. //返回验证结果
  199. return result;
  200. }
  201. }

5.2寝室长 

  1. package 学生宿舍管理系统;
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Font;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.sql.Connection;
  8. import java.sql.PreparedStatement;
  9. import java.sql.ResultSet;
  10. import javax.swing.JButton;
  11. import javax.swing.JFrame;
  12. import javax.swing.JLabel;
  13. import javax.swing.JOptionPane;
  14. import javax.swing.JPanel;
  15. import javax.swing.JPasswordField;
  16. import javax.swing.JScrollPane;
  17. import javax.swing.JTabbedPane;
  18. import javax.swing.JTable;
  19. import javax.swing.JTextArea;
  20. import javax.swing.JTextField;
  21. public class 寝室长 extends JFrame{
  22. JTabbedPane jbb = new JTabbedPane(JTabbedPane.TOP);
  23. Connection connection = new GetConnection().GetConnection();
  24. JPanel 寝室人员,报修,修改密码;
  25. 登录界面 c = new 登录界面();
  26. String a = c.chaxu;//"紫园一栋107";//c.chaxu;
  27. String pass1 = c.pass1;//"12345678";//c.pass1;
  28. public 寝室长() {
  29. this.setTitle("寝室长界面");
  30. this.setSize(800,600);
  31. this.setLayout(null);
  32. this.setLocation(400,400);
  33. this.setVisible(true);
  34. 寝室人员 = new JPanel();
  35. 寝室人员.setSize(700,500);
  36. 报修 = new JPanel();
  37. 报修.setSize(700,500);
  38. 报修.setLayout(null);
  39. 修改密码 = new JPanel();
  40. 修改密码.setSize(700,500);
  41. 修改密码.setLayout(null);
  42. jbb.addTab("寝室人员", 寝室人员);
  43. jbb.addTab("报修", 报修);
  44. jbb.addTab("修改密码", 修改密码);
  45. this.setContentPane(jbb);
  46. this.寝室人员界面();
  47. this.报修();
  48. this.修改密码();
  49. }
  50. public void 寝室人员界面() {
  51. JScrollPane scpDome = new JScrollPane();
  52. scpDome.setPreferredSize(new Dimension(700, 400));
  53. 寝室人员.add(scpDome);
  54. //Connection connection = new GetConnection().GetConnection();
  55. String sql = "select * from student where Dormitory='"+a.substring(4,7)+"'and Qinlou='"+a.substring(0,4)+"'";
  56. try {
  57. PreparedStatement state;
  58. ResultSet re;
  59. state=connection.prepareStatement(sql);
  60. re=state.executeQuery();
  61. int count=0;
  62. while(re.next()) {
  63. count++;
  64. }
  65. re = state.executeQuery();
  66. Object[][] info= new Object[count][8];
  67. count = 0;
  68. while(re.next()) {
  69. info[count][0]=re.getString("Xuehao");
  70. info[count][1]=re.getString("Name");
  71. info[count][2]=re.getString("Sex");
  72. info[count][3]=re.getString("Specialistion");
  73. info[count][4]=re.getString("Class");
  74. info[count][5]=re.getString("Dormitory");
  75. info[count][6]=re.getString("Qinlou");
  76. info[count][7]=re.getString("Phone");
  77. count++;
  78. }
  79. String[] title = {"学号","姓名","性别","专业","班级","宿舍号","寝楼","联系电话"};
  80. JTable tabDome = new JTable(info,title);
  81. //JTableHeader jth = tabDome.getTableHeader();
  82. scpDome.getViewport().add(tabDome);
  83. // connection.close();
  84. }catch (Exception e) {
  85. e.printStackTrace();
  86. }
  87. }
  88. public void 报修() {
  89. JScrollPane scpDome1 = new JScrollPane();
  90. scpDome1.setBounds(5,5,400,400);
  91. 报修.add(scpDome1);
  92. //Connection connection1 = new GetConnection().GetConnection();
  93. String sql = "select * from baoxun where Dormitory='"+a.substring(4,7)+"'and Qinlou='"+a.substring(0,4)+"'";
  94. try {
  95. PreparedStatement state;
  96. ResultSet re;
  97. state=connection.prepareStatement(sql);
  98. re=state.executeQuery();
  99. int count=0;
  100. while(re.next()) {
  101. count++;
  102. }
  103. re = state.executeQuery();
  104. Object[][] info= new Object[count][6];
  105. count = 0;
  106. while(re.next()) {
  107. info[count][0]=Integer.valueOf(re.getString("Number1"));
  108. info[count][1]=re.getString("Qinlou");
  109. info[count][2]=re.getString("Dormitory");
  110. info[count][3]=re.getString("Time1");
  111. info[count][4]=re.getString("Question");
  112. info[count][5]=re.getString("Situation");
  113. count++;
  114. }
  115. String[] title = {"报修编号","寝楼","宿舍号","时间","问题","状况"};
  116. JTable tabDome = new JTable(info,title);
  117. //JTableHeader jth = tabDome.getTableHeader();
  118. scpDome1.getViewport().add(tabDome);
  119. //connection.close();
  120. }catch (Exception e) {
  121. e.printStackTrace();
  122. }
  123. JLabel r1 = new JLabel("寝 楼:");
  124. r1.setForeground(new Color(000));
  125. r1.setFont(new Font("微软雅黑", Font.PLAIN,20));
  126. r1.setBounds(430,10,100,100);
  127. 报修.add(r1);
  128. JTextField b1 = new JTextField(5);
  129. b1.setFont(new Font("微软雅黑", Font.PLAIN,18));
  130. b1.setSelectedTextColor(new Color(0xFF0000));
  131. b1.setBounds(500,40,180,40);
  132. 报修.add(b1);
  133. JLabel r2 = new JLabel("宿舍号:");
  134. r2.setForeground(new Color(000));
  135. r2.setFont(new Font("微软雅黑", Font.PLAIN,20));
  136. r2.setBounds(430,72,100,100);
  137. 报修.add(r2);
  138. JTextField b2 = new JTextField(5);
  139. b2.setFont(new Font("微软雅黑", Font.PLAIN,18));
  140. b2.setSelectedTextColor(new Color(0xFF0000));
  141. b2.setBounds(500,100,180,40);
  142. 报修.add(b2);
  143. JLabel r3 = new JLabel("时 间:");
  144. r3.setForeground(new Color(000));
  145. r3.setFont(new Font("微软雅黑", Font.PLAIN,20));
  146. r3.setBounds(430,134,100,100);
  147. 报修.add(r3);
  148. JTextField b3 = new JTextField(5);
  149. b3.setFont(new Font("微软雅黑", Font.PLAIN,18));
  150. b3.setSelectedTextColor(new Color(0xFF0000));
  151. b3.setBounds(500,170,180,40);
  152. 报修.add(b3);
  153. JLabel r4 = new JLabel("问 题:");
  154. r4.setForeground(new Color(000));
  155. r4.setFont(new Font("微软雅黑", Font.PLAIN,20));
  156. r4.setBounds(430,196,100,100);
  157. 报修.add(r4);
  158. JTextArea b4 = new JTextArea();
  159. b4.setFont(new Font("微软雅黑", Font.PLAIN,18));
  160. b4.setSelectedTextColor(new Color(0xFF0000));
  161. b4.setBounds(500,230,180,100);
  162. 报修.add(b4);
  163. JButton j1 = new JButton("报 修");
  164. j1.setForeground(new Color(128));
  165. j1.setBackground(new Color(225,225,255));
  166. j1.setFont(new Font("微软雅黑", Font.PLAIN,20));
  167. j1.setBorderPainted(false);
  168. j1.setBounds(530,360,120,40);
  169. 报修.add(j1);
  170. j1.addActionListener(new ActionListener(){
  171. public void actionPerformed(ActionEvent arg0){
  172. String a1 = b1.getText();
  173. String a2 = b2.getText();
  174. String a3 = b3.getText();
  175. String a4 = b4.getText();
  176. b1.setText("");
  177. b2.setText("");
  178. b3.setText("");
  179. b4.setText("");
  180. if(a1.equals(a.substring(0,4))&& a2.equals(a.substring(4,7))) {
  181. //Connection connection2 = new GetConnection().GetConnection();
  182. String sql = "insert into baoxun(Qinlou,Dormitory,Time1,Question) values('"+a1+"','"+a2+"','"+a3+"','"+a4+"');";
  183. try {
  184. PreparedStatement state;
  185. state=(PreparedStatement)connection.prepareStatement(sql);
  186. state.executeUpdate();
  187. JOptionPane.showMessageDialog(null, "报修成功!");
  188. }catch (Exception e) {
  189. JOptionPane.showMessageDialog(null, "报修失败!");
  190. System.out.println("报修失败");
  191. e.printStackTrace();
  192. }finally {
  193. 报修.remove(scpDome1);
  194. JScrollPane scpDome1 = new JScrollPane();
  195. scpDome1.setBounds(5,5,400,400);
  196. 报修.add(scpDome1);
  197. //Connection connection1 = new GetConnection().GetConnection();
  198. String sql1 = "select * from baoxun where Dormitory='"+a.substring(4,7)+"'and Qinlou='"+a.substring(0,4)+"'";
  199. try {
  200. PreparedStatement state;
  201. ResultSet re;
  202. state=connection.prepareStatement(sql1);
  203. re=state.executeQuery();
  204. int count=0;
  205. while(re.next()) {
  206. count++;
  207. }
  208. re = state.executeQuery();
  209. Object[][] info= new Object[count][6];
  210. count = 0;
  211. while(re.next()) {
  212. info[count][0]=Integer.valueOf(re.getString("Number1"));
  213. info[count][1]=re.getString("Qinlou");
  214. info[count][2]=re.getString("Dormitory");
  215. info[count][3]=re.getString("Time1");
  216. info[count][4]=re.getString("Question");
  217. info[count][5]=re.getString("Situation");
  218. count++;
  219. }
  220. String[] title = {"报修编号","寝楼","宿舍号","时间","问题","状况"};
  221. JTable tabDome = new JTable(info,title);
  222. //JTableHeader jth = tabDome.getTableHeader();
  223. scpDome1.getViewport().add(tabDome);
  224. //connection.close();
  225. }catch (Exception e) {
  226. e.printStackTrace();
  227. }
  228. }
  229. }
  230. else {
  231. JOptionPane.showMessageDialog(null, "输入有误!");
  232. }
  233. }
  234. });
  235. }
  236. public void 修改密码() {
  237. JLabel title = new JLabel("修 改 密 码");
  238. title.setForeground(new Color(000));
  239. title.setFont(new Font("华文行楷", Font.PLAIN,40));
  240. title.setBounds(300,20,200,200);
  241. 修改密码.add(title);
  242. JLabel x1 = new JLabel("原密码:");
  243. x1.setForeground(new Color(000));
  244. x1.setFont(new Font("微软雅黑", Font.PLAIN,30));
  245. x1.setBounds(200,140,100,100);
  246. 修改密码.add(x1);
  247. JPasswordField password1 = new JPasswordField(20);
  248. password1.setBounds(330,177,250,30);
  249. 修改密码.add(password1);
  250. // JTextField y1 = new JTextField(5);
  251. // y1.setFont(new Font("微软雅黑", Font.PLAIN,18));
  252. // y1.setSelectedTextColor(new Color(0xFF0000));
  253. // y1.setBounds(340,170,250,40);
  254. // 修改密码.add(y1);
  255. JLabel x2 = new JLabel("新密码:");
  256. x2.setForeground(new Color(000));
  257. x2.setFont(new Font("微软雅黑", Font.PLAIN,30));
  258. x2.setBounds(200,200,100,100);
  259. 修改密码.add(x2);
  260. JPasswordField password2 = new JPasswordField(20);
  261. password2.setBounds(330,238,250,30);
  262. 修改密码.add(password2);
  263. // JTextField y2 = new JTextField(5);
  264. // y2.setFont(new Font("微软雅黑", Font.PLAIN,18));
  265. // y2.setSelectedTextColor(new Color(0xFF0000));
  266. // y2.setBounds(340,230,250,40);
  267. // 修改密码.add(y2);
  268. JButton jb1 = new JButton("修 改");
  269. jb1.setForeground(new Color(16711680));
  270. jb1.setBackground(new Color(5526612));
  271. jb1.setFont(new Font("华文行楷", Font.PLAIN,30));
  272. jb1.setBorderPainted(false);
  273. jb1.setBounds(360,300,130,40);
  274. 修改密码.add(jb1);
  275. jb1.addActionListener(new ActionListener(){
  276. public void actionPerformed(ActionEvent arg0){
  277. String a1 = password1.getText();
  278. String a2 = password2.getText();
  279. password1.setText("");
  280. password2.setText("");
  281. if(a1.equals(pass1)) {
  282. //Connection connection2 = new GetConnection().GetConnection();
  283. String sql = "update qinshizhang set Mima1 = '"+a2+"' where Zhanghao1 = '"+a+"'";
  284. try {
  285. PreparedStatement state;
  286. state=(PreparedStatement)connection.prepareStatement(sql);
  287. state.executeUpdate();
  288. JOptionPane.showMessageDialog(null, "修改成功,请重新登录本系统!");
  289. connection.close();
  290. }catch (Exception e) {
  291. JOptionPane.showMessageDialog(null, "修改失败!");
  292. System.out.println("修改失败");
  293. e.printStackTrace();
  294. }finally {
  295. System.exit(0);
  296. }
  297. }
  298. else {
  299. JOptionPane.showMessageDialog(null, "原密码输入有误!");
  300. }
  301. }
  302. });
  303. }
  304. public static void main(String[] args) {
  305. new 寝室长();
  306. }
  307. }

 5.3宿管员

  1. package 学生宿舍管理系统;
  2. import java.awt.Color;
  3. import java.awt.Dimension;
  4. import java.awt.Font;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.sql.Connection;
  8. import java.sql.PreparedStatement;
  9. import java.sql.ResultSet;
  10. import javax.swing.JButton;
  11. import javax.swing.JComboBox;
  12. import javax.swing.JFrame;
  13. import javax.swing.JLabel;
  14. import javax.swing.JMenu;
  15. import javax.swing.JMenuBar;
  16. import javax.swing.JOptionPane;
  17. import javax.swing.JPanel;
  18. import javax.swing.JPasswordField;
  19. import javax.swing.JScrollPane;
  20. import javax.swing.JTabbedPane;
  21. import javax.swing.JTable;
  22. import javax.swing.JTextField;
  23. public class 宿管员 extends JFrame{
  24. JLabel jlabel=new JLabel();
  25. JScrollPane scpDome = new JScrollPane();
  26. JTabbedPane jbb = new JTabbedPane(JTabbedPane.LEFT);
  27. Connection connection = new GetConnection().GetConnection();
  28. JPanel 查看学生住宿信息,管理学生住宿信息,处理报修信息,管理学生账号,修改密码;
  29. 登录界面 c = new 登录界面();
  30. String a = c.chaxu;//"紫园一栋";//c.chaxu;
  31. String pass1 = c.pass1;//"12345678";//c.pass1;
  32. public 宿管员() {
  33. this.setTitle("宿管员界面");
  34. this.setSize(800,800);
  35. this.setLayout(null);
  36. this.setLocation(350,50);
  37. this.setVisible(true);
  38. 查看学生住宿信息 = new JPanel();
  39. 查看学生住宿信息.setSize(750,750);
  40. 查看学生住宿信息.setLayout(null);
  41. 管理学生住宿信息 = new JPanel();
  42. 管理学生住宿信息.setSize(750,750);
  43. 管理学生住宿信息.setLayout(null);
  44. 处理报修信息 = new JPanel();
  45. 处理报修信息.setSize(750,750);
  46. 处理报修信息.setLayout(null);
  47. 管理学生账号 = new JPanel();
  48. 管理学生账号.setSize(750,750);
  49. 管理学生账号.setLayout(null);
  50. 修改密码 = new JPanel();
  51. 修改密码.setSize(700,500);
  52. 修改密码.setLayout(null);
  53. jbb.addTab("查看学生住宿信息", 查看学生住宿信息);
  54. jbb.addTab("管理学生住宿信息", 管理学生住宿信息);
  55. jbb.addTab("处理报修信息", 处理报修信息);
  56. jbb.addTab("管理学生账号", 管理学生账号);
  57. jbb.addTab("修改密码", 修改密码);
  58. this.setContentPane(jbb);
  59. this.查看学生住宿信息();
  60. this.管理学生住宿信息();
  61. this.处理报修信息();
  62. this.管理学生账号();
  63. this.修改密码();
  64. }
  65. public void 查看学生住宿信息() {
  66. JLabel title1 = new JLabel("查看学生住宿信息");
  67. title1.setForeground(new Color(000));
  68. title1.setFont(new Font("华文行楷", Font.PLAIN,30));
  69. title1.setBounds(186,10,326,40);
  70. 查看学生住宿信息.add(title1);
  71. JButton jbt1 = new JButton("搜索");
  72. jbt1.setForeground(new Color(16711680));
  73. jbt1.setBackground(new Color(13487565));
  74. jbt1.setFont(new Font("华文行楷", Font.PLAIN,13));
  75. jbt1.setBorderPainted(false);
  76. jbt1.setBounds(165,65,60,18);
  77. 查看学生住宿信息.add(jbt1);
  78. JTextField b1 = new JTextField(25);
  79. b1.setFont(new Font("微软雅黑", Font.PLAIN,15));
  80. b1.setSelectedTextColor(new Color(0xFF0000));
  81. b1.setBounds(5,65,160,20);
  82. 查看学生住宿信息.add(b1);
  83. //JScrollPane scpDome = new JScrollPane();
  84. scpDome.setBounds(5,85,650,600);
  85. 查看学生住宿信息.add(scpDome);
  86. //Connection connection = new GetConnection().GetConnection();
  87. String sql = "select * from student where Qinlou='"+a+"'";
  88. try {
  89. PreparedStatement state;
  90. ResultSet re;
  91. state=connection.prepareStatement(sql);
  92. re=state.executeQuery();
  93. int count=0;
  94. while(re.next()) {
  95. count++;
  96. }
  97. re = state.executeQuery();
  98. Object[][] info= new Object[count][8];
  99. count = 0;
  100. while(re.next()) {
  101. info[count][0]=re.getString("Xuehao");
  102. info[count][1]=re.getString("Name");
  103. info[count][2]=re.getString("Sex");
  104. info[count][3]=re.getString("Specialistion");
  105. info[count][4]=re.getString("Class");
  106. info[count][5]=re.getString("Dormitory");
  107. info[count][6]=re.getString("Qinlou");
  108. info[count][7]=re.getString("Phone");
  109. count++;
  110. }
  111. String[] title = {"学号","姓名","性别","专业","班级","宿舍号","寝楼","联系电话"};
  112. JTable tabDome = new JTable(info,title);
  113. //JTableHeader jth = tabDome.getTableHeader();
  114. scpDome.getViewport().add(tabDome);
  115. // connection.close();
  116. }catch (Exception e) {
  117. e.printStackTrace();
  118. }
  119. jbt1.addActionListener(new ActionListener(){
  120. public void actionPerformed(ActionEvent arg0){
  121. String a1 = b1.getText();
  122. b1.setText("");
  123. if(a1.equals("")) {
  124. 查看学生住宿信息.remove(scpDome);
  125. //JScrollPane scpDome = new JScrollPane();
  126. scpDome.setBounds(5,85,650,600);
  127. 查看学生住宿信息.add(scpDome);
  128. //Connection connection = new GetConnection().GetConnection();
  129. String sql2 = "select * from student where Qinlou='"+a+"'";
  130. try {
  131. PreparedStatement state;
  132. ResultSet re;
  133. state=connection.prepareStatement(sql2);
  134. re=state.executeQuery();
  135. int count=0;
  136. while(re.next()) {
  137. count++;
  138. }
  139. re = state.executeQuery();
  140. Object[][] info= new Object[count][8];
  141. count = 0;
  142. while(re.next()) {
  143. info[count][0]=re.getString("Xuehao");
  144. info[count][1]=re.getString("Name");
  145. info[count][2]=re.getString("Sex");
  146. info[count][3]=re.getString("Specialistion");
  147. info[count][4]=re.getString("Class");
  148. info[count][5]=re.getString("Dormitory");
  149. info[count][6]=re.getString("Qinlou");
  150. info[count][7]=re.getString("Phone");
  151. count++;
  152. }
  153. String[] title = {"学号","姓名","性别","专业","班级","宿舍号","寝楼","联系电话"};
  154. JTable tabDome = new JTable(info,title);
  155. //JTableHeader jth = tabDome.getTableHeader();
  156. scpDome.getViewport().add(tabDome);
  157. // connection.close();
  158. }catch (Exception e) {
  159. e.printStackTrace();
  160. }
  161. }else {
  162. //Connection connection2 = new GetConnection().GetConnection();
  163. scpDome.setBounds(5,85,650,600);
  164. 查看学生住宿信息.add(scpDome);
  165. //Connection connection = new GetConnection().GetConnection();
  166. String sql1 = "select * from student where Xuehao like '%"+a1+"%'";
  167. try {
  168. PreparedStatement state;
  169. ResultSet re;
  170. state=connection.prepareStatement(sql1);
  171. re=state.executeQuery();
  172. int count=0;
  173. while(re.next()) {
  174. count++;
  175. }
  176. if(count==0) {
  177. JOptionPane.showMessageDialog(null, "搜索失败,该学号不存在!");
  178. System.out.println("搜索失败,该学号不存在!");
  179. }
  180. re = state.executeQuery();
  181. Object[][] info= new Object[count][8];
  182. count = 0;
  183. while(re.next()) {
  184. info[count][0]=re.getString("Xuehao");
  185. info[count][1]=re.getString("Name");
  186. info[count][2]=re.getString("Sex");
  187. info[count][3]=re.getString("Specialistion");
  188. info[count][4]=re.getString("Class");
  189. info[count][5]=re.getString("Dormitory");
  190. info[count][6]=re.getString("Qinlou");
  191. info[count][7]=re.getString("Phone");
  192. count++;
  193. }
  194. String[] title = {"学号","姓名","性别","专业","班级","宿舍号","寝楼","联系电话"};
  195. JTable tabDome = new JTable(info,title);
  196. //JTableHeader jth = tabDome.getTableHeader();
  197. scpDome.getViewport().add(tabDome);
  198. // connection.close();
  199. }catch (Exception e) {
  200. JOptionPane.showMessageDialog(null, "搜索失败,该学号不存在!");
  201. System.out.println("搜索失败,该学号不存在!");
  202. e.printStackTrace();
  203. }
  204. }
  205. }
  206. });
  207. }
  208. public void 管理学生住宿信息() {
  209. JLabel title1 = new JLabel("添加学生住宿信息");
  210. title1.setForeground(new Color(000));
  211. title1.setFont(new Font("华文行楷", Font.PLAIN,30));
  212. title1.setBounds(186,20,326,40);
  213. 管理学生住宿信息.add(title1);
  214. JLabel r1 = new JLabel("学 号:");
  215. r1.setForeground(new Color(000));
  216. r1.setFont(new Font("微软雅黑", Font.PLAIN,20));
  217. r1.setBounds(77,50,100,100);
  218. 管理学生住宿信息.add(r1);
  219. JTextField b1 = new JTextField(25);
  220. b1.setFont(new Font("微软雅黑", Font.PLAIN,15));
  221. b1.setSelectedTextColor(new Color(0xFF0000));
  222. b1.setBounds(140,90,160,30);
  223. 管理学生住宿信息.add(b1);
  224. JLabel r2 = new JLabel("姓 名:");
  225. r2.setForeground(new Color(000));
  226. r2.setFont(new Font("微软雅黑", Font.PLAIN,20));
  227. r2.setBounds(350,50,100,100);
  228. 管理学生住宿信息.add(r2);
  229. JTextField b2 = new JTextField(25);
  230. b2.setFont(new Font("微软雅黑", Font.PLAIN,15));
  231. b2.setSelectedTextColor(new Color(0xFF0000));
  232. b2.setBounds(440,90,160,30);
  233. 管理学生住宿信息.add(b2);
  234. JLabel r3 = new JLabel("性 别:");
  235. r3.setForeground(new Color(000));
  236. r3.setFont(new Font("微软雅黑", Font.PLAIN,20));
  237. r3.setBounds(77,100,100,100);
  238. 管理学生住宿信息.add(r3);
  239. JTextField b3 = new JTextField(25);
  240. b3.setFont(new Font("微软雅黑", Font.PLAIN,15));
  241. b3.setSelectedTextColor(new Color(0xFF0000));
  242. b3.setBounds(140,135,160,30);
  243. 管理学生住宿信息.add(b3);
  244. JLabel r4 = new JLabel("专 业:");
  245. r4.setForeground(new Color(000));
  246. r4.setFont(new Font("微软雅黑", Font.PLAIN,20));
  247. r4.setBounds(350,100,100,100);
  248. 管理学生住宿信息.add(r4);
  249. JTextField b4 = new JTextField(25);
  250. b4.setFont(new Font("微软雅黑", Font.PLAIN,15));
  251. b4.setSelectedTextColor(new Color(0xFF0000));
  252. b4.setBounds(440,135,160,30);
  253. 管理学生住宿信息.add(b4);
  254. JLabel r5 = new JLabel("班 级:");
  255. r5.setForeground(new Color(000));
  256. r5.setFont(new Font("微软雅黑", Font.PLAIN,20));
  257. r5.setBounds(77,150,100,100);
  258. 管理学生住宿信息.add(r5);
  259. JTextField b5 = new JTextField(25);
  260. b5.setFont(new Font("微软雅黑", Font.PLAIN,15));
  261. b5.setSelectedTextColor(new Color(0xFF0000));
  262. b5.setBounds(140,188,160,30);
  263. 管理学生住宿信息.add(b5);
  264. JLabel r6 = new JLabel("宿 舍 号:");
  265. r6.setForeground(new Color(000));
  266. r6.setFont(new Font("微软雅黑", Font.PLAIN,20));
  267. r6.setBounds(350,150,100,100);
  268. 管理学生住宿信息.add(r6);
  269. JTextField b6 = new JTextField(25);
  270. b6.setFont(new Font("微软雅黑", Font.PLAIN,15));
  271. b6.setSelectedTextColor(new Color(0xFF0000));
  272. b6.setBounds(440,188,160,30);
  273. 管理学生住宿信息.add(b6);
  274. JLabel r7 = new JLabel("寝 楼:");
  275. r7.setForeground(new Color(000));
  276. r7.setFont(new Font("微软雅黑", Font.PLAIN,20));
  277. r7.setBounds(77,200,100,100);
  278. 管理学生住宿信息.add(r7);
  279. JTextField b7 = new JTextField(25);
  280. b7.setFont(new Font("微软雅黑", Font.PLAIN,15));
  281. b7.setSelectedTextColor(new Color(0xFF0000));
  282. b7.setBounds(140,238,160,30);
  283. 管理学生住宿信息.add(b7);
  284. JLabel r8 = new JLabel("联系电话:");
  285. r8.setForeground(new Color(000));
  286. r8.setFont(new Font("微软雅黑", Font.PLAIN,20));
  287. r8.setBounds(350,200,100,100);
  288. 管理学生住宿信息.add(r8);
  289. JTextField b8 = new JTextField(25);
  290. b8.setFont(new Font("微软雅黑", Font.PLAIN,15));
  291. b8.setSelectedTextColor(new Color(0xFF0000));
  292. b8.setBounds(440,238,160,30);
  293. 管理学生住宿信息.add(b8);
  294. JButton jbt1 = new JButton("添 加");
  295. jbt1.setForeground(new Color(16711680));
  296. jbt1.setBackground(new Color(13487565));
  297. jbt1.setFont(new Font("华文行楷", Font.PLAIN,30));
  298. jbt1.setBorderPainted(false);
  299. jbt1.setBounds(150,300,130,40);
  300. 管理学生住宿信息.add(jbt1);
  301. JButton jbt2 = new JButton("重 置");
  302. jbt2.setForeground(new Color(16711680));
  303. jbt2.setBackground(new Color(13487565));
  304. jbt2.setFont(new Font("华文行楷", Font.PLAIN,30));
  305. jbt2.setBorderPainted(false);
  306. jbt2.setBounds(370,300,130,40);
  307. 管理学生住宿信息.add(jbt2);
  308. jbt2.addActionListener(new ActionListener(){//为重置按钮添加监听事件
  309. //同时清空name、password的数据
  310. public void actionPerformed(ActionEvent arg0) {
  311. b1.setText("");
  312. b2.setText("");
  313. b3.setText("");
  314. b4.setText("");
  315. b5.setText("");
  316. b6.setText("");
  317. b7.setText("");
  318. b8.setText("");
  319. }
  320. });
  321. jbt1.addActionListener(new ActionListener(){
  322. public void actionPerformed(ActionEvent arg0){
  323. String a1 = b1.getText();
  324. String a2 = b2.getText();
  325. String a3 = b3.getText();
  326. String a4 = b4.getText();
  327. String a5 = b5.getText();
  328. String a6 = b6.getText();
  329. String a7 = b7.getText();
  330. String a8 = b8.getText();
  331. if(a1!=null&& a2!=null && a3!=null&& a4!=null) {
  332. //Connection connection2 = new GetConnection().GetConnection();
  333. String sql = "insert into student(Xuehao,Name,Sex,Specialistion,Class,Dormitory,Qinlou,Phone) values('"+a1+"','"+a2+"','"+a3+"','"+a4+"','"+a5+"','"+a6+"','"+a7+"','"+a8+"')";
  334. try {
  335. PreparedStatement state;
  336. state=(PreparedStatement)connection.prepareStatement(sql);
  337. // int abc = Integer.valueOf(a8);;
  338. // state.setInt(1, abc);
  339. state.executeUpdate();
  340. JOptionPane.showMessageDialog(null, "添加成功!");
  341. }catch (Exception e) {
  342. JOptionPane.showMessageDialog(null, "添加失败,该学号已经存在!");
  343. System.out.println("添加失败,该学号已经存在!");
  344. e.printStackTrace();
  345. }finally {
  346. 查看学生住宿信息.remove(scpDome);
  347. //JScrollPane scpDome = new JScrollPane();
  348. scpDome.setBounds(5,85,650,600);
  349. 查看学生住宿信息.add(scpDome);
  350. //Connection connection = new GetConnection().GetConnection();
  351. String sql1 = "select * from student where Qinlou='"+a+"'";
  352. try {
  353. PreparedStatement state;
  354. ResultSet re;
  355. state=connection.prepareStatement(sql1);
  356. re=state.executeQuery();
  357. int count=0;
  358. while(re.next()) {
  359. count++;
  360. }
  361. re = state.executeQuery();
  362. Object[][] info= new Object[count][8];
  363. count = 0;
  364. while(re.next()) {
  365. info[count][0]=re.getString("Xuehao");
  366. info[count][1]=re.getString("Name");
  367. info[count][2]=re.getString("Sex");
  368. info[count][3]=re.getString("Specialistion");
  369. info[count][4]=re.getString("Class");
  370. info[count][5]=re.getString("Dormitory");
  371. info[count][6]=re.getString("Qinlou");
  372. info[count][7]=re.getString("Phone");
  373. count++;
  374. }
  375. String[] title = {"学号","姓名","性别","专业","班级","宿舍号","寝楼","联系电话"};
  376. JTable tabDome = new JTable(info,title);
  377. //JTableHeader jth = tabDome.getTableHeader();
  378. scpDome.getViewport().add(tabDome);
  379. // connection.close();
  380. }catch (Exception e) {
  381. e.printStackTrace();
  382. }
  383. }
  384. }
  385. else {
  386. JOptionPane.showMessageDialog(null, "输入有误,请修改信息!");
  387. }
  388. }
  389. });
  390. JLabel title2 = new JLabel("删除学生住宿信息");
  391. title2.setForeground(new Color(000));
  392. title2.setFont(new Font("华文行楷", Font.PLAIN,30));
  393. title2.setBounds(186,450,326,40);
  394. 管理学生住宿信息.add(title2);
  395. JLabel title3 = new JLabel("#(删除学生住宿信息只用提供学生的学号)");
  396. title3.setForeground(new Color(7396243));
  397. title3.setFont(new Font("华文行楷", Font.PLAIN,14));
  398. title3.setBounds(260,480,326,40);
  399. 管理学生住宿信息.add(title3);
  400. JLabel x1 = new JLabel(" 学 号:");
  401. x1.setForeground(new Color(000));
  402. x1.setFont(new Font("微软雅黑", Font.PLAIN,20));
  403. x1.setBounds(77,512,100,100);
  404. 管理学生住宿信息.add(x1);
  405. JTextField y1 = new JTextField(25);
  406. y1.setFont(new Font("微软雅黑", Font.PLAIN,15));
  407. y1.setSelectedTextColor(new Color(0xFF0000));
  408. y1.setBounds(160,550,170,30);
  409. 管理学生住宿信息.add(y1);
  410. JButton jbt3 = new JButton("删 除");
  411. jbt3.setForeground(new Color(16711680));
  412. jbt3.setBackground(new Color(13487565));
  413. jbt3.setFont(new Font("华文行楷", Font.PLAIN,30));
  414. jbt3.setBorderPainted(false);
  415. jbt3.setBounds(410,545,130,40);
  416. 管理学生住宿信息.add(jbt3);
  417. jbt3.addActionListener(new ActionListener(){
  418. public void actionPerformed(ActionEvent arg0){
  419. String a1 = y1.getText();
  420. y1.setText("");
  421. if(a1!=null) {
  422. //Connection connection2 = new GetConnection().GetConnection();
  423. String sql = "delete from student"+
  424. " where Xuehao = '"+a1+"'";
  425. try {
  426. PreparedStatement state;
  427. state=(PreparedStatement)connection.prepareStatement(sql);
  428. // int abc = Integer.valueOf(a8);;
  429. // state.setInt(1, abc);
  430. state.executeUpdate();
  431. JOptionPane.showMessageDialog(null, "删除成功!");
  432. }catch (Exception e) {
  433. JOptionPane.showMessageDialog(null, "删除失败,该学号不存在!");
  434. System.out.println("删除失败,该学号不存在!");
  435. e.printStackTrace();
  436. }finally {
  437. 查看学生住宿信息.remove(scpDome);
  438. //JScrollPane scpDome = new JScrollPane();
  439. scpDome.setBounds(5,5,650,600);
  440. 查看学生住宿信息.add(scpDome);
  441. //Connection connection = new GetConnection().GetConnection();
  442. String sql1 = "select * from student where Qinlou='"+a+"'";
  443. try {
  444. PreparedStatement state;
  445. ResultSet re;
  446. state=connection.prepareStatement(sql1);
  447. re=state.executeQuery();
  448. int count=0;
  449. while(re.next()) {
  450. count++;
  451. }
  452. re = state.executeQuery();
  453. Object[][] info= new Object[count][8];
  454. count = 0;
  455. while(re.next()) {
  456. info[count][0]=re.getString("Xuehao");
  457. info[count][1]=re.getString("Name");
  458. info[count][2]=re.getString("Sex");
  459. info[count][3]=re.getString("Specialistion");
  460. info[count][4]=re.getString("Class");
  461. info[count][5]=re.getString("Dormitory");
  462. info[count][6]=re.getString("Qinlou");
  463. info[count][7]=re.getString("Phone");
  464. count++;
  465. }
  466. String[] title = {"学号","姓名","性别","专业","班级","宿舍号","寝楼","联系电话"};
  467. JTable tabDome = new JTable(info,title);
  468. //JTableHeader jth = tabDome.getTableHeader();
  469. scpDome.getViewport().add(tabDome);
  470. // connection.close();
  471. }catch (Exception e) {
  472. e.printStackTrace();
  473. }
  474. }
  475. }
  476. else {
  477. JOptionPane.showMessageDialog(null, "输入有误,学号不能为空!");
  478. }
  479. }
  480. });
  481. }
  482. public void 处理报修信息() {
  483. JLabel title1 = new JLabel("处理报修信息");
  484. title1.setForeground(new Color(000));
  485. title1.setFont(new Font("华文行楷", Font.PLAIN,30));
  486. title1.setBounds(186,10,326,40);
  487. 处理报修信息.add(title1);
  488. JScrollPane scpDome1 = new JScrollPane();
  489. scpDome1.setBounds(5,80,400,550);
  490. 处理报修信息.add(scpDome1);
  491. //Connection connection1 = new GetConnection().GetConnection();
  492. String sql = "select * from baoxun where Qinlou='"+a+"'";
  493. try {
  494. PreparedStatement state;
  495. ResultSet re;
  496. state=connection.prepareStatement(sql);
  497. re=state.executeQuery();
  498. int count=0;
  499. while(re.next()) {
  500. count++;
  501. }
  502. re = state.executeQuery();
  503. Object[][] info= new Object[count][6];
  504. count = 0;
  505. while(re.next()) {
  506. info[count][0]=Integer.valueOf(re.getString("Number1"));
  507. info[count][1]=re.getString("Qinlou");
  508. info[count][2]=re.getString("Dormitory");
  509. info[count][3]=re.getString("Time1");
  510. info[count][4]=re.getString("Question");
  511. info[count][5]=re.getString("Situation");
  512. count++;
  513. }
  514. String[] title = {"报修编号","寝楼","宿舍号","时间","问题","状况"};
  515. JTable tabDome = new JTable(info,title);
  516. //JTableHeader jth = tabDome.getTableHeader();
  517. scpDome1.getViewport().add(tabDome);
  518. //connection.close();
  519. }catch (Exception e) {
  520. e.printStackTrace();
  521. }
  522. JLabel title2 = new JLabel("处 理");
  523. title2.setForeground(new Color(2186785));
  524. title2.setFont(new Font("华文行楷", Font.PLAIN,30));
  525. title2.setBounds(480,180,326,40);
  526. 处理报修信息.add(title2);
  527. JLabel r1 = new JLabel("处理序号:");
  528. r1.setForeground(new Color(000));
  529. r1.setFont(new Font("微软雅黑", Font.PLAIN,20));
  530. r1.setBounds(410,200,100,100);
  531. 处理报修信息.add(r1);
  532. JTextField b1 = new JTextField(25);
  533. b1.setFont(new Font("微软雅黑", Font.PLAIN,15));
  534. b1.setSelectedTextColor(new Color(0xFF0000));
  535. b1.setBounds(500,238,100,30);
  536. 处理报修信息.add(b1);
  537. JLabel r2 = new JLabel("处理状态:");
  538. r2.setForeground(new Color(000));
  539. r2.setFont(new Font("微软雅黑", Font.PLAIN,20));
  540. r2.setBounds(410,254,100,100);
  541. 处理报修信息.add(r2);
  542. JComboBox<Object> jc2 = new JComboBox<>();
  543. jc2.setBounds(500,290,100,30);
  544. jc2.addItem("等待处理");
  545. jc2.addItem("正在处理");
  546. jc2.addItem("已处理");
  547. 处理报修信息.add(jc2);
  548. JButton jb1 = new JButton("处 理");
  549. jb1.setForeground(new Color(16711680));
  550. jb1.setBackground(new Color(5526612));
  551. jb1.setFont(new Font("华文行楷", Font.PLAIN,30));
  552. jb1.setBorderPainted(false);
  553. jb1.setBounds(450,360,130,40);
  554. 处理报修信息.add(jb1);
  555. jb1.addActionListener(new ActionListener(){
  556. public void actionPerformed(ActionEvent arg0){
  557. String a1 = b1.getText();
  558. String a2 = jc2.getSelectedItem().toString();
  559. b1.setText("");
  560. //Connection connection2 = new GetConnection().GetConnection();
  561. String sql1 = "update baoxun set Situation = '"+a2+"' where Number1= ?";
  562. try {
  563. PreparedStatement state;
  564. state=(PreparedStatement)connection.prepareStatement(sql1);
  565. int z = Integer.parseInt(a1);
  566. state.setInt(1, z);
  567. state.executeUpdate();
  568. JOptionPane.showMessageDialog(null, "修改成功!");
  569. //connection.close();
  570. }catch (Exception e) {
  571. JOptionPane.showMessageDialog(null, "你输入的编号有问题,请重新输入!");
  572. System.out.println("修改失败");
  573. e.printStackTrace();
  574. }finally {
  575. 处理报修信息.remove(scpDome1);
  576. JScrollPane scpDome1 = new JScrollPane();
  577. scpDome1.setBounds(5,80,400,550);
  578. 处理报修信息.add(scpDome1);
  579. //Connection connection1 = new GetConnection().GetConnection();
  580. String sql2 = "select * from baoxun where Qinlou='"+a+"'";
  581. try {
  582. PreparedStatement state;
  583. ResultSet re;
  584. state=connection.prepareStatement(sql2);
  585. re=state.executeQuery();
  586. int count=0;
  587. while(re.next()) {
  588. count++;
  589. }
  590. re = state.executeQuery();
  591. Object[][] info= new Object[count][6];
  592. count = 0;
  593. while(re.next()) {
  594. info[count][0]=Integer.valueOf(re.getString("Number1"));
  595. info[count][1]=re.getString("Qinlou");
  596. info[count][2]=re.getString("Dormitory");
  597. info[count][3]=re.getString("Time1");
  598. info[count][4]=re.getString("Question");
  599. info[count][5]=re.getString("Situation");
  600. count++;
  601. }
  602. String[] title = {"报修编号","寝楼","宿舍号","时间","问题","状况"};
  603. JTable tabDome = new JTable(info,title);
  604. //JTableHeader jth = tabDome.getTableHeader();
  605. scpDome1.getViewport().add(tabDome);
  606. //connection.close();
  607. }catch (Exception e) {
  608. e.printStackTrace();
  609. }
  610. }
  611. }
  612. });
  613. }
  614. public void 管理学生账号() {
  615. JLabel title1 = new JLabel("管理学生账号");
  616. title1.setForeground(new Color(000));
  617. title1.setFont(new Font("华文行楷", Font.PLAIN,30));
  618. title1.setBounds(186,10,326,40);
  619. 管理学生账号.add(title1);
  620. JScrollPane scpDome1 = new JScrollPane();
  621. scpDome1.setBounds(5,80,320,550);
  622. 管理学生账号.add(scpDome1);
  623. //Connection connection1 = new GetConnection().GetConnection();
  624. String sql = "select * from qinshizhang ";
  625. try {
  626. PreparedStatement state;
  627. ResultSet re;
  628. state=connection.prepareStatement(sql);
  629. re=state.executeQuery();
  630. int count=0;
  631. while(re.next()) {
  632. count++;
  633. }
  634. re = state.executeQuery();
  635. Object[][] info= new Object[count][2];
  636. count = 0;
  637. while(re.next()) {
  638. info[count][0]=re.getString("Zhanghao1");
  639. info[count][1]=re.getString("Mima1");
  640. count++;
  641. }
  642. String[] title = {"账号","密码"};
  643. JTable tabDome = new JTable(info,title);
  644. //JTableHeader jth = tabDome.getTableHeader();
  645. scpDome1.getViewport().add(tabDome);
  646. //connection.close();
  647. }catch (Exception e) {
  648. e.printStackTrace();
  649. }
  650. JLabel title2 = new JLabel("管理账号");
  651. title2.setForeground(new Color(3329433));
  652. title2.setFont(new Font("华文行楷", Font.PLAIN,30));
  653. title2.setBounds(440,80,326,40);
  654. 管理学生账号.add(title2);
  655. JLabel r1 = new JLabel(" 账 号:");
  656. r1.setForeground(new Color(000));
  657. r1.setFont(new Font("微软雅黑", Font.PLAIN,20));
  658. r1.setBounds(370,120,100,100);
  659. 管理学生账号.add(r1);
  660. JTextField b1 = new JTextField(25);
  661. b1.setFont(new Font("微软雅黑", Font.PLAIN,15));
  662. b1.setSelectedTextColor(new Color(0xFF0000));
  663. b1.setBounds(460,158,150,30);
  664. 管理学生账号.add(b1);
  665. JLabel r2 = new JLabel(" 密 码:");
  666. r2.setForeground(new Color(000));
  667. r2.setFont(new Font("微软雅黑", Font.PLAIN,20));
  668. r2.setBounds(370,180,100,100);
  669. 管理学生账号.add(r2);
  670. JTextField b2 = new JTextField(25);
  671. b2.setFont(new Font("微软雅黑", Font.PLAIN,15));
  672. b2.setSelectedTextColor(new Color(0xFF0000));
  673. b2.setBounds(460,215,150,30);
  674. 管理学生账号.add(b2);
  675. JButton jb1 = new JButton("添加");
  676. jb1.setForeground(new Color(16711680));
  677. jb1.setBackground(new Color(5526612));
  678. jb1.setFont(new Font("华文行楷", Font.PLAIN,20));
  679. jb1.setBorderPainted(false);
  680. jb1.setBounds(380,280,80,40);
  681. 管理学生账号.add(jb1);
  682. JButton jb2 = new JButton("删除");
  683. jb2.setForeground(new Color(16711680));
  684. jb2.setBackground(new Color(5526612));
  685. jb2.setFont(new Font("华文行楷", Font.PLAIN,20));
  686. jb2.setBorderPainted(false);
  687. jb2.setBounds(530,280,80,40);
  688. 管理学生账号.add(jb2);
  689. jb1.addActionListener(new ActionListener(){
  690. public void actionPerformed(ActionEvent arg0){
  691. String a1 = b1.getText();
  692. String a2 = b2.getText();
  693. b1.setText("");
  694. b2.setText("");
  695. //Connection connection2 = new GetConnection().GetConnection();
  696. String sql = "insert into qinshizhang(Zhanghao1,Mima1) values('"+a1+"','"+a2+"')";
  697. try {
  698. PreparedStatement state;
  699. state=(PreparedStatement)connection.prepareStatement(sql);
  700. // int abc = Integer.valueOf(a8);;
  701. // state.setInt(1, abc);
  702. state.executeUpdate();
  703. JOptionPane.showMessageDialog(null, "添加成功!");
  704. }catch (Exception e) {
  705. JOptionPane.showMessageDialog(null, "添加失败,该账号已经存在!");
  706. System.out.println("添加失败,该账号已经存在!");
  707. e.printStackTrace();
  708. }finally {
  709. 管理学生账号.remove(scpDome1);
  710. JScrollPane scpDome1 = new JScrollPane();
  711. scpDome1.setBounds(5,80,320,550);
  712. 管理学生账号.add(scpDome1);
  713. //Connection connection1 = new GetConnection().GetConnection();
  714. String sql1 = "select * from qinshizhang ";
  715. try {
  716. PreparedStatement state;
  717. ResultSet re;
  718. state=connection.prepareStatement(sql1);
  719. re=state.executeQuery();
  720. int count=0;
  721. while(re.next()) {
  722. count++;
  723. }
  724. re = state.executeQuery();
  725. Object[][] info= new Object[count][2];
  726. count = 0;
  727. while(re.next()) {
  728. info[count][0]=re.getString("Zhanghao1");
  729. info[count][1]=re.getString("Mima1");
  730. count++;
  731. }
  732. String[] title = {"账号","密码"};
  733. JTable tabDome = new JTable(info,title);
  734. //JTableHeader jth = tabDome.getTableHeader();
  735. scpDome1.getViewport().add(tabDome);
  736. //connection.close();
  737. }catch (Exception e) {
  738. e.printStackTrace();
  739. }
  740. }
  741. }
  742. });
  743. jb2.addActionListener(new ActionListener(){
  744. public void actionPerformed(ActionEvent arg0){
  745. String a1 = b1.getText();
  746. //String a2 = b2.getText();
  747. b1.setText("");
  748. b2.setText("");
  749. //Connection connection2 = new GetConnection().GetConnection();
  750. String sql2 = "delete from qinshizhang where Zhanghao1='"+a1+"'";
  751. try {
  752. PreparedStatement state;
  753. state=(PreparedStatement)connection.prepareStatement(sql2);
  754. // int abc = Integer.valueOf(a8);;
  755. // state.setInt(1, abc);
  756. state.executeUpdate();
  757. JOptionPane.showMessageDialog(null, "删除成功!");
  758. }catch (Exception e) {
  759. JOptionPane.showMessageDialog(null, "删除失败,该账号不存在!");
  760. System.out.println("删除失败,该账号不存在!");
  761. e.printStackTrace();
  762. }finally {
  763. 管理学生账号.remove(scpDome1);
  764. JScrollPane scpDome1 = new JScrollPane();
  765. scpDome1.setBounds(5,80,320,550);
  766. 管理学生账号.add(scpDome1);
  767. //Connection connection1 = new GetConnection().GetConnection();
  768. String sql1 = "select * from qinshizhang ";
  769. try {
  770. PreparedStatement state;
  771. ResultSet re;
  772. state=connection.prepareStatement(sql1);
  773. re=state.executeQuery();
  774. int count=0;
  775. while(re.next()) {
  776. count++;
  777. }
  778. re = state.executeQuery();
  779. Object[][] info= new Object[count][2];
  780. count = 0;
  781. while(re.next()) {
  782. info[count][0]=re.getString("Zhanghao1");
  783. info[count][1]=re.getString("Mima1");
  784. count++;
  785. }
  786. String[] title = {"账号","密码"};
  787. JTable tabDome = new JTable(info,title);
  788. //JTableHeader jth = tabDome.getTableHeader();
  789. scpDome1.getViewport().add(tabDome);
  790. //connection.close();
  791. }catch (Exception e) {
  792. e.printStackTrace();
  793. }
  794. }
  795. }
  796. });
  797. }
  798. public void 修改密码() {
  799. JLabel title = new JLabel("修 改 密 码");
  800. title.setForeground(new Color(000));
  801. title.setFont(new Font("华文行楷", Font.PLAIN,40));
  802. title.setBounds(240,20,200,200);
  803. 修改密码.add(title);
  804. JLabel x1 = new JLabel("原密码:");
  805. x1.setForeground(new Color(000));
  806. x1.setFont(new Font("微软雅黑", Font.PLAIN,30));
  807. x1.setBounds(140,140,100,100);
  808. 修改密码.add(x1);
  809. JPasswordField password1 = new JPasswordField(20);
  810. password1.setBounds(270,177,250,30);
  811. 修改密码.add(password1);
  812. // JTextField y1 = new JTextField(5);
  813. // y1.setFont(new Font("微软雅黑", Font.PLAIN,18));
  814. // y1.setSelectedTextColor(new Color(0xFF0000));
  815. // y1.setBounds(340,170,250,40);
  816. // 修改密码.add(y1);
  817. JLabel x2 = new JLabel("新密码:");
  818. x2.setForeground(new Color(000));
  819. x2.setFont(new Font("微软雅黑", Font.PLAIN,30));
  820. x2.setBounds(140,200,100,100);
  821. 修改密码.add(x2);
  822. JPasswordField password2 = new JPasswordField(20);
  823. password2.setBounds(270,238,250,30);
  824. 修改密码.add(password2);
  825. // JTextField y2 = new JTextField(5);
  826. // y2.setFont(new Font("微软雅黑", Font.PLAIN,18));
  827. // y2.setSelectedTextColor(new Color(0xFF0000));
  828. // y2.setBounds(340,230,250,40);
  829. // 修改密码.add(y2);
  830. JButton jb1 = new JButton("修 改");
  831. jb1.setForeground(new Color(16711680));
  832. jb1.setBackground(new Color(5526612));
  833. jb1.setFont(new Font("华文行楷", Font.PLAIN,30));
  834. jb1.setBorderPainted(false);
  835. jb1.setBounds(300,300,130,40);
  836. 修改密码.add(jb1);
  837. jb1.addActionListener(new ActionListener(){
  838. public void actionPerformed(ActionEvent arg0){
  839. String a1 = password1.getText();
  840. String a2 = password2.getText();
  841. password1.setText("");
  842. password2.setText("");
  843. if(a1.equals(pass1)) {
  844. //Connection connection2 = new GetConnection().GetConnection();
  845. String sql = "update Suguan set Mima = '"+a2+"' where Zhanghao = '"+a+"'";
  846. try {
  847. PreparedStatement state;
  848. state=(PreparedStatement)connection.prepareStatement(sql);
  849. state.executeUpdate();
  850. JOptionPane.showMessageDialog(null, "修改成功,请重新登录本系统!");
  851. connection.close();
  852. }catch (Exception e) {
  853. JOptionPane.showMessageDialog(null, "修改失败!");
  854. System.out.println("修改失败");
  855. e.printStackTrace();
  856. }finally {
  857. System.exit(0);
  858. }
  859. }
  860. else {
  861. JOptionPane.showMessageDialog(null, "原密码输入有误!");
  862. }
  863. }
  864. });
  865. }
  866. // public static void main(String [] args)
  867. // {
  868. // new 宿管员();
  869. // }
  870. }

 5.4数据库链接辅助类

  1. package 学生宿舍管理系统;
  2. import java.sql.Connection;
  3. import java.sql.DriverManager;
  4. import java.sql.ResultSet;
  5. import java.sql.Statement;
  6. //连接到mySQL数据库
  7. public class GetConnection {
  8. private Connection con=null;
  9. public Connection GetConnection(){
  10. //数据库连接URL(url:就是一个jdbc的规范的约定)
  11. String url = "jdbc:mysql://localhost:3306/sushesystem?useSSL=false&serverTimezone=UTC";
  12. String username = "root";
  13. String passwords = "yu1314520";
  14. try {
  15. Class.forName("com.mysql.cj.jdbc.Driver");//加载数据库驱动
  16. con= DriverManager.getConnection(url, username, passwords);//数据库连接用户名、密码
  17. } catch (Exception e) {
  18. // TODO 自动生成的 catch 块
  19. e.printStackTrace();
  20. }
  21. return con;// 返回的con就是一个数据库连接对象,通过它你就可以对这个数据库做添删改查的动作
  22. }
  23. }

六、程序运行和数据库截图

  • 登录界面

  •  宿管员操作界面

  • 管理学生信息(添加)

  • 管理学生信息(删除)

  • 处理报修信息

  • 管理学生账号

  • 修改密码

  • 寝室人员查看

  • 报修操作

  • 寝室长账号表

  • 宿管员账号

  • 学生信息

  • 报修信息

  • 存储过程

六、源代码链接

链接:https://download.csdn.net/download/m0_56068773/88808954

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号