Compare commits

..

2 Commits

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="F:/mysql-connector-java-8.0.16.jar">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>user</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=17

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -0,0 +1,100 @@
package DB;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
// 数据库地址
private String Driver_name = "jdbc:mysql://localhost:3306/student_a?serverTimezone=Asia/Shanghai&useSSL=false";
// 数据库用户名
private String USER = "root"; // 这里需要修改为自己的用户名和密码
// 数据库密码
private String PASS = "Wyy031105";
// 数据库连接
public static Connection con;
// 构造方法
public DB() {
try {
// 加载驱动
Class.forName("com.mysql.cj.jdbc.Driver"); // 这个驱动是mysql8版本的
// 获取连接
con = DriverManager.getConnection(Driver_name, USER, PASS);
} catch (Exception e) {
e.printStackTrace();
}
}
// 获取连接
public static Connection getConnection() {
if (con == null) {
new DB();
}
return con;
}
// 释放连接
public static void close(ResultSet resultSet, Statement statement, Connection connection) {
if (resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
// 释放连接
public static void close(Statement statement, Connection connection) {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
// 释放连接
public static void close(Connection connection) {
if (connection != null) {
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}

@ -0,0 +1,8 @@
/**
*
*/
/**
*
*/
module user {
}

@ -0,0 +1,17 @@
package user;
import java.sql.SQLException;
import java.util.List;
import com.system.entity.Student;
public interface UserDao {
public boolean LoginCheck(String id, String pwd) throws SQLException;
public boolean Register(String id, String name ,String pwd) throws SQLException;
public List<Student> res() throws Exception;
public List<Student> Select(String sno, String name) throws Exception;
public boolean insert(String sno, String name, String gender, String age, String clas , String major, String dept) throws SQLException;
public boolean delete(String sno) throws SQLException;
public Student select(String sno) throws SQLException;
public boolean update(String sno, String name, String gender, String age, String clas , String major, String dept) throws SQLException;
}

@ -0,0 +1,49 @@
package user.admin;
public class Admin {
private int aId;
private String aName;
private String aPwd;
public Admin() {
super();
}
public Admin(int aId, String aName, String aPwd) {
super();
this.aId = aId;
this.aName = aName;
this.aPwd = aPwd;
}
public int getaId() {
return aId;
}
public void setaId(int aId) {
this.aId = aId;
}
public String getaName() {
return aName;
}
public void setaName(String aName) {
this.aName = aName;
}
public String getaPwd() {
return aPwd;
}
public void setaPwd(String aPwd) {
this.aPwd = aPwd;
}
@Override
public String toString() {
return "Admin [aId=" + aId + ", aName=" + aName + ", aPwd=" + aPwd + "]";
}
}

@ -0,0 +1,210 @@
package userimpl;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.system.entity.Student;
import com.system.utils.DB;
public class Userimpl {
Connection conn = null;
DB dataBase = new DB();
//管理员登录
public boolean LoginCheck(String id, String pwd) throws SQLException {
try {
conn = dataBase.getConnection();
Statement stat = null;
ResultSet rs = null;
stat = conn.createStatement();
String sql = "SELECT * FROM admin WHERE Aid ='" + id + "' and Apwd = '" + pwd + "'";
rs = stat.executeQuery(sql);
if (rs.next()){
return true;
}else{
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
conn.close();
return false;
}
//管理员注册
public boolean Register(String id, String name ,String pwd) throws SQLException {
try {
conn = dataBase.getConnection();
Statement stat = null;
ResultSet rs = null;
stat = conn.createStatement();
String sql = "SELECT * FROM admin WHERE Aid ='" + id + "' and Apwd = '" + pwd + "'";
rs = stat.executeQuery(sql);
if (rs.next()){
return false;
}else{
sql = "INSERT INTO admin VALUES ('" + id + "','" + name + "','" + pwd + "')";
stat.executeUpdate(sql);
}
} catch (Exception e) {
e.printStackTrace();
}
conn.close();
return true;
}
//返回学生信息对象列表
public List<Student> res() throws Exception {
List<Student> students = new ArrayList<>();
Student student;
conn = dataBase.getConnection();
Statement stat = null;
ResultSet rs = null;
stat = conn.createStatement();
String sql = "SELECT * FROM student";
rs = stat.executeQuery(sql);
while (true) {
if ( rs.next() ) {
student = new Student();
student.setSno( rs.getInt("Sno") );
student.setName( rs.getString("Sname") );
student.setGender( rs.getString("Sgender") );
student.setAge( rs.getInt("Sage") );
student.setClas( rs.getString("Sclass") );
student.setMajor(rs.getString("Smajor"));
student.setDept( rs.getString("Sdept") );
students.add(student);
}else
break;
}
conn.close();
return students;
}
//返回指定学生的信息
public List<Student> Select(String sno, String name) throws Exception {
List<Student> students = new ArrayList<>();
Student student;
conn = dataBase.getConnection();
Statement stat = null;
ResultSet rs = null;
stat = conn.createStatement();
String sql = "SELECT * FROM student WHERE Sno ='"+sno+"' OR Sname = '"+name+"'";
rs = stat.executeQuery(sql);
while (true) {
if ( rs.next() ) {
student = new Student();
student.setSno( rs.getInt("Sno") );
student.setName( rs.getString("Sname") );
student.setGender( rs.getString("Sgender") );
student.setAge( rs.getInt("Sage") );
student.setClas( rs.getString("Sclass") );
student.setMajor(rs.getString("Smajor"));
student.setDept( rs.getString("Sdept") );
students.add(student);
}else
break;
}
conn.close();
return students;
}
//录入学生信息
public boolean insert(String sno, String name, String gender, String age, String clas , String major, String dept) throws SQLException {
try {
conn = dataBase.getConnection();
Statement stat = null;
stat = conn.createStatement();
String sql = "INSERT INTO student (sno,sname,sgender,sage,sclass,smajor,sdept)"
+ " VALUES ( '"+sno+"','"+name+"', '"+gender+"' ,'"+age+"' ,'"+clas+"' ,'"+major+"' ,'"+dept+"')";
if (stat.executeUpdate(sql) == 1) {
return true;
}
} catch (Exception e) {
}
conn.close();
return false;
}
//删除学生信息
public boolean delete(String sno) throws SQLException {
int key = Integer.parseInt(sno);
try {
conn = dataBase.getConnection();
Statement stat = null;
stat = conn.createStatement();
String sql = "DELETE FROM student WHERE sno = " + key;
System.out.println(sql);
if ( stat.executeUpdate(sql)==1 ){
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
conn.close();
return false;
}
//根据学号查询单个学生
public Student select(String sno) throws SQLException {
try {
conn = dataBase.getConnection();
Statement stat = null;
stat = conn.createStatement();
ResultSet rs = null;
Student stu = null;
String sql = "SELECT * FROM student WHERE sno = '"+sno+"' ";
rs = stat.executeQuery(sql);
if ( rs.next() ){
stu = new Student();
stu.setSno( rs.getInt("Sno") );
stu.setName( rs.getString("Sname") );
stu.setGender( rs.getString("Sgender") );
stu.setAge( rs.getInt("Sage") );
stu.setClas( rs.getString("Sclass") );
stu.setMajor(rs.getString("Smajor"));
stu.setDept( rs.getString("Sdept") );
return stu;
}
} catch (Exception e) {
e.printStackTrace();
}
conn.close();
return null;
}
//更新学生信息
public boolean update(String sno, String name, String gender, String age, String clas , String major, String dept) throws SQLException {
try {
conn = dataBase.getConnection();
Statement stat = null;
stat = conn.createStatement();
String sql = "UPDATE student SET sno = '"+sno+"', sname = '"+name+"', sgender = '"+gender+"', sage = '"+age+"',"
+ "sclass = '"+clas+"', smajor = '"+major+"', sdept = '"+dept+"' WHERE sno = '"+sno+"' ";
if ( stat.executeUpdate(sql)==1 ){
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
conn.close();
return false;
}
}

@ -0,0 +1,148 @@
package view;
import java.awt.Color;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
public class Bg extends JFrame {
private JPanel contentPane;
private JPanel panel_2; // 学生模块
private JPanel panel_3; // 成绩模块
private JPanel panel_4; // 课程模块
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// BgAdmin frame = new BgAdmin();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
/**
* Create the frame.
*/
public Bg(String flag) {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 933, 586);
contentPane = new JPanel();
contentPane.setBackground(Color.WHITE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBackground(SystemColor.activeCaption);
panel.setBounds(0, 0, 917, 53);
contentPane.add(panel);
panel.setLayout(null);
JLabel label = new JLabel("学生信息管理系统");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("微软雅黑", Font.BOLD, 16));
label.setBounds(371, 10, 213, 33);
panel.add(label);
JPanel panel_1 = new JPanel();
panel_1.setBackground(SystemColor.activeCaptionBorder);
panel_1.setBounds(0, 52, 166, 495);
contentPane.add(panel_1);
panel_1.setLayout(null);
JLabel lblNewLabel = new JLabel("学生模块");
lblNewLabel.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
if (flag.equals("admin")) {
// 管理员端
setVisible(false);
new StudentOpetion("admin").setVisible(true);
} else {
// 学生端
setVisible(false);
new StudentOpetion("学生").setVisible(true);
}
}
});
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(0, 0, 166, 58);
panel_1.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("成绩模块");
lblNewLabel_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (flag.equals("admin")) {
// 管理员端
setVisible(false);
new ScoreOperation("admin").setVisible(true);
} else {
// 学生端
setVisible(false);
new ScoreOperation("学生").setVisible(true);
}
}
});
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1.setBounds(0, 63, 166, 58);
panel_1.add(lblNewLabel_1);
JLabel lblNewLabel_2 = new JLabel("课程模块");
lblNewLabel_2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (flag.equals("admin")) {
// 管理员端
setVisible(false);
new CourseOperation("admin").setVisible(true);
} else {
// 学生端
setVisible(false);
new CourseOperation("学生").setVisible(true);
}
}
});
lblNewLabel_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_2.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_2.setBounds(0, 131, 166, 58);
panel_1.add(lblNewLabel_2);
JLabel lblNewLabel_3 = new JLabel("退出系统");
lblNewLabel_3.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
System.exit(0);
}
});
lblNewLabel_3.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_3.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_3.setBounds(0, 199, 166, 58);
panel_1.add(lblNewLabel_3);
}
}

@ -0,0 +1,164 @@
package view;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;
import com.system.impl.Studentimpl;
import com.system.impl.Userimpl;
public class Login extends JFrame {
private JPanel contentPane;
private JTextField usernameField;
private JPasswordField passwordField;
private JComboBox comboBox;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Login frame = new Login();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Login() {
setTitle("学生信息管理系统");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 689, 428);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBounds(0, 0, 673, 389);
contentPane.add(panel);
panel.setLayout(null);
JLabel lblNewLabel = new JLabel("学生信息管理系统");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setFont(new Font("微软雅黑", Font.BOLD, 18));
lblNewLabel.setBounds(114, 36, 393, 55);
panel.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("用户名:");
lblNewLabel_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1.setBounds(106, 112, 145, 31);
panel.add(lblNewLabel_1);
JLabel lblNewLabel_1_1 = new JLabel("密码:");
lblNewLabel_1_1.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_1.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1_1.setBounds(106, 173, 145, 31);
panel.add(lblNewLabel_1_1);
JLabel lblNewLabel_1_2 = new JLabel("身份:");
lblNewLabel_1_2.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel_1_2.setFont(new Font("微软雅黑", Font.BOLD, 16));
lblNewLabel_1_2.setBounds(106, 242, 145, 31);
panel.add(lblNewLabel_1_2);
usernameField = new JTextField();
usernameField.setBounds(227, 112, 249, 37);
panel.add(usernameField);
usernameField.setColumns(10);
passwordField = new JPasswordField();
passwordField.setBounds(227, 170, 249, 37);
panel.add(passwordField);
String[] a = new String[] { "管理员", "学生" };
comboBox = new JComboBox(a);
comboBox.setBounds(227, 237, 249, 42);
panel.add(comboBox);
JButton btnNewButton = new JButton("登录");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// 获取文本框数据
String username = usernameField.getText();
String password = passwordField.getText();
String type = (String) comboBox.getSelectedItem();
// 判断是否为空
if (username.equals("") || password.equals("")) {
JOptionPane.showMessageDialog(null, "用户名或密码不能为空!");
} else {
if ("管理员".equals(type)) {
// 管理员登录
try {
Userimpl log = new Userimpl();
boolean istrue = log.LoginCheck(username, password);
if (istrue) {
JOptionPane.showMessageDialog(null, "登录成功!");
String a = "admin";
setVisible(false);
new Bg(a).setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
} else {
// 学生登录
try {
Studentimpl log = new Studentimpl();
boolean istrue = log.LoginCheck(username, password);
if (istrue) {
JOptionPane.showMessageDialog(null, "登录成功!");
String a = "学生"; // 不可修改,控制权限!
setVisible(false);
new Bg(a).setVisible(true);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误!");
}
} catch (SQLException e1) {
e1.printStackTrace();
}
}
}
}
});
btnNewButton.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton.setBounds(132, 308, 108, 37);
panel.add(btnNewButton);
JButton btnNewButton_1 = new JButton("重置");
btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
usernameField.setText("");
passwordField.setText("");
}
});
btnNewButton_1.setFont(new Font("微软雅黑", Font.BOLD, 14));
btnNewButton_1.setBounds(399, 308, 108, 37);
panel.add(btnNewButton_1);
}
}
Loading…
Cancel
Save