TeacherUI:JTable completed and modify checkIn code

This commit is contained in:
cccccyb
2022-06-12 16:41:06 +08:00
parent a6dae2b772
commit 77e8f9374e
7 changed files with 125 additions and 56 deletions

View File

@@ -28,7 +28,7 @@
<tabbedpane title="已签"/> <tabbedpane title="已签"/>
</constraints> </constraints>
<properties> <properties>
<enabled value="false"/> <enabled value="true"/>
</properties> </properties>
<border type="none"/> <border type="none"/>
<children> <children>
@@ -63,6 +63,7 @@
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/> <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false"/>
</constraints> </constraints>
<properties> <properties>
<horizontalAlignment value="0"/>
<text value="刷新"/> <text value="刷新"/>
</properties> </properties>
</component> </component>

View File

@@ -31,7 +31,7 @@ public class Attend {
private static final JFrame frame = new JFrame("考勤情况"); private static final JFrame frame = new JFrame("考勤情况");
private JPanel rootPanel; private JPanel rootPanel;
private JTabbedPane tabbedPane1; private JTabbedPane tabbedPane1;
private final Object[] t1_columnTitle = {"学号", "姓名", "签到时间"}; private final Object[] t1_columnTitle = {"考勤号","学号", "姓名", "签到时间","签到状态"};
private final Object[] t2_columnTitle = {"考勤号", "学号", "姓名", "签到状态"}; private final Object[] t2_columnTitle = {"考勤号", "学号", "姓名", "签到状态"};
private JTable table_already; private JTable table_already;
private JTable table_undo; private JTable table_undo;
@@ -50,6 +50,7 @@ public class Attend {
teacherNet.setOnReceiveListener(new ReceiveListener() { teacherNet.setOnReceiveListener(new ReceiveListener() {
@Override @Override
public void onReceive(MessageObject messageObject) { public void onReceive(MessageObject messageObject) {
if(messageObject.getStuNo()!=null){
//判断该信息类型是否为签到并且签到状态是否为已签 //判断该信息类型是否为签到并且签到状态是否为已签
if (messageObject.getMessageType() == MessageType.CheckIn && messageObject.getAttStatus() == AttStatus.signed) { if (messageObject.getMessageType() == MessageType.CheckIn && messageObject.getAttStatus() == AttStatus.signed) {
try { try {
@@ -64,11 +65,52 @@ public class Attend {
} catch (DependenciesNotFoundException e) { } catch (DependenciesNotFoundException e) {
LOGGER.error("DependenciesNotFoundException", e); LOGGER.error("DependenciesNotFoundException", e);
} }
//刷新表格
bt_refresh.doClick();
}
} }
} }
}); });
} }
//已签表格的鼠标点击事件
table_already.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
//获取鼠标所点击的行和列
int row = table_already.getSelectedRow();
int col = table_already.getSelectedColumn();
//修改学生签到状态
if (col == 4) {
Object[] options = {AttStatus.absence, AttStatus.signed, AttStatus.leave_early, AttStatus.late, AttStatus.personal_leave, AttStatus.public_holiday, AttStatus.sick_leave, AttStatus.not_signed};
AttStatus attStatus = (AttStatus) JOptionPane.showInputDialog(null, "选择您所要修改的签到状态", "提示",
JOptionPane.PLAIN_MESSAGE, null, options, options[0]);
if (attStatus != null) {
String modifyStat = String.valueOf(attStatus);
//将修改后的状态显示出来
table_already.getModel().setValueAt(modifyStat, row, col);
//将修改在数据库中更改
try {
DatabaseHelper.updateAttendance(String.valueOf(table_already.getModel().getValueAt(row, 0)), attStatus, null);
} catch (NoConfigException ex) {
JOptionPane.showMessageDialog(null, "没有数据库配置文件", "警告", JOptionPane.ERROR_MESSAGE);
LOGGER.error("No configuration", e);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, "数据库出错", "警告", JOptionPane.ERROR_MESSAGE);
LOGGER.error("SQLException", e);
} catch (DependenciesNotFoundException ex) {
JOptionPane.showMessageDialog(null, "未查询到该数据", "错误", JOptionPane.ERROR_MESSAGE);
LOGGER.error("DependenciesNotFoundException", e);
}
//刷新表格
bt_refresh.doClick();
}
}
}
});
//未签表格的鼠标点击事件 //未签表格的鼠标点击事件
table_undo.addMouseListener(new MouseAdapter() { table_undo.addMouseListener(new MouseAdapter() {
@Override @Override
@@ -100,8 +142,12 @@ public class Attend {
JOptionPane.showMessageDialog(null, "未查询到该数据", "错误", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "未查询到该数据", "错误", JOptionPane.ERROR_MESSAGE);
LOGGER.error("DependenciesNotFoundException", e); LOGGER.error("DependenciesNotFoundException", e);
} }
//如果修改为已签则刷新表格
if(attStatus==AttStatus.signed){
bt_refresh.doClick(); bt_refresh.doClick();
} }
}
} }
} }
}); });
@@ -141,11 +187,13 @@ public class Attend {
}; };
if (alreadyList != null) { if (alreadyList != null) {
for (Attendance attendance : alreadyList) { for (Attendance attendance : alreadyList) {
String attID = attendance.getAttID();
String stuID = String.valueOf(attendance.getStudent().getStuID()); String stuID = String.valueOf(attendance.getStudent().getStuID());
String stuName = String.valueOf(attendance.getStudent().getStuName()); String stuName = String.valueOf(attendance.getStudent().getStuName());
LocalDateTime attTime = attendance.getAttTime(); LocalDateTime attTime = attendance.getAttTime();
AttStatus attStatus = attendance.getAttStatus();
String attTime1 = attTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String attTime1 = attTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
Object row[] = {stuID, stuName, attTime1}; Object row[] = {attID,stuID, stuName, attTime1,String.valueOf(attStatus)};
alreadyTableModel.addRow(row); alreadyTableModel.addRow(row);
} }
} }
@@ -201,7 +249,7 @@ public class Attend {
if (attendance.getAttStatus() == AttStatus.signed) { //筛选出已签到的考勤列表 if (attendance.getAttStatus() == AttStatus.signed) { //筛选出已签到的考勤列表
alreadyList.add(attendance); alreadyList.add(attendance);
} else { } else {
undoList.add(attendance); undoList.add(attendance); //筛选出未签到成功的列表
} }
} }
LOGGER.debug("alreadyList:" + alreadyList); LOGGER.debug("alreadyList:" + alreadyList);
@@ -222,24 +270,35 @@ public class Attend {
}; };
if (alreadyList != null) { if (alreadyList != null) {
for (Attendance attendance : alreadyList) { for (Attendance attendance : alreadyList) {
String attID = attendance.getAttID();
String stuID = String.valueOf(attendance.getStudent().getStuID()); String stuID = String.valueOf(attendance.getStudent().getStuID());
String stuName = String.valueOf(attendance.getStudent().getStuName()); String stuName = String.valueOf(attendance.getStudent().getStuName());
LocalDateTime attTime = attendance.getAttTime(); LocalDateTime attTime = attendance.getAttTime();
AttStatus attStatus = attendance.getAttStatus();
String attTime1 = attTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String attTime1 = attTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
Object row[] = {stuID, stuName, attTime1}; Object row[] = {attID,stuID, stuName, attTime1,String.valueOf(attStatus)};
alreadyTableModel.addRow(row); alreadyTableModel.addRow(row);
} }
} }
attend.table_already.setModel(alreadyTableModel); attend.table_already.setModel(alreadyTableModel);
TableColumn tableColumn1 = attend.table_already.getColumnModel().getColumn(0);
tableColumn1.setWidth(0);
tableColumn1.setMinWidth(0);
tableColumn1.setPreferredWidth(0);
tableColumn1.setMaxWidth(0);
attend.table_already.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
attend.table_already.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
attend.table_already.setCellSelectionEnabled(true);
//未签考勤表格 //未签考勤表格
if(undoList!=null){ //判断该课程是否有学生名单
undoTableModel = new DefaultTableModel(t2_columnTitle, 0){ undoTableModel = new DefaultTableModel(t2_columnTitle, 0){
@Override @Override
public boolean isCellEditable(int row, int column) { public boolean isCellEditable(int row, int column) {
return false; return false;
} }
}; };
for (Attendance attendance : undoList) { for (Attendance attendance : undoList) { //遍历插入数据
String attID = attendance.getAttID(); String attID = attendance.getAttID();
String stuID = String.valueOf(attendance.getStudent().getStuID()); String stuID = String.valueOf(attendance.getStudent().getStuID());
String stuName = String.valueOf(attendance.getStudent().getStuName()); String stuName = String.valueOf(attendance.getStudent().getStuName());
@@ -248,15 +307,19 @@ public class Attend {
undoTableModel.addRow(row); undoTableModel.addRow(row);
} }
attend.table_undo.setModel(undoTableModel); attend.table_undo.setModel(undoTableModel);
//设置第一列隐藏 //设置未签表格的第一列考勤号隐藏
TableColumn tableColumn = attend.table_undo.getColumnModel().getColumn(0); TableColumn tableColumn2 = attend.table_undo.getColumnModel().getColumn(0);
tableColumn.setWidth(0); tableColumn2.setWidth(0);
tableColumn.setMinWidth(0); tableColumn2.setMinWidth(0);
tableColumn.setPreferredWidth(0); tableColumn2.setPreferredWidth(0);
tableColumn.setMaxWidth(0); tableColumn2.setMaxWidth(0);
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0); attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0); attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
attend.table_undo.setCellSelectionEnabled(true); attend.table_undo.setCellSelectionEnabled(true);
}else {
JOptionPane.showMessageDialog(null,"该课程学生名单未导入","提醒!",JOptionPane.INFORMATION_MESSAGE);
}
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true); frame.setVisible(true);

View File

@@ -75,10 +75,10 @@ public class CheckIn {
bt_confim.addActionListener(new ActionListener() { bt_confim.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
number = n1 + n2 + n3 + n4; //获取签到码广播出去
number = textField1.getText() + textField2.getText() + textField3.getText() + textField4.getText();
if (number != null) { if (number != null) {
LOGGER.info(number); teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, null, MessageType.CheckIn));
teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null,null,MessageType.CheckIn));
JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
frame.dispose(); frame.dispose();
} else { } else {

View File

@@ -34,6 +34,7 @@ public class ClassList {
subName = select.substring(select.indexOf(" ") + 1); subName = select.substring(select.indexOf(" ") + 1);
LOGGER.debug(courseID + " " + subName); LOGGER.debug(courseID + " " + subName);
Main.start(workerNo, courseID, subName); Main.start(workerNo, courseID, subName);
frame.dispose();
} else { } else {
JOptionPane.showMessageDialog(null, "请选择您想要进入的课程", "温馨提示!", JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(null, "请选择您想要进入的课程", "温馨提示!", JOptionPane.WARNING_MESSAGE);
} }

View File

@@ -156,15 +156,18 @@ public class Main {
teacherNet.setOnReceiveListener(new ReceiveListener() { teacherNet.setOnReceiveListener(new ReceiveListener() {
@Override @Override
public void onReceive(MessageObject messageObject) { public void onReceive(MessageObject messageObject) {
if(messageObject.getStuNo()!=null){
//学生端举手监听 //学生端举手监听
if (messageObject.getMessageType() == MessageType.RaiseHand) { if (messageObject.getMessageType() == MessageType.RaiseHand) {
JOptionPane.showMessageDialog(null, messageObject.getStuName() + " 举手", "温馨提示!", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "学生 "+messageObject.getStuName() + " 向您举手", "温馨提示!", JOptionPane.INFORMATION_MESSAGE);
} }
//学生留言监听 //学生留言监听
if (messageObject.getMessageType() == MessageType.Chat) { if (messageObject.getMessageType() == MessageType.Chat) {
JOptionPane.showMessageDialog(null, messageObject.getMessage(), "学生 " + messageObject.getStuName() + " 向您留言", JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, messageObject.getMessage(), "学生 " + messageObject.getStuName() + " 向您留言", JOptionPane.INFORMATION_MESSAGE);
} }
} }
}
}); });
} }

View File

@@ -29,12 +29,12 @@ public class SendMessage {
teacherNet.setOnReceiveListener(new ReceiveListener() { teacherNet.setOnReceiveListener(new ReceiveListener() {
@Override @Override
public void onReceive(MessageObject messageObject) { public void onReceive(MessageObject messageObject) {
if(messageObject.getStuNo()!=null){
if(messageObject.getMessageType()==MessageType.Chat){ if(messageObject.getMessageType()==MessageType.Chat){
LocalDateTime sendTime = LocalDateTime.now(); LocalDateTime sendTime = LocalDateTime.now();
messageShow.append("学生 "+messageObject.getStuName()+": "+sendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage()); messageShow.append("学生 "+messageObject.getStuName()+": "+sendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage()+'\n');
System.out.println(); }
} }
} }
}); });
} }

View File

@@ -50,6 +50,7 @@ public class SignIn {
frame.setVisible(false); frame.setVisible(false);
} else { } else {
JOptionPane.showMessageDialog(null, "密码错误,请重新输入", "错误!!", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "密码错误,请重新输入", "错误!!", JOptionPane.ERROR_MESSAGE);
sigIn.password_input.setText(""); //清空输入框内容
} }
isConnectedToDatabase = true; isConnectedToDatabase = true;
} catch (NoConfigException ex) { } catch (NoConfigException ex) {