added lock feature
This commit is contained in:
parent
77c659d8e5
commit
65631a126d
5 changed files with 297 additions and 257 deletions
src
database
gui
readsafefile
|
@ -76,6 +76,7 @@ public class DatabaseManager {
|
||||||
data.getYoutubeLink().get(i), // YouTube-Link
|
data.getYoutubeLink().get(i), // YouTube-Link
|
||||||
Integer.parseInt(data.getQualification().get(i)), // Qualifikation
|
Integer.parseInt(data.getQualification().get(i)), // Qualifikation
|
||||||
data.getVictors().get(i), // Sieger
|
data.getVictors().get(i), // Sieger
|
||||||
|
false,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,278 +15,285 @@ import java.sql.ResultSet;
|
||||||
public class Sqlite {
|
public class Sqlite {
|
||||||
|
|
||||||
private static String url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
private static String url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
||||||
private static String filename;
|
private static String filename;
|
||||||
|
|
||||||
private ArrayList<String> levelname = new ArrayList<String>();
|
private ArrayList<String> levelname = new ArrayList<String>();
|
||||||
private ArrayList<String> levelID = new ArrayList<String>();
|
private ArrayList<String> levelID = new ArrayList<String>();
|
||||||
private ArrayList<String> author = new ArrayList<String>();
|
private ArrayList<String> author = new ArrayList<String>();
|
||||||
private ArrayList<String> creators = new ArrayList<String>();
|
private ArrayList<String> creators = new ArrayList<String>();
|
||||||
private ArrayList<String> verifier = new ArrayList<String>();
|
private ArrayList<String> verifier = new ArrayList<String>();
|
||||||
private ArrayList<String> verificationLink = new ArrayList<String>();
|
private ArrayList<String> verificationLink = new ArrayList<String>();
|
||||||
private ArrayList<String> percenttoqualify = new ArrayList<String>();
|
private ArrayList<String> percenttoqualify = new ArrayList<String>();
|
||||||
private ArrayList<String> records = new ArrayList<String>();
|
private ArrayList<String> records = new ArrayList<String>();
|
||||||
private ArrayList<String> completed = new ArrayList<String>();
|
private ArrayList<String> completed = new ArrayList<String>();
|
||||||
private ArrayList<String> rawLevelNames = new ArrayList<String>();
|
private ArrayList<String> rawLevelNames = new ArrayList<String>();
|
||||||
private ArrayList<Integer> attempts = new ArrayList<Integer>();
|
private ArrayList<Integer> attempts = new ArrayList<Integer>();
|
||||||
|
private ArrayList<Boolean> locked = new ArrayList<Boolean>(); // New column
|
||||||
|
|
||||||
|
public ArrayList<String> getLevelname() {
|
||||||
|
return levelname;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getLevelID() {
|
||||||
|
return levelID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getCreators() {
|
||||||
|
return creators;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getVerifier() {
|
||||||
|
return verifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getVerificationLink() {
|
||||||
|
return verificationLink;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getPercenttoqualify() {
|
||||||
|
return percenttoqualify;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getRecords() {
|
||||||
|
return records;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getCompleted() {
|
||||||
|
return completed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getRawLevelNames() {
|
||||||
|
return rawLevelNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Integer> getAttempts() {
|
||||||
|
return attempts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Boolean> getLocked() {
|
||||||
|
return locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sqlite(String dbname) { // setzt variablen
|
||||||
|
url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
||||||
|
url += dbname + ".db";
|
||||||
|
filename = dbname + "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean exists() { // überprüft, ob datenbank existiert
|
||||||
|
|
||||||
|
File file = new File("C:\\ExtremeDemonList\\database\\sqlite\\" + filename + ".db");
|
||||||
|
if(file.exists()) {
|
||||||
|
return true; // ja
|
||||||
|
} else {
|
||||||
|
return false; // nein
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createNewDatabase(String dbname) { // erstellt eine neue datenbank
|
||||||
|
url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
||||||
|
url += dbname + ".db";
|
||||||
|
filename = dbname;
|
||||||
|
try (Connection conn = DriverManager.getConnection(url)) {
|
||||||
|
} catch(SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<String> getLevelname() {
|
public void createNewTable(String tablename) {
|
||||||
return levelname;
|
String sql = "CREATE TABLE IF NOT EXISTS " + tablename + " (\n"
|
||||||
}
|
+ " id INTEGER PRIMARY KEY,\n"
|
||||||
|
+ " placement INTEGER NOT NULL,\n"
|
||||||
public ArrayList<String> getLevelID() {
|
+ " levelname TEXT NOT NULL,\n"
|
||||||
return levelID;
|
+ " levelnameRaw TEXT NOT NULL,\n" // Hinzugefügt
|
||||||
}
|
+ " levelID INTEGER NOT NULL,\n"
|
||||||
|
+ " author TEXT NOT NULL,\n"
|
||||||
public ArrayList<String> getAuthor() {
|
+ " creators TEXT NOT NULL,\n"
|
||||||
return author;
|
+ " verifier TEXT NOT NULL,\n"
|
||||||
}
|
+ " verificationLink TEXT NOT NULL,\n"
|
||||||
|
+ " percentToQualify INTEGER NOT NULL,\n"
|
||||||
public ArrayList<String> getCreators() {
|
+ " records TEXT NOT NULL,\n"
|
||||||
return creators;
|
+ " attempts INTEGER NOT NULL,\n"
|
||||||
}
|
+ " completed BOOLEAN NOT NULL,\n"
|
||||||
|
+ " locked BOOLEAN NOT NULL\n" // Neue Spalte
|
||||||
public ArrayList<String> getVerifier() {
|
+ ");";
|
||||||
return verifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getVerificationLink() {
|
|
||||||
return verificationLink;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getPercenttoqualify() {
|
|
||||||
return percenttoqualify;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getRecords() {
|
|
||||||
return records;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getCompleted() {
|
|
||||||
return completed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getRawLevelNames() {
|
|
||||||
return rawLevelNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Integer> getAttempts() {
|
|
||||||
return attempts;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sqlite(String dbname) { // setzt variablen
|
|
||||||
url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
|
||||||
url += dbname + ".db";
|
|
||||||
filename = dbname + "";
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean exists() { // überprüft, ob datenbank existiert
|
|
||||||
|
|
||||||
File file = new File("C:\\ExtremeDemonList\\database\\sqlite\\" + filename + ".db");
|
|
||||||
if(file.exists()) {
|
|
||||||
return true; // ja
|
|
||||||
} else {
|
|
||||||
return false; // nein
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createNewDatabase(String dbname) { // erstellt eine neue datenbank
|
|
||||||
url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
|
|
||||||
url += dbname + ".db";
|
|
||||||
filename = dbname;
|
|
||||||
try (Connection conn = DriverManager.getConnection(url)) {
|
|
||||||
} catch(SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void createNewTable(String tablename) {
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
String sql = "CREATE TABLE IF NOT EXISTS " + tablename + " (\n"
|
|
||||||
+ " id INTEGER PRIMARY KEY,\n"
|
|
||||||
+ " placement INTEGER NOT NULL,\n"
|
|
||||||
+ " levelname TEXT NOT NULL,\n"
|
|
||||||
+ " levelnameRaw TEXT NOT NULL,\n" // Hinzugefügt
|
|
||||||
+ " levelID INTEGER NOT NULL,\n"
|
|
||||||
+ " author TEXT NOT NULL,\n"
|
|
||||||
+ " creators TEXT NOT NULL,\n"
|
|
||||||
+ " verifier TEXT NOT NULL,\n"
|
|
||||||
+ " verificationLink TEXT NOT NULL,\n"
|
|
||||||
+ " percentToQualify INTEGER NOT NULL,\n"
|
|
||||||
+ " records TEXT NOT NULL,\n"
|
|
||||||
+ " attempts INTEGER NOT NULL,\n"
|
|
||||||
+ " completed BOOLEAN NOT NULL\n"
|
|
||||||
+ ");";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
|
||||||
Statement stmt = conn.createStatement()) {
|
Statement stmt = conn.createStatement()) {
|
||||||
// create a new table
|
// create a new table
|
||||||
stmt.execute(sql);
|
stmt.execute(sql);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void insertData(String tablename, Integer attempts, int placement, String levelname, String levelnameRaw, int levelid, String author, String creators, String verifier, String verificationLink, int percenttoqualify, String records, boolean completed) {
|
public void insertData(String tablename, Integer attempts, int placement, String levelname, String levelnameRaw, int levelid, String author, String creators, String verifier, String verificationLink, int percenttoqualify, String records, boolean completed, boolean locked) {
|
||||||
String sql = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
String sql = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed, locked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
System.out.println("tablename: " + levelname);
|
System.out.println("tablename: " + levelname);
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||||
pstmt.setInt(1, placement);
|
pstmt.setInt(1, placement);
|
||||||
pstmt.setString(2, levelname);
|
pstmt.setString(2, levelname);
|
||||||
pstmt.setString(3, levelnameRaw);
|
pstmt.setString(3, levelnameRaw);
|
||||||
pstmt.setInt(4, levelid);
|
pstmt.setInt(4, levelid);
|
||||||
pstmt.setString(5, author);
|
pstmt.setString(5, author);
|
||||||
pstmt.setString(6, creators);
|
pstmt.setString(6, creators);
|
||||||
pstmt.setString(7, verifier);
|
pstmt.setString(7, verifier);
|
||||||
pstmt.setString(8, verificationLink);
|
pstmt.setString(8, verificationLink);
|
||||||
pstmt.setInt(9, percenttoqualify);
|
pstmt.setInt(9, percenttoqualify);
|
||||||
pstmt.setString(10, records);
|
pstmt.setString(10, records);
|
||||||
pstmt.setInt(11, attempts);
|
pstmt.setInt(11, attempts);
|
||||||
pstmt.setBoolean(12, completed);
|
pstmt.setBoolean(12, completed);
|
||||||
pstmt.executeUpdate();
|
pstmt.setBoolean(13, locked);
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void queryData(String tablename) {
|
public void queryData(String tablename) {
|
||||||
|
|
||||||
String sql = "SELECT levelname, levelNameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, attempts, completed, records FROM " + tablename;
|
String sql = "SELECT levelname, levelNameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, attempts, completed, records, locked FROM " + tablename;
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
Statement stmt = conn.createStatement();
|
Statement stmt = conn.createStatement();
|
||||||
ResultSet rs = stmt.executeQuery(sql)){
|
ResultSet rs = stmt.executeQuery(sql)){
|
||||||
|
|
||||||
// loop through the result set
|
// loop through the result set
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
levelname.add(rs.getString("levelname"));
|
levelname.add(rs.getString("levelname"));
|
||||||
levelID.add(rs.getInt("levelID") + "");
|
levelID.add(rs.getInt("levelID") + "");
|
||||||
author.add(rs.getString("author"));
|
author.add(rs.getString("author"));
|
||||||
creators.add(rs.getString("creators"));
|
creators.add(rs.getString("creators"));
|
||||||
verifier.add(rs.getString("verifier"));
|
verifier.add(rs.getString("verifier"));
|
||||||
verificationLink.add(rs.getString("verificationLink"));
|
verificationLink.add(rs.getString("verificationLink"));
|
||||||
percenttoqualify.add(rs.getInt("percentToQualify") + "");
|
percenttoqualify.add(rs.getInt("percentToQualify") + "");
|
||||||
completed.add(rs.getBoolean("completed") + "");
|
completed.add(rs.getBoolean("completed") + "");
|
||||||
records.add(rs.getString("records"));
|
records.add(rs.getString("records"));
|
||||||
rawLevelNames.add(rs.getString("levelNameRaw"));
|
rawLevelNames.add(rs.getString("levelNameRaw"));
|
||||||
attempts.add(rs.getInt("attempts"));
|
attempts.add(rs.getInt("attempts"));
|
||||||
|
locked.add(rs.getBoolean("locked")); // Get the value of the new column
|
||||||
|
}
|
||||||
|
|
||||||
}
|
} catch(SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
} catch(SQLException e) {
|
}
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
public void sortData(String tablename) throws SQLException {
|
||||||
|
FetchData data = new FetchData();
|
||||||
|
|
||||||
public void sortData(String tablename) throws SQLException {
|
ArrayList<String> levelnamelocal = new ArrayList<String>();
|
||||||
FetchData data = new FetchData();
|
ArrayList<String> levelIDlocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> authorlocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> creatorslocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> verifierlocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> verificationLinklocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> percenttoqualifylocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> recordslocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> completedlocal = new ArrayList<String>();
|
||||||
|
ArrayList<String> rawLevelNameslocal = new ArrayList<String>();
|
||||||
|
ArrayList<Integer> attemptsLocal = new ArrayList<Integer>();
|
||||||
|
ArrayList<Boolean> lockedLocal = new ArrayList<Boolean>();
|
||||||
|
|
||||||
ArrayList<String> levelnamelocal = new ArrayList<String>();
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
ArrayList<String> levelIDlocal = new ArrayList<String>();
|
Statement stmt = conn.createStatement()) {
|
||||||
ArrayList<String> authorlocal = new ArrayList<String>();
|
|
||||||
ArrayList<String> creatorslocal = new ArrayList<String>();
|
|
||||||
ArrayList<String> verifierlocal = new ArrayList<String>();
|
|
||||||
ArrayList<String> verificationLinklocal = new ArrayList<String>();
|
|
||||||
ArrayList<String> percenttoqualifylocal = new ArrayList<String>();
|
|
||||||
ArrayList<String> recordslocal = new ArrayList<String>();
|
|
||||||
ArrayList<String> completedlocal = new ArrayList<String>();
|
|
||||||
ArrayList<String> rawLevelNameslocal = new ArrayList<String>();
|
|
||||||
ArrayList<Integer> attemptsLocal = new ArrayList<Integer>();
|
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
// Erstelle eine neue Tabelle mit einem temporären Namen
|
||||||
Statement stmt = conn.createStatement()) {
|
String tempTableName = tablename + "_temp";
|
||||||
|
createNewTable(tempTableName);
|
||||||
|
|
||||||
// Erstelle eine neue Tabelle mit einem temporären Namen
|
// Holen Sie sich die maximale Platzierung in der Tabelle
|
||||||
String tempTableName = tablename + "_temp";
|
int maxPlacement = 0;
|
||||||
createNewTable(tempTableName);
|
String getMaxPlacementQuery = "SELECT MAX(placement) AS maxPlacement FROM " + tablename;
|
||||||
|
ResultSet maxPlacementResult = stmt.executeQuery(getMaxPlacementQuery);
|
||||||
|
if (maxPlacementResult.next()) {
|
||||||
|
maxPlacement = maxPlacementResult.getInt("maxPlacement");
|
||||||
|
}
|
||||||
|
|
||||||
// Holen Sie sich die maximale Platzierung in der Tabelle
|
// Durchlaufen Sie die Platzierungen und holen Sie die Daten entsprechend
|
||||||
int maxPlacement = 0;
|
for (int i = 1; i <= maxPlacement; i++) {
|
||||||
String getMaxPlacementQuery = "SELECT MAX(placement) AS maxPlacement FROM " + tablename;
|
String sql = "SELECT * FROM " + tablename + " WHERE placement = " + i;
|
||||||
ResultSet maxPlacementResult = stmt.executeQuery(getMaxPlacementQuery);
|
ResultSet rs = stmt.executeQuery(sql);
|
||||||
if (maxPlacementResult.next()) {
|
while (rs.next()) {
|
||||||
maxPlacement = maxPlacementResult.getInt("maxPlacement");
|
levelnamelocal.add(rs.getString("levelname"));
|
||||||
}
|
levelIDlocal.add(rs.getInt("levelID") + "");
|
||||||
|
authorlocal.add(rs.getString("author"));
|
||||||
|
creatorslocal.add(rs.getString("creators"));
|
||||||
|
verifierlocal.add(rs.getString("verifier"));
|
||||||
|
verificationLinklocal.add(rs.getString("verificationLink"));
|
||||||
|
percenttoqualifylocal.add(rs.getInt("percentToQualify") + "");
|
||||||
|
completedlocal.add(rs.getBoolean("completed") + "");
|
||||||
|
recordslocal.add(rs.getString("records"));
|
||||||
|
rawLevelNameslocal.add(rs.getString("levelNameRaw"));
|
||||||
|
attemptsLocal.add(rs.getInt("attempts"));
|
||||||
|
lockedLocal.add(rs.getBoolean("locked"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Durchlaufen Sie die Platzierungen und holen Sie die Daten entsprechend
|
// Lösche die alte Tabelle
|
||||||
for (int i = 1; i <= maxPlacement; i++) {
|
stmt.executeUpdate("DROP TABLE IF EXISTS " + tablename);
|
||||||
String sql = "SELECT * FROM " + tablename + " WHERE placement = " + i;
|
|
||||||
ResultSet rs = stmt.executeQuery(sql);
|
|
||||||
while (rs.next()) {
|
|
||||||
levelnamelocal.add(rs.getString("levelname"));
|
|
||||||
levelIDlocal.add(rs.getInt("levelID") + "");
|
|
||||||
authorlocal.add(rs.getString("author"));
|
|
||||||
creatorslocal.add(rs.getString("creators"));
|
|
||||||
verifierlocal.add(rs.getString("verifier"));
|
|
||||||
verificationLinklocal.add(rs.getString("verificationLink"));
|
|
||||||
percenttoqualifylocal.add(rs.getInt("percentToQualify") + "");
|
|
||||||
completedlocal.add(rs.getBoolean("completed") + "");
|
|
||||||
recordslocal.add(rs.getString("records"));
|
|
||||||
rawLevelNameslocal.add(rs.getString("levelNameRaw"));
|
|
||||||
attemptsLocal.add(rs.getInt("attempts"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Lösche die alte Tabelle
|
// Erstelle eine neue Tabelle mit dem ursprünglichen Namen
|
||||||
stmt.executeUpdate("DROP TABLE IF EXISTS " + tablename);
|
createNewTable(tablename);
|
||||||
|
|
||||||
// Erstelle eine neue Tabelle mit dem ursprünglichen Namen
|
// Füge Daten in die neue Tabelle ein
|
||||||
createNewTable(tablename);
|
String insert = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed, locked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
try (PreparedStatement pstmt = conn.prepareStatement(insert)) {
|
||||||
|
for (int i = 0; i < levelnamelocal.size(); i++) {
|
||||||
|
pstmt.setInt(1, i + 1);
|
||||||
|
pstmt.setString(2, levelnamelocal.get(i));
|
||||||
|
pstmt.setString(3, rawLevelNameslocal.get(data.allLevels().indexOf(rawLevelNameslocal.get(i))));
|
||||||
|
pstmt.setInt(4, Integer.parseInt(levelIDlocal.get(i)));
|
||||||
|
pstmt.setString(5, authorlocal.get(i));
|
||||||
|
pstmt.setString(6, creatorslocal.get(i));
|
||||||
|
pstmt.setString(7, verifierlocal.get(i));
|
||||||
|
pstmt.setString(8, verificationLinklocal.get(i));
|
||||||
|
pstmt.setInt(9, Integer.parseInt(percenttoqualifylocal.get(i)));
|
||||||
|
pstmt.setString(10, recordslocal.get(i));
|
||||||
|
pstmt.setInt(11, attemptsLocal.get(i));
|
||||||
|
pstmt.setBoolean(12, false);
|
||||||
|
pstmt.setBoolean(13, lockedLocal.get(i)); // Insert value of locked column
|
||||||
|
pstmt.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Füge Daten in die neue Tabelle ein
|
public void modifyData(String levelname, boolean completedStatus, int attempts, boolean lock) {
|
||||||
String insert = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
String sql = "UPDATE levels SET completed = ?, attempts = ?, locked = ? WHERE levelname = ?";
|
||||||
try (PreparedStatement pstmt = conn.prepareStatement(insert)) {
|
|
||||||
for (int i = 0; i < levelnamelocal.size(); i++) {
|
|
||||||
pstmt.setInt(1, i + 1);
|
|
||||||
pstmt.setString(2, levelnamelocal.get(i));
|
|
||||||
pstmt.setString(3, rawLevelNameslocal.get(data.allLevels().indexOf(rawLevelNameslocal.get(i))));
|
|
||||||
pstmt.setInt(4, Integer.parseInt(levelIDlocal.get(i)));
|
|
||||||
pstmt.setString(5, authorlocal.get(i));
|
|
||||||
pstmt.setString(6, creatorslocal.get(i));
|
|
||||||
pstmt.setString(7, verifierlocal.get(i));
|
|
||||||
pstmt.setString(8, verificationLinklocal.get(i));
|
|
||||||
pstmt.setInt(9, Integer.parseInt(percenttoqualifylocal.get(i)));
|
|
||||||
pstmt.setString(10, recordslocal.get(i));
|
|
||||||
pstmt.setInt(11, attemptsLocal.get(i));
|
|
||||||
pstmt.setBoolean(12, false);
|
|
||||||
pstmt.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void modifyData(String levelname, boolean completedStatus, int attempts) {
|
|
||||||
String sql = "UPDATE levels SET completed = ?, attempts = ? WHERE levelname = ?";
|
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url);
|
|
||||||
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
|
||||||
pstmt.setBoolean(1, completedStatus);
|
|
||||||
pstmt.setInt(2, attempts);
|
|
||||||
pstmt.setString(3, levelname);
|
|
||||||
|
|
||||||
int rowsUpdated = pstmt.executeUpdate();
|
|
||||||
if (rowsUpdated > 0) {
|
|
||||||
System.out.println("Data updated successfully.");
|
|
||||||
} else {
|
|
||||||
System.out.println("Data not found for levelname: " + levelname);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
try (Connection conn = DriverManager.getConnection(url);
|
||||||
|
PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||||
|
pstmt.setBoolean(1, completedStatus);
|
||||||
|
pstmt.setInt(2, attempts);
|
||||||
|
pstmt.setBoolean(3, lock); // Korrigierte Reihenfolge
|
||||||
|
pstmt.setString(4, levelname); // Korrigierte Reihenfolge
|
||||||
|
|
||||||
|
int rowsUpdated = pstmt.executeUpdate();
|
||||||
|
if (rowsUpdated > 0) {
|
||||||
|
System.out.println("Data updated successfully.");
|
||||||
|
} else {
|
||||||
|
System.out.println("Data not found for levelname: " + levelname);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package gui;
|
||||||
import java.awt.Button;
|
import java.awt.Button;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
@ -145,6 +146,7 @@ public class MainGUI {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean[] comp = new boolean[data.getLevelname().size()];
|
boolean[] comp = new boolean[data.getLevelname().size()];
|
||||||
|
boolean[] lockbool = new boolean[data.getLevelname().size()];
|
||||||
for(int i = 0; i < data.getLevelname().size(); i++) {
|
for(int i = 0; i < data.getLevelname().size(); i++) {
|
||||||
final int index = i;
|
final int index = i;
|
||||||
progress.setValue(i + 1);
|
progress.setValue(i + 1);
|
||||||
|
@ -157,34 +159,62 @@ public class MainGUI {
|
||||||
contents.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
|
contents.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
|
||||||
contents.setLayout(null);
|
contents.setLayout(null);
|
||||||
|
|
||||||
|
JPanel lockind = new JPanel();
|
||||||
|
lockind.setBounds(678, 0, 2, 50);
|
||||||
|
|
||||||
JButton completed = new JButton("x");
|
JButton completed = new JButton("x");
|
||||||
completed.setBounds(610, 17, 17, 17);
|
completed.setBounds(610, 17, 18, 18);
|
||||||
completed.setMargin(new Insets(0,0,0,0));
|
completed.setMargin(new Insets(0,0,0,0));
|
||||||
completed.setVisible(false);
|
completed.setVisible(false);
|
||||||
|
|
||||||
JButton uncompleted = new JButton("\u2713");
|
JButton uncompleted = new JButton("\u2713");
|
||||||
uncompleted.setBounds(610, 17, 17, 17);
|
uncompleted.setBounds(610, 17, 18, 18);
|
||||||
uncompleted.setMargin(new Insets(0,0,0,0));
|
uncompleted.setMargin(new Insets(0,0,0,0));
|
||||||
uncompleted.setVisible(false);
|
uncompleted.setVisible(false);
|
||||||
|
|
||||||
JTextField attempts = new JTextField("0");
|
JTextField attempts = new JTextField("0");
|
||||||
attempts.setBounds(535, 17, 70, 18);
|
attempts.setBounds(500, 17, 70, 18);
|
||||||
attempts.setVisible(false);
|
attempts.setVisible(false);
|
||||||
|
|
||||||
JButton confirm = new JButton("\uD83D\uDDAB");
|
JButton confirm = new JButton("\uD83D\uDDAB");
|
||||||
confirm.setBounds(640, 17, 17, 17);
|
confirm.setBounds(640, 17, 18, 18);
|
||||||
confirm.setMargin(new Insets(0, 0, 0, 0));
|
confirm.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
|
||||||
JButton anpassen = new JButton("⚙");
|
JButton anpassen = new JButton("⚙");
|
||||||
anpassen.setBounds(640, 17, 17, 17);
|
anpassen.setBounds(640, 17, 18, 18);
|
||||||
anpassen.setMargin(new Insets(0, 0, 0, 0));
|
anpassen.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
|
||||||
|
JButton sperren = new JButton("\uD83D\uDD12"); // Schlüssel-Symbol
|
||||||
|
sperren.setBounds(580, 17, 18, 18);
|
||||||
|
sperren.setMargin(new Insets(0, 0, 0, 0));
|
||||||
|
sperren.setVisible(false);
|
||||||
|
|
||||||
if(data.getAttempts().get(i) != null) {
|
if(data.getAttempts().get(i) != null) {
|
||||||
attempts.setText(data.getAttempts().get(i) + "");
|
attempts.setText(data.getAttempts().get(i) + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(data.getLocked().get(index)) {
|
||||||
|
lockbool[index] = true;
|
||||||
|
lockind.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
sperren.addActionListener(new ActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
|
if(lockbool[index]) {
|
||||||
|
lockbool[index] = false;
|
||||||
|
lockind.setBackground(Color.WHITE);
|
||||||
|
} else {
|
||||||
|
lockbool[index] = true;
|
||||||
|
|
||||||
|
lockind.setBackground(Color.RED);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
completed.addActionListener(new ActionListener() {
|
completed.addActionListener(new ActionListener() {
|
||||||
|
@ -213,6 +243,7 @@ public class MainGUI {
|
||||||
anpassen.setVisible(false);
|
anpassen.setVisible(false);
|
||||||
confirm.setVisible(true);
|
confirm.setVisible(true);
|
||||||
attempts.setVisible(true);
|
attempts.setVisible(true);
|
||||||
|
sperren.setVisible(true);
|
||||||
if(Boolean.parseBoolean(data.getCompleted().get(index))) {
|
if(Boolean.parseBoolean(data.getCompleted().get(index))) {
|
||||||
uncompleted.setVisible(true);
|
uncompleted.setVisible(true);
|
||||||
completed.setVisible(false);
|
completed.setVisible(false);
|
||||||
|
@ -229,8 +260,8 @@ public class MainGUI {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
||||||
if(!(comp[index] == Boolean.parseBoolean(data.getCompleted().get(index))) || !(attempts.getText().equals(data.getAttempts().get(index) + ""))) {
|
if(!(comp[index] == Boolean.parseBoolean(data.getCompleted().get(index))) || !(attempts.getText().equals(data.getAttempts().get(index) + "")) || !(data.getLocked().get(index) == lockbool[index])) {
|
||||||
data.modifyData(data.getLevelname().get(index), comp[index], Integer.parseInt(attempts.getText()));
|
data.modifyData(data.getLevelname().get(index), comp[index], Integer.parseInt(attempts.getText()), lockbool[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,6 +277,7 @@ public class MainGUI {
|
||||||
uncompleted.setVisible(false);
|
uncompleted.setVisible(false);
|
||||||
completed.setVisible(false);
|
completed.setVisible(false);
|
||||||
attempts.setVisible(false);
|
attempts.setVisible(false);
|
||||||
|
sperren.setVisible(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -407,6 +439,8 @@ public class MainGUI {
|
||||||
contents.add(anpassen);
|
contents.add(anpassen);
|
||||||
contents.add(confirm);
|
contents.add(confirm);
|
||||||
contents.add(attempts);
|
contents.add(attempts);
|
||||||
|
contents.add(sperren);
|
||||||
|
contents.add(lockind);
|
||||||
levelpanel.add(contents);
|
levelpanel.add(contents);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,13 @@
|
||||||
package readsafefile;
|
package readsafefile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
import org.w3c.dom.Node;
|
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
public class ReadAttemptsFromXML {
|
public class ReadAttemptsFromXML {
|
||||||
|
|
||||||
|
@ -42,6 +37,7 @@ public class ReadAttemptsFromXML {
|
||||||
|
|
||||||
// Prüfen, ob der Wert des <k> Elements eine Level-ID ist
|
// Prüfen, ob der Wert des <k> Elements eine Level-ID ist
|
||||||
String currentLevelID = kElement.getTextContent();
|
String currentLevelID = kElement.getTextContent();
|
||||||
|
|
||||||
if (currentLevelID.equals(levelID)) {
|
if (currentLevelID.equals(levelID)) {
|
||||||
// Das übergeordnete <d> Element finden
|
// Das übergeordnete <d> Element finden
|
||||||
Element dElement = (Element) kElement.getNextSibling();
|
Element dElement = (Element) kElement.getNextSibling();
|
||||||
|
|
|
@ -46,7 +46,9 @@ public class SafeFileManager {
|
||||||
attempts = read.getAttempts(database.getLevelID().get(i));
|
attempts = read.getAttempts(database.getLevelID().get(i));
|
||||||
|
|
||||||
prog.update(database.getLevelname().get(i), Integer.parseInt(attempts), 1, i);
|
prog.update(database.getLevelname().get(i), Integer.parseInt(attempts), 1, i);
|
||||||
database.modifyData(database.getLevelname().get(i), Boolean.parseBoolean(database.getCompleted().get(i)), Integer.parseInt(attempts));
|
if(!database.getLocked().get(i)) {
|
||||||
|
database.modifyData(database.getLevelname().get(i), Boolean.parseBoolean(database.getCompleted().get(i)), Integer.parseInt(attempts), database.getLocked().get(i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue