added lock feature

This commit is contained in:
potzplitz 2024-03-29 00:32:13 +01:00
parent 77c659d8e5
commit 65631a126d
5 changed files with 297 additions and 257 deletions

View file

@ -76,6 +76,7 @@ public class DatabaseManager {
data.getYoutubeLink().get(i), // YouTube-Link
Integer.parseInt(data.getQualification().get(i)), // Qualifikation
data.getVictors().get(i), // Sieger
false,
false
);
}

View file

@ -28,7 +28,7 @@ public class Sqlite {
private ArrayList<String> completed = new ArrayList<String>();
private ArrayList<String> rawLevelNames = new ArrayList<String>();
private ArrayList<Integer> attempts = new ArrayList<Integer>();
private ArrayList<Boolean> locked = new ArrayList<Boolean>(); // New column
public ArrayList<String> getLevelname() {
return levelname;
@ -74,6 +74,10 @@ public class Sqlite {
return attempts;
}
public ArrayList<Boolean> getLocked() {
return locked;
}
public Sqlite(String dbname) { // setzt variablen
url = "jdbc:sqlite:C:\\ExtremeDemonList\\database\\sqlite\\";
url += dbname + ".db";
@ -116,11 +120,11 @@ public class Sqlite {
+ " percentToQualify INTEGER NOT NULL,\n"
+ " records TEXT NOT NULL,\n"
+ " attempts INTEGER NOT NULL,\n"
+ " completed BOOLEAN NOT NULL\n"
+ " completed BOOLEAN NOT NULL,\n"
+ " locked BOOLEAN NOT NULL\n" // Neue Spalte
+ ");";
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
// create a new table
@ -130,8 +134,8 @@ public class Sqlite {
}
}
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) {
String sql = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
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, locked) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
System.out.println("tablename: " + levelname);
@ -149,6 +153,7 @@ public class Sqlite {
pstmt.setString(10, records);
pstmt.setInt(11, attempts);
pstmt.setBoolean(12, completed);
pstmt.setBoolean(13, locked);
pstmt.executeUpdate();
} catch (SQLException e) {
@ -160,7 +165,7 @@ public class Sqlite {
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);
Statement stmt = conn.createStatement();
@ -179,7 +184,7 @@ public class Sqlite {
records.add(rs.getString("records"));
rawLevelNames.add(rs.getString("levelNameRaw"));
attempts.add(rs.getInt("attempts"));
locked.add(rs.getBoolean("locked")); // Get the value of the new column
}
} catch(SQLException e) {
@ -202,6 +207,7 @@ public class Sqlite {
ArrayList<String> completedlocal = new ArrayList<String>();
ArrayList<String> rawLevelNameslocal = new ArrayList<String>();
ArrayList<Integer> attemptsLocal = new ArrayList<Integer>();
ArrayList<Boolean> lockedLocal = new ArrayList<Boolean>();
try (Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement()) {
@ -234,6 +240,7 @@ public class Sqlite {
recordslocal.add(rs.getString("records"));
rawLevelNameslocal.add(rs.getString("levelNameRaw"));
attemptsLocal.add(rs.getInt("attempts"));
lockedLocal.add(rs.getBoolean("locked"));
}
}
@ -244,7 +251,7 @@ public class Sqlite {
createNewTable(tablename);
// Füge Daten in die neue Tabelle ein
String insert = "INSERT INTO " + tablename + " (placement, levelname, levelnameRaw, levelID, author, creators, verifier, verificationLink, percentToQualify, records, attempts, completed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
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);
@ -259,6 +266,7 @@ public class Sqlite {
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();
}
}
@ -267,14 +275,15 @@ public class Sqlite {
}
}
public void modifyData(String levelname, boolean completedStatus, int attempts) {
String sql = "UPDATE levels SET completed = ?, attempts = ? WHERE levelname = ?";
public void modifyData(String levelname, boolean completedStatus, int attempts, boolean lock) {
String sql = "UPDATE levels SET completed = ?, attempts = ?, locked = ? 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);
pstmt.setBoolean(3, lock); // Korrigierte Reihenfolge
pstmt.setString(4, levelname); // Korrigierte Reihenfolge
int rowsUpdated = pstmt.executeUpdate();
if (rowsUpdated > 0) {
@ -287,6 +296,4 @@ public class Sqlite {
}
}
}

View file

@ -3,6 +3,7 @@ package gui;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Toolkit;
@ -145,6 +146,7 @@ public class MainGUI {
@Override
public void run() {
boolean[] comp = new boolean[data.getLevelname().size()];
boolean[] lockbool = new boolean[data.getLevelname().size()];
for(int i = 0; i < data.getLevelname().size(); i++) {
final int index = i;
progress.setValue(i + 1);
@ -157,34 +159,62 @@ public class MainGUI {
contents.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
contents.setLayout(null);
JPanel lockind = new JPanel();
lockind.setBounds(678, 0, 2, 50);
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.setVisible(false);
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.setVisible(false);
JTextField attempts = new JTextField("0");
attempts.setBounds(535, 17, 70, 18);
attempts.setBounds(500, 17, 70, 18);
attempts.setVisible(false);
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));
JButton anpassen = new JButton("");
anpassen.setBounds(640, 17, 17, 17);
anpassen.setBounds(640, 17, 18, 18);
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) {
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() {
@ -213,6 +243,7 @@ public class MainGUI {
anpassen.setVisible(false);
confirm.setVisible(true);
attempts.setVisible(true);
sperren.setVisible(true);
if(Boolean.parseBoolean(data.getCompleted().get(index))) {
uncompleted.setVisible(true);
completed.setVisible(false);
@ -229,8 +260,8 @@ public class MainGUI {
@Override
public void actionPerformed(ActionEvent e) {
if(!(comp[index] == Boolean.parseBoolean(data.getCompleted().get(index))) || !(attempts.getText().equals(data.getAttempts().get(index) + ""))) {
data.modifyData(data.getLevelname().get(index), comp[index], Integer.parseInt(attempts.getText()));
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()), lockbool[index]);
}
@ -246,6 +277,7 @@ public class MainGUI {
uncompleted.setVisible(false);
completed.setVisible(false);
attempts.setVisible(false);
sperren.setVisible(false);
}
});
@ -407,6 +439,8 @@ public class MainGUI {
contents.add(anpassen);
contents.add(confirm);
contents.add(attempts);
contents.add(sperren);
contents.add(lockind);
levelpanel.add(contents);
}

View file

@ -1,18 +1,13 @@
package readsafefile;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class ReadAttemptsFromXML {
@ -42,6 +37,7 @@ public class ReadAttemptsFromXML {
// Prüfen, ob der Wert des <k> Elements eine Level-ID ist
String currentLevelID = kElement.getTextContent();
if (currentLevelID.equals(levelID)) {
// Das übergeordnete <d> Element finden
Element dElement = (Element) kElement.getNextSibling();

View file

@ -46,7 +46,9 @@ public class SafeFileManager {
attempts = read.getAttempts(database.getLevelID().get(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));
}
}
}