TeacherUI:JTable reModify by 6.22 00:00

This commit is contained in:
cccccyb
2022-06-12 00:00:43 +08:00
parent bcb2ca2d05
commit 697ee1ef41
10 changed files with 273 additions and 197 deletions

View File

@@ -175,7 +175,7 @@ SELECT attID,
teacher.salt, teacher.salt,
faculty.facID, faculty.facID,
facName facName
FROM attendance, FROM attend,
student, student,
class, class,
major, major,
@@ -183,8 +183,8 @@ FROM attendance,
subject, subject,
teacher, teacher,
faculty faculty
where attendance.courID = course.courID where attend.courID = course.courID
AND attendance.stuID = student.stuID AND attend.stuID = student.stuID
AND class.classID = student.classID AND class.classID = student.classID
AND class.majorID = major.majorID AND class.majorID = major.majorID
AND major.facID = faculty.facID AND major.facID = faculty.facID

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.cfive.classroom.teacher.Attendance"> <form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.cfive.classroom.teacher.Attend">
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> <grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/> <margin top="0" left="0" bottom="0" right="0"/>
<constraints> <constraints>
<xy x="20" y="20" width="500" height="400"/> <xy x="20" y="20" width="500" height="400"/>
@@ -27,12 +27,16 @@
<constraints> <constraints>
<tabbedpane title="已签"/> <tabbedpane title="已签"/>
</constraints> </constraints>
<properties/> <properties>
<enabled value="false"/>
</properties>
<border type="none"/> <border type="none"/>
<children> <children>
<component id="8aba9" class="javax.swing.JTable" binding="table_already"> <component id="8aba9" class="javax.swing.JTable" binding="table_already">
<constraints/> <constraints/>
<properties/> <properties>
<enabled value="true"/>
</properties>
</component> </component>
</children> </children>
</scrollpane> </scrollpane>
@@ -45,21 +49,15 @@
<children> <children>
<component id="6cfbd" class="javax.swing.JTable" binding="table_undo"> <component id="6cfbd" class="javax.swing.JTable" binding="table_undo">
<constraints/> <constraints/>
<properties/> <properties>
<enabled value="true"/>
<font name="Microsoft YaHei" size="14" style="0"/>
</properties>
</component> </component>
</children> </children>
</scrollpane> </scrollpane>
</children> </children>
</tabbedpane> </tabbedpane>
<component id="babc6" class="javax.swing.JLabel" binding="test">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font size="20" style="1"/>
<text value=""/>
</properties>
</component>
</children> </children>
</grid> </grid>
</form> </form>

View File

@@ -0,0 +1,194 @@
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.Attendance;
import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
import com.cfive.classroom.library.database.util.NoConfigException;
import com.cfive.classroom.library.net.TeacherNet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
public class Attend {
private static final Attend attend = new Attend();
private static final JFrame frame = new JFrame("考勤情况");
private JPanel rootPanel;
private JTabbedPane tabbedPane1;
private final Object[] t1_columnTitle = {"学号", "姓名", "签到时间"};
private final Object[] t2_columnTitle = {"考勤号", "学号", "姓名", "签到状态"};
private JTable table_already;
private JTable table_undo;
private TeacherNet teacherNet;
private String courseID;
private final List<Attendance> attendancesList = new ArrayList<>();
private final List<Attendance> alreadyList = new ArrayList<>();
private final List<Attendance> undoList = new ArrayList<>();
private static final Logger LOGGER = LogManager.getLogger();
public Attend() {
//学生签到信息监听
/*
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.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
//获取鼠标所点击的行和列
int row = table_undo.getSelectedRow();
int col = table_undo.getSelectedColumn();
//修改学生签到状态
if (col == 3) {
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]);
LOGGER.debug("attStatus: " + attStatus);
if (attStatus == null) {
LOGGER.debug("test: " + table_undo.getModel().getValueAt(row, col));
table_undo.getModel().setValueAt(AttStatus.not_signed, row, col);
}
String modifyStat = String.valueOf(attStatus);
if (modifyStat != null) {
//将修改后的状态显示出来
table_undo.getModel().setValueAt(modifyStat, row, col);
//将修改在数据库中更改
try {
LocalDateTime currentTime = LocalDateTime.now();
DatabaseHelper.updateAttendance(String.valueOf(table_undo.getModel().getValueAt(row, 0)), attStatus, currentTime);
} 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);
}
} else {
JOptionPane.showMessageDialog(null, "您未进行选择", "提示", JOptionPane.INFORMATION_MESSAGE);
}
}
}
});
}
public static void main(String[] args) {
frame.setContentPane(attend.rootPanel);
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(false);
}
public void start(TeacherNet teacherNet1, String courseID) {
frame.setContentPane(attend.rootPanel);
frame.setSize(600, 400);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
attend.teacherNet = teacherNet1;
attend.courseID = courseID;
try {
attendancesList.addAll(DatabaseHelper.selectAttendanceByCourse(Long.parseLong(courseID))); //导入该课程考勤名单
LOGGER.debug("attendanceList:" + attendancesList);
for (Attendance attendance : attendancesList) {
if (attendance.getAttStatus() == AttStatus.signed) { //筛选出已签到的考勤列表
alreadyList.add(attendance);
} else {
undoList.add(attendance);
}
}
LOGGER.debug("alreadyList:" + alreadyList);
LOGGER.debug("undoList:" + undoList);
} 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(t1_columnTitle, 0) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
if (alreadyList != null) {
for (Attendance attendance : alreadyList) {
String stuID = String.valueOf(attendance.getStudent().getStuID());
String stuName = String.valueOf(attendance.getStudent().getStuName());
LocalDateTime attTime = attendance.getAttTime();
String attTime1 = attTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
Object row[] = {stuID, stuName, attTime1};
alreadyTableModel.addRow(row);
}
}
attend.table_already.setModel(alreadyTableModel);
//未签考勤表格
DefaultTableModel undoTableModel = new DefaultTableModel(t2_columnTitle, 0);
for (Attendance attendance : undoList) {
LOGGER.debug(attendance.getAttID());
String attID = attendance.getAttID();
String stuID = String.valueOf(attendance.getStudent().getStuID());
String stuName = String.valueOf(attendance.getStudent().getStuName());
AttStatus attStatus = attendance.getAttStatus();
Object row[] = {attID, stuID, stuName, String.valueOf(attStatus)};
undoTableModel.addRow(row);
}
attend.table_undo.setModel(undoTableModel);
//设置第一列隐藏
TableColumn tableColumn = attend.table_undo.getColumnModel().getColumn(0);
tableColumn.setWidth(0);
tableColumn.setMinWidth(0);
tableColumn.setPreferredWidth(0);
tableColumn.setMaxWidth(0);
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(0);
attend.table_undo.getTableHeader().getColumnModel().getColumn(0).setMinWidth(0);
LOGGER.debug(table_undo.getColumnModel().getColumnCount());
LOGGER.debug(undoTableModel.getColumnCount());
attend.table_undo.setCellSelectionEnabled(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
}

View File

@@ -1,119 +0,0 @@
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;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
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();
private static final JFrame frame = new JFrame("考勤情况");
private JPanel rootPanel;
private JTabbedPane tabbedPane1;
private Object[] t1_columnTitle = {"学号" , "姓名" , "签到时间"};
private Object[] t2_columnTitle={"学号","姓名","签到状态"};
private Object[][] data={{"a","b","c"},{"d","e","f"},{"1","2","3"}};
private JTable table_already;
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() {
@Override
public void valueChanged(ListSelectionEvent e) {
int row = table_undo.getSelectedRow();
// int col = table_undo.getSelectedColumn();
String newString=table_undo.getValueAt(row,2).toString();
attendance.test.setText(newString);
LOGGER.info(newString);
}
});
}
public static void main(String[] args) {
frame.setContentPane(attendance.rootPanel);
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(false);
}
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);
attendance.table_undo.setCellSelectionEnabled(true);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
}

View File

@@ -12,7 +12,7 @@ import java.security.spec.InvalidKeySpecException;
import java.sql.SQLException; import java.sql.SQLException;
public class ChangePassword { public class ChangePassword {
private static final ChangePassword changePassword=new ChangePassword(); private static final ChangePassword changePassword = new ChangePassword();
private static JFrame frame = new JFrame("修改密码"); private static JFrame frame = new JFrame("修改密码");
private JPanel rootPanel; private JPanel rootPanel;
private JTextField workNo_input; private JTextField workNo_input;
@@ -20,29 +20,29 @@ public class ChangePassword {
private JButton confirm; private JButton confirm;
private JPasswordField newPw_ok; private JPasswordField newPw_ok;
private JPasswordField newPassword; private JPasswordField newPassword;
private String workNo,password1,password2; private String workNo, password1, password2;
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
public ChangePassword() { public ChangePassword() {
confirm.addActionListener(e -> { confirm.addActionListener(e -> {
if(check()){ if (check()) {
//将修改后的密码在数据表修改 //将修改后的密码在数据表修改
try { try {
DatabaseHelper.changePasswdInTeacher(Long.valueOf(workNo_input.getText()),String.valueOf(newPw_ok.getPassword())); DatabaseHelper.changePasswdInTeacher(Long.valueOf(workNo_input.getText()), String.valueOf(newPw_ok.getPassword()));
LOGGER.debug(String.valueOf(newPw_ok.getPassword())); LOGGER.debug(String.valueOf(newPw_ok.getPassword()));
} catch (NoConfigException ex) { } catch (NoConfigException ex) {
JOptionPane.showMessageDialog(null,"没有数据库配置文件","警告",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "没有数据库配置文件", "警告", JOptionPane.ERROR_MESSAGE);
LOGGER.error("No configuration", e); LOGGER.error("No configuration", e);
} catch (SQLException ex) { } catch (SQLException ex) {
JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "数据库出错", "警告", JOptionPane.ERROR_MESSAGE);
LOGGER.error("SQLException",e); LOGGER.error("SQLException", e);
} catch (DependenciesNotFoundException ex) { } catch (DependenciesNotFoundException ex) {
LOGGER.error("DependenciesNotFoundException",e); LOGGER.error("DependenciesNotFoundException", e);
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
LOGGER.error("NoSuchAlgorithmException",e); LOGGER.error("NoSuchAlgorithmException", e);
} catch (InvalidKeySpecException ex) { } catch (InvalidKeySpecException ex) {
LOGGER.error("InvalidKeySpecException",e); LOGGER.error("InvalidKeySpecException", e);
} }
frame.dispose(); frame.dispose();
} }
@@ -56,16 +56,16 @@ public class ChangePassword {
frame.setContentPane(changePassword.rootPanel); frame.setContentPane(changePassword.rootPanel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,400); frame.setSize(600, 400);
frame.setVisible(false); frame.setVisible(false);
} }
public void start(String workNo) { public void start(String workNo) {
frame.setContentPane(changePassword.rootPanel); frame.setContentPane(changePassword.rootPanel);
frame.setSize(600,400); frame.setSize(600, 400);
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
frame.setResizable(false); frame.setResizable(false);
changePassword.workNo=workNo; changePassword.workNo = workNo;
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true); frame.setVisible(true);
} }
@@ -73,16 +73,15 @@ public class ChangePassword {
private boolean check() { private boolean check() {
password1 = String.valueOf(changePassword.newPw_ok.getPassword()); password1 = String.valueOf(changePassword.newPw_ok.getPassword());
password2 = String.valueOf(changePassword.newPassword.getPassword()); password2 = String.valueOf(changePassword.newPassword.getPassword());
if(String.valueOf(changePassword.workNo_input.getText()).equals(workNo)) if (String.valueOf(changePassword.workNo_input.getText()).equals(workNo)) {
{ if (password1.length() == 0 || password2.length() == 0) {
if (password1.length()==0 || password2.length()==0) { JOptionPane.showMessageDialog(null, "输入的密码为空");
JOptionPane.showMessageDialog(null,"输入的密码为空");
return false; return false;
} else if (!password1.equals(password2)) { } else if (!password1.equals(password2)) {
JOptionPane.showMessageDialog(null, "两次输入密码不同"); JOptionPane.showMessageDialog(null, "两次输入密码不同");
return false; return false;
} else return true; } else return true;
}else { } else {
JOptionPane.showMessageDialog(null, "请输入正确的工号"); JOptionPane.showMessageDialog(null, "请输入正确的工号");
return false; return false;
} }

View File

@@ -13,8 +13,8 @@ import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
public class CheckIn { public class CheckIn {
private static final CheckIn checkIn=new CheckIn(); private static final CheckIn checkIn = new CheckIn();
private static final JFrame frame= new JFrame("发布签到码"); private static final JFrame frame = new JFrame("发布签到码");
private JPanel rootPanel; private JPanel rootPanel;
private JTextField textField1; private JTextField textField1;
private JTextField textField2; private JTextField textField2;
@@ -22,9 +22,9 @@ public class CheckIn {
private JTextField textField4; private JTextField textField4;
private JButton bt_confim; private JButton bt_confim;
private JButton bt_cancel; private JButton bt_cancel;
private String n1,n2,n3,n4,number; private String n1, n2, n3, n4, number;
private TeacherNet teacherNet; private TeacherNet teacherNet;
private static final Logger LOGGER= LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
public CheckIn() { public CheckIn() {
//取消按钮的监听 //取消按钮的监听
@@ -38,8 +38,8 @@ public class CheckIn {
textField1.addKeyListener(new KeyAdapter() { textField1.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
n1=textField1.getText(); n1 = textField1.getText();
if(n1.length()>=1){ if (n1.length() >= 1) {
e.consume(); e.consume();
} }
} }
@@ -47,8 +47,8 @@ public class CheckIn {
textField2.addKeyListener(new KeyAdapter() { textField2.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
n2=textField2.getText(); n2 = textField2.getText();
if(n2.length()>=1){ if (n2.length() >= 1) {
e.consume(); e.consume();
} }
} }
@@ -56,16 +56,17 @@ public class CheckIn {
textField3.addKeyListener(new KeyAdapter() { textField3.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
n3=textField3.getText(); n3 = textField3.getText();
if(n3.length()>=1){ if (n3.length() >= 1) {
e.consume(); e.consume();
} }
} }
});textField4.addKeyListener(new KeyAdapter() { });
textField4.addKeyListener(new KeyAdapter() {
@Override @Override
public void keyTyped(KeyEvent e) { public void keyTyped(KeyEvent e) {
n4=textField4.getText(); n4 = textField4.getText();
if(n4.length()>=1){ if (n4.length() >= 1) {
e.consume(); e.consume();
} }
} }
@@ -74,14 +75,14 @@ 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 = n1 + n2 + n3 + n4;
if(number!=null){ if (number != null) {
LOGGER.info(number); LOGGER.info(number);
teacherNet.sendAllMessage(new MessageObject(null,null,number,null,null, MessageType.CheckIn)); teacherNet.sendAllMessage(new MessageObject(null, null, number, null, null, null, MessageType.CheckIn));
JOptionPane.showMessageDialog(null,"签到码发布成功","消息",JOptionPane.INFORMATION_MESSAGE); JOptionPane.showMessageDialog(null, "签到码发布成功", "消息", JOptionPane.INFORMATION_MESSAGE);
frame.dispose(); frame.dispose();
}else { } else {
JOptionPane.showMessageDialog(null,"签到码不能为空","错误",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "签到码不能为空", "错误", JOptionPane.ERROR_MESSAGE);
} }
} }
@@ -94,12 +95,13 @@ public class CheckIn {
frame.pack(); frame.pack();
frame.setVisible(false); frame.setVisible(false);
} }
public void start(TeacherNet teacherNet1){
public void start(TeacherNet teacherNet1) {
frame.setContentPane(checkIn.rootPanel); frame.setContentPane(checkIn.rootPanel);
frame.setSize(600,400); frame.setSize(600, 400);
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);
frame.setResizable(false); frame.setResizable(false);
checkIn.teacherNet=teacherNet1; checkIn.teacherNet = teacherNet1;
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true); frame.setVisible(true);
} }

View File

@@ -20,7 +20,7 @@ public class ClassList {
private JButton bt_enter; private JButton bt_enter;
private JComboBox comboBox; private JComboBox comboBox;
private JPanel selectPanel; private JPanel selectPanel;
private String workerNo,courseID,subName; private String workerNo, courseID, subName;
private final List<Course> courseList = new ArrayList<>(); private final List<Course> courseList = new ArrayList<>();
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();
@@ -31,9 +31,9 @@ public class ClassList {
if (!Objects.equals(classList.comboBox.getSelectedItem(), "--请选择--")) { //判断是否有选择内容 if (!Objects.equals(classList.comboBox.getSelectedItem(), "--请选择--")) { //判断是否有选择内容
String select = classList.comboBox.getSelectedItem().toString(); String select = classList.comboBox.getSelectedItem().toString();
courseID = select.substring(0, select.indexOf(" ")); courseID = select.substring(0, select.indexOf(" "));
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);
} else { } else {
JOptionPane.showMessageDialog(null, "请选择您想要进入的课程", "温馨提示!", JOptionPane.WARNING_MESSAGE); JOptionPane.showMessageDialog(null, "请选择您想要进入的课程", "温馨提示!", JOptionPane.WARNING_MESSAGE);
} }
@@ -60,7 +60,7 @@ public class ClassList {
classList.comboBox.addItem("--请选择--"); classList.comboBox.addItem("--请选择--");
courseList.addAll(DatabaseHelper.queryCourses(Long.parseLong(classList.workerNo))); courseList.addAll(DatabaseHelper.queryCourses(Long.parseLong(classList.workerNo)));
for (Course course : courseList) { for (Course course : courseList) {
classList.comboBox.addItem(course.getCourID()+" "+course.getSubject().getSubName()); classList.comboBox.addItem(course.getCourID() + " " + course.getSubject().getSubName());
} }
} catch (NoConfigException e) { } catch (NoConfigException e) {
JOptionPane.showMessageDialog(null, "没有数据库配置文件", "警告", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "没有数据库配置文件", "警告", JOptionPane.ERROR_MESSAGE);

View File

@@ -1,9 +1,7 @@
package com.cfive.classroom.teacher; package com.cfive.classroom.teacher;
import com.cfive.classroom.library.database.DatabaseHelper; import com.cfive.classroom.library.database.DatabaseHelper;
import com.cfive.classroom.library.database.bean.Course;
import com.cfive.classroom.library.database.bean.Student; import com.cfive.classroom.library.database.bean.Student;
import com.cfive.classroom.library.database.bean.Subject;
import com.cfive.classroom.library.database.util.DependenciesNotFoundException; import com.cfive.classroom.library.database.util.DependenciesNotFoundException;
import com.cfive.classroom.library.database.util.NoConfigException; import com.cfive.classroom.library.database.util.NoConfigException;
import com.cfive.classroom.library.net.TeacherNet; import com.cfive.classroom.library.net.TeacherNet;
@@ -32,8 +30,9 @@ public class Main {
private JButton changePasswordButton; private JButton changePasswordButton;
private JTextField workNo_show; private JTextField workNo_show;
private JTextField subName_show; private JTextField subName_show;
private String workNo,courseID; private String workNo, courseID;
private final List<Student> studentList = new ArrayList<>();; private final List<Student> studentList = new ArrayList<>();
;
private String[] student; private String[] student;
private TeacherNet teacherNet; private TeacherNet teacherNet;
private final Logger LOGGER = LogManager.getLogger(); private final Logger LOGGER = LogManager.getLogger();
@@ -78,8 +77,8 @@ public class Main {
bt_attendance.addActionListener(new ActionListener() { bt_attendance.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Attendance attendance = new Attendance(); Attend attend = new Attend();
attendance.start(teacherNet,courseID); attend.start(teacherNet, courseID);
} }
}); });
@@ -88,7 +87,7 @@ public class Main {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
int person; int person;
String count=""; String count = "";
Object[] dropList = {"提问1个同学", "提问2个同学", "提问3个同学", "提问4个同学", "提问5个同学", "提问6个同学", "提问7个同学"}; Object[] dropList = {"提问1个同学", "提问2个同学", "提问3个同学", "提问4个同学", "提问5个同学", "提问6个同学", "提问7个同学"};
Object selectedValue = JOptionPane.showInputDialog(null, "选择提问同学个数", "随机选人,持续工作中...", Object selectedValue = JOptionPane.showInputDialog(null, "选择提问同学个数", "随机选人,持续工作中...",
JOptionPane.INFORMATION_MESSAGE, null, dropList, dropList[0]); //下拉列表的内容:选择提问的人数 JOptionPane.INFORMATION_MESSAGE, null, dropList, dropList[0]); //下拉列表的内容:选择提问的人数
@@ -121,12 +120,12 @@ public class Main {
for (int s = 0; s < arr.length; s++) { //遍历该数组并把每一个随机数所对应的人放到count中 for (int s = 0; s < arr.length; s++) { //遍历该数组并把每一个随机数所对应的人放到count中
person = Integer.parseInt(arr[s]); person = Integer.parseInt(arr[s]);
count += student[person]; count += student[person];
count+=" "; count += " ";
} }
JOptionPane.showMessageDialog(null, "恭喜以下同学被选中:\n\t\n" + count); JOptionPane.showMessageDialog(null, "恭喜以下同学被选中:\n\t\n" + count);
//将选人结果群发出去 //将选人结果群发出去
teacherNet.sendAllMessage(new MessageObject(null, null, null, null, count, null,MessageType.Select)); teacherNet.sendAllMessage(new MessageObject(null, null, null, null, count, null, MessageType.Select));
}else { } else {
JOptionPane.showMessageDialog(null, "学生名单未导入", "错误", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, "学生名单未导入", "错误", JOptionPane.ERROR_MESSAGE);
} }
} catch (DependenciesNotFoundException ex) { } catch (DependenciesNotFoundException ex) {
@@ -175,7 +174,7 @@ public class Main {
frame.setVisible(false); frame.setVisible(false);
} }
public static void start(String workerNo,String courseID,String subName) { public static void start(String workerNo, String courseID, String subName) {
frame.setContentPane(main.rootPanel); frame.setContentPane(main.rootPanel);
frame.setSize(600, 400); frame.setSize(600, 400);
frame.setLocationRelativeTo(null); frame.setLocationRelativeTo(null);

View File

@@ -10,6 +10,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter; import java.awt.event.ComponentAdapter;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class SendMessage { public class SendMessage {
private static final SendMessage sendMessage=new SendMessage(); private static final SendMessage sendMessage=new SendMessage();
@@ -28,8 +30,8 @@ public class SendMessage {
@Override @Override
public void onReceive(MessageObject messageObject) { public void onReceive(MessageObject messageObject) {
if(messageObject.getMessageType()==MessageType.Chat){ if(messageObject.getMessageType()==MessageType.Chat){
SimpleDateFormat sendTime = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒"); LocalDateTime sendTime = LocalDateTime.now();
messageShow.append("学生 "+messageObject.getStuName()+": "+sendTime.format(System.currentTimeMillis())+'\n'+messageObject.getMessage()); messageShow.append("学生 "+messageObject.getStuName()+": "+sendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageObject.getMessage());
System.out.println(); System.out.println();
} }
@@ -44,8 +46,8 @@ public class SendMessage {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String messageToAll = messageInput.getText(); String messageToAll = messageInput.getText();
if(messageToAll!=null){ if(messageToAll!=null){
SimpleDateFormat sendTime = new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒"); LocalDateTime sendTime = LocalDateTime.now();
messageShow.append("@所有人: "+sendTime.format(System.currentTimeMillis())+'\n'+messageToAll+'\n'); messageShow.append("@所有人: "+sendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒"))+'\n'+messageToAll+'\n');
MessageObject messageObject = new MessageObject(null,null,null,"@所有人:"+messageToAll,null,null,MessageType.ChatToAll); MessageObject messageObject = new MessageObject(null,null,null,"@所有人:"+messageToAll,null,null,MessageType.ChatToAll);
teacherNet.sendAllMessage(messageObject); teacherNet.sendAllMessage(messageObject);
messageInput.setText(""); messageInput.setText("");

View File

@@ -56,7 +56,8 @@ public class SignIn {
JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null,"数据库出错","警告",JOptionPane.ERROR_MESSAGE);
LOGGER.error("SQLException",e); LOGGER.error("SQLException",e);
} catch (DependenciesNotFoundException ex) { } catch (DependenciesNotFoundException ex) {
LOGGER.error("DependenciesNotFoundException",e); JOptionPane.showMessageDialog(null,"未查询到该数据","错误",JOptionPane.ERROR_MESSAGE);
LOGGER.error("DependenciesNotFoundException", e);
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
LOGGER.error("NoSuchAlgorithmException",e); LOGGER.error("NoSuchAlgorithmException",e);
} catch (InvalidKeySpecException ex) { } catch (InvalidKeySpecException ex) {