3 Коміти 86c382840b ... c925ecc170

Автор SHA1 Опис Дата
  BlackPhreak c925ecc170 Added delete option 6 роки тому
  BlackPhreak c44d9d67af Added Class: EditGradesCommand 6 роки тому
  BlackPhreak 18c78bd98c change modifier 6 роки тому

+ 4 - 1
src/me/blackphreak/CommandHandling/CommandManager.java

@@ -1,12 +1,15 @@
 package me.blackphreak.CommandHandling;
 
 import me.blackphreak.CommandHandling.Handlers.CreateStudentCommand;
+import me.blackphreak.CommandHandling.Handlers.EditGradesCommand;
+import me.blackphreak.CommandHandling.Handlers.EditStudentCommand;
 import me.blackphreak.CommandHandling.Handlers.SearchStudentCommand;
 
 public class CommandManager {
 	public static void registerCommands() {
 		CommandHandler.registerHandler("Search Student",    new SearchStudentCommand("Search student(s) from database with condition(s)"));
 		CommandHandler.registerHandler("Create Student",    new CreateStudentCommand("Insert a new student record to database"));
-		CommandHandler.registerHandler("Edit Student",      new EditStudentCommand("Modify the information of a selected student"));
+		CommandHandler.registerHandler("Edit Student",      new EditStudentCommand("Modify a information of selected student"));
+		CommandHandler.registerHandler("Edit Grades",       new EditGradesCommand("Modify grades of a selected student"));
 	}
 }

+ 16 - 0
src/me/blackphreak/CommandHandling/Handlers/EditGradesCommand.java

@@ -0,0 +1,16 @@
+package me.blackphreak.CommandHandling.Handlers;
+
+import me.blackphreak.CommandHandling.AbstractCommandHandler;
+
+public class EditGradesCommand extends AbstractCommandHandler {
+	
+	public EditGradesCommand(String desc) {
+		super(desc);
+	}
+	
+	@Override
+	public boolean handle() {
+		
+		return false;
+	}
+}

+ 33 - 4
src/me/blackphreak/CommandHandling/EditStudentCommand.java → src/me/blackphreak/CommandHandling/Handlers/EditStudentCommand.java

@@ -1,6 +1,6 @@
-package me.blackphreak.CommandHandling;
+package me.blackphreak.CommandHandling.Handlers;
 
-import me.blackphreak.CommandHandling.Handlers.SearchStudentCommand;
+import me.blackphreak.CommandHandling.AbstractCommandHandler;
 import me.blackphreak.Database;
 import me.blackphreak.Debug.Debug;
 
@@ -110,6 +110,13 @@ public class EditStudentCommand extends AbstractCommandHandler {
 				));
 			}
 			
+			// delete option
+			System.out.println(String.format(
+					"  %2s. %-15s",
+					"98",
+					"!! Delete Selected Student(s) !!"
+			));
+			
 			// exit option
 			System.out.println(String.format(
 					"  %2s. %-15s",
@@ -122,6 +129,24 @@ public class EditStudentCommand extends AbstractCommandHandler {
 			if (selected == -1)
 				continue;
 			
+			if (selected == 98)
+			{
+				System.out.println("Are you sure to DELETE selected student(s)? This process is IRREVERSIBLE!");
+				System.out.println("** DEFAULT action is back to main menu **");
+				System.out.println("** type \"confirm\" to delete **");
+				var confirmation = promptQuestion("confirm deletion? > ", false);
+				if (confirmation.equalsIgnoreCase("confirm")) {
+					var updated = Database.getInstance().update("DELETE FROM Student WHERE StudentID IN (\""
+							+ selectedIDs() + "\");");
+					
+					System.out.println("Deleted " + updated + " student(s).");
+					System.out.println("Deleted student(s): " + String.join(", ", selectedStudentID));
+				}
+				
+				lastCmd = "exit";  // back to main menu
+				return false;
+			}
+			
 			if (selected == 99)
 			{
 				lastCmd = "exit";
@@ -143,12 +168,16 @@ public class EditStudentCommand extends AbstractCommandHandler {
 	
 	private void doEdit() {
 		var newValue = promptQuestion("The value that you want it to be: ");
-		var ids = String.join("\",\"", selectedStudentID);
-		var updated = Database.getInstance().update("UPDATE Student SET " + selectedColumn + " = \""+newValue+"\" WHERE StudentID IN (\""+ids+"\");");
+		var updated = Database.getInstance().update("UPDATE Student SET " + selectedColumn
+				+ " = \""+newValue+"\" WHERE StudentID IN (\"" + selectedIDs() + "\");");
 		
 		if (updated <= 0)
 			System.out.println("No changes have been made.");
 		else
 			System.out.println("Update successfully made to "+updated+" student(s).");
 	}
+	
+	private String selectedIDs() {
+		return String.join("\",\"", selectedStudentID);
+	}
 }

+ 1 - 1
src/me/blackphreak/Database.java

@@ -7,7 +7,7 @@ import java.sql.*;
 
 public class Database {
 	// ref.: http://www.runoob.com/sqlite/sqlite-java.html
-	Connection conn;
+	private Connection conn;
 	
 	private static Database instance;