TeacherUI:The test of selectStudent and modify teacherPassword was completed

MessageObject: Adding attStat
This commit is contained in:
cccccyb
2022-06-11 15:45:51 +08:00
parent e265913792
commit 48fd914a06
5 changed files with 69 additions and 16 deletions

View File

@@ -1,6 +1,15 @@
package com.cfive.classroom.teacher;
import com.cfive.classroom.library.database.DatabaseHelper;
import com.cfive.classroom.library.database.bean.AttStatus;
import com.cfive.classroom.library.database.bean.Course;
import com.cfive.classroom.library.database.bean.Student;
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
import com.cfive.classroom.library.database.util.NoConfigException;
import com.cfive.classroom.library.net.TeacherNet;
import com.cfive.classroom.library.net.util.MessageObject;
import com.cfive.classroom.library.net.util.MessageType;
import com.cfive.classroom.library.net.util.ReceiveListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -11,6 +20,9 @@ import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.*;
import java.awt.event.ComponentAdapter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class Attendance {
private static final Attendance attendance=new Attendance();
@@ -24,9 +36,32 @@ public class Attendance {
private JTable table_undo;
private JLabel test;
private TeacherNet teacherNet;
private String courseID;
private final List<Student> studentList = new ArrayList<>();
private static final Logger LOGGER= LogManager.getLogger();
public Attendance() {
//学生签到信息监听
teacherNet.setOnReceiveListener(new ReceiveListener() {
@Override
public void onReceive(MessageObject messageObject) {
//判断该信息类型是否为签到并且签到状态是否为已签
if(messageObject.getMessageType()== MessageType.CheckIn&&messageObject.getAttStatus()==AttStatus.signed){
try {
//将学生签到状态修改进数据表中
DatabaseHelper.updateAttendance(messageObject.getStuNo(), messageObject.getAttStatus());
} catch (NoConfigException e) {
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("No configuration", e);
} catch (SQLException e) {
JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("SQLException",e);
} catch (DependenciesNotFoundException e) {
LOGGER.error("DependenciesNotFoundException",e);
}
}
}
});
table_undo.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@@ -37,10 +72,6 @@ public class Attendance {
String newString=table_undo.getValueAt(row,2).toString();
attendance.test.setText(newString);
LOGGER.info(newString);
}
});
}
@@ -54,15 +85,27 @@ public class Attendance {
frame.setVisible(false);
}
public void start(TeacherNet teacherNet1){
public void start(TeacherNet teacherNet1,String courseID){
frame.setContentPane(attendance.rootPanel);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
attendance.teacherNet=teacherNet1;
attendance.courseID=courseID;
try {
studentList.addAll(DatabaseHelper.selectStudentsFromCourse(Long.parseLong(courseID))); //导入该课程学生名单
} catch (DependenciesNotFoundException e) {
throw new RuntimeException(e);
} catch (NoConfigException e) {
throw new RuntimeException(e);
} catch (SQLException e) {
throw new RuntimeException(e);
}
//已签考勤表格
DefaultTableModel alreadyTableModel=new DefaultTableModel(data,t1_columnTitle);
alreadyTableModel.setColumnCount(3);
attendance.table_already.setModel(alreadyTableModel);
//未签考勤表格
DefaultTableModel undoTableModel=new DefaultTableModel(data,t2_columnTitle);
undoTableModel.setColumnCount(3);
attendance.table_undo.setModel(undoTableModel);

View File

@@ -29,7 +29,8 @@ public class ChangePassword {
if(check()){
//将修改后的密码在数据表修改
try {
DatabaseHelper.changePasswdInTeacher(Long.valueOf(workNo_input.getText()),newPw_ok.getPassword().toString());
DatabaseHelper.changePasswdInTeacher(Long.valueOf(workNo_input.getText()),String.valueOf(newPw_ok.getPassword()));
LOGGER.debug(String.valueOf(newPw_ok.getPassword()));
} catch (NoConfigException ex) {
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("No configuration", e);

View File

@@ -18,10 +18,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.*;
public class Main {
private static final Main main = new Main();
@@ -36,7 +33,7 @@ public class Main {
private JTextField workNo_show;
private JTextField subName_show;
private String workNo,courseID;
private List<Student> studentList;
private final List<Student> studentList = new ArrayList<>();;
private String[] student;
private TeacherNet teacherNet;
private final Logger LOGGER = LogManager.getLogger();
@@ -82,7 +79,7 @@ public class Main {
@Override
public void actionPerformed(ActionEvent e) {
Attendance attendance = new Attendance();
attendance.start(teacherNet);
attendance.start(teacherNet,courseID);
}
});
@@ -100,7 +97,7 @@ public class Main {
String[] arr = new String[i]; //new一个该数长度的String数组
try {
studentList = DatabaseHelper.selectStudentsFromCourse(Long.parseLong(courseID));
studentList.addAll(DatabaseHelper.selectStudentsFromCourse(Long.parseLong(courseID)));
if (!studentList.isEmpty()) { //判断是否获取到学生名单
LOGGER.info("学生列表" + studentList);
for (int j = 0; j < i; ) {
@@ -128,7 +125,7 @@ public class Main {
}
JOptionPane.showMessageDialog(null, "恭喜以下同学被选中:\n\t\n" + count);
//将选人结果群发出去
teacherNet.sendAllMessage(new MessageObject(null, null, null, null, count, MessageType.Select));
teacherNet.sendAllMessage(new MessageObject(null, null, null, null, count, null,MessageType.Select));
}else {
JOptionPane.showMessageDialog(null, "学生名单未导入", "错误", JOptionPane.ERROR_MESSAGE);
}

View File

@@ -46,7 +46,7 @@ public class SendMessage {
if(messageToAll!=null){
SimpleDateFormat sendTime = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
messageShow.append("@所有人: "+sendTime.format(System.currentTimeMillis())+'\n'+messageToAll+'\n');
MessageObject messageObject = new MessageObject(null,null,null,"@所有人:"+messageToAll,null, MessageType.ChatToAll);
MessageObject messageObject = new MessageObject(null,null,null,"@所有人:"+messageToAll,null,null,MessageType.ChatToAll);
teacherNet.sendAllMessage(messageObject);
messageInput.setText("");
}else {