1 系统需求分析
学校每年都有新生入学、老生毕业,还有其他各种人事变动。如何有效地管理这些学生的信息,帮助学校和老师掌握学生的情况,这就是学生信息管理系统需要完成的功能。
1.1 系统功能分析
本系统主要的功能是收集学生的个人信息,以便向教师提供每个学生在校的情况。系统的主要功能有:
l ①学生个人信息输入,包括:姓名、性别、院系、生日、籍贯、生源所在地等。
l ②学生流动情况的输入,包括:转系、休学、复学、退学、毕业。
③奖惩情况的输入。
l ④学生个人情况查询和修改,包括流动情况和奖罚情况。
1.2 系统功能模块设计(划分)
根据系统功能要求可以将系统分解成几个模块来分别设计应用程序界面,如图所示。
1.3 与其它系统的关系
学生信息管理系统是校园信息管理系统的一个组成部分。它为其它系统,如班级信息管理系统、教学管理系统、成绩单系统、宿舍分配系统等,提供学生的基本情况。同时需要其他系统提供的班级设置和院系设置等情况。这些系统可以使用同一个数据库,直接相互调用所需的数据。
1.4 数据流程图
学生信息管理系统的数据流程如图所示。
学生信息管理系统数据流程图
2 数据库设计
2.1 数据库需求分析
根据上一节的数据流程图,可以列出以下记录学生信息所需的数据项和数据结构:
l ①学生:学号、姓名、性别、生日、籍贯、所在院系、所在班级。
l ②处罚记录:记录号、级别、处罚对象、记录时间、详细描述、是否生效。
l ③奖励记录:记录号、级别、奖励对象、记录时间、详细描述。
l ④学籍变更记录:记录号、变更情况、记录对象、记录时间、详细描述。
所需的外部数据支持:
l ①班级:班级编号、班级名称、所属院系。
l ②院系:代码、名称。
2.2 数据库概念结构设计
本系统所需数据的 E-R 模型图。
2.3 数据库逻辑结构设计
根据系统 E-R 图,需要设计 4 个数据表来存放学生的信息。为了系统的完整,系统中包括了应用程序设计中所需的 2 个外部数据表。为了优化数据表结构,部分字段采用代码形式,因此需要附加 3 个代码表。这 9 个数据表的结构如表 1 到表 9 所示。
表 1 STUDENT 学生个人信息表
表 2 CHANGE 学籍变更信息表
表 3 REWARD 奖励记录信息表
表 4 PUNISHMENT 处罚记录信息表
表 5 DEPARTMENT 院系信息表
表 6 CLASS 班级信息表
表7 密码表
表 8 REWARD_LEVELS 奖励等级代码表
表 9 PUNISH_LEVELS 处罚等级代码表
2.4 数据库的建立
2.4.1 数据库的建立(请设计者完成)
不说了,直接上图上代码
代码如下
package com.itheima.jdbc;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.Font;
import java.awt.HeadlessException;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.awt.event.ActionEvent;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JRadioButton;
import java.awt.Color;
/**
*
* @author lzg
* @date 2019年12月21日 下午6:50:00
* @Description
*/
@SuppressWarnings("serial")
public class Register extends JFrame {
public int flag = 1;
JDBCutil query = new JDBCutil();// 创建数据库的操作类对象,用于数据库的各种操作
private JPanel contentPane;
private JPasswordField passwordField_1;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Register frame = new Register();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Register() {
setTitle("用户登录");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 435, 550);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
setLocationRelativeTo(null);// 窗体居中显示
JLabel lblNewLabel = new JLabel("账 号:");
lblNewLabel.setForeground(Color.BLACK);
lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING);
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel.setBounds(38, 329, 50, 35);
contentPane.add(lblNewLabel);
textField = new JTextField();
textField.setFont(new Font("微软雅黑", Font.PLAIN, 14));
textField.setBounds(98, 329, 311, 35);
contentPane.add(textField);
textField.setColumns(10);
JLabel label = new JLabel("密 码:");
label.setHorizontalAlignment(SwingConstants.TRAILING);
label.setFont(new Font("微软雅黑", Font.BOLD, 16));
label.setBounds(38, 374, 50, 35);
contentPane.add(label);
passwordField_1 = new JPasswordField();
passwordField_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
passwordField_1.setBounds(98, 374, 311, 35);
contentPane.add(passwordField_1);
JButton button = new JButton("取消");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "恭喜你已安全退出!", "信息", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
});
button.setFont(new Font("微软雅黑", Font.BOLD, 18));
button.setBounds(279, 460, 93, 41);
contentPane.add(button);
ButtonGroup group = new ButtonGroup();
JLabel lblNewLabel_1 = new JLabel("");
lblNewLabel_1
.setIcon(new ImageIcon(Register.class.getResource("/ico/u=1173560350,67453878&fm=26&gp=0[1].jpg")));
lblNewLabel_1.setBounds(0, 0, 424, 283);
contentPane.add(lblNewLabel_1);
JRadioButton rdbtnNewRadioButton = new JRadioButton("\u5B66\u751F");
rdbtnNewRadioButton.setSelected(true); // 默认选择
rdbtnNewRadioButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
flag = 1;// 学生
}
});
rdbtnNewRadioButton.setFont(new Font("微软雅黑", Font.BOLD, 16));
rdbtnNewRadioButton.setBounds(128, 416, 69, 23);
contentPane.add(rdbtnNewRadioButton);
JRadioButton rdbtnNewRadioButton_1 = new JRadioButton("\u6559\u5E08");
rdbtnNewRadioButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
flag = 2;// 教师
}
});
rdbtnNewRadioButton_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
rdbtnNewRadioButton_1.setBounds(248, 416, 61, 23);
contentPane.add(rdbtnNewRadioButton_1);
group.add(rdbtnNewRadioButton_1);
group.add(rdbtnNewRadioButton);
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (flag == 1) {
String sql = "select *from student_password where 账号='" + textField.getText() + "'and 密码='"
+ new String(passwordField_1.getPassword()) + "'";
try {
ResultSet rs = query.query(sql);// 调用数据库的查询方法
if (textField.getText().length() <= 0 && passwordField_1.getPassword().length <= 0) {
JOptionPane.showMessageDialog(null, "账号和密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
} else if (textField.getText().length() <= 0) {
JOptionPane.showMessageDialog(null, "账号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
} else if (passwordField_1.getPassword().length <= 0) {
JOptionPane.showMessageDialog(null, "密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
} else if (rs.next()) {
// 第一个参数是控制弹出对话框相对的中心位置,如果是null,则是在屏幕中间,如果是其它组件参数,则会在其它组件的中心弹出。
JOptionPane.showMessageDialog(null, "恭喜你已成功登录!", "信息", JOptionPane.INFORMATION_MESSAGE);
StudentViews frame = new StudentViews();
frame.setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "用户名或者密码不正确!", "警告", JOptionPane.ERROR_MESSAGE);
textField.requestFocus();
textField.setText(null);
passwordField_1.setText(null);
}
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
if (flag == 2) {
String sql = "select *from teacher_password where 账号='" + textField.getText() + "'and 密码='"
+ new String(passwordField_1.getPassword()) + "'";
try {
ResultSet rs = query.query(sql);// 调用数据库的查询方法
if (textField.getText().length() <= 0 && passwordField_1.getPassword().length <= 0) {
JOptionPane.showMessageDialog(null, "账号和密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
} else if (textField.getText().length() <= 0) {
JOptionPane.showMessageDialog(null, "账号不能为空", "警告", JOptionPane.ERROR_MESSAGE);
} else if (passwordField_1.getPassword().length <= 0) {
JOptionPane.showMessageDialog(null, "密码不能为空", "警告", JOptionPane.ERROR_MESSAGE);
} else if (rs.next()) {
// 第一个参数是控制弹出对话框相对的中心位置,如果是null,则是在屏幕中间,如果是其它组件参数,则会在其它组件的中心弹出。
JOptionPane.showMessageDialog(null, "恭喜你已成功登录!", "信息", JOptionPane.INFORMATION_MESSAGE);
TeacherViews frame = new TeacherViews();
frame.setVisible(true);
dispose();
} else {
JOptionPane.showMessageDialog(null, "用户名或者密码不正确!", "警告", JOptionPane.ERROR_MESSAGE);
textField.requestFocus();
textField.setText(null);
passwordField_1.setText(null);
}
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 18));
btnNewButton.setBounds(156, 460, 93, 41);
contentPane.add(btnNewButton);
JButton button_1 = new JButton("注册");
button_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Post frame = new Post();
frame.setVisible(true);
}
});
button_1.setFont(new Font("微软雅黑", Font.BOLD, 18));
button_1.setBounds(37, 460, 93, 41);
contentPane.add(button_1);
JLabel lblNewLabel_2 = new JLabel("");
lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 14));
lblNewLabel_2.setIcon(new ImageIcon(Register.class.getResource("/ico/用户名.png")));
lblNewLabel_2.setBounds(27, 329, 26, 35);
contentPane.add(lblNewLabel_2);
JLabel label_1 = new JLabel("");
label_1.setIcon(new ImageIcon(Register.class.getResource("/ico/密码.png")));
label_1.setFont(new Font("宋体", Font.PLAIN, 14));
label_1.setBounds(27, 374, 26, 35);
contentPane.add(label_1);
}
}
package com.itheima.jdbc;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
/**
* @author lzg
* @date 2019年12月27日 上午9:37:52
* @Description
*/
@SuppressWarnings("serial")
public class Delete extends JFrame {
public int flag=1;
private JPanel contentPane;
private JTextField textField;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Delete frame = new Delete();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Delete() {
setFont(new Font("微软雅黑", Font.PLAIN, 14));
setTitle("删除界面");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 607, 391);
contentPane = new JPanel();
contentPane.setBackground(Color.CYAN);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
setLocationRelativeTo(null);//将窗口居中
JLabel lbl