|
@@ -3,6 +3,7 @@ package me.blackphreak.CommandHandling.Handlers;
|
|
|
import me.blackphreak.CommandHandling.AbstractCommandHandler;
|
|
|
import me.blackphreak.Database;
|
|
|
import me.blackphreak.Debug.Debug;
|
|
|
+import me.blackphreak.ImmutableList;
|
|
|
import me.blackphreak.Student.AbstractStudent;
|
|
|
import me.blackphreak.Student.Types.LocalStudent;
|
|
|
import me.blackphreak.Student.Types.OverseaStudent;
|
|
@@ -19,7 +20,8 @@ import static me.blackphreak.Lib.promptQuestion;
|
|
|
import static me.blackphreak.Lib.tryParseUInt;
|
|
|
|
|
|
public class SearchStudentCommand extends AbstractCommandHandler {
|
|
|
- private List<String> colNames = new ArrayList<>();
|
|
|
+ private static List<String> colNames = new ArrayList<>();
|
|
|
+ public static ImmutableList<String> unmodColNames;
|
|
|
private HashMap</*colName*/String, /*searchCondition*/String> selectedCols;
|
|
|
|
|
|
public SearchStudentCommand(String desc) {
|
|
@@ -35,6 +37,8 @@ public class SearchStudentCommand extends AbstractCommandHandler {
|
|
|
} catch (SQLException e) {
|
|
|
db.close();
|
|
|
}
|
|
|
+
|
|
|
+ unmodColNames = new ImmutableList<>(colNames);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -89,6 +93,13 @@ public class SearchStudentCommand extends AbstractCommandHandler {
|
|
|
&& targetCol.matches("\\d+")
|
|
|
)
|
|
|
.sorted()
|
|
|
+ .filter(targetCol -> {
|
|
|
+ var col = tryParseUInt(targetCol) - 1;
|
|
|
+ if (col == -1)
|
|
|
+ return false; // filter it out
|
|
|
+ else
|
|
|
+ return col >= 0 && col < colNames.size();
|
|
|
+ })
|
|
|
.forEach(targetCol ->
|
|
|
selectedCols.put(colNames.get(
|
|
|
tryParseUInt(targetCol)-1
|
|
@@ -135,14 +146,15 @@ public class SearchStudentCommand extends AbstractCommandHandler {
|
|
|
try {
|
|
|
do {
|
|
|
// read cols
|
|
|
- String StudentID = rs.getString("StudentID");
|
|
|
- String HKID = rs.getString("HKID");
|
|
|
- String VISA = rs.getString("VISA");
|
|
|
- String Nationality = rs.getString("Nationality");
|
|
|
- String ChtName = rs.getString("ChtName");
|
|
|
- String EngName = rs.getString("EngName");
|
|
|
- String Address = rs.getString("Address");
|
|
|
- String MobileNum = rs.getString("MobileNum");
|
|
|
+ var StudentID = rs.getString("StudentID");
|
|
|
+ var HKID = rs.getString("HKID");
|
|
|
+ var VISA = rs.getString("VISA");
|
|
|
+ var Nationality = rs.getString("Nationality");
|
|
|
+ var ChtName = rs.getString("ChtName");
|
|
|
+ var EngName = rs.getString("EngName");
|
|
|
+ var Address = rs.getString("Address");
|
|
|
+ var MobileNum = rs.getString("MobileNum");
|
|
|
+ var Semester = rs.getInt("Semester");
|
|
|
|
|
|
AbstractStudent stu;
|
|
|
if (VISA != null && !VISA.isBlank() && !VISA.isEmpty())
|
|
@@ -159,7 +171,7 @@ public class SearchStudentCommand extends AbstractCommandHandler {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- stu.assign(StudentID, ChtName, EngName, Address, MobileNum, Nationality);
|
|
|
+ stu.assign(StudentID, ChtName, EngName, Address, MobileNum, Nationality, Semester);
|
|
|
students.put(StudentID, stu);
|
|
|
} while (rs.next());
|
|
|
}
|
|
@@ -170,27 +182,29 @@ public class SearchStudentCommand extends AbstractCommandHandler {
|
|
|
}
|
|
|
|
|
|
System.out.println(String.format(
|
|
|
- "\nResults:\n+ %-13s | %-13s | %-13s | %-20s | %-30s | %-10s | %s",
|
|
|
+ "\nResults:\n+ %-13s | %-13s | %-13s | %-10s | %-20s | %-30s | %-10s | %s",
|
|
|
"StudentID",
|
|
|
"HKID/VISA",
|
|
|
"Nationality",
|
|
|
+ "Semester",
|
|
|
"ChtName",
|
|
|
"EngName",
|
|
|
"Mobile",
|
|
|
"Address"
|
|
|
));
|
|
|
- // + id + hkid/visa + nationality +
|
|
|
- System.out.print("+---------------+---------------+---------------+");
|
|
|
+ // + id + hkid/visa + nationality + semester
|
|
|
+ System.out.print("+---------------+---------------+---------------+------------+");
|
|
|
// ChtName + EngName + mobile + addr
|
|
|
System.out.println("----------------------+--------------------------------+------------+-->");
|
|
|
|
|
|
students.forEach((k, v) -> System.out.println(
|
|
|
- String.format("+ %-13s | %-13s | %-13s | %-"+(20-v.getChtName().length())+"s | %-30s | %-10s | %s",
|
|
|
+ String.format("+ %-13s | %-13s | %-13s | %-10s | %-"+(20-v.getChtName().length())+"s | %-30s | %-10s | %s",
|
|
|
k,
|
|
|
(v instanceof LocalStudent)
|
|
|
? ((LocalStudent)v).getHKID()
|
|
|
: ((OverseaStudent)v).getVisa(),
|
|
|
v.getNationality(),
|
|
|
+ v.getSemester(),
|
|
|
v.getChtName(),
|
|
|
v.getEngName(),
|
|
|
v.getMobileNumber(),
|
|
@@ -198,14 +212,10 @@ public class SearchStudentCommand extends AbstractCommandHandler {
|
|
|
)
|
|
|
));
|
|
|
|
|
|
- // + id + hkid/visa + nationality +
|
|
|
- System.out.print("+---------------+---------------+---------------+");
|
|
|
+ // + id + hkid/visa + nationality + semester
|
|
|
+ System.out.print("+---------------+---------------+---------------+------------+");
|
|
|
// ChtName + EngName + mobile + addr
|
|
|
System.out.println("----------------------+--------------------------------+------------+-->");
|
|
|
|
|
|
}
|
|
|
-
|
|
|
- private void undo() {
|
|
|
-
|
|
|
- }
|
|
|
}
|