diff --git a/studentguanli/.classpath b/studentguanli/.classpath new file mode 100644 index 0000000..d1153ed --- /dev/null +++ b/studentguanli/.classpath @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/studentguanli/.project b/studentguanli/.project new file mode 100644 index 0000000..a5d6b41 --- /dev/null +++ b/studentguanli/.project @@ -0,0 +1,17 @@ + + + studentguanli + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/studentguanli/.settings/org.eclipse.core.resources.prefs b/studentguanli/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..99f26c0 --- /dev/null +++ b/studentguanli/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding/=UTF-8 diff --git a/studentguanli/.settings/org.eclipse.jdt.core.prefs b/studentguanli/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..8c9943d --- /dev/null +++ b/studentguanli/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/studentguanli/bin/com/system/dao/AttendancesbwDao.class b/studentguanli/bin/com/system/dao/AttendancesbwDao.class new file mode 100644 index 0000000..5f5fa5a Binary files /dev/null and b/studentguanli/bin/com/system/dao/AttendancesbwDao.class differ diff --git a/studentguanli/bin/com/system/impl/Attendancesbwimpl.class b/studentguanli/bin/com/system/impl/Attendancesbwimpl.class new file mode 100644 index 0000000..196d45c Binary files /dev/null and b/studentguanli/bin/com/system/impl/Attendancesbwimpl.class differ diff --git a/studentguanli/bin/com/system/javaBean/Attendancesbw.class b/studentguanli/bin/com/system/javaBean/Attendancesbw.class new file mode 100644 index 0000000..ed0526b Binary files /dev/null and b/studentguanli/bin/com/system/javaBean/Attendancesbw.class differ diff --git a/studentguanli/bin/com/system/utils/DB.class b/studentguanli/bin/com/system/utils/DB.class new file mode 100644 index 0000000..ca26d4a Binary files /dev/null and b/studentguanli/bin/com/system/utils/DB.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwAdd$1.class b/studentguanli/bin/com/system/view/AttendancesbwAdd$1.class new file mode 100644 index 0000000..c12c910 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwAdd$1.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwAdd$2.class b/studentguanli/bin/com/system/view/AttendancesbwAdd$2.class new file mode 100644 index 0000000..bf22240 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwAdd$2.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwAdd.class b/studentguanli/bin/com/system/view/AttendancesbwAdd.class new file mode 100644 index 0000000..883693d Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwAdd.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwDelete$1.class b/studentguanli/bin/com/system/view/AttendancesbwDelete$1.class new file mode 100644 index 0000000..d37bc96 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwDelete$1.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwDelete.class b/studentguanli/bin/com/system/view/AttendancesbwDelete.class new file mode 100644 index 0000000..c0c8bd4 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwDelete.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwOperation$1.class b/studentguanli/bin/com/system/view/AttendancesbwOperation$1.class new file mode 100644 index 0000000..a676bae Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwOperation$1.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwOperation$2.class b/studentguanli/bin/com/system/view/AttendancesbwOperation$2.class new file mode 100644 index 0000000..d6b4d9e Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwOperation$2.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwOperation$3.class b/studentguanli/bin/com/system/view/AttendancesbwOperation$3.class new file mode 100644 index 0000000..733d7d4 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwOperation$3.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwOperation$4.class b/studentguanli/bin/com/system/view/AttendancesbwOperation$4.class new file mode 100644 index 0000000..df435b5 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwOperation$4.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwOperation.class b/studentguanli/bin/com/system/view/AttendancesbwOperation.class new file mode 100644 index 0000000..8b9958d Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwOperation.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwSelect$1.class b/studentguanli/bin/com/system/view/AttendancesbwSelect$1.class new file mode 100644 index 0000000..369f00d Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwSelect$1.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwSelect$2.class b/studentguanli/bin/com/system/view/AttendancesbwSelect$2.class new file mode 100644 index 0000000..e2155c0 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwSelect$2.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwSelect.class b/studentguanli/bin/com/system/view/AttendancesbwSelect.class new file mode 100644 index 0000000..017eb6a Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwSelect.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwUpdate$1.class b/studentguanli/bin/com/system/view/AttendancesbwUpdate$1.class new file mode 100644 index 0000000..cdd3493 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwUpdate$1.class differ diff --git a/studentguanli/bin/com/system/view/AttendancesbwUpdate.class b/studentguanli/bin/com/system/view/AttendancesbwUpdate.class new file mode 100644 index 0000000..e2b5201 Binary files /dev/null and b/studentguanli/bin/com/system/view/AttendancesbwUpdate.class differ diff --git a/studentguanli/bin/com/system/view/Bg$1.class b/studentguanli/bin/com/system/view/Bg$1.class new file mode 100644 index 0000000..046d99f Binary files /dev/null and b/studentguanli/bin/com/system/view/Bg$1.class differ diff --git a/studentguanli/bin/com/system/view/Bg$2.class b/studentguanli/bin/com/system/view/Bg$2.class new file mode 100644 index 0000000..e75c10b Binary files /dev/null and b/studentguanli/bin/com/system/view/Bg$2.class differ diff --git a/studentguanli/bin/com/system/view/Bg.class b/studentguanli/bin/com/system/view/Bg.class new file mode 100644 index 0000000..e0b26fd Binary files /dev/null and b/studentguanli/bin/com/system/view/Bg.class differ diff --git a/studentguanli/bin/module-info.class b/studentguanli/bin/module-info.class new file mode 100644 index 0000000..3f90db9 Binary files /dev/null and b/studentguanli/bin/module-info.class differ diff --git a/studentguanli/src/com/system/dao/AttendancesbwDao.java b/studentguanli/src/com/system/dao/AttendancesbwDao.java new file mode 100644 index 0000000..2960f97 --- /dev/null +++ b/studentguanli/src/com/system/dao/AttendancesbwDao.java @@ -0,0 +1,15 @@ +package com.system.dao; + +import java.sql.SQLException; +import java.util.List; + +import com.system.javaBean.Attendancesbw; + +public interface AttendancesbwDao { + + public boolean deleteAttendance(String snosbw) throws SQLException; + public List selectBySno(String snosbw); + public boolean updateById(String idsbw, String snosbw, String namesbw, String cnosbw, String datesbw, String statussbw)throws SQLException; + public boolean addAttendance(Attendancesbw attendancesbw) throws SQLException; + public List findAll() throws SQLException; + } \ No newline at end of file diff --git a/studentguanli/src/com/system/impl/Attendancesbwimpl.java b/studentguanli/src/com/system/impl/Attendancesbwimpl.java new file mode 100644 index 0000000..cd0345e --- /dev/null +++ b/studentguanli/src/com/system/impl/Attendancesbwimpl.java @@ -0,0 +1,153 @@ +package com.system.impl; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.List; + +import com.system.dao.AttendancesbwDao; +import com.system.javaBean.Attendancesbw; +import com.system.utils.DB; + +public class Attendancesbwimpl implements AttendancesbwDao { + private Connection connsbw; + private DB dataBasesbw = new DB(); + + + @Override + public boolean deleteAttendance(String idsbw) throws SQLException { + try { + connsbw = dataBasesbw.getConnection(); + Statement statsbw = null; + statsbw = connsbw.createStatement(); + String sqlsbw = "DELETE FROM attendance WHERE id = '"+idsbw+"' "; + if ( statsbw.executeUpdate(sqlsbw)==1 ){ + return true; + } + } catch (Exception e) { + e.printStackTrace(); + } + connsbw.close(); + return false; + } + @Override + public List selectBySno(String snosbw) { + List attendanceListsbw = new ArrayList<>(); + // 假设您有一个可以执行数据库操作的数据库访问对象,例如使用JDBC + String sqlsbw = "SELECT id, sno, name,cno, date, status " + + "FROM attendance " + + "WHERE sno = ?"; + try (Connection connsbw = dataBasesbw.getConnection(); + PreparedStatement pstmtsbw = connsbw.prepareStatement(sqlsbw)) { + pstmtsbw.setString(1, snosbw); + ResultSet rssbw = pstmtsbw.executeQuery(); + while (rssbw.next()) { + Attendancesbw attendancesbw = new Attendancesbw(); + attendancesbw.setId(rssbw.getString("id")); + attendancesbw.setStudentId(rssbw.getString("sno")); + attendancesbw.setName(rssbw.getString("name")); + attendancesbw.setCourseCno(rssbw.getString("cno")); + attendancesbw.setDate(rssbw.getString("date")); + attendancesbw.setStatus(rssbw.getString("status")); + attendanceListsbw.add(attendancesbw); + } + } catch (SQLException e) { + // 处理异常 + e.printStackTrace(); + } + return attendanceListsbw; + } + + + // 更新课程 + @Override + public boolean updateById(String idsbw, String snosbw, String namesbw, String cnosbw, String datesbw, String statussbw) throws SQLException { + try { + connsbw = dataBasesbw.getConnection(); + // 使用PreparedStatement来防止SQL注入 + String sqlsbw = "UPDATE attendance SET sno = ?, name = ?, cno = ?, date = ?, status = ? WHERE id = ?"; + try (PreparedStatement pstmtsbw = connsbw.prepareStatement(sqlsbw)) { + // 按顺序设置参数值 + pstmtsbw.setString(1, snosbw); + pstmtsbw.setString(2, namesbw); + pstmtsbw.setString(3, cnosbw); + pstmtsbw.setString(4, datesbw); + pstmtsbw.setString(5, statussbw); + pstmtsbw.setString(6, idsbw); + + // 执行更新操作 + int affectedRowssbw = pstmtsbw.executeUpdate(); + // 检查是否至少有一行被更新 + return affectedRowssbw > 0; + } + } catch (SQLException e) { + e.printStackTrace(); + throw e; // 重新抛出异常,以便调用者可以处理它 + } + } + + @Override + public boolean addAttendance(Attendancesbw attendancesbw) throws SQLException { + try { + connsbw = dataBasesbw.getConnection(); + String sqlsbw = "INSERT INTO attendance (id, sno, name, cno, date, status) VALUES (?, ?, ?, ?, ?, ?)"; + try (PreparedStatement pstmtsbw = connsbw.prepareStatement(sqlsbw)) { + // 按顺序设置参数值 + pstmtsbw.setString(1, attendancesbw.getId()); + pstmtsbw.setString(2, attendancesbw.getStudentId()); + pstmtsbw.setString(3, attendancesbw.getName()); + pstmtsbw.setString(4, attendancesbw.getCourseCno()); + pstmtsbw.setString(5, attendancesbw.getDate()); // + pstmtsbw.setString(6, attendancesbw.getStatus()); + + // 执行插入操作 + int affectedRowssbw = pstmtsbw.executeUpdate(); + // 检查是否插入成功 + return affectedRowssbw > 0; + } + } catch (SQLException e) { + e.printStackTrace(); + throw e; // 重新抛出异常,以便调用者可以处理它 + } + } + + @Override + public List findAll() throws SQLException { + List attendanceListsbw = new ArrayList<>(); + // 数据库查询逻辑 + String sqlsbw = "SELECT id, sno, name, cno, date, status FROM attendance"; // 假设Attendance表中有这些列 + try (Connection connsbw = dataBasesbw.getConnection(); + PreparedStatement pstmt = connsbw.prepareStatement(sqlsbw); + ResultSet rssbw = pstmt.executeQuery()) { + + while (rssbw.next()) { + Attendancesbw attendancesbw = new Attendancesbw(); + // 根据ResultSet中的数据设置Attendance对象的属性 + attendancesbw.setId(rssbw.getString("id")); + attendancesbw.setStudentId(rssbw.getString("sno")); + attendancesbw.setName(rssbw.getString("name")); + attendancesbw.setCourseCno(rssbw.getString("cno")); + attendancesbw.setDate(rssbw.getString("date")); + attendancesbw.setStatus(rssbw.getString("status")); + + + attendanceListsbw.add(attendancesbw); + } + return attendanceListsbw; + } catch (SQLException e) { + // 异常处理 + e.printStackTrace(); + throw e; + } + } + } + + + + + + + \ No newline at end of file diff --git a/studentguanli/src/com/system/javaBean/Attendancesbw.java b/studentguanli/src/com/system/javaBean/Attendancesbw.java new file mode 100644 index 0000000..63d539c --- /dev/null +++ b/studentguanli/src/com/system/javaBean/Attendancesbw.java @@ -0,0 +1,83 @@ +package com.system.javaBean; + +import java.time.LocalDate; + +public class Attendancesbw { + private String idsbw; + private String snosbw; + private String namesbw; + private String cnosbw; + private String datesbw; + private String statussbw; + + // 默认构造函数 + public Attendancesbw() { + } + + // 带参数的构造函数 + public Attendancesbw(String idsbw,String snosbw,String namesbw, String cnosbw, String datesbw, String statussbw) { + this.idsbw=idsbw; + this.snosbw=snosbw; + this.namesbw=namesbw; + this.cnosbw = cnosbw; + this.datesbw = datesbw; + this.statussbw=statussbw; + } + + // Getter 和 Setter 方法 + public String getId() { + return idsbw; + } + + public void setId(String id) { + this.idsbw = idsbw; + } + + public String getStudentId() { + return snosbw; + } + + public void setStudentId(String sno) { + this.snosbw = snosbw; + } + + public String getName() { + return namesbw; + } + public void setName(String name) { + this.namesbw=namesbw; + } + public String getCourseCno() { + return cnosbw; + } + + public void setCourseCno(String cno) { + this.cnosbw = cnosbw; + } + + public String getDate() { + return datesbw; + } + + public void setDate(String date) { + this.datesbw = datesbw; + } + + public String getStatus() { + return statussbw; + } + + public void setStatus(String status) { + this.statussbw = statussbw; + } + + // 重写 toString 方法 + @Override + public String toString() { + return "Attendancesbw{" +"id=" + idsbw + ", sno=" + snosbw + ",sname="+ namesbw +", cno=" + cnosbw +", date=" + datesbw +", status=" + statussbw + '}'; + } + + + + +} \ No newline at end of file diff --git a/studentguanli/src/com/system/utils/DB.java b/studentguanli/src/com/system/utils/DB.java new file mode 100644 index 0000000..8ea53fa --- /dev/null +++ b/studentguanli/src/com/system/utils/DB.java @@ -0,0 +1,100 @@ +package com.system.utils; + +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 Driversbw = "jdbc:mysql://localhost:3306/student_a?serverTimezone=Asia/Shanghai&useSSL=false"; + // 数据库用户名 + private String usersbw = "root"; // 这里需要修改为自己的用户名和密码 + // 数据库密码 + private String passsbw = "sbw20040420"; + // 数据库连接 + public static Connection consbw; + + // 构造方法 + public DB() { + try { + // 加载驱动 + Class.forName("com.mysql.cj.jdbc.Driver"); // 这个驱动是mysql8版本的 + // 获取连接 + consbw = DriverManager.getConnection(Driversbw, usersbw, passsbw); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // 获取连接 + public static Connection getConnection() { + if (consbw == null) { + new DB(); + } + return consbw; + } + + // 释放连接 + public static void close(ResultSet resultSetsbw, Statement statementsbw, Connection connectionsbw) { + + if (resultSetsbw != null) { + try { + resultSetsbw.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + if (statementsbw != null) { + try { + statementsbw.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + if (connectionsbw != null) { + try { + connectionsbw.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + // 释放连接 + public static void close(Statement statementsbw, Connection connectionsbw) { + + if (statementsbw != null) { + try { + statementsbw.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + if (connectionsbw != null) { + try { + connectionsbw.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + // 释放连接 + public static void close(Connection connectionsbw) { + + if (connectionsbw != null) { + try { + connectionsbw.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/studentguanli/src/com/system/view/AttendancesbwAdd.java b/studentguanli/src/com/system/view/AttendancesbwAdd.java new file mode 100644 index 0000000..e7227ea --- /dev/null +++ b/studentguanli/src/com/system/view/AttendancesbwAdd.java @@ -0,0 +1,167 @@ +package com.system.view; + +import javax.swing.*; + +import com.system.dao.AttendancesbwDao; +import com.system.impl.Attendancesbwimpl; +import com.system.javaBean.Attendancesbw; + +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class AttendancesbwAdd extends JFrame { + + private AttendancesbwDao attendancesbwDao; // 声明为成员变量 + private JTextField idFieldsbw; + private JTextField snoFieldsbw; + private JTextField nameFieldsbw; + private JTextField cnoFieldsbw; + private JTextField dateFieldsbw; + private JComboBox statusComboBoxsbw; + private JButton markButtonsbw; + + + + public AttendancesbwAdd() { + setTitle("考勤添加界面"); + setSize(500, 350); // 调整窗口大小 + setLocationRelativeTo(null); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + initUI(); + attendancesbwDao = new Attendancesbwimpl(); + } + + private void initUI() { + JPanel panelsbw = new JPanel(new GridBagLayout()); + panelsbw.setBackground(Color.WHITE); + getContentPane().add(panelsbw); + + GridBagConstraints gbc = new GridBagConstraints(); + gbc.anchor = GridBagConstraints.NORTHWEST; + gbc.insets = new Insets(10, 10, 10, 10); + + // 序号字段可编辑 + JLabel lblSequencesbw = new JLabel("序号:"); + panelsbw.add(lblSequencesbw, gbc); + + gbc.gridx = 1; + idFieldsbw = new JTextField(20); + panelsbw.add(idFieldsbw, gbc); + gbc.gridx = 0; + gbc.gridy = 1; + JLabel lblStudentId = new JLabel("学号:"); + panelsbw.add(lblStudentId, gbc); + + gbc.gridx = 1; + snoFieldsbw = new JTextField(20); + panelsbw.add(snoFieldsbw, gbc); + + gbc.gridx = 0; + gbc.gridy = 2; + JLabel lblStudentName = new JLabel("姓名:"); + panelsbw.add(lblStudentName, gbc); + + gbc.gridx = 1; + nameFieldsbw = new JTextField(20); + panelsbw.add(nameFieldsbw, gbc); + + gbc.gridx = 0; + gbc.gridy = 3; + JLabel lblCourseNumber = new JLabel("课程号:"); + panelsbw.add(lblCourseNumber, gbc); + + gbc.gridx = 1; + cnoFieldsbw = new JTextField(20); + panelsbw.add(cnoFieldsbw, gbc); + + gbc.gridx = 0; + gbc.gridy = 4; + JLabel lblCheckInTime = new JLabel("签到时间:"); + panelsbw.add(lblCheckInTime, gbc); + + gbc.gridx = 1; + dateFieldsbw = new JTextField(20); + dateFieldsbw.setEnabled(false); // 签到时间自动生成 + panelsbw.add(dateFieldsbw, gbc); + + gbc.gridx = 0; + gbc.gridy = 5; + JLabel lblStatus = new JLabel("考勤状态:"); + panelsbw.add(lblStatus, gbc); + + gbc.gridx = 1; + String[] statusOptions = {"出勤", "缺勤"}; + statusComboBoxsbw = new JComboBox<>(statusOptions); + panelsbw.add(statusComboBoxsbw, gbc); + + gbc.gridx = 0; + gbc.gridy = 6; + gbc.gridwidth = 2; + markButtonsbw = new JButton("记录考勤"); + markButtonsbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + markAttendance(); + } + }); + panelsbw.add(markButtonsbw, gbc); + } + + private void markAttendance() { + String idTextsbw = idFieldsbw.getText(); // 假设id对应序号字段 + String snosbw = snoFieldsbw.getText(); + String namesbw = nameFieldsbw.getText(); + String cnosbw = cnoFieldsbw.getText(); + String statussbw = (String) statusComboBoxsbw.getSelectedItem(); + + // 验证输入是否完整 + if (snosbw.isEmpty() || namesbw.isEmpty() || cnosbw.isEmpty() || idTextsbw.isEmpty()) { + JOptionPane.showMessageDialog(this, "请输入所有必填信息!"); + return; + } + + String datesbw = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + dateFieldsbw.setText(datesbw); // 设置签到时间到字段 + + Attendancesbw attendancesbw = new Attendancesbw(); + attendancesbw.setId(idTextsbw); + attendancesbw.setStudentId(snosbw); + attendancesbw.setName(namesbw); + attendancesbw.setCourseCno(cnosbw); + attendancesbw.setDate(datesbw); // 通过setter方法设置签到时间 + attendancesbw.setStatus(statussbw); + + try { + // 使用AttendanceDao的实现类来添加考勤记录 + boolean isAddedsbw = attendancesbwDao.addAttendance(attendancesbw); + if (isAddedsbw) { + JOptionPane.showMessageDialog(this, "考勤信息已成功保存到数据库!"); + } else { + JOptionPane.showMessageDialog(this, "保存考勤信息失败!"); + } + } catch (SQLException e) { + JOptionPane.showMessageDialog(this, "数据库访问出错:" + e.getMessage()); + } + + // 清空文本字段,准备下一次输入 + idFieldsbw.setText(""); // 清空id字段 + snoFieldsbw.setText(""); + nameFieldsbw.setText(""); + cnoFieldsbw.setText(""); + statusComboBoxsbw.setSelectedIndex(0); + } + + public static void main(String[] argssbw) { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new AttendancesbwAdd().setVisible(true); + } + }); + } +} \ No newline at end of file diff --git a/studentguanli/src/com/system/view/AttendancesbwDelete.java b/studentguanli/src/com/system/view/AttendancesbwDelete.java new file mode 100644 index 0000000..746fc0e --- /dev/null +++ b/studentguanli/src/com/system/view/AttendancesbwDelete.java @@ -0,0 +1,78 @@ +package com.system.view; + +import java.awt.BorderLayout; +import java.awt.Color; +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.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +import com.system.impl.Attendancesbwimpl; + +public class AttendancesbwDelete extends Bg { + + private JPanel contentPanesbw; + private JTextField keyFieldsbw; // 假设使用学号作为关键字来删除考勤记录 + public AttendancesbwDelete(String a) { + + super(a); + + JPanel panelsbw = new JPanel(); + panelsbw.setBackground(Color.WHITE); + panelsbw.setBounds(165, 54, 752, 493); + getContentPane().add(panelsbw); + panelsbw.setLayout(null); + + JLabel lblNewLabelsbw = new JLabel("删除考勤记录"); + lblNewLabelsbw.setFont(new Font("微软雅黑", Font.BOLD, 18)); + lblNewLabelsbw.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabelsbw.setBounds(275, 55, 189, 33); + panelsbw.add(lblNewLabelsbw); + + JLabel lblNewLabel_1sbw = new JLabel("序号:"); + lblNewLabel_1sbw.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel_1sbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_1sbw.setBounds(202, 120, 100, 33); + panelsbw.add(lblNewLabel_1sbw); + + keyFieldsbw = new JTextField(); + keyFieldsbw.setBounds(303, 120, 204, 33); + panelsbw.add(keyFieldsbw); + keyFieldsbw.setColumns(10); + + JButton btnNewButtonsbw = new JButton("删除"); + btnNewButtonsbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + String keysbw = keyFieldsbw.getText(); + if (keysbw.equals("")) { + JOptionPane.showMessageDialog(null, "请输入序号!"); + } else { + Attendancesbwimpl attendancesbw = new Attendancesbwimpl(); + boolean flagsbw = false; + try { + flagsbw = attendancesbw.deleteAttendance(keysbw); + } catch (SQLException e1) { + e1.printStackTrace(); + } + if (flagsbw) { + JOptionPane.showMessageDialog(null, "考勤记录删除成功!"); + } else { + JOptionPane.showMessageDialog(null, "考勤记录删除失败,请检查学号是否正确!"); + } + } + } + }); + btnNewButtonsbw.setFont(new Font("微软雅黑", Font.BOLD, 14)); + btnNewButtonsbw.setBounds(525, 120, 102, 33); + panelsbw.add(btnNewButtonsbw); + } +} \ No newline at end of file diff --git a/studentguanli/src/com/system/view/AttendancesbwOperation.java b/studentguanli/src/com/system/view/AttendancesbwOperation.java new file mode 100644 index 0000000..275db74 --- /dev/null +++ b/studentguanli/src/com/system/view/AttendancesbwOperation.java @@ -0,0 +1,91 @@ +package com.system.view; + +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.SwingConstants; + + +public class AttendancesbwOperation extends Bg { + + /** + * Create the frame for attendance operation. + */ + public AttendancesbwOperation(String a) { + super(a); + + JLabel lblNewLabelsbw = new JLabel("考勤相关操作"); + lblNewLabelsbw.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabelsbw.setFont(new Font("微软雅黑", Font.BOLD, 18)); + lblNewLabelsbw.setBounds(370, 94, 352, 43); + getContentPane().add(lblNewLabelsbw); + + JButton btnNewButtonsbw = new JButton("录入考勤"); + btnNewButtonsbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (a.equals("学生")) { + JOptionPane.showMessageDialog(null, "没有权限!"); + } else { + setVisible(false); + new AttendancesbwAdd().setVisible(true); + } + } + }); + btnNewButtonsbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + btnNewButtonsbw.setBounds(622, 174, 148, 37); + getContentPane().add(btnNewButtonsbw); + + JButton btnNewButton_1sbw = new JButton("查询考勤"); + btnNewButtonsbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (a.equals("学生")) { + JOptionPane.showMessageDialog(null, "没有权限!"); + } else { + setVisible(false); + new AttendancesbwSelect().setVisible(true); + } + } + }); + btnNewButtonsbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + btnNewButtonsbw.setBounds(353, 174, 148, 37); + getContentPane().add(btnNewButtonsbw); + + JButton btnUpdateAttendancesbw = new JButton("修改考勤"); + btnUpdateAttendancesbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (a.equals("学生")) { + JOptionPane.showMessageDialog(null, "没有权限!"); + } else { + setVisible(false); + new AttendancesbwUpdate(a).setVisible(true); + } + } + }); + btnUpdateAttendancesbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + btnUpdateAttendancesbw.setBounds(353, 257, 148, 37); + getContentPane().add(btnUpdateAttendancesbw); + + // 添加“删除考勤”按钮 + JButton btnDeleteAttendancesbw = new JButton("删除考勤"); + btnDeleteAttendancesbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (a.equals("学生")) { + JOptionPane.showMessageDialog(null, "没有权限!"); + } else { + setVisible(false); + new AttendancesbwDelete(a).setVisible(true); + } + } + }); + btnDeleteAttendancesbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + btnDeleteAttendancesbw.setBounds(622, 257, 148, 37); + getContentPane().add(btnDeleteAttendancesbw); + // 根据需要添加更多考勤相关按钮和操作 + } + + // 其他方法和类定义,如 AttendanceRecord 和 AttendanceQuery 等 +} \ No newline at end of file diff --git a/studentguanli/src/com/system/view/AttendancesbwSelect.java b/studentguanli/src/com/system/view/AttendancesbwSelect.java new file mode 100644 index 0000000..1c39cb3 --- /dev/null +++ b/studentguanli/src/com/system/view/AttendancesbwSelect.java @@ -0,0 +1,138 @@ +package com.system.view; + +import java.awt.Color; +import java.awt.Font; +import java.awt.SystemColor; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.SQLException; +import java.util.List; +import java.util.Vector; + +import javax.swing.JButton; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTable; +import javax.swing.JTextField; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +import com.system.impl.Attendancesbwimpl; +import com.system.javaBean.Attendancesbw; + + + +public class AttendancesbwSelect extends JFrame { + + private JPanel contentPanesbw; + private JTextField studentIdFieldsbw; + private JTable tablesbw; + private JScrollPane scrollPanesbw; + + public AttendancesbwSelect() { + + setTitle("学生考勤查询"); + setBounds(100, 100, 600, 400); + contentPanesbw = new JPanel(); + contentPanesbw.setBackground(Color.WHITE); + contentPanesbw.setBorder(new EmptyBorder(5, 5, 5, 5)); + setContentPane(contentPanesbw); + contentPanesbw.setLayout(null); + + final Vector columnNamessbw = new Vector<>(); + columnNamessbw.add("序号"); + columnNamessbw.add("学生编号"); + columnNamessbw.add("姓名"); + columnNamessbw.add("课程号"); + columnNamessbw.add("签到时间"); + columnNamessbw.add("考勤状态"); + + Vector> datasbw = new Vector<>(); + + JPanel panelsbw = new JPanel(); + panelsbw.setBackground(SystemColor.activeCaption); + panelsbw.setBounds(0, 0, 584, 45); + contentPanesbw.add(panelsbw); + panelsbw.setLayout(null); + + JLabel lblNewLabelsbw = new JLabel("学生考勤查询系统"); + lblNewLabelsbw.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabelsbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabelsbw.setBounds(155, 10, 280, 25); + panelsbw.add(lblNewLabelsbw); + + JPanel panel_1sbw = new JPanel(); + panel_1sbw.setBackground(Color.WHITE); + panel_1sbw.setBounds(0, 44, 584, 51); + contentPanesbw.add(panel_1sbw); + panel_1sbw.setLayout(null); + + JLabel lblNewLabel_1sbw = new JLabel("学生编号:"); + lblNewLabel_1sbw.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel_1sbw.setFont(new Font("微软雅黑", Font.BOLD, 14)); + lblNewLabel_1sbw.setBounds(100, 10, 91, 31); + panel_1sbw.add(lblNewLabel_1sbw); + + studentIdFieldsbw = new JTextField(); + studentIdFieldsbw.setBounds(191, 10, 194, 31); + panel_1sbw.add(studentIdFieldsbw); + studentIdFieldsbw.setColumns(10); + + JButton btnNewButtonsbw = new JButton("查询"); + btnNewButtonsbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + String snosbw = studentIdFieldsbw.getText(); + if (snosbw.isEmpty()) { + JOptionPane.showMessageDialog(null, "学生编号不能为空!"); + } else { + // 这里添加查询考勤的逻辑 + datasbw.clear(); + Attendancesbwimpl attendancesbw = new Attendancesbwimpl(); + List attendanceListsbw = attendancesbw.selectBySno(snosbw); + for (Attendancesbw attendance1sbw : attendanceListsbw) { + Vector rowsbw = new Vector<>(); + rowsbw.add(String.valueOf(attendance1sbw.getId())); // 假设Attendance有一个id字段 + rowsbw.add(attendance1sbw.getStudentId()); + rowsbw.add(attendance1sbw.getName()); + rowsbw.add(attendance1sbw.getCourseCno()); + rowsbw.add(attendance1sbw.getDate()); + rowsbw.add(attendance1sbw.getStatus()); + datasbw.add(rowsbw); + } + tablesbw = new JTable(datasbw, columnNamessbw); + scrollPanesbw.setViewportView(tablesbw); + } + } + }); + btnNewButtonsbw.setFont(new Font("微软雅黑", Font.BOLD, 14)); + btnNewButtonsbw.setBounds(395, 11, 79, 28); + panel_1sbw.add(btnNewButtonsbw); + + scrollPanesbw = new JScrollPane(); + scrollPanesbw.setBounds(0, 94, 584, 287); + contentPanesbw.add(scrollPanesbw); + + // 初始化表格数据,这里可以添加加载所有考勤记录的逻辑 + // 例如加载所有学生的考勤记录 + + tablesbw = new JTable(datasbw, columnNamessbw); + scrollPanesbw.setViewportView(tablesbw); + } + + public static void main(String[] argssbw) { + // 启动应用程序 + java.awt.EventQueue.invokeLater(new Runnable() { + public void run() { + try { + AttendancesbwSelect frame = new AttendancesbwSelect(); + frame.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } +} \ No newline at end of file diff --git a/studentguanli/src/com/system/view/AttendancesbwUpdate.java b/studentguanli/src/com/system/view/AttendancesbwUpdate.java new file mode 100644 index 0000000..b47bff9 --- /dev/null +++ b/studentguanli/src/com/system/view/AttendancesbwUpdate.java @@ -0,0 +1,176 @@ +package com.system.view; + +import java.awt.Color; +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.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.SwingConstants; + +import com.system.impl.Attendancesbwimpl; +import com.system.javaBean.Attendancesbw; + + +public class AttendancesbwUpdate extends Bg { + + private JPanel contentPanesbw; + private JTextField idkeyFieldsbw; + + private JTextField snoFieldsbw; + private JTextField nameFieldsbw; + private JTextField cnoFieldsbw; + private JTextField dateFieldsbw; + private JTextField statusFieldsbw; + private JTextField idFieldsbw = new JTextField(); + + + public AttendancesbwUpdate(String a) { + // setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + // setBounds(100, 100, 450, 300); + // contentPane = new JPanel(); + // contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); + // contentPane.setLayout(new BorderLayout(0, 0)); + // setContentPane(contentPane); + super(a); + + + JPanel panelsbw = new JPanel(); + panelsbw.setBackground(Color.WHITE); + panelsbw.setBounds(166, 32, 751, 495); + getContentPane().add(panelsbw); + panelsbw.setLayout(null); + + + + JLabel lblNewLabelsbw = new JLabel("修改考勤信息"); + lblNewLabelsbw.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabelsbw.setFont(new Font("微软雅黑", Font.BOLD, 18)); + lblNewLabelsbw.setBounds(256, 28, 233, 38); + panelsbw.add(lblNewLabelsbw); + + //JLabel lblNewLabel_2 = new JLabel("考勤基本信息"); + //lblNewLabel_2.setFont(new Font("微软雅黑", Font.BOLD, 16)); + //lblNewLabel_2.setBounds(155, 136, 170, 28); + //panel.add(lblNewLabel_2); + + + + + + // 考勤序号标签 + JLabel lblNewLabel_3sbw = new JLabel("考勤序号:"); + lblNewLabel_3sbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_3sbw.setBounds(155, 131, 90, 28); + panelsbw.add(lblNewLabel_3sbw); + + // 学生学号标签 + JLabel lblNewLabel_3_1sbw = new JLabel("学生学号:"); + lblNewLabel_3_1sbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_3_1sbw.setBounds(155, 171, 90, 28); + panelsbw.add(lblNewLabel_3_1sbw); + + // 学生姓名标签 + JLabel lblNewLabel_3_2sbw = new JLabel("学生姓名:"); + lblNewLabel_3_2sbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_3_2sbw.setBounds(155, 212, 90, 28); + panelsbw.add(lblNewLabel_3_2sbw); + + // 课程号标签 + JLabel lblNewLabel_3_3sbw = new JLabel("课程号:"); + lblNewLabel_3_3sbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_3_3sbw.setBounds(171, 259, 73, 28); + panelsbw.add(lblNewLabel_3_3sbw); + + // 考勤日期标签 + JLabel lblNewLabel_3_4sbw = new JLabel("考勤日期:"); + lblNewLabel_3_4sbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_3_4sbw.setBounds(155, 306, 90, 28); + panelsbw.add(lblNewLabel_3_4sbw); + + // 考勤状态标签 + JLabel lblNewLabel_3_5sbw = new JLabel("考勤状态:"); + lblNewLabel_3_5sbw.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_3_5sbw.setBounds(155, 348, 90, 28); + panelsbw.add(lblNewLabel_3_5sbw); + + // 考勤序号文本框 + JTextField idFieldsbw = new JTextField(); + idFieldsbw.setBounds(238, 135, 240, 30); + panelsbw.add(idFieldsbw); + idFieldsbw.setColumns(8); + + // 学生学号文本框 + JTextField snoFieldsbw = new JTextField(); + snoFieldsbw.setBounds(238, 175, 240, 30); + panelsbw.add(snoFieldsbw); + snoFieldsbw.setColumns(8); + + // 学生姓名文本框 + JTextField nameFieldsbw = new JTextField(); + nameFieldsbw.setBounds(238, 217, 240, 30); + panelsbw.add(nameFieldsbw); + nameFieldsbw.setColumns(8); + + // 课程号文本框 + JTextField cnoFieldsbw = new JTextField(); + cnoFieldsbw.setBounds(238, 264, 240, 30); + panelsbw.add(cnoFieldsbw); + cnoFieldsbw.setColumns(8); + + // 考勤日期文本框 + JTextField dateFieldsbw = new JTextField(); + dateFieldsbw.setBounds(238, 311, 240, 30); + panelsbw.add(dateFieldsbw); + dateFieldsbw.setColumns(8); + + // 考勤状态文本框 + JTextField statusFieldsbw = new JTextField(); + statusFieldsbw.setBounds(238, 352, 240, 30); + panelsbw.add(statusFieldsbw); + statusFieldsbw.setColumns(8); + + JButton btnNewButton_1sbw = new JButton("修改"); + btnNewButton_1sbw.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + String idsbw = idFieldsbw.getText(); // 考勤序号 + String snosbw = snoFieldsbw.getText(); // 学生学号 + String namesbw = nameFieldsbw.getText(); // 学生姓名 + String cnosbw = cnoFieldsbw.getText(); // 课程号 + String datesbw = dateFieldsbw.getText(); // 考勤日期 + String statussbw = statusFieldsbw.getText(); // 考勤状态 + + if (idsbw.equals("") || snosbw.equals("") ||namesbw.equals("") ||cnosbw.equals("") ||datesbw.equals("") || statussbw.equals("") ) { + JOptionPane.showMessageDialog(null, "请输入完整的信息!"); + } else { + + Attendancesbwimpl attendancesbwDao = new Attendancesbwimpl(); + boolean istrue = false; + try{ + istrue = attendancesbwDao.updateById(idsbw, snosbw, namesbw, cnosbw, datesbw, statussbw); + }catch (SQLException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + if (istrue) { + JOptionPane.showMessageDialog(null, "修改成功!"); + } else { + JOptionPane.showMessageDialog(null, "修改失败,请检查输入信息是否正确!"); + } + } + } + }); + + btnNewButton_1sbw.setBackground(Color.RED); + btnNewButton_1sbw.setFont(new Font("微软雅黑", Font.BOLD, 14)); + btnNewButton_1sbw.setBounds(280, 447, 136, 38); + panelsbw.add(btnNewButton_1sbw); + } + +} diff --git a/studentguanli/src/com/system/view/Bg.java b/studentguanli/src/com/system/view/Bg.java new file mode 100644 index 0000000..eb7e55e --- /dev/null +++ b/studentguanli/src/com/system/view/Bg.java @@ -0,0 +1,58 @@ +package com.system.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; + + + public Bg(String flag) { + + 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_4 = new JLabel("考勤模块"); + lblNewLabel_4.addMouseListener(new MouseAdapter() { + + @Override + public void mouseClicked(MouseEvent e) { + setVisible(false); + new AttendancesbwOperation(flag).setVisible(true); + } + }); + lblNewLabel_4.setHorizontalAlignment(SwingConstants.CENTER); + lblNewLabel_4.setFont(new Font("微软雅黑", Font.BOLD, 16)); + lblNewLabel_4.setBounds(0, 199, 166, 58); + panel_1.add(lblNewLabel_4); + + 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, 262, 166, 58); + panel_1.add(lblNewLabel_3); + + + } + +} diff --git a/studentguanli/src/module-info.java b/studentguanli/src/module-info.java new file mode 100644 index 0000000..d65f0e5 --- /dev/null +++ b/studentguanli/src/module-info.java @@ -0,0 +1,4 @@ +module studentguanli { + requires java.sql; + requires java.desktop; +} \ No newline at end of file