From 02026633ed1bdef8b971b3ba01eb011061af214b Mon Sep 17 00:00:00 2001 From: localhorst Date: Tue, 17 Feb 2026 19:04:16 +0100 Subject: [PATCH 01/11] update to new versions and build system --- .gitignore | 1 + .vscode/extensions.json | 7 + .vscode/launch.json | 20 + .vscode/settings.json | 11 + .vscode/tasks.json | 51 ++ README.md | 70 ++- pom.xml | 53 +- .../java/com/jFxKasse/application/Main.java | 55 +-- .../com/jFxKasse/application/PrintJob.java | 18 +- .../com/jFxKasse/controller/DBController.java | 128 ++--- .../controller/MainWindowController.java | 460 ++++++++---------- .../controller/PrinterController.java | 41 +- .../jFxKasse/controller/XMLController.java | 63 +-- src/main/java/com/jFxKasse/datatypes/Job.java | 54 +- .../com/jFxKasse/datatypes/PrintData.java | 59 ++- .../jFxKasse/datatypes/PrintDataSimple.java | 20 +- .../jFxKasse/datatypes/PrintDataSplitted.java | 33 +- .../datatypes/tableDataPositionen.java | 59 +-- src/main/resources/css/application.css | 2 +- 19 files changed, 575 insertions(+), 630 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2f7896d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..89a04f7 --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,7 @@ +{ + "recommendations": [ + "vscjava.vscode-java-pack", + "vscjava.vscode-maven", + "redhat.java" + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..25e126f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Run jFxKasse", + "request": "launch", + "mainClass": "com.jFxKasse.application.JavaFX11Main", + "projectName": "jFxKasse", + "vmArgs": "--module-path ${env:PATH_TO_FX} --add-modules javafx.controls,javafx.fxml --add-opens javafx.graphics/com.sun.javafx.scene=ALL-UNNAMED" + }, + { + "type": "java", + "name": "Run jFxKasse (Maven)", + "request": "launch", + "mainClass": "com.jFxKasse.application.JavaFX11Main", + "projectName": "jFxKasse" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..30ac6c3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,11 @@ +{ + "java.project.sourcePaths": [ + "src/main/java" + ], + "java.project.outputPath": "target/classes", + "java.project.referencedLibraries": [], + "java.configuration.updateBuildConfiguration": "automatic", + "java.compile.nullAnalysis.mode": "automatic", + "editor.formatOnSave": true, + "files.encoding": "utf8" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..6c6b9bf --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,51 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "mvn compile", + "type": "shell", + "command": "mvn compile", + "group": "build", + "problemMatcher": [ + "$javac" + ] + }, + { + "label": "mvn package", + "type": "shell", + "command": "mvn package -DskipTests", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [ + "$javac" + ] + }, + { + "label": "mvn clean", + "type": "shell", + "command": "mvn clean", + "group": "build", + "problemMatcher": [] + }, + { + "label": "mvn javafx:run", + "type": "shell", + "command": "mvn javafx:run", + "group": "build", + "problemMatcher": [ + "$javac" + ] + }, + { + "label": "mvn test", + "type": "shell", + "command": "mvn test", + "group": "test", + "problemMatcher": [ + "$javac" + ] + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index b6ca634..96f8598 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,60 @@ # jFxKasse -easy payment system for small to middel sized events with a sales slip printer -Simples Kassensystem für kleine bis mittlere Veranstaltungen mit Bon-Drucker +Simple POS (Point of Sale) system for small to medium-sized events with receipt printer support. + +## Requirements + +- Java JDK 17+ +- Maven 3.6+ +- Display >= 1366x768 ## Video Tutorials (German | Deutsch) [YouTube Video: jFxKasse - Kassensystem - Kurzanleitung](https://www.youtube.com/watch?v=DV9DDESw40I) [YouTube Video: jFxKasse - Kassensystem - Installieren](https://www.youtube.com/watch?v=IY1bqRjwh0Q) +## Setup (VSCode on openSUSE Tumbleweed) + +### 1. Install dependencies + +```bash +sudo zypper install java-17-openjdk-devel maven +``` + +### 2. Install VSCode extensions + +Open the project in VSCode. You will be prompted to install the recommended extensions: + +- **Extension Pack for Java** (`vscjava.vscode-java-pack`) +- **Maven for Java** (`vscjava.vscode-maven`) +- **Language Support for Java** (`redhat.java`) + +### 3. Build & Run + +```bash +# Compile +mvn compile + +# Run via Maven +mvn javafx:run + +# Package as fat JAR +mvn package +java -jar target/jFxKasse-shaded.jar +``` + +Or use the preconfigured VSCode tasks (`Ctrl+Shift+B`) and launch configurations (`F5`). + ## Screenshots -### Main View | Hauptansicht -![](https://git.mosad.xyz/localhorst/jFxKasse/raw/branch/master/screenshots/newjob) +| Main View | Jobs | Positions | Settings | +|-----------|------|-----------|----------| +| ![](screenshots/newjob) | ![](screenshots/jobs) | ![](screenshots/positions) | ![](screenshots/settings) | -### Jobs | Auftäge -![](https://git.mosad.xyz/localhorst/jFxKasse/raw/branch/master/screenshots/jobs) +## Hardware -### Positions | Positionen -![](https://git.mosad.xyz/localhorst/jFxKasse/raw/branch/master/screenshots/positions) +Tested with: [Epson TM T20II](https://www.epson.de/products/sd/pos-printer/epson-tm-t20ii). Other receipt printers should work as well. -### Settings | Einstellungen -![](https://git.mosad.xyz/localhorst/jFxKasse/raw/branch/master/screenshots/settings) +## License - -## Requirements | Anforderungen - -### Software - -* Java JRE 11 -* Display/Bildschirm > 1366px X 768px -* Windoofs, Mac, GNU/Linux (openSuse tested) - -### Hardware - -I used this printer: [Epson TM T20II](https://www.epson.de/products/sd/pos-printer/epson-tm-t20ii) - -Other sales slip printer are possible. \ No newline at end of file +GPL-3.0 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 458f967..e9bbd81 100644 --- a/pom.xml +++ b/pom.xml @@ -1,42 +1,48 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com jFxKasse - 0.3.2 + 0.4.0 jFxKasse + + UTF-8 + 17 + 17 + 21.0.5 + + - junit - junit - 4.12 + org.junit.jupiter + junit-jupiter + 5.11.4 test org.openjfx javafx-controls - 11 + ${javafx.version} org.openjfx javafx-fxml - 11 + ${javafx.version} com.jfoenix jfoenix - 9.0.8 + 9.0.10 org.xerial sqlite-jdbc - 3.23.1 + 3.47.1.0 @@ -46,11 +52,10 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 3.13.0 - 11 - 11 - + 17 + 17 true true @@ -59,7 +64,7 @@ org.codehaus.mojo exec-maven-plugin - 1.6.0 + 3.5.0 @@ -71,17 +76,16 @@ com.jFxKasse.application.Main - + org.apache.maven.plugins maven-shade-plugin - 3.2.1 + 3.6.0 jFxKasse true - + com.jFxKasse.application.JavaFX11Main @@ -95,7 +99,16 @@ - + + + org.openjfx + javafx-maven-plugin + 0.0.8 + + com.jFxKasse.application.JavaFX11Main + + + diff --git a/src/main/java/com/jFxKasse/application/Main.java b/src/main/java/com/jFxKasse/application/Main.java index 3044e0a..cf23d73 100644 --- a/src/main/java/com/jFxKasse/application/Main.java +++ b/src/main/java/com/jFxKasse/application/Main.java @@ -20,9 +20,8 @@ import javafx.scene.Scene; import javafx.scene.input.KeyEvent; import javafx.scene.layout.AnchorPane; -public class Main extends Application -{ - // path to config.xml and the database +public class Main extends Application { + // Path to config.xml and the database public static String filepath; private static String osName = System.getProperty("os.name"); @@ -36,48 +35,44 @@ public class Main extends Application private DBController dbc = new DBController(filepath); private PrinterController pc = new PrinterController(); - + private KeyController kc; private Stage primaryStage; @Override - public void start(Stage primaryStage) - { + public void start(Stage primaryStage) { this.primaryStage = primaryStage; System.out.println("\nstarting jFxKasse\n"); mainWindow(); } - private void mainWindow() - { + private void mainWindow() { try { FXMLLoader loader = new FXMLLoader( getClass().getResource("/fxml/MainWindow.fxml")); AnchorPane pane = loader.load(); - primaryStage.setTitle("jFxKasse"); // Title of window + primaryStage.setTitle("jFxKasse"); // Window title - mwc = loader.getController(); // set the mwc as the JavaFx - // MainWindowController - pc.searchPrinters(); // search for available printers - mwc.setMain(this, dbc, xmlc, pc); // set the created instances to the - // mwc + mwc = loader.getController(); // Set the MainWindowController + pc.searchPrinters(); // Search for available printers + mwc.setMain(this, dbc, xmlc, pc); // Pass instances to the controller - firstStart(); // test if this is the first run + firstStart(); // Check if this is the first run Scene scene = new Scene(pane); scene.getStylesheets().add( Main.class.getResource("/css/application.css").toExternalForm()); primaryStage.setScene(scene); - primaryStage.show(); // shows the stage + primaryStage.show(); // Show the stage - //attach the KeyController + // Attach the KeyController kc = new KeyController(scene, mwc); - + Timeline timeline = new Timeline( new KeyFrame(Duration.seconds(1), ev -> { - mwc.updateTimeLabel(); // update time label on UI + mwc.updateTimeLabel(); // Update time label on UI })); timeline.setCycleCount(Animation.INDEFINITE); timeline.play(); @@ -86,8 +81,7 @@ public class Main extends Application } } - public static void main(String[] args) - { + public static void main(String[] args) { if (osName.contains("Windows")) { System.out.println("FCK Windows"); filepath = userHome + "/Documents/jFxKasse/"; @@ -100,30 +94,29 @@ public class Main extends Application /** * Checks if the config.xml is preset. */ - private void firstStart() throws Exception - { + private void firstStart() throws Exception { if (xmlc.loadSettings()) { // config.xml found, app starting normal System.out.println("XML found!"); - mwc.initUI(); // Starting the UI elements + mwc.initUI(); // Initialize the UI elements mwc.setDBLabel(); // Set database labels - dbc.setDbname(xmlc.getDatabaseName()); // handover database name - dbc.connectDatabase(); // estabishing DB conection - mwc.fillTablePositionen(); // fill TreeTable 'Positionen' + dbc.setDbname(xmlc.getDatabaseName()); // Pass database name + dbc.connectDatabase(); // Establish DB connection + mwc.fillTablePositionen(); // Fill TreeTable 'Positions' mwc.fillCategory(); mwc.fillPrinterSettings(); mwc.fillTableJobs(); mwc.loadGridButtons(); - mwc.getSelectedCat(); // Load DB entries in Chois Box + mwc.getSelectedCat(); // Load DB entries in ChoiceBox mwc.createNewJob(); } else { // config.xml NOT found, first start of app System.out.println("no XML found!"); - xmlc.initXML(); // set default values - mwc.blockUI(true); // disable UI elements that need DB + xmlc.initXML(); // Set default values + mwc.blockUI(true); // Disable UI elements that need DB mwc.blockUnlock(); File dir = new File(filepath); - dir.mkdir(); // Create new Subfolder + dir.mkdir(); // Create new subfolder } } } diff --git a/src/main/java/com/jFxKasse/application/PrintJob.java b/src/main/java/com/jFxKasse/application/PrintJob.java index 95b0dcf..67acf5d 100644 --- a/src/main/java/com/jFxKasse/application/PrintJob.java +++ b/src/main/java/com/jFxKasse/application/PrintJob.java @@ -16,19 +16,17 @@ import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.util.Pair; -public class PrintJob -{ +public class PrintJob { private TimeDate timedate = new TimeDate(); public void printJob(int jobID, XMLController xmlc, DBController dbc, - PrinterController pc) - { + PrinterController pc) { if ((xmlc.getPrintername().equals("Drucker auswählen") || xmlc.getPrintername() == null)) { - // no printer selected - System.out.println("Kein Drucker eingestellt!!!"); + // No printer selected + System.out.println("No printer configured!"); // creates a dialog Dialog> dialog = new Dialog<>(); @@ -52,11 +50,11 @@ public class PrintJob dialog.showAndWait(); } else { - // printer selected + // Printer selected pc.selectPrinter(xmlc.getPrintername()); - /* Single bill or splitted */ + /* Single bill or split by category */ if (xmlc.getCategorySplitted()) { - // split the bills + // Split the bills PrintDataSplitted pdsplitted = new PrintDataSplitted( xmlc.getLinebreak(), xmlc.getOffsetHeader(), @@ -78,7 +76,7 @@ public class PrintJob } } else { - // one single bills + // Single bill PrintDataSimple pds = new PrintDataSimple(xmlc.getLinebreak(), xmlc.getOffsetHeader(), xmlc.getOffsetFooter(), timedate.getSystemTime() + " " + timedate.getSystemDate(), diff --git a/src/main/java/com/jFxKasse/controller/DBController.java b/src/main/java/com/jFxKasse/controller/DBController.java index ee276cc..ac0c521 100644 --- a/src/main/java/com/jFxKasse/controller/DBController.java +++ b/src/main/java/com/jFxKasse/controller/DBController.java @@ -11,16 +11,14 @@ import com.jFxKasse.datatypes.tableDataJob; import com.jFxKasse.datatypes.tableDataPositionen; import java.io.File; -public class DBController -{ +public class DBController { private Connection connection; private String DB_PATH; private String dbname; - public void main() - { + public void main() { try { connection = DriverManager .getConnection("jdbc:sqlite:" + DB_PATH + dbname + ".db"); @@ -30,18 +28,15 @@ public class DBController } } - public DBController(String path) - { + public DBController(String path) { this.DB_PATH = path; } - public void setDbname(String dbname) - { + public void setDbname(String dbname) { this.dbname = dbname; } - public void connectDatabase() - { // connect to database + public void connectDatabase() { // Connect to database System.out.println("Connecting... DB name: " + dbname); try { if (connection != null) @@ -54,8 +49,7 @@ public class DBController throw new RuntimeException(e); } Runtime.getRuntime().addShutdownHook(new Thread() { - public void run() - { + public void run() { try { if (!connection.isClosed() && connection != null) { connection.close(); @@ -69,8 +63,7 @@ public class DBController }); } - public boolean existDB(String pPfad) - { // does the DB exists? + public boolean existDB(String pPfad) { // Check if the DB exists File varTmpDir = new File(pPfad); if (!varTmpDir.exists()) { return false; @@ -79,8 +72,7 @@ public class DBController } } - public String getCategoryNameFromPositionen(int pID) - { + public String getCategoryNameFromPositionen(int pID) { int catInPos = 0; try { Statement stmt = connection.createStatement(); @@ -108,9 +100,8 @@ public class DBController } - // table Position section // - public void createTablePositionen() - { // create table position + // Table 'Positionen' section // + public void createTablePositionen() { // Create table 'positionen' System.out.println("Creating table Positionen"); try { Statement stmt = connection.createStatement(); @@ -122,7 +113,7 @@ public class DBController e.printStackTrace(); } - // create 25 demo/default data entries + // Create 25 demo/default data entries for (int i = 0; i < 25; i++) { fillPositionen_Positionen(i + 1, "Noch frei", (float) 0.00, 6, "#ad0000"); @@ -130,8 +121,7 @@ public class DBController } public void fillPositionen_Positionen(int pID, String pName, float pValue, - int pCat, String pColor) - { // create new data in table + int pCat, String pColor) { // Create new entry in table System.out.println("Creating new positionen entry"); try { PreparedStatement ps = connection.prepareStatement( @@ -152,8 +142,7 @@ public class DBController } } - public String getName_Positionen(int pID) - { + public String getName_Positionen(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -166,8 +155,7 @@ public class DBController } } - public String getValue_Positionen(int pID) - { + public String getValue_Positionen(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -181,8 +169,7 @@ public class DBController } } - public int getCat_Positionen(int pID) - { + public int getCat_Positionen(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -196,8 +183,7 @@ public class DBController } } - public String getColor_Positionen(int pID) - { + public String getColor_Positionen(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -211,8 +197,7 @@ public class DBController } } - public void setName_Positionen(int pID, String pName) - { + public void setName_Positionen(int pID, String pName) { try { Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE positionen SET name = '" + pName @@ -223,8 +208,7 @@ public class DBController } } - public void setValue_Positionen(int pID, String pValue) - { + public void setValue_Positionen(int pID, String pValue) { try { Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE positionen SET value = '" + pValue @@ -235,8 +219,7 @@ public class DBController } } - public void setCat_Positionen(int pID, int pCat) - { + public void setCat_Positionen(int pID, int pCat) { try { Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE positionen SET cat = '" + pCat @@ -247,8 +230,7 @@ public class DBController } } - public void setColor_Positionen(int pID, String pColor) - { + public void setColor_Positionen(int pID, String pColor) { try { Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE positionen SET color = '" + pColor @@ -259,8 +241,7 @@ public class DBController } } - public ArrayList ladeTabellePositionen() - { + public ArrayList ladeTabellePositionen() { ArrayList daten = new ArrayList<>(); try { Statement stmt = connection.createStatement(); @@ -282,8 +263,7 @@ public class DBController return daten; } - public void ausgebenSysoPositionen() - { + public void ausgebenSysoPositionen() { System.out.println("Print positionen"); try { Statement stmt = connection.createStatement(); @@ -302,10 +282,9 @@ public class DBController } } - // table Category section // - public void createTableCategory() - { // create table position - System.out.println("Erstelle Tabelle Kategorie"); + // Table 'Category' section // + public void createTableCategory() { // Create table 'category' + System.out.println("Creating table Category"); try { Statement stmt = connection.createStatement(); stmt.executeUpdate("DROP TABLE IF EXISTS category;"); @@ -323,8 +302,7 @@ public class DBController } - public void setName_Category(int pID, String pName) - { + public void setName_Category(int pID, String pName) { try { Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE category SET catname = '" + pName @@ -335,10 +313,9 @@ public class DBController } } - public void fillCategory_Category(int pID, String pName) - { + public void fillCategory_Category(int pID, String pName) { - System.out.println("Erstelle neuen Kategorie Eintrag"); + System.out.println("Creating new category entry"); try { PreparedStatement ps = connection .prepareStatement("INSERT INTO category VALUES (?, ?);"); @@ -355,8 +332,7 @@ public class DBController } - public String getName_Category(int pID) - { + public String getName_Category(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -370,9 +346,8 @@ public class DBController } } - // table Jobs section // - public void erstelleTabelleJobs() - { // create table jobs + // Table 'Jobs' section // + public void erstelleTabelleJobs() { // Create table 'jobs' System.out.println("Creating table Jobs"); try { Statement stmt = connection.createStatement(); @@ -385,8 +360,7 @@ public class DBController } } - public int getLatestJobNumber_Job() - { + public int getLatestJobNumber_Job() { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -400,8 +374,7 @@ public class DBController return 0; } - public String getTime_Job(int pID) - { + public String getTime_Job(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -414,8 +387,7 @@ public class DBController } } - public String getQuantity_Job(int pID) - { + public String getQuantity_Job(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -429,8 +401,7 @@ public class DBController } } - public String getName_Job(int pID) - { + public String getName_Job(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -444,8 +415,7 @@ public class DBController } } - public String getValue_Job(int pID) - { + public String getValue_Job(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -459,8 +429,7 @@ public class DBController } } - public String getCategory_Job(int pID) - { + public String getCategory_Job(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -474,8 +443,7 @@ public class DBController } } - public String getState_Job(int pID) - { + public String getState_Job(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -488,8 +456,7 @@ public class DBController } } - public String getJobValue_Job(int pID) - { + public String getJobValue_Job(int pID) { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -502,8 +469,7 @@ public class DBController } } - public String getAllJobValue_Job() - { + public String getAllJobValue_Job() { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -517,8 +483,7 @@ public class DBController } } - public String getJobCount() - { + public String getJobCount() { try { Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery( @@ -532,8 +497,7 @@ public class DBController } } - public void setStatus_Jobs(int pID, String pStatus) - { + public void setStatus_Jobs(int pID, String pStatus) { try { Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE jobs SET state = '" + pStatus @@ -544,8 +508,7 @@ public class DBController } } - public ArrayList loadTableJobs_Job() - { + public ArrayList loadTableJobs_Job() { ArrayList tmp = new ArrayList(); try { @@ -576,9 +539,8 @@ public class DBController public void fillJobs_Jobs(int pID, String pTime, String pPositionen_quantity, String pPositionen_name, String pPositionen_value, - String pPositionen_cat, String pState, String pJobvalue) - { - System.out.println("Create new Job Entry"); + String pPositionen_cat, String pState, String pJobvalue) { + System.out.println("Creating new job entry"); try { PreparedStatement ps = connection.prepareStatement( "INSERT INTO jobs VALUES (?, ?, ?, ?, ?, ?, ?, ?);"); diff --git a/src/main/java/com/jFxKasse/controller/MainWindowController.java b/src/main/java/com/jFxKasse/controller/MainWindowController.java index 7f062e1..0a4f1cc 100644 --- a/src/main/java/com/jFxKasse/controller/MainWindowController.java +++ b/src/main/java/com/jFxKasse/controller/MainWindowController.java @@ -38,8 +38,7 @@ import com.jFxKasse.datatypes.tableDataCurrentOrder; import com.jFxKasse.datatypes.tableDataJob; import com.jFxKasse.datatypes.tableDataPositionen; -public class MainWindowController -{ +public class MainWindowController { @FXML private AnchorPane mainAnchorpane; @@ -381,8 +380,7 @@ public class MainWindowController new tableDataPositionen(0, "0", "0", "0", "0")); @FXML - public void ueberbtnAction(ActionEvent event) - { // opens the 'Über' dialog + public void ueberbtnAction(ActionEvent event) { // Opens the 'About' dialog // creates a dialog Dialog> dialog = new Dialog<>(); @@ -413,8 +411,7 @@ public class MainWindowController } @FXML - public void btnOpenFolderAction(ActionEvent event) throws IOException - { + public void btnOpenFolderAction(ActionEvent event) throws IOException { if (System.getProperty("os.name").contains("Windows")) { System.out.println("FCK Windows"); @@ -427,15 +424,14 @@ public class MainWindowController } @FXML - public void btnCreateNewDatabaseAction(ActionEvent event) throws Exception - { + public void btnCreateNewDatabaseAction(ActionEvent event) throws Exception { if (!(tftNewDBName.getText().equals(""))) { xmlc.setDatabaseName(tftNewDBName.getText()); dbc.setDbname(xmlc.getDatabaseName()); - dbc.connectDatabase(); // establish DB connection + dbc.connectDatabase(); // Establish DB connection dbc.createTablePositionen(); // Create new table dbc.erstelleTabelleJobs(); // Create new table dbc.createTableCategory(); // Create new table @@ -446,12 +442,12 @@ public class MainWindowController // TODO Auto-generated catch block e.printStackTrace(); } - setDBLabel(); // Set new databese labels - blockUI(false); // unlock UI elements that need DB - fillTablePositionen(); // fill TreeTable 'Positionen' + setDBLabel(); // Set new database labels + blockUI(false); // Unlock UI elements that need DB + fillTablePositionen(); // Fill TreeTable 'Positions' fillCategory(); fillPrinterSettings(); - initUI(); // Starting the UI elements + initUI(); // Initialize the UI elements getSelectedCat(); createNewJob(); @@ -460,42 +456,39 @@ public class MainWindowController } @FXML - public void btnSaveEntryAction(ActionEvent event) - { + public void btnSaveEntryAction(ActionEvent event) { dbc.setName_Positionen(idPositionen, tftNewPosition.getText()); dbc.setValue_Positionen(idPositionen, tftNewValue.getText()); dbc.setColor_Positionen(idPositionen, getColorCodes(selectedColorName)); dbc.setCat_Positionen(idPositionen, getSelectedCat()); - fillTablePositionen(); // fill TreeTable 'Positionen' + fillTablePositionen(); // Fill TreeTable 'Positions' loadGridButtons(); } @FXML - public void btnClearEntryAction(ActionEvent event) - { - // set default values + public void btnClearEntryAction(ActionEvent event) { + // Set default values dbc.setName_Positionen(idPositionen, "Noch frei"); dbc.setValue_Positionen(idPositionen, "0.00"); dbc.setColor_Positionen(idPositionen, "#FAF0E6"); dbc.setCat_Positionen(idPositionen, 6); - fillTablePositionen(); // fill TreeTable 'Positionen' + fillTablePositionen(); // Fill TreeTable 'Positions' } @FXML - public void btnCalcStatsAction(ActionEvent event) - { + public void btnCalcStatsAction(ActionEvent event) { int allActiveJobs = Integer.valueOf(dbc.getJobCount()); if (dbc.getAllJobValue_Job() != null) { - // summed up values of all jobs that are active + // Summed up values of all active jobs float allValue = Float.valueOf(dbc.getAllJobValue_Job()); - // count of all jobs that are active + // Count of all active jobs float avgJobValue = ((float) allValue / allActiveJobs); @@ -507,8 +500,7 @@ public class MainWindowController } @FXML - public void btnSavePrinterAction(ActionEvent event) - { + public void btnSavePrinterAction(ActionEvent event) { System.out.println("btnSavePrinterAction"); xmlc.setPrintername( @@ -530,8 +522,7 @@ public class MainWindowController } @FXML - public void btnCancelJobAction(ActionEvent event) - { + public void btnCancelJobAction(ActionEvent event) { dbc.setStatus_Jobs(selectedJobId + 1, "storniert"); fillTableJobs(); btnCancelJob.setDisable(true); @@ -539,8 +530,7 @@ public class MainWindowController } @FXML - public void btnLockAction(ActionEvent event) - { + public void btnLockAction(ActionEvent event) { lockState = !lockState; blockUI(lockState); @@ -552,8 +542,7 @@ public class MainWindowController } @FXML - public void btnSaveCatAction(ActionEvent event) - { + public void btnSaveCatAction(ActionEvent event) { dbc.setName_Category(1, tftKat01.getText()); dbc.setName_Category(2, tftKat02.getText()); dbc.setName_Category(3, tftKat03.getText()); @@ -566,8 +555,7 @@ public class MainWindowController } @FXML - public void btnDeleteSelectedPositionAction(ActionEvent event) - { + public void btnDeleteSelectedPositionAction(ActionEvent event) { currentJob.deletePosName(currentOrderPosName); rootCurrentJob.getChildren().remove(0, rootCurrentJob.getChildren().size()); @@ -592,8 +580,7 @@ public class MainWindowController } @FXML - public void btnPrintBillAction(ActionEvent event) - { + public void btnPrintBillAction(ActionEvent event) { btnPrintBill.setDisable(true); tapPosEdit.setDisable(false); btnDeleteSelectedPosition.setDisable(true); @@ -626,165 +613,138 @@ public class MainWindowController } @FXML - public void btnReprintJobAction(ActionEvent event) - { + public void btnReprintJobAction(ActionEvent event) { System.out.println("reprint job"); pj.printJob((selectedJobId + 1), xmlc, dbc, pc); } @FXML - public void gridButton01Action(ActionEvent event) - { + public void gridButton01Action(ActionEvent event) { handleGridButtons(1); } @FXML - public void gridButton02Action(ActionEvent event) - { + public void gridButton02Action(ActionEvent event) { handleGridButtons(2); } @FXML - public void gridButton03Action(ActionEvent event) - { + public void gridButton03Action(ActionEvent event) { handleGridButtons(3); } @FXML - public void gridButton04Action(ActionEvent event) - { + public void gridButton04Action(ActionEvent event) { handleGridButtons(4); } @FXML - public void gridButton05Action(ActionEvent event) - { + public void gridButton05Action(ActionEvent event) { handleGridButtons(5); } @FXML - public void gridButton06Action(ActionEvent event) - { + public void gridButton06Action(ActionEvent event) { handleGridButtons(6); } @FXML - public void gridButton07Action(ActionEvent event) - { + public void gridButton07Action(ActionEvent event) { handleGridButtons(7); } @FXML - public void gridButton08Action(ActionEvent event) - { + public void gridButton08Action(ActionEvent event) { handleGridButtons(8); } @FXML - public void gridButton09Action(ActionEvent event) - { + public void gridButton09Action(ActionEvent event) { handleGridButtons(9); } @FXML - public void gridButton10Action(ActionEvent event) - { + public void gridButton10Action(ActionEvent event) { handleGridButtons(10); } @FXML - public void gridButton11Action(ActionEvent event) - { + public void gridButton11Action(ActionEvent event) { handleGridButtons(11); } @FXML - public void gridButton12Action(ActionEvent event) - { + public void gridButton12Action(ActionEvent event) { handleGridButtons(12); } @FXML - public void gridButton13Action(ActionEvent event) - { + public void gridButton13Action(ActionEvent event) { handleGridButtons(13); } @FXML - public void gridButton14Action(ActionEvent event) - { + public void gridButton14Action(ActionEvent event) { handleGridButtons(14); } @FXML - public void gridButton15Action(ActionEvent event) - { + public void gridButton15Action(ActionEvent event) { handleGridButtons(15); } @FXML - public void gridButton16Action(ActionEvent event) - { + public void gridButton16Action(ActionEvent event) { handleGridButtons(16); } @FXML - public void gridButton17Action(ActionEvent event) - { + public void gridButton17Action(ActionEvent event) { handleGridButtons(17); } @FXML - public void gridButton18Action(ActionEvent event) - { + public void gridButton18Action(ActionEvent event) { handleGridButtons(18); } @FXML - public void gridButton19Action(ActionEvent event) - { + public void gridButton19Action(ActionEvent event) { handleGridButtons(19); } @FXML - public void gridButton20Action(ActionEvent event) - { + public void gridButton20Action(ActionEvent event) { handleGridButtons(20); } @FXML - public void gridButton21Action(ActionEvent event) - { + public void gridButton21Action(ActionEvent event) { handleGridButtons(21); } @FXML - public void gridButton22Action(ActionEvent event) - { + public void gridButton22Action(ActionEvent event) { handleGridButtons(22); } @FXML - public void gridButton23Action(ActionEvent event) - { + public void gridButton23Action(ActionEvent event) { handleGridButtons(23); } @FXML - public void gridButton24Action(ActionEvent event) - { + public void gridButton24Action(ActionEvent event) { handleGridButtons(24); } @FXML - public void gridButton25Action(ActionEvent event) - { + public void gridButton25Action(ActionEvent event) { handleGridButtons(25); } @FXML - public void fillTablePositionen() - { // loads the table in the TreeTableView + public void fillTablePositionen() { // Load positions into the TreeTableView rootPositionen.getChildren().remove(0, rootPositionen.getChildren().size()); @@ -808,8 +768,7 @@ public class MainWindowController } } - public void initUI() - { + public void initUI() { System.out.println("initUI"); for (int i = 0; i < 25; i++) { getButtonByID(i).setVisible(false); @@ -835,8 +794,7 @@ public class MainWindowController } - public int getSelectedCat() - { + public int getSelectedCat() { ObservableList cats = FXCollections.observableArrayList(); for (int i = 1; i < 5; i++) { @@ -853,8 +811,7 @@ public class MainWindowController .addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, - Number value, Number new_value) - { + Number value, Number new_value) { try { selectedCatName = catChoise.getItems().get((int) new_value) .toString(); @@ -871,8 +828,7 @@ public class MainWindowController return 5; } - public void fillPrinterSettings() - { + public void fillPrinterSettings() { System.out.println("Fill printer Settings"); ObservableList printers = FXCollections @@ -884,16 +840,16 @@ public class MainWindowController int index = 0; for (String currentPrinter : printers) { if (xmlc.getPrintername().equals(currentPrinter)) { - // saved printer is available + // Saved printer is available printerFound = true; - // select saved printer in UI + // Select saved printer in UI printerChoise.getSelectionModel().select(index); } index++; } if (!printerFound) { - // saved printer is not available + // Saved printer is not available printerChoise.getSelectionModel().select(printers.size() - 1); System.out.println("no printer found"); } @@ -924,8 +880,7 @@ public class MainWindowController } - public void fillCategory() - { + public void fillCategory() { tftKat01.setText(dbc.getName_Category(1)); tftKat02.setText(dbc.getName_Category(2)); tftKat03.setText(dbc.getName_Category(3)); @@ -933,8 +888,7 @@ public class MainWindowController tftKat05.setText(dbc.getName_Category(5)); } - private void initPositionen() - { + private void initPositionen() { entryTreeTable.setRoot(rootPositionen); entryTreeTable.setShowRoot(false); entryTreeTable.setEditable(false); @@ -954,8 +908,7 @@ public class MainWindowController .addListener(new ChangeListener() { @Override public void changed(ObservableValue ov, - Number value, Number new_value) - { + Number value, Number new_value) { selectedColorName = colorChoise.getItems() .get((int) new_value).toString(); } @@ -980,10 +933,9 @@ public class MainWindowController .addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldVal, - Object newVal) - { + Object newVal) { int selected = entryTreeTable.getSelectionModel() - .getSelectedIndex(); // get selected item + .getSelectedIndex(); // Get selected item try { idPositionen = columnPosnumber.getCellData(selected); @@ -1006,8 +958,7 @@ public class MainWindowController tftNewValue.textProperty().addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, - String oldValue, String newValue) - { + String oldValue, String newValue) { if (!newValue.matches("\\d{0,4}([\\.]\\d{0,2})?")) { tftNewValue.setText(oldValue); } @@ -1031,16 +982,14 @@ public class MainWindowController } public void setMain(Main main, DBController dbc, XMLController xmlc, - PrinterController pc) - { + PrinterController pc) { this.main = main; this.dbc = dbc; this.xmlc = xmlc; this.pc = pc; } - public void setDBLabel() throws Exception - { + public void setDBLabel() throws Exception { if (xmlc.loadSettings() == true) { labelDBStatus.setText( "Geladene Datenbank: " + xmlc.getDatabaseName() + ".db"); @@ -1059,94 +1008,90 @@ public class MainWindowController } } - private String getColorCodes(String pColorName) - { + private String getColorCodes(String pColorName) { switch (pColorName) { - case "Rot": - return "#ad0000"; - case "Orange": - return "#FF4500"; - case "Braun": - return "#8B4513"; - case "Weiß": - return "#FAF0E6"; - case "Gelb": - return "#FFD700"; - case "Gr\u00fcn": - return "#556B2F"; - case "Blau": - return "#00BFFF"; - case "Indigo": - return "#4B0082"; + case "Rot": + return "#ad0000"; + case "Orange": + return "#FF4500"; + case "Braun": + return "#8B4513"; + case "Weiß": + return "#FAF0E6"; + case "Gelb": + return "#FFD700"; + case "Gr\u00fcn": + return "#556B2F"; + case "Blau": + return "#00BFFF"; + case "Indigo": + return "#4B0082"; - default: - return "#FFFFFF"; + default: + return "#FFFFFF"; } } - private String getColorNames(String pColorCode) - { + private String getColorNames(String pColorCode) { switch (pColorCode) { - case "#ad0000": - return "Rot"; - case "#FF4500": - return "Orange"; - case "#8B4513": - return "Braun"; - case "#FAF0E6": - return "Weiß"; - case "#FFD700": - return "Gelb"; - case "#556B2F": - return "Gr\u00fcn"; - case "#00BFFF": - return "Blau"; - case "#4B0082": - return "Indigo"; + case "#ad0000": + return "Rot"; + case "#FF4500": + return "Orange"; + case "#8B4513": + return "Braun"; + case "#FAF0E6": + return "Weiß"; + case "#FFD700": + return "Gelb"; + case "#556B2F": + return "Gr\u00fcn"; + case "#00BFFF": + return "Blau"; + case "#4B0082": + return "Indigo"; - default: - return "Farbe"; + default: + return "Farbe"; } } - private Integer getColorID(String pColorCode) - { + private Integer getColorID(String pColorCode) { switch (pColorCode) { - case "#ad0000": - return 0; - case "#FF4500": - return 1; - case "#8B4513": - return 2; - case "#FAF0E6": - return 3; - case "#FFD700": - return 4; - case "#556B2F": - return 5; - case "#00BFFF": - return 6; - case "#4B0082": - return 7; + case "#ad0000": + return 0; + case "#FF4500": + return 1; + case "#8B4513": + return 2; + case "#FAF0E6": + return 3; + case "#FFD700": + return 4; + case "#556B2F": + return 5; + case "#00BFFF": + return 6; + case "#4B0082": + return 7; - default: - return 0; + default: + return 0; } } - public void blockUI(boolean pState) - { + public void blockUI(boolean pState) { btnCalcStats.setDisable(pState); btnClearEntry.setDisable(pState); if ((!isPrintBtnDisabled) && (!pState)) { - // print was not disabled and will be enabled again + // Print was not disabled and will be enabled again btnPrintBill.setDisable(pState); btnDeleteSelectedPosition.setDisable(pState); } if (pState) { - // disable allways + // Always disable btnPrintBill.setDisable(pState); btnDeleteSelectedPosition.setDisable(pState); } @@ -1181,8 +1126,7 @@ public class MainWindowController } - public void loadGridButtons() - { + public void loadGridButtons() { for (int i = 0; i < 25; i++) { getButtonByID(i).setText(dbc.getName_Positionen(i + 1)); getButtonByID(i).setFocusTraversable(false); @@ -1204,66 +1148,64 @@ public class MainWindowController } } - public Button getButtonByID(int pID) - { + public Button getButtonByID(int pID) { switch (pID) { - case 0: - return gridButton01; - case 1: - return gridButton02; - case 2: - return gridButton03; - case 3: - return gridButton04; - case 4: - return gridButton05; - case 5: - return gridButton06; - case 6: - return gridButton07; - case 7: - return gridButton08; - case 8: - return gridButton09; - case 9: - return gridButton10; - case 10: - return gridButton11; - case 11: - return gridButton12; - case 12: - return gridButton13; - case 13: - return gridButton14; - case 14: - return gridButton15; - case 15: - return gridButton16; - case 16: - return gridButton17; - case 17: - return gridButton18; - case 18: - return gridButton19; - case 19: - return gridButton20; - case 20: - return gridButton21; - case 21: - return gridButton22; - case 22: - return gridButton23; - case 23: - return gridButton24; - case 24: - return gridButton25; - default: - return gridButton01; + case 0: + return gridButton01; + case 1: + return gridButton02; + case 2: + return gridButton03; + case 3: + return gridButton04; + case 4: + return gridButton05; + case 5: + return gridButton06; + case 6: + return gridButton07; + case 7: + return gridButton08; + case 8: + return gridButton09; + case 9: + return gridButton10; + case 10: + return gridButton11; + case 11: + return gridButton12; + case 12: + return gridButton13; + case 13: + return gridButton14; + case 14: + return gridButton15; + case 15: + return gridButton16; + case 16: + return gridButton17; + case 17: + return gridButton18; + case 18: + return gridButton19; + case 19: + return gridButton20; + case 20: + return gridButton21; + case 21: + return gridButton22; + case 22: + return gridButton23; + case 23: + return gridButton24; + case 24: + return gridButton25; + default: + return gridButton01; } } - private void handleGridButtons(int pID) - { + private void handleGridButtons(int pID) { if (!getButtonByID(pID - 1).isVisible()) { // Button is not visible, no action @@ -1292,8 +1234,7 @@ public class MainWindowController } - private void initCurrentOrderTreeTableView() - { + private void initCurrentOrderTreeTableView() { columnQuantity .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); columnPosition @@ -1313,13 +1254,12 @@ public class MainWindowController .addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldVal, - Object newVal) - { + Object newVal) { int selected = tableCurrentOrder.getSelectionModel() - .getSelectedIndex(); // get selected item + .getSelectedIndex(); // Get selected item if (columnPosition.getCellData(selected) != null) { - currentOrderPosName = columnPosition.getCellData(selected); // Ausgewählte + currentOrderPosName = columnPosition.getCellData(selected); // Selected position btnDeleteSelectedPosition.setDisable(false); } } @@ -1327,8 +1267,7 @@ public class MainWindowController } - private void initJobTreeTableView() - { + private void initJobTreeTableView() { columnJobNumber .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); @@ -1365,10 +1304,9 @@ public class MainWindowController .addListener(new ChangeListener() { @Override public void changed(ObservableValue observable, Object oldVal, - Object newVal) - { + Object newVal) { selectedJobId = jobsTreeTable.getSelectionModel() - .getSelectedIndex(); // get selected item + .getSelectedIndex(); // Get selected item if (dbc.getState_Job(selectedJobId + 1).equals("storniert")) { btnCancelJob.setDisable(true); @@ -1382,8 +1320,7 @@ public class MainWindowController } @FXML - public void fillTableJobs() - { // loads the table in the TreeTableView + public void fillTableJobs() { // Load jobs into the TreeTableView rootJobs.getChildren().remove(0, rootJobs.getChildren().size()); for (int i = 0; i < dbc.loadTableJobs_Job().size(); i++) { @@ -1415,15 +1352,13 @@ public class MainWindowController } - public void createNewJob() - { + public void createNewJob() { currentJob = new Job(dbc.getLatestJobNumber_Job() + 1); labelJobCounter.setText("Auftragsnummer: " + String.valueOf(dbc.getLatestJobNumber_Job() + 1)); } - private static String createJobDescription(String pNames, String pQuantities) - { + private static String createJobDescription(String pNames, String pQuantities) { String line = pQuantities; int size = line.length() - line.replace(";", "").length() + 1; @@ -1441,15 +1376,13 @@ public class MainWindowController return tmp; } - private void setJobPrizeLabel(float pPrize) - { + private void setJobPrizeLabel(float pPrize) { String str = String.format("%.02f", pPrize); str.replace('.', ','); labelAllPrize.setText(str + "€"); } - private void setJobStatLabel(int pCounter, float pAvgValue, float pAllValue) - { + private void setJobStatLabel(int pCounter, float pAvgValue, float pAllValue) { labelJobCount.setText("Anzahl Aufträge: " + pCounter); String str = String.format("%.02f", pAvgValue); @@ -1468,19 +1401,16 @@ public class MainWindowController + timedate.getSystemDate()); } - public void updateTimeLabel() - { + public void updateTimeLabel() { labelTime.setText("Uhrzeit: " + timedate.getSystemTime()); } - public void blockUnlock() - { + public void blockUnlock() { btnLock.setDisable(true); } - public int getActiveTab() - { + public int getActiveTab() { if (tapNewJob.isSelected()) { return 0; diff --git a/src/main/java/com/jFxKasse/controller/PrinterController.java b/src/main/java/com/jFxKasse/controller/PrinterController.java index bd23806..ea44dd9 100644 --- a/src/main/java/com/jFxKasse/controller/PrinterController.java +++ b/src/main/java/com/jFxKasse/controller/PrinterController.java @@ -1,5 +1,5 @@ /** - * some parts are from http://www.mets-blog.com/java-pos-thermal-printer-example/ + * Some parts are from http://www.mets-blog.com/java-pos-thermal-printer-example/ */ package com.jFxKasse.controller; @@ -21,26 +21,23 @@ import javax.print.SimpleDoc; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; -public class PrinterController implements Printable -{ - // All available Printers on this system +public class PrinterController implements Printable { + // All available printers on this system private PrintService[] printService; - // selected printer + // Selected printer private PrintService selectedPrinter; private DocFlavor flavor; - public PrinterController() - { + public PrinterController() { flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; } /** * @return A String array with all available printers */ - public String[] getAvailablePrinters() - { + public String[] getAvailablePrinters() { int printerSize = PrinterJob.lookupPrintServices().length; String printers[] = new String[printerSize]; @@ -51,10 +48,9 @@ public class PrinterController implements Printable } /** - * searchs connected printers on the system + * Searches for connected printers on the system */ - public void searchPrinters() - { + public void searchPrinters() { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); this.printService = PrintServiceLookup.lookupPrintServices(flavor, pras); String printers[] = getAvailablePrinters(); @@ -67,11 +63,11 @@ public class PrinterController implements Printable } /** - * Selects the printer via its name + * Selects the printer by its name + * * @param printerName */ - public void selectPrinter(String printerName) - { + public void selectPrinter(String printerName) { String printers[] = getAvailablePrinters(); for (int i = 0; i < printers.length; i++) { @@ -84,11 +80,11 @@ public class PrinterController implements Printable } /** + * Prints a string to the selected printer * - * @param input data as String + * @param text data as String */ - public void printString(String text) - { + public void printString(String text) { PrintService service = selectedPrinter; DocPrintJob job = service.createPrintJob(); @@ -103,8 +99,7 @@ public class PrinterController implements Printable } } - public int print(Graphics g, PageFormat pf, int page) throws PrinterException - { + public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { /* We have only one page, and 'page' is zero-based */ return NO_SUCH_PAGE; } @@ -119,8 +114,7 @@ public class PrinterController implements Printable return PAGE_EXISTS; } - public void printBytes(byte[] bytes) - { + public void printBytes(byte[] bytes) { PrintService service = selectedPrinter; DocPrintJob job = service.createPrintJob(); @@ -132,8 +126,7 @@ public class PrinterController implements Printable } } - public void cutPaper() - { + public void cutPaper() { byte[] cutP = new byte[] { 0x1d, 'V', 1 }; printBytes(cutP); } diff --git a/src/main/java/com/jFxKasse/controller/XMLController.java b/src/main/java/com/jFxKasse/controller/XMLController.java index 874b6ae..37d9d7f 100644 --- a/src/main/java/com/jFxKasse/controller/XMLController.java +++ b/src/main/java/com/jFxKasse/controller/XMLController.java @@ -7,8 +7,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Properties; -public class XMLController -{ +public class XMLController { private String databaseName = null; private String printername = null; @@ -29,14 +28,12 @@ public class XMLController private Properties props = null; - public XMLController(String filePath) - { + public XMLController(String filePath) { this.filePath = filePath + "config.xml"; props = new Properties(); } - public void saveSettings() throws Exception - { // Save settings to config.xml + public void saveSettings() throws Exception { // Save settings to config.xml System.out.println("Saving XML"); @@ -71,8 +68,7 @@ public class XMLController } } - public boolean loadSettings() throws Exception - { // reads the settings from config.xml + public boolean loadSettings() throws Exception { // Read settings from config.xml InputStream inputStream; try { inputStream = new FileInputStream(filePath); @@ -121,8 +117,7 @@ public class XMLController } } - public void initXML() - { + public void initXML() { this.printername = "Drucker auswählen"; this.offsetHeader = 1; @@ -136,83 +131,67 @@ public class XMLController this.footer = "Vielen Dank für den Einkauf"; } - public String getDatabaseName() - { + public String getDatabaseName() { return databaseName; } - public void setDatabaseName(String databaseName) - { + public void setDatabaseName(String databaseName) { this.databaseName = databaseName; } - public String getPrintername() - { + public String getPrintername() { return printername; } - public void setPrintername(String printername) - { + public void setPrintername(String printername) { this.printername = printername; } - public int getLinebreak() - { + public int getLinebreak() { return linebreak; } - public void setLinebreak(int linebreak) - { + public void setLinebreak(int linebreak) { this.linebreak = linebreak; } - public int getOffsetHeader() - { + public int getOffsetHeader() { return offsetHeader; } - public void setOffsetHeader(int offsetHeader) - { + public void setOffsetHeader(int offsetHeader) { this.offsetHeader = offsetHeader; } - public int getOffsetFooter() - { + public int getOffsetFooter() { return offsetFooter; } - public void setOffsetFooter(int offsetFooter) - { + public void setOffsetFooter(int offsetFooter) { this.offsetFooter = offsetFooter; } - public String getHeader() - { + public String getHeader() { return header; } - public void setHeader(String header) - { + public void setHeader(String header) { this.header = header; } - public String getFooter() - { + public String getFooter() { return footer; } - public void setFooter(String footer) - { + public void setFooter(String footer) { this.footer = footer; } - public boolean getCategorySplitted() - { + public boolean getCategorySplitted() { return categorySplitted; } - public void setCategorySplitted(boolean categorySplitted) - { + public void setCategorySplitted(boolean categorySplitted) { this.categorySplitted = categorySplitted; } diff --git a/src/main/java/com/jFxKasse/datatypes/Job.java b/src/main/java/com/jFxKasse/datatypes/Job.java index 418a604..ecf50bb 100644 --- a/src/main/java/com/jFxKasse/datatypes/Job.java +++ b/src/main/java/com/jFxKasse/datatypes/Job.java @@ -3,8 +3,7 @@ package com.jFxKasse.datatypes; import java.math.BigDecimal; import java.util.ArrayList; -public class Job -{ +public class Job { private int jobnumber; private float jobvalue; @@ -19,8 +18,7 @@ public class Job private ArrayList positionenCat; - public Job(int pJobnumber) - { + public Job(int pJobnumber) { this.jobnumber = pJobnumber; positionenQuantity = new ArrayList(); positionenName = new ArrayList(); @@ -29,23 +27,19 @@ public class Job } - public void setJobtime(String jobtime) - { + public void setJobtime(String jobtime) { this.jobtime = jobtime; } - public int getJobnumber() - { + public int getJobnumber() { return this.jobnumber; } - public String getJobtime() - { + public String getJobtime() { return this.jobtime; } - public float getJobValue() - { + public float getJobValue() { calcJobValue(); @@ -53,8 +47,7 @@ public class Job } public void addPosition(String pPositionenName, float pPositionenValue, - String pPositionenCat) - { + String pPositionenCat) { for (int i = 0; i < positionenName.size(); i++) { if (positionenName.get(i).equals(pPositionenName)) { // Item is already in list, increase quantity @@ -71,8 +64,7 @@ public class Job calcJobValue(); } - public void printJobOnConsole() - { + public void printJobOnConsole() { System.out.println("---------------------------------------------"); System.out.println("JobNummer: " + jobnumber); System.out.println("---------------------------------------------"); @@ -88,10 +80,9 @@ public class Job } - public ArrayList getCurrentJobPositionen() - { + public ArrayList getCurrentJobPositionen() { ArrayList jobitems = new ArrayList(); - + for (int i = 0; i < positionenName.size(); i++) { tableDataCurrentOrder tmp = new tableDataCurrentOrder( @@ -102,20 +93,18 @@ public class Job return jobitems; } - private void calcJobValue() - { + private void calcJobValue() { jobvalue = 0; for (int i = 0; i < positionenValue.size(); i++) { jobvalue = jobvalue + (positionenQuantity.get(i) * positionenValue.get(i)); } - //Round to two decimals - jobvalue = BigDecimal.valueOf(jobvalue).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); + // Round to two decimal places + jobvalue = BigDecimal.valueOf(jobvalue).setScale(2, BigDecimal.ROUND_HALF_UP).floatValue(); } - public String createPosQuantityDBString() - { + public String createPosQuantityDBString() { String tmp = String.valueOf(positionenQuantity.get(0)); for (int i = 1; i < positionenName.size(); i++) { @@ -124,8 +113,7 @@ public class Job return tmp; } - public String createPosNameDBString() - { + public String createPosNameDBString() { String tmp = positionenName.get(0); for (int i = 1; i < positionenName.size(); i++) { @@ -134,8 +122,7 @@ public class Job return tmp; } - public String createPosValueDBString() - { + public String createPosValueDBString() { String tmp = String.valueOf(positionenValue.get(0)); for (int i = 1; i < positionenName.size(); i++) { @@ -144,8 +131,7 @@ public class Job return tmp; } - public String createPosCatDBString() - { + public String createPosCatDBString() { String tmp = positionenCat.get(0); for (int i = 1; i < positionenName.size(); i++) { @@ -154,8 +140,7 @@ public class Job return tmp; } - public void deletePosName(String pPosName) - { + public void deletePosName(String pPosName) { for (int i = 0; i < positionenName.size(); i++) { @@ -178,8 +163,7 @@ public class Job } - public boolean existsPosName(String pPosName) - { + public boolean existsPosName(String pPosName) { for (int i = 0; i < positionenName.size(); i++) { if (positionenName.get(i).equals(pPosName)) { return true; diff --git a/src/main/java/com/jFxKasse/datatypes/PrintData.java b/src/main/java/com/jFxKasse/datatypes/PrintData.java index 1c15c42..08c7cde 100644 --- a/src/main/java/com/jFxKasse/datatypes/PrintData.java +++ b/src/main/java/com/jFxKasse/datatypes/PrintData.java @@ -1,7 +1,6 @@ package com.jFxKasse.datatypes; -public abstract class PrintData -{ +public abstract class PrintData { protected int headerSpace; @@ -30,7 +29,8 @@ public abstract class PrintData protected String jobValue; /** - * Constructor with all data that is not in the DB + * Constructor with all data that is not stored in the DB + * * @param lineBreak * @param headerSpace * @param footerSpace @@ -39,8 +39,7 @@ public abstract class PrintData * @param footer */ public PrintData(int lineBreak, int headerSpace, int footerSpace, - String timeAndDatePrint, String header, String footer) - { + String timeAndDatePrint, String header, String footer) { this.lineBreak = lineBreak; this.headerSpace = headerSpace; this.footerSpace = footerSpace; @@ -50,7 +49,8 @@ public abstract class PrintData } /** - * set all Data that is in the DB + * Set all data that is stored in the DB + * * @param jobID * @param timeAndDateOrder * @param positionenQuantity @@ -61,8 +61,7 @@ public abstract class PrintData */ public void setData(String jobID, String timeAndDateOrder, String positionsQuantity, String positionsName, - String positionsValue, String positionsCategory, String jobValue) - { + String positionsValue, String positionsCategory, String jobValue) { this.jobID = jobID; this.timeAndDateOrder = timeAndDateOrder; this.positionsQuantity = positionsQuantity; @@ -73,25 +72,25 @@ public abstract class PrintData } /** + * Breaks a string with newlines after the max line length * * @param data String - * @return same String splitted with \n after the max. line lenght + * @return the same String split with \n after max line length */ - protected String breakLines(String data) - { + protected String breakLines(String data) { boolean next = false; int count = lineBreak; if (data.length() > lineBreak) { - // Needs to be splitted + // Needs to be split next = true; } else { - // No need to be splitted + // No need to split return data; } - // first part + // First part String tmp = data.substring(0, lineBreak); while (next) { @@ -100,20 +99,20 @@ public abstract class PrintData tmp = tmp + "\n" + data.substring(count, lineBreak + count); count = count + lineBreak; } catch (Exception e) { - // data string not long enough + // Data string not long enough next = false; } } - // add the last part + // Add the last part return tmp + "\n" + data.substring(count); } /** - * prints a line of '--------' - * @return + * Prints a line of dashes '--------' + * + * @return separator line */ - protected String getSeparator() - { + protected String getSeparator() { String tmp = "-"; for (int i = 1; i < lineBreak; i++) { @@ -123,12 +122,12 @@ public abstract class PrintData } /** - * sets a String into the center + * Centers a string within the line width + * * @param data - * @return the centered String + * @return the centered string */ - protected String setCenter(String data) - { + protected String setCenter(String data) { int dataLenght = data.length(); int prefix = ((lineBreak - dataLenght) / 2); String tmp = " "; @@ -137,18 +136,18 @@ public abstract class PrintData tmp = tmp + " "; } tmp = tmp + data; - + return breakLines(tmp); } /** - * sets a String right-justified after an prefix + * Right-justifies a string after a prefix + * * @param prefix * @param data - * @return the right-justified String + * @return the right-justified string */ - protected String setRight(String prefix, String data) - { + protected String setRight(String prefix, String data) { int prefixLenght = prefix.length(); @@ -173,7 +172,7 @@ public abstract class PrintData } /** - * How the print String or Strings are made + * Defines how the print string(s) are generated */ abstract protected void generatePrintString(); diff --git a/src/main/java/com/jFxKasse/datatypes/PrintDataSimple.java b/src/main/java/com/jFxKasse/datatypes/PrintDataSimple.java index 9abc9fc..c78c9cc 100644 --- a/src/main/java/com/jFxKasse/datatypes/PrintDataSimple.java +++ b/src/main/java/com/jFxKasse/datatypes/PrintDataSimple.java @@ -1,12 +1,12 @@ package com.jFxKasse.datatypes; -public class PrintDataSimple extends PrintData -{ +public class PrintDataSimple extends PrintData { private String printString; /** - * Constructor with all data that is not in the DB + * Constructor with all data that is not stored in the DB + * * @param lineBreak * @param headerSpace * @param footerSpace @@ -15,25 +15,23 @@ public class PrintDataSimple extends PrintData * @param footer */ public PrintDataSimple(int lineBreak, int headerSpace, int footerSpace, - String timeAndDatePrint, String header, String footer) - { + String timeAndDatePrint, String header, String footer) { super(lineBreak, headerSpace, footerSpace, timeAndDatePrint, header, footer); } /** - * Generates the String - * @return the final Print String + * Generates the print string + * + * @return the final print string */ - public String getPrintString() - { + public String getPrintString() { generatePrintString(); return this.printString; } @Override - protected void generatePrintString() - { + protected void generatePrintString() { /* Header */ String header = " "; for (int i = 1; i < headerSpace; i++) { diff --git a/src/main/java/com/jFxKasse/datatypes/PrintDataSplitted.java b/src/main/java/com/jFxKasse/datatypes/PrintDataSplitted.java index e8318cc..393933d 100644 --- a/src/main/java/com/jFxKasse/datatypes/PrintDataSplitted.java +++ b/src/main/java/com/jFxKasse/datatypes/PrintDataSplitted.java @@ -2,8 +2,7 @@ package com.jFxKasse.datatypes; import java.util.ArrayList; -public class PrintDataSplitted extends PrintData -{ +public class PrintDataSplitted extends PrintData { private ArrayList printString = new ArrayList(); private ArrayList categories = new ArrayList(); @@ -11,7 +10,8 @@ public class PrintDataSplitted extends PrintData private int categoryCount = 0; /** - * Constructor with all data that is not in the DB + * Constructor with all data that is not stored in the DB + * * @param lineBreak * @param headerSpace * @param footerSpace @@ -20,25 +20,23 @@ public class PrintDataSplitted extends PrintData * @param footer */ public PrintDataSplitted(int lineBreak, int headerSpace, int footerSpace, - String timeAndDatePrint, String header, String footer) - { + String timeAndDatePrint, String header, String footer) { super(lineBreak, headerSpace, footerSpace, timeAndDatePrint, header, footer); } /** - * Generates the String - * @return the final Array with the Print Strings + * Generates the print strings + * + * @return the final array of print strings */ - public ArrayList getPrintStrings() - { + public ArrayList getPrintStrings() { generatePrintString(); return printString; } @Override - protected void generatePrintString() - { + protected void generatePrintString() { String firstBill; @@ -57,7 +55,7 @@ public class PrintDataSplitted extends PrintData + setRight("Druck: ", timeAndDatePrint) + "\n" + setRight("Bestellnummer: ", jobID); - /* Splitted Bills */ + /* Splitted Bills by Category */ /* Price */ @@ -81,9 +79,9 @@ public class PrintDataSplitted extends PrintData printString.add(firstBill); - /* first bill ends here */ + /* First bill ends here */ - /* Categories in extra bills */ + /* Category-specific extra bills */ String positions = null; @@ -101,7 +99,7 @@ public class PrintDataSplitted extends PrintData positionCategory[i]); } - // loops through all categories + // Loops through all categories for (int i = 0; i < categories.size(); i++) { String thisBill; @@ -147,8 +145,7 @@ public class PrintDataSplitted extends PrintData } private void insertToCategory(int quantity, String name, String value, - String category) - { + String category) { boolean createNewCategorie = true; for (int i = 0; i < categoryCount; i++) { if (category.equals(categories.get(i).getCategoryName())) { @@ -158,7 +155,7 @@ public class PrintDataSplitted extends PrintData } if (createNewCategorie) { - // position has a new category + // Position has a new category categories.add(new Category(category)); categories.get(categoryCount).addPosition(quantity, name, value, this); categoryCount++; diff --git a/src/main/java/com/jFxKasse/datatypes/tableDataPositionen.java b/src/main/java/com/jFxKasse/datatypes/tableDataPositionen.java index f9107a8..bbbf578 100644 --- a/src/main/java/com/jFxKasse/datatypes/tableDataPositionen.java +++ b/src/main/java/com/jFxKasse/datatypes/tableDataPositionen.java @@ -5,21 +5,20 @@ import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; -public class tableDataPositionen -{ // data-object with id, name, value, color +public class tableDataPositionen { // Data object with id, name, value, color private final IntegerProperty id = new SimpleIntegerProperty(); private final StringProperty name = new SimpleStringProperty(); private final StringProperty value = new SimpleStringProperty(); - + private final StringProperty cat = new SimpleStringProperty(); - + private final StringProperty color = new SimpleStringProperty(); - public tableDataPositionen(final int id, final String name, final String value, final String cat, final String color) - { + public tableDataPositionen(final int id, final String name, final String value, final String cat, + final String color) { this.id.set(id); this.name.set(name); this.value.set(value); @@ -27,75 +26,63 @@ public class tableDataPositionen this.color.set(color); } - public IntegerProperty idProperty() - { + public IntegerProperty idProperty() { return id; } - public StringProperty nameProperty() - { + public StringProperty nameProperty() { return name; } - public StringProperty valueProperty() - { + public StringProperty valueProperty() { return value; } - + public StringProperty catProperty() { return cat; } - - public StringProperty colorProperty() - { + + public StringProperty colorProperty() { return color; } - public int getID() - { + public int getID() { return idProperty().get(); } - public String getName() - { + public String getName() { return nameProperty().get(); } - public String getValue() - { + public String getValue() { return valueProperty().get(); } - + public String getCat() { return catProperty().get(); } - - public String getColor() - { + + public String getColor() { return colorProperty().get(); } - public final void setID(int id) - { + public final void setID(int id) { idProperty().set(id); } - public final void setName(String name) - { + public final void setName(String name) { nameProperty().set(name); } - public final void setValue(String value) - { + public final void setValue(String value) { valueProperty().set(value); } - + public final void setCat(String cat) { catProperty().set(cat); } - - public final void setColor(String color) - { + + public final void setColor(String color) { colorProperty().set(color); } } diff --git a/src/main/resources/css/application.css b/src/main/resources/css/application.css index 83d6f33..53345be 100644 --- a/src/main/resources/css/application.css +++ b/src/main/resources/css/application.css @@ -1 +1 @@ -/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file +/* JavaFX CSS - Leave this comment until you have at least one rule which uses -fx-Property */ \ No newline at end of file -- 2.50.1 From c40be1c203f47e859c0fd09e60c5e33763e81b06 Mon Sep 17 00:00:00 2001 From: localhorst Date: Sat, 21 Feb 2026 18:22:25 +0100 Subject: [PATCH 02/11] fix first start --- .../java/com/jFxKasse/application/Main.java | 280 +- .../controller/MainWindowController.java | 2878 +++++++++-------- src/main/resources/fxml/MainWindow.fxml | 159 +- 3 files changed, 1684 insertions(+), 1633 deletions(-) diff --git a/src/main/java/com/jFxKasse/application/Main.java b/src/main/java/com/jFxKasse/application/Main.java index cf23d73..4f609e5 100644 --- a/src/main/java/com/jFxKasse/application/Main.java +++ b/src/main/java/com/jFxKasse/application/Main.java @@ -1,122 +1,158 @@ -package com.jFxKasse.application; - -import javafx.application.Application; -import javafx.event.EventHandler; - -import java.io.File; -import javafx.animation.Animation; -import javafx.animation.KeyFrame; -import javafx.animation.Timeline; -import javafx.fxml.FXMLLoader; -import javafx.stage.Stage; -import javafx.util.Duration; -import com.jFxKasse.controller.MainWindowController; -import com.jFxKasse.controller.PrinterController; -import com.jFxKasse.controller.XMLController; -import com.jFxKasse.controller.DBController; -import com.jFxKasse.controller.KeyController; - -import javafx.scene.Scene; -import javafx.scene.input.KeyEvent; -import javafx.scene.layout.AnchorPane; - -public class Main extends Application { - // Path to config.xml and the database - public static String filepath; - - private static String osName = System.getProperty("os.name"); - - private static String userHome = System.getProperty("user.home"); - - private MainWindowController mwc; - - private XMLController xmlc = new XMLController(filepath); - - private DBController dbc = new DBController(filepath); - - private PrinterController pc = new PrinterController(); - - private KeyController kc; - - private Stage primaryStage; - - @Override - public void start(Stage primaryStage) { - this.primaryStage = primaryStage; - System.out.println("\nstarting jFxKasse\n"); - mainWindow(); - } - - private void mainWindow() { - try { - FXMLLoader loader = new FXMLLoader( - getClass().getResource("/fxml/MainWindow.fxml")); - - AnchorPane pane = loader.load(); - primaryStage.setTitle("jFxKasse"); // Window title - - mwc = loader.getController(); // Set the MainWindowController - pc.searchPrinters(); // Search for available printers - mwc.setMain(this, dbc, xmlc, pc); // Pass instances to the controller - - firstStart(); // Check if this is the first run - - Scene scene = new Scene(pane); - scene.getStylesheets().add( - Main.class.getResource("/css/application.css").toExternalForm()); - primaryStage.setScene(scene); - primaryStage.show(); // Show the stage - - // Attach the KeyController - kc = new KeyController(scene, mwc); - - Timeline timeline = new Timeline( - new KeyFrame(Duration.seconds(1), ev -> { - mwc.updateTimeLabel(); // Update time label on UI - })); - timeline.setCycleCount(Animation.INDEFINITE); - timeline.play(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void main(String[] args) { - if (osName.contains("Windows")) { - System.out.println("FCK Windows"); - filepath = userHome + "/Documents/jFxKasse/"; - } else { - filepath = userHome + "/jFxKasse/"; - } - launch(args); - } - - /** - * Checks if the config.xml is preset. - */ - private void firstStart() throws Exception { - if (xmlc.loadSettings()) { - // config.xml found, app starting normal - System.out.println("XML found!"); - mwc.initUI(); // Initialize the UI elements - mwc.setDBLabel(); // Set database labels - dbc.setDbname(xmlc.getDatabaseName()); // Pass database name - dbc.connectDatabase(); // Establish DB connection - mwc.fillTablePositionen(); // Fill TreeTable 'Positions' - mwc.fillCategory(); - mwc.fillPrinterSettings(); - mwc.fillTableJobs(); - mwc.loadGridButtons(); - mwc.getSelectedCat(); // Load DB entries in ChoiceBox - mwc.createNewJob(); - } else { - // config.xml NOT found, first start of app - System.out.println("no XML found!"); - xmlc.initXML(); // Set default values - mwc.blockUI(true); // Disable UI elements that need DB - mwc.blockUnlock(); - File dir = new File(filepath); - dir.mkdir(); // Create new subfolder - } - } -} +package com.jFxKasse.application; + +import javafx.application.Application; +import javafx.event.EventHandler; + +import java.io.File; +import javafx.animation.Animation; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.fxml.FXMLLoader; +import javafx.stage.Stage; +import javafx.util.Duration; +import com.jFxKasse.controller.MainWindowController; +import com.jFxKasse.controller.PrinterController; +import com.jFxKasse.controller.XMLController; +import com.jFxKasse.controller.DBController; +import com.jFxKasse.controller.KeyController; + +import javafx.scene.Scene; +import javafx.scene.input.KeyEvent; +import javafx.scene.layout.AnchorPane; + +public class Main extends Application { + // Path to config.xml and the database + public static String filepath; + + private static String osName = System.getProperty("os.name"); + + private static String userHome = System.getProperty("user.home"); + + private MainWindowController mwc; + + // Initialized in start() after filepath is set by main() + private XMLController xmlc; + + private DBController dbc; + + private PrinterController pc = new PrinterController(); + + private KeyController kc; + + private Stage primaryStage; + + @Override + public void start(Stage primaryStage) { + this.primaryStage = primaryStage; + // filepath is set by main() before launch(); initialize controllers here + xmlc = new XMLController(filepath); + dbc = new DBController(filepath); + System.out.println("\nstarting jFxKasse\n"); + mainWindow(); + } + + private void mainWindow() { + try { + FXMLLoader loader = new FXMLLoader( + getClass().getResource("/fxml/MainWindow.fxml")); + + AnchorPane pane = loader.load(); + primaryStage.setTitle("jFxKasse"); // Window title + + mwc = loader.getController(); // Set the MainWindowController + pc.searchPrinters(); // Search for available printers + mwc.setMain(this, dbc, xmlc, pc); // Pass instances to the controller + + firstStart(); // Check if this is the first run + + Scene scene = new Scene(pane); + scene.getStylesheets().add( + Main.class.getResource("/css/application.css").toExternalForm()); + primaryStage.setScene(scene); + primaryStage.show(); // Show the stage + + // Attach the KeyController + kc = new KeyController(scene, mwc); + + Timeline timeline = new Timeline( + new KeyFrame(Duration.seconds(1), ev -> { + mwc.updateTimeLabel(); // Update time label on UI + })); + timeline.setCycleCount(Animation.INDEFINITE); + timeline.play(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public static void main(String[] args) { + if (osName.contains("Windows")) { + System.out.println("FCK Windows"); + filepath = userHome + "/Documents/jFxKasse/"; + } else { + filepath = userHome + "/jFxKasse/"; + } + launch(args); + } + + /** + * Checks if the config.xml is present and initializes accordingly. + */ + private void firstStart() throws Exception { + if (xmlc.loadSettings()) { + // config.xml found, app starting normally + System.out.println("XML found!"); + mwc.initUI(); // Initialize the UI elements + mwc.setDBLabel(); // Set database labels + dbc.setDbname(xmlc.getDatabaseName()); // Pass database name + try { + dbc.connectDatabase(); // Establish DB connection + } catch (Exception e) { + e.printStackTrace(); + showErrorDialog("Datenbankfehler", + "Die Datenbank konnte nicht geöffnet werden.", + "Datei: " + xmlc.getDatabaseName() + ".db\n\n" + + "Bitte prüfen Sie, ob die Datei vorhanden und nicht beschädigt ist.\n" + + "Fehlermeldung: " + e.getMessage()); + return; + } + mwc.fillTablePositionen(); // Fill TreeTable 'Positions' + mwc.fillCategory(); + mwc.fillPrinterSettings(); + mwc.fillTableJobs(); + mwc.loadGridButtons(); + mwc.getSelectedCat(); // Load DB entries in ChoiceBox + mwc.createNewJob(); + } else { + // config.xml NOT found — first start of app + System.out.println("no XML found!"); + xmlc.initXML(); // Set default values in memory + File dir = new File(filepath); + dir.mkdir(); // Create config directory + try { + xmlc.saveSettings(); // Persist defaults immediately so next start is normal + System.out.println("Default config.xml written."); + } catch (Exception e) { + e.printStackTrace(); + showErrorDialog("Konfigurationsfehler", + "Die Konfigurationsdatei konnte nicht geschrieben werden.", + "Pfad: " + filepath + "config.xml\n\n" + + "Bitte prüfen Sie die Schreibrechte.\n" + + "Fehlermeldung: " + e.getMessage()); + } + mwc.blockUI(true); // Disable UI elements that need a DB + mwc.blockUnlock(); // Show first-start hint, disable lock button + } + } + + /** Shows a modal error alert dialog on the JavaFX thread. */ + private void showErrorDialog(String title, String header, String content) { + javafx.scene.control.Alert alert = new javafx.scene.control.Alert( + javafx.scene.control.Alert.AlertType.ERROR); + alert.setTitle(title); + alert.setHeaderText(header); + alert.setContentText(content); + alert.setResizable(true); + alert.showAndWait(); + } +} diff --git a/src/main/java/com/jFxKasse/controller/MainWindowController.java b/src/main/java/com/jFxKasse/controller/MainWindowController.java index 0a4f1cc..65db077 100644 --- a/src/main/java/com/jFxKasse/controller/MainWindowController.java +++ b/src/main/java/com/jFxKasse/controller/MainWindowController.java @@ -1,1434 +1,1444 @@ -package com.jFxKasse.controller; - -import javafx.fxml.FXML; -import javafx.geometry.Insets; -import javafx.scene.control.Button; -import javafx.scene.control.ButtonType; -import javafx.scene.control.Dialog; -import javafx.scene.control.TreeTableColumn; -import javafx.scene.control.TreeTableView; -import javafx.scene.control.TextField; -import javafx.scene.control.TreeItem; -import javafx.scene.control.TitledPane; -import javafx.scene.control.Tooltip; -import javafx.scene.control.ChoiceBox; - -import java.awt.Desktop; -import java.io.File; -import java.io.IOException; -import com.jfoenix.controls.JFXTextField; -import com.jfoenix.controls.JFXToggleButton; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; -import javafx.collections.FXCollections; -import javafx.collections.ObservableList; -import javafx.event.ActionEvent; -import javafx.scene.control.Label; -import javafx.scene.control.Spinner; -import javafx.scene.control.SpinnerValueFactory; -import javafx.scene.control.Tab; -import javafx.scene.layout.AnchorPane; -import javafx.scene.layout.GridPane; -import javafx.util.Pair; -import com.jFxKasse.application.Main; -import com.jFxKasse.application.PrintJob; -import com.jFxKasse.application.TimeDate; -import com.jFxKasse.datatypes.Job; -import com.jFxKasse.datatypes.tableDataCurrentOrder; -import com.jFxKasse.datatypes.tableDataJob; -import com.jFxKasse.datatypes.tableDataPositionen; - -public class MainWindowController { - @FXML - private AnchorPane mainAnchorpane; - - @FXML - private AnchorPane paneDB; - - @FXML - private Tab tapNewJob; - - @FXML - private Tab tapJobs; - - @FXML - private Tab tapPosEdit; - - @FXML - private Tab tapSettings; - - @FXML - private TreeTableView tableCurrentOrder; - - @FXML - private TreeTableColumn columnQuantity; - - @FXML - private TreeTableColumn columnPosition; - - @FXML - private TreeTableColumn idSpalte01 = new TreeTableColumn<>( - "tableCurrentOrder"); - - @FXML - private TreeTableView jobsTreeTable; - - @FXML - private TreeTableColumn columnJobValue; - - @FXML - private TreeTableColumn columnState; - - @FXML - private TreeTableColumn columnPositions; - - @FXML - private TreeTableColumn columnTime; - - @FXML - private TreeTableColumn columnJobNumber; - - @FXML - private TreeTableColumn idSpalte02 = new TreeTableColumn<>( - "jobsTreeTable"); - - @FXML - private TreeTableView entryTreeTable; - - @FXML - private TreeTableColumn columnColor; - - @FXML - private TreeTableColumn columnCat; - - @FXML - private TreeTableColumn columnPrize; - - @FXML - private TreeTableColumn columnPositionsEdit; - - @FXML - private TreeTableColumn columnPosnumber; - - @FXML - private ChoiceBox colorChoise; - - @FXML - private ChoiceBox catChoise; - - @FXML - private ChoiceBox printerChoise; - - @FXML - private Spinner linesSpinner; - - @FXML - private Spinner offsetHeaderSpinner; - - @FXML - private Spinner offsetFooterSpinner; - - @FXML - private Button ueberbtn; - - @FXML - private Button gridButton01; - - @FXML - private Button gridButton02; - - @FXML - private Button gridButton03; - - @FXML - private Button gridButton04; - - @FXML - private Button gridButton05; - - @FXML - private Button gridButton06; - - @FXML - private Button gridButton07; - - @FXML - private Button gridButton08; - - @FXML - private Button gridButton09; - - @FXML - private Button gridButton10; - - @FXML - private Button gridButton11; - - @FXML - private Button gridButton12; - - @FXML - private Button gridButton13; - - @FXML - private Button gridButton14; - - @FXML - private Button gridButton15; - - @FXML - private Button gridButton16; - - @FXML - private Button gridButton17; - - @FXML - private Button gridButton18; - - @FXML - private Button gridButton19; - - @FXML - private Button gridButton20; - - @FXML - private Button gridButton21; - - @FXML - private Button gridButton22; - - @FXML - private Button gridButton23; - - @FXML - private Button gridButton24; - - @FXML - private Button gridButton25; - - @FXML - public Button btnSavePrinter; - - @FXML - public Button btnDeleteSelectedPosition; - - @FXML - public Button btnPrintBill; - - @FXML - public Button btnLock; - - @FXML - public Button btnReprintJob; - - @FXML - public Button btnCancelJob; - - @FXML - public Button btnCalcStats; - - @FXML - public Button btnSaveEntry; - - @FXML - public Button btnClearEntry; - - @FXML - public Button btnCreateNewDatabase; - - @FXML - private Button btnOpenFolder; - - @FXML - private Label labelCat01; - - @FXML - private Label labelCat02; - - @FXML - private Label labelCat05; - - @FXML - private Label labelCat04; - - @FXML - private Label labelCat03; - - @FXML - private JFXTextField tftfooter; - - @FXML - private JFXTextField tftheader; - - @FXML - private JFXTextField tftKat01; - - @FXML - private JFXTextField tftKat02; - - @FXML - private JFXTextField tftKat03; - - @FXML - private JFXTextField tftKat04; - - @FXML - private JFXTextField tftKat05; - - @FXML - public Button btnSaveCat; - - @FXML - private Label labelAllPrize; - - @FXML - private Label labelJobCounter; - - @FXML - private Label labelTime; - - @FXML - private Label labelJobCount; - - @FXML - private Label labelAvgJob; - - @FXML - private Label labelAllValue; - - @FXML - private Label labelSelectCat; - - @FXML - private Label labelNewPosition; - - @FXML - private Label labelNewValue; - - @FXML - private Label labelNewColor; - - @FXML - private Label labelDBStatus; - - @FXML - private Label labelDBName; - - @FXML - private TitledPane titlePaneStats; - - @FXML - private TitledPane titlePaneCat; - - @FXML - private TitledPane titledPaneEntry; - - @FXML - private TitledPane titlePanePrint; - - @FXML - private TextField tftNewPosition; - - @FXML - private TextField tftNewValue; - - @FXML - private TextField tftNewDBName; - - @FXML - private JFXToggleButton switchSeparate; - - @SuppressWarnings("unused") - private Main main; - - private DBController dbc; - - private XMLController xmlc; - - private PrinterController pc; - - private TimeDate timedate = new TimeDate(); - - private PrintJob pj = new PrintJob(); - - private int idPositionen = 0; - - private String selectedColorName; - - private String selectedCatName; - - private boolean lockState = false; - - private boolean isPrintBtnDisabled = true; - - private Job currentJob = null; - - private String currentOrderPosName; - - private int selectedJobId; - - @FXML - TreeItem rootCurrentJob = new TreeItem<>( - new tableDataCurrentOrder("0", 0)); - - @FXML - TreeItem rootJobs = new TreeItem<>( - new tableDataJob(0, "0", "0", "0", "0")); - - @FXML - TreeItem rootPositionen = new TreeItem<>( - new tableDataPositionen(0, "0", "0", "0", "0")); - - @FXML - public void ueberbtnAction(ActionEvent event) { // Opens the 'About' dialog - - // creates a dialog - Dialog> dialog = new Dialog<>(); - dialog.setTitle("Über jFxKasse"); - dialog.setHeaderText("Informationen und Lizenzen - Version 0.3.2"); - - dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK); - - GridPane grid = new GridPane(); - grid.setHgap(10); - grid.setVgap(10); - grid.setPadding(new Insets(20, 150, 10, 10)); - - grid.add(new Label( - "Einfaches Kassensystem für kleine bis mittel große Veranstaltungen mit Bon-Drucker\n" - + "\nUnter Lizenz GPL-3.0 abrufbar auf https://git.mosad.xyz/localhorst/jFxKasse\n" - + "\nDatenbank: sqlite.org - Public Domain" - + " \nUI Design01: eclipse.org/efxclipse/install.html - Eclipse Public License 1.0" - + " \nUI Design02: http://www.jfoenix.com/ - Apache License 2.0" - + " \nUI - Datenbank Integration: basierend auf Project-HomeFlix - github.com/Seil0/Project-HomeFlix - GPLv3 \n" - + " \nMaintainer: hendrik.schutter@coptersicht.de" - + " \n(c) 2018 Hendrik Schutter"), - 0, 0); - - dialog.getDialogPane().setContent(grid); - dialog.setResizable(true); - dialog.showAndWait(); - } - - @FXML - public void btnOpenFolderAction(ActionEvent event) throws IOException { - - if (System.getProperty("os.name").contains("Windows")) { - System.out.println("FCK Windows"); - File file = new File(Main.filepath); - Desktop desktop = Desktop.getDesktop(); - desktop.open(file); - } else { - Runtime.getRuntime().exec("xdg-open " + Main.filepath); - } - } - - @FXML - public void btnCreateNewDatabaseAction(ActionEvent event) throws Exception { - - if (!(tftNewDBName.getText().equals(""))) { - - xmlc.setDatabaseName(tftNewDBName.getText()); - - dbc.setDbname(xmlc.getDatabaseName()); - dbc.connectDatabase(); // Establish DB connection - dbc.createTablePositionen(); // Create new table - dbc.erstelleTabelleJobs(); // Create new table - dbc.createTableCategory(); // Create new table - try { - // saveSettings(getDatabaseName()); - xmlc.saveSettings(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - setDBLabel(); // Set new database labels - blockUI(false); // Unlock UI elements that need DB - fillTablePositionen(); // Fill TreeTable 'Positions' - fillCategory(); - fillPrinterSettings(); - initUI(); // Initialize the UI elements - getSelectedCat(); - createNewJob(); - - btnLock.setDisable(false); - } - } - - @FXML - public void btnSaveEntryAction(ActionEvent event) { - dbc.setName_Positionen(idPositionen, tftNewPosition.getText()); - dbc.setValue_Positionen(idPositionen, tftNewValue.getText()); - dbc.setColor_Positionen(idPositionen, getColorCodes(selectedColorName)); - - dbc.setCat_Positionen(idPositionen, getSelectedCat()); - - fillTablePositionen(); // Fill TreeTable 'Positions' - loadGridButtons(); - - } - - @FXML - public void btnClearEntryAction(ActionEvent event) { - // Set default values - dbc.setName_Positionen(idPositionen, "Noch frei"); - dbc.setValue_Positionen(idPositionen, "0.00"); - dbc.setColor_Positionen(idPositionen, "#FAF0E6"); - dbc.setCat_Positionen(idPositionen, 6); - - fillTablePositionen(); // Fill TreeTable 'Positions' - } - - @FXML - public void btnCalcStatsAction(ActionEvent event) { - int allActiveJobs = Integer.valueOf(dbc.getJobCount()); - - if (dbc.getAllJobValue_Job() != null) { - - // Summed up values of all active jobs - float allValue = Float.valueOf(dbc.getAllJobValue_Job()); - - // Count of all active jobs - - float avgJobValue = ((float) allValue / allActiveJobs); - - setJobStatLabel(allActiveJobs, avgJobValue, allValue); - } else { - setJobStatLabel(allActiveJobs, 0, 0); - } - titlePaneStats.setVisible(true); - } - - @FXML - public void btnSavePrinterAction(ActionEvent event) { - System.out.println("btnSavePrinterAction"); - - xmlc.setPrintername( - printerChoise.getSelectionModel().getSelectedItem().toString()); - xmlc.setLinebreak(linesSpinner.getValue()); - xmlc.setOffsetHeader(offsetHeaderSpinner.getValue()); - xmlc.setOffsetFooter(offsetFooterSpinner.getValue()); - xmlc.setHeader(tftheader.getText()); - xmlc.setFooter(tftfooter.getText()); - xmlc.setCategorySplitted(switchSeparate.isSelected()); - - try { - xmlc.saveSettings(); - } catch (Exception e) { - // TODO Auto-generated catch block - // e.printStackTrace(); - } - fillPrinterSettings(); - } - - @FXML - public void btnCancelJobAction(ActionEvent event) { - dbc.setStatus_Jobs(selectedJobId + 1, "storniert"); - fillTableJobs(); - btnCancelJob.setDisable(true); - btnReprintJob.setDisable(true); - } - - @FXML - public void btnLockAction(ActionEvent event) { - lockState = !lockState; - blockUI(lockState); - - if (lockState) { - btnLock.setText("Kasse entsperren"); - } else { - btnLock.setText("Kasse sperren"); - } - } - - @FXML - public void btnSaveCatAction(ActionEvent event) { - dbc.setName_Category(1, tftKat01.getText()); - dbc.setName_Category(2, tftKat02.getText()); - dbc.setName_Category(3, tftKat03.getText()); - dbc.setName_Category(4, tftKat04.getText()); - dbc.setName_Category(5, tftKat05.getText()); - - fillCategory(); - fillTablePositionen(); - getSelectedCat(); - } - - @FXML - public void btnDeleteSelectedPositionAction(ActionEvent event) { - currentJob.deletePosName(currentOrderPosName); - rootCurrentJob.getChildren().remove(0, - rootCurrentJob.getChildren().size()); - - for (int i = 0; i < currentJob.getCurrentJobPositionen().size(); i++) { - rootCurrentJob.getChildren().add(new TreeItem( - currentJob.getCurrentJobPositionen().get(i))); - - } - setJobPrizeLabel(currentJob.getJobValue()); - - if (rootCurrentJob.getChildren().size() == 0) { - btnPrintBill.setDisable(true); - isPrintBtnDisabled = true; - tapPosEdit.setDisable(false); - btnDeleteSelectedPosition.setDisable(true); - } - - if (!currentJob.existsPosName(currentOrderPosName)) { - btnDeleteSelectedPosition.setDisable(true); - } - } - - @FXML - public void btnPrintBillAction(ActionEvent event) { - btnPrintBill.setDisable(true); - tapPosEdit.setDisable(false); - btnDeleteSelectedPosition.setDisable(true); - isPrintBtnDisabled = true; - tapJobs.setDisable(false); - - setJobPrizeLabel(0); - - currentJob.setJobtime( - timedate.getSystemTime() + " " + timedate.getSystemDate()); - - rootCurrentJob.getChildren().remove(0, - rootCurrentJob.getChildren().size()); - - dbc.fillJobs_Jobs(currentJob.getJobnumber(), currentJob.getJobtime(), - currentJob.createPosQuantityDBString(), - currentJob.createPosNameDBString(), - currentJob.createPosValueDBString(), - currentJob.createPosCatDBString(), "verbucht", - String.valueOf(currentJob.getJobValue())); - - pj.printJob(currentJob.getJobnumber(), xmlc, dbc, pc); - - fillTableJobs(); - - currentJob = null; - - createNewJob(); - - } - - @FXML - public void btnReprintJobAction(ActionEvent event) { - System.out.println("reprint job"); - pj.printJob((selectedJobId + 1), xmlc, dbc, pc); - } - - @FXML - public void gridButton01Action(ActionEvent event) { - handleGridButtons(1); - } - - @FXML - public void gridButton02Action(ActionEvent event) { - handleGridButtons(2); - } - - @FXML - public void gridButton03Action(ActionEvent event) { - handleGridButtons(3); - } - - @FXML - public void gridButton04Action(ActionEvent event) { - handleGridButtons(4); - } - - @FXML - public void gridButton05Action(ActionEvent event) { - handleGridButtons(5); - } - - @FXML - public void gridButton06Action(ActionEvent event) { - handleGridButtons(6); - } - - @FXML - public void gridButton07Action(ActionEvent event) { - handleGridButtons(7); - } - - @FXML - public void gridButton08Action(ActionEvent event) { - handleGridButtons(8); - } - - @FXML - public void gridButton09Action(ActionEvent event) { - handleGridButtons(9); - } - - @FXML - public void gridButton10Action(ActionEvent event) { - handleGridButtons(10); - } - - @FXML - public void gridButton11Action(ActionEvent event) { - handleGridButtons(11); - } - - @FXML - public void gridButton12Action(ActionEvent event) { - handleGridButtons(12); - } - - @FXML - public void gridButton13Action(ActionEvent event) { - handleGridButtons(13); - } - - @FXML - public void gridButton14Action(ActionEvent event) { - handleGridButtons(14); - } - - @FXML - public void gridButton15Action(ActionEvent event) { - handleGridButtons(15); - } - - @FXML - public void gridButton16Action(ActionEvent event) { - handleGridButtons(16); - } - - @FXML - public void gridButton17Action(ActionEvent event) { - handleGridButtons(17); - } - - @FXML - public void gridButton18Action(ActionEvent event) { - handleGridButtons(18); - } - - @FXML - public void gridButton19Action(ActionEvent event) { - handleGridButtons(19); - } - - @FXML - public void gridButton20Action(ActionEvent event) { - handleGridButtons(20); - } - - @FXML - public void gridButton21Action(ActionEvent event) { - handleGridButtons(21); - } - - @FXML - public void gridButton22Action(ActionEvent event) { - handleGridButtons(22); - } - - @FXML - public void gridButton23Action(ActionEvent event) { - handleGridButtons(23); - } - - @FXML - public void gridButton24Action(ActionEvent event) { - handleGridButtons(24); - } - - @FXML - public void gridButton25Action(ActionEvent event) { - handleGridButtons(25); - } - - @FXML - public void fillTablePositionen() { // Load positions into the TreeTableView - - rootPositionen.getChildren().remove(0, - rootPositionen.getChildren().size()); - - for (int i = 0; i < dbc.ladeTabellePositionen().size(); i++) { - - float fValue = Float - .valueOf(dbc.ladeTabellePositionen().get(i).getValue()); - - String strValue = String.format("%.02f", fValue); - - strValue.replace('.', ','); - - tableDataPositionen helpTableData = new tableDataPositionen( - dbc.ladeTabellePositionen().get(i).getID(), - dbc.ladeTabellePositionen().get(i).getName(), (strValue + "€"), - dbc.getCategoryNameFromPositionen(i + 1), - getColorNames(dbc.ladeTabellePositionen().get(i).getColor())); - rootPositionen.getChildren() - .add(new TreeItem(helpTableData)); - } - } - - public void initUI() { - System.out.println("initUI"); - for (int i = 0; i < 25; i++) { - getButtonByID(i).setVisible(false); - } - tftNewDBName.setText(xmlc.getDatabaseName()); - tftKat05.setDisable(true); - titlePaneStats.setVisible(false); - btnPrintBill.setDisable(true); - btnReprintJob.setDisable(true); - btnCancelJob.setDisable(true); - btnDeleteSelectedPosition.setDisable(true); - tapJobs.setDisable(true); - btnOpenFolder.setFocusTraversable(false); - switchSeparate.setFocusTraversable(false); - ueberbtn.setFocusTraversable(false); - isPrintBtnDisabled = true; - btnPrintBill - .setStyle("-fx-background-color: #2ac8fc; -fx-text-fill: black;"); - btnLock.setFocusTraversable(false); - initPositionen(); - initCurrentOrderTreeTableView(); - initJobTreeTableView(); - - } - - public int getSelectedCat() { - ObservableList cats = FXCollections.observableArrayList(); - - for (int i = 1; i < 5; i++) { - if (dbc.getName_Category(i).equals("Standard")) { - } else { - cats.add(dbc.getName_Category(i)); - } - } - - cats.add(dbc.getName_Category(5)); - - catChoise.setItems(cats); - catChoise.getSelectionModel().selectedIndexProperty() - .addListener(new ChangeListener() { - @Override - public void changed(ObservableValue ov, - Number value, Number new_value) { - try { - selectedCatName = catChoise.getItems().get((int) new_value) - .toString(); - } catch (Exception e) { - } - } - }); - - for (int i = 1; i < 6; i++) { - if (dbc.getName_Category(i).equals(selectedCatName)) { - return i; - } - } - return 5; - } - - public void fillPrinterSettings() { - System.out.println("Fill printer Settings"); - - ObservableList printers = FXCollections - .observableArrayList(pc.getAvailablePrinters()); - printers.add("Drucker auswählen"); - printerChoise.setItems(printers); - - boolean printerFound = false; - int index = 0; - for (String currentPrinter : printers) { - if (xmlc.getPrintername().equals(currentPrinter)) { - // Saved printer is available - printerFound = true; - // Select saved printer in UI - printerChoise.getSelectionModel().select(index); - } - index++; - } - - if (!printerFound) { - // Saved printer is not available - printerChoise.getSelectionModel().select(printers.size() - 1); - System.out.println("no printer found"); - } - - SpinnerValueFactory valueFactoryLines = // - new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 99, - xmlc.getLinebreak()); - - linesSpinner.setValueFactory(valueFactoryLines); - - SpinnerValueFactory valueFactoryHeader = // - new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 99, - xmlc.getOffsetHeader()); - - offsetHeaderSpinner.setValueFactory(valueFactoryHeader); - - SpinnerValueFactory valueFactoryFooter = // - new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 99, - xmlc.getOffsetFooter()); - - offsetFooterSpinner.setValueFactory(valueFactoryFooter); - - tftheader.setText(xmlc.getHeader()); - - tftfooter.setText(xmlc.getFooter()); - - switchSeparate.setSelected(xmlc.getCategorySplitted()); - - } - - public void fillCategory() { - tftKat01.setText(dbc.getName_Category(1)); - tftKat02.setText(dbc.getName_Category(2)); - tftKat03.setText(dbc.getName_Category(3)); - tftKat04.setText(dbc.getName_Category(4)); - tftKat05.setText(dbc.getName_Category(5)); - } - - private void initPositionen() { - entryTreeTable.setRoot(rootPositionen); - entryTreeTable.setShowRoot(false); - entryTreeTable.setEditable(false); - - columnPosnumber - .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - columnPositionsEdit - .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - columnPrize.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - columnCat.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - columnColor.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - - ObservableList color = FXCollections.observableArrayList("Rot", - "Orange", "Braun", "Weiß", "Gelb", "Gr\u00fcn", "Blau", "Indigo"); - colorChoise.setItems(color); - colorChoise.getSelectionModel().selectedIndexProperty() - .addListener(new ChangeListener() { - @Override - public void changed(ObservableValue ov, - Number value, Number new_value) { - selectedColorName = colorChoise.getItems() - .get((int) new_value).toString(); - } - }); - - columnPosnumber.setCellValueFactory( - cellData -> cellData.getValue().getValue().idProperty().asObject()); - - columnPositionsEdit.setCellValueFactory( - cellData -> cellData.getValue().getValue().nameProperty()); - - columnPrize.setCellValueFactory( - cellData -> cellData.getValue().getValue().valueProperty()); - - columnCat.setCellValueFactory( - cellData -> cellData.getValue().getValue().catProperty()); - - columnColor.setCellValueFactory( - cellData -> cellData.getValue().getValue().colorProperty()); - - entryTreeTable.getSelectionModel().selectedItemProperty() - .addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, Object oldVal, - Object newVal) { - int selected = entryTreeTable.getSelectionModel() - .getSelectedIndex(); // Get selected item - - try { - idPositionen = columnPosnumber.getCellData(selected); - tftNewPosition - .setText(dbc.getName_Positionen(idPositionen)); - tftNewValue.setText(dbc.getValue_Positionen(idPositionen)); - colorChoise.getSelectionModel().select( - getColorID(dbc.getColor_Positionen(idPositionen))); - - catChoise.getSelectionModel().select( - dbc.getCategoryNameFromPositionen(idPositionen)); - - } catch (Exception e) { - // TODO Auto-generated catch block - // e.printStackTrace(); - } - } - }); - - tftNewValue.textProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, - String oldValue, String newValue) { - if (!newValue.matches("\\d{0,4}([\\.]\\d{0,2})?")) { - tftNewValue.setText(oldValue); - } - } - }); - - final Tooltip tooltipName = new Tooltip(); - tooltipName.setText("Name der neuen Position"); - tooltipName.setStyle("-fx-font: normal bold 20 Cantarell; " - + "-fx-base: #AE3522; " + "-fx-text-fill: orange;"); - tftNewPosition.setTooltip(tooltipName); - - final Tooltip tooltipValue = new Tooltip(); - tooltipValue - .setText("Preis der neuen Position.\nPunkt als Trennzeichen!"); - tooltipValue.setStyle("-fx-font: normal bold 20 Cantarell; " - + "-fx-base: #AE3522; " + "-fx-text-fill: orange;"); - tftNewValue.setTooltip(tooltipValue); - labelNewValue.setTooltip(tooltipValue); - - } - - public void setMain(Main main, DBController dbc, XMLController xmlc, - PrinterController pc) { - this.main = main; - this.dbc = dbc; - this.xmlc = xmlc; - this.pc = pc; - } - - public void setDBLabel() throws Exception { - if (xmlc.loadSettings() == true) { - labelDBStatus.setText( - "Geladene Datenbank: " + xmlc.getDatabaseName() + ".db"); - btnCreateNewDatabase.setDisable(true); - tftNewDBName.setDisable(true); - labelDBName.setTooltip(new Tooltip( - "Um eine neue Datenbank zu erzeugen muss die vorherige config.xml und " - + xmlc.getDatabaseName() - + ".db gelöscht werden! Anwendung danach neustarten!")); - labelDBStatus.setTooltip(new Tooltip( - "Um eine neue Datenbank zu erzeugen muss die vorherige config.xml und " - + xmlc.getDatabaseName() - + ".db gelöscht werden! Anwendung danach neustarten!")); - } else { - labelDBStatus.setText("Keine Datenbank gefunden!"); - } - } - - private String getColorCodes(String pColorName) { - switch (pColorName) { - case "Rot": - return "#ad0000"; - case "Orange": - return "#FF4500"; - case "Braun": - return "#8B4513"; - case "Weiß": - return "#FAF0E6"; - case "Gelb": - return "#FFD700"; - case "Gr\u00fcn": - return "#556B2F"; - case "Blau": - return "#00BFFF"; - case "Indigo": - return "#4B0082"; - - default: - return "#FFFFFF"; - } - } - - private String getColorNames(String pColorCode) { - switch (pColorCode) { - case "#ad0000": - return "Rot"; - case "#FF4500": - return "Orange"; - case "#8B4513": - return "Braun"; - case "#FAF0E6": - return "Weiß"; - case "#FFD700": - return "Gelb"; - case "#556B2F": - return "Gr\u00fcn"; - case "#00BFFF": - return "Blau"; - case "#4B0082": - return "Indigo"; - - default: - return "Farbe"; - } - } - - private Integer getColorID(String pColorCode) { - switch (pColorCode) { - case "#ad0000": - return 0; - case "#FF4500": - return 1; - case "#8B4513": - return 2; - case "#FAF0E6": - return 3; - case "#FFD700": - return 4; - case "#556B2F": - return 5; - case "#00BFFF": - return 6; - case "#4B0082": - return 7; - - default: - return 0; - } - } - - public void blockUI(boolean pState) { - btnCalcStats.setDisable(pState); - btnClearEntry.setDisable(pState); - - if ((!isPrintBtnDisabled) && (!pState)) { - // Print was not disabled and will be enabled again - btnPrintBill.setDisable(pState); - btnDeleteSelectedPosition.setDisable(pState); - } - - if (pState) { - // Always disable - btnPrintBill.setDisable(pState); - btnDeleteSelectedPosition.setDisable(pState); - } - - btnReprintJob.setDisable(pState); - btnSaveEntry.setDisable(pState); - btnCancelJob.setDisable(pState); - - for (int i = 0; i < 25; i++) { - getButtonByID(i).setDisable(pState); - } - - tftNewPosition.setDisable(pState); - tftNewValue.setDisable(pState); - colorChoise.setDisable(pState); - catChoise.setDisable(pState); - - tableCurrentOrder.setDisable(pState); - jobsTreeTable.setDisable(pState); - entryTreeTable.setDisable(pState); - - labelAllPrize.setVisible(!pState); - labelJobCounter.setVisible(!pState); - - if (pState) { - titlePaneStats.setVisible(!pState); - } - - titledPaneEntry.setDisable(pState); - titlePaneCat.setDisable(pState); - titlePanePrint.setDisable(pState); - - } - - public void loadGridButtons() { - for (int i = 0; i < 25; i++) { - getButtonByID(i).setText(dbc.getName_Positionen(i + 1)); - getButtonByID(i).setFocusTraversable(false); - if ((getColorID(dbc.getColor_Positionen(i + 1)) == 0) - || (getColorID(dbc.getColor_Positionen(i + 1)) == 7)) { - getButtonByID(i).setStyle("-fx-background-color: " - + dbc.getColor_Positionen(i + 1) + "; -fx-text-fill: white;"); - } else { - getButtonByID(i).setStyle("-fx-background-color: " - + dbc.getColor_Positionen(i + 1) + "; -fx-text-fill: black;"); - } - } - for (int i = 0; i < 25; i++) { - if (dbc.getName_Positionen(i + 1).equals("Noch frei")) { - getButtonByID(i).setVisible(false); - } else { - getButtonByID(i).setVisible(true); - } - } - } - - public Button getButtonByID(int pID) { - switch (pID) { - case 0: - return gridButton01; - case 1: - return gridButton02; - case 2: - return gridButton03; - case 3: - return gridButton04; - case 4: - return gridButton05; - case 5: - return gridButton06; - case 6: - return gridButton07; - case 7: - return gridButton08; - case 8: - return gridButton09; - case 9: - return gridButton10; - case 10: - return gridButton11; - case 11: - return gridButton12; - case 12: - return gridButton13; - case 13: - return gridButton14; - case 14: - return gridButton15; - case 15: - return gridButton16; - case 16: - return gridButton17; - case 17: - return gridButton18; - case 18: - return gridButton19; - case 19: - return gridButton20; - case 20: - return gridButton21; - case 21: - return gridButton22; - case 22: - return gridButton23; - case 23: - return gridButton24; - case 24: - return gridButton25; - default: - return gridButton01; - } - } - - private void handleGridButtons(int pID) { - - if (!getButtonByID(pID - 1).isVisible()) { - // Button is not visible, no action - return; - } - - currentJob.addPosition(dbc.getName_Positionen(pID), - Float.parseFloat(dbc.getValue_Positionen(pID)), - dbc.getCategoryNameFromPositionen(pID)); - - btnPrintBill.setDisable(false); - isPrintBtnDisabled = false; - tapPosEdit.setDisable(true); - - rootCurrentJob.getChildren().remove(0, - rootCurrentJob.getChildren().size()); - - for (int i = 0; i < currentJob.getCurrentJobPositionen().size(); i++) { - rootCurrentJob.getChildren().add(new TreeItem( - currentJob.getCurrentJobPositionen().get(i))); - } - - setJobPrizeLabel(currentJob.getJobValue()); - - btnPrintBill.setFocusTraversable(false); - - } - - private void initCurrentOrderTreeTableView() { - columnQuantity - .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - columnPosition - .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - - tableCurrentOrder.setRoot(rootCurrentJob); - tableCurrentOrder.setShowRoot(false); - tableCurrentOrder.setEditable(false); - - columnQuantity.setCellValueFactory(cellData -> cellData.getValue() - .getValue().quantityProperty().asObject()); - - columnPosition.setCellValueFactory( - cellData -> cellData.getValue().getValue().positionProperty()); - - tableCurrentOrder.getSelectionModel().selectedItemProperty() - .addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, Object oldVal, - Object newVal) { - int selected = tableCurrentOrder.getSelectionModel() - .getSelectedIndex(); // Get selected item - - if (columnPosition.getCellData(selected) != null) { - currentOrderPosName = columnPosition.getCellData(selected); // Selected position - btnDeleteSelectedPosition.setDisable(false); - } - } - }); - - } - - private void initJobTreeTableView() { - columnJobNumber - .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - - columnTime.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - - columnPositions - .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - - columnState.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - - columnJobValue - .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); - - jobsTreeTable.setRoot(rootJobs); - jobsTreeTable.setShowRoot(false); - jobsTreeTable.setEditable(false); - - columnJobNumber.setCellValueFactory(cellData -> cellData.getValue() - .getValue().numberProperty().asObject()); - - columnTime.setCellValueFactory( - cellData -> cellData.getValue().getValue().timeProperty()); - - columnPositions.setCellValueFactory( - cellData -> cellData.getValue().getValue().positionProperty()); - - columnState.setCellValueFactory( - cellData -> cellData.getValue().getValue().statusProperty()); - - columnJobValue.setCellValueFactory( - cellData -> cellData.getValue().getValue().valueProperty()); - - jobsTreeTable.getSelectionModel().selectedItemProperty() - .addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, Object oldVal, - Object newVal) { - selectedJobId = jobsTreeTable.getSelectionModel() - .getSelectedIndex(); // Get selected item - - if (dbc.getState_Job(selectedJobId + 1).equals("storniert")) { - btnCancelJob.setDisable(true); - btnReprintJob.setDisable(true); - } else { - btnCancelJob.setDisable(false); - btnReprintJob.setDisable(false); - } - } - }); - } - - @FXML - public void fillTableJobs() { // Load jobs into the TreeTableView - rootJobs.getChildren().remove(0, rootJobs.getChildren().size()); - - for (int i = 0; i < dbc.loadTableJobs_Job().size(); i++) { - - float fValue = Float - .valueOf(dbc.loadTableJobs_Job().get(i).getValue()); - - String strValue = String.format("%.02f", fValue); - - strValue.replace('.', ','); - - strValue = (strValue + "€"); - - String strJobDescription = createJobDescription( - dbc.loadTableJobs_Job().get(i).getPosition(), - dbc.getQuantity_Job(dbc.loadTableJobs_Job().get(i).getNumber())); - - tableDataJob tmp = new tableDataJob( - dbc.loadTableJobs_Job().get(i).getNumber(), - dbc.loadTableJobs_Job().get(i).getTime(), strJobDescription, - dbc.loadTableJobs_Job().get(i).getStatus(), strValue); - - rootJobs.getChildren().add(new TreeItem(tmp)); - } - - if (!dbc.getJobCount().equals("0")) { - tapJobs.setDisable(false); - } - - } - - public void createNewJob() { - currentJob = new Job(dbc.getLatestJobNumber_Job() + 1); - labelJobCounter.setText("Auftragsnummer: " - + String.valueOf(dbc.getLatestJobNumber_Job() + 1)); - } - - private static String createJobDescription(String pNames, String pQuantities) { - String line = pQuantities; - int size = line.length() - line.replace(";", "").length() + 1; - - String[] namesArray = new String[size]; - String[] quantitiesArray = new String[size]; - - namesArray = pNames.split(";"); - quantitiesArray = pQuantities.split(";"); - - String tmp = quantitiesArray[0] + "x " + namesArray[0]; - - for (int i = 1; i < namesArray.length; i++) { - tmp = tmp + ", " + quantitiesArray[i] + "x " + namesArray[i]; - } - return tmp; - } - - private void setJobPrizeLabel(float pPrize) { - String str = String.format("%.02f", pPrize); - str.replace('.', ','); - labelAllPrize.setText(str + "€"); - } - - private void setJobStatLabel(int pCounter, float pAvgValue, float pAllValue) { - labelJobCount.setText("Anzahl Aufträge: " + pCounter); - - String str = String.format("%.02f", pAvgValue); - - str.replace('.', ','); - - labelAvgJob.setText("Durchschnittlicher Auftragswert: " + str + "€"); - - str = String.format("%.02f", pAllValue); - - str.replace('.', ','); - - labelAllValue.setText("Gesamt: " + str + "€"); - - titlePaneStats.setText("Statistik - " + timedate.getSystemTime() + " " - + timedate.getSystemDate()); - } - - public void updateTimeLabel() { - labelTime.setText("Uhrzeit: " + timedate.getSystemTime()); - - } - - public void blockUnlock() { - btnLock.setDisable(true); - } - - public int getActiveTab() { - - if (tapNewJob.isSelected()) { - return 0; - } - - if (tapJobs.isSelected()) { - return 1; - } - - if (tapPosEdit.isSelected()) { - return 2; - } - - if (tapSettings.isSelected()) { - return 3; - } - - return 404; - } - -} +package com.jFxKasse.controller; + +import javafx.fxml.FXML; +import javafx.geometry.Insets; +import javafx.scene.control.Button; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.TreeTableColumn; +import javafx.scene.control.TreeTableView; +import javafx.scene.control.TextField; +import javafx.scene.control.TreeItem; +import javafx.scene.control.TitledPane; +import javafx.scene.control.Tooltip; +import javafx.scene.control.ChoiceBox; + +import java.awt.Desktop; +import java.io.File; +import java.io.IOException; +import javafx.scene.control.CheckBox; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.event.ActionEvent; +import javafx.scene.control.Label; +import javafx.scene.control.Spinner; +import javafx.scene.control.SpinnerValueFactory; +import javafx.scene.control.Tab; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import javafx.util.Pair; +import com.jFxKasse.application.Main; +import com.jFxKasse.application.PrintJob; +import com.jFxKasse.application.TimeDate; +import com.jFxKasse.datatypes.Job; +import com.jFxKasse.datatypes.tableDataCurrentOrder; +import com.jFxKasse.datatypes.tableDataJob; +import com.jFxKasse.datatypes.tableDataPositionen; + +public class MainWindowController { + @FXML + private AnchorPane mainAnchorpane; + + @FXML + private AnchorPane paneDB; + + @FXML + private Tab tapNewJob; + + @FXML + private Tab tapJobs; + + @FXML + private Tab tapPosEdit; + + @FXML + private Tab tapSettings; + + @FXML + private TreeTableView tableCurrentOrder; + + @FXML + private TreeTableColumn columnQuantity; + + @FXML + private TreeTableColumn columnPosition; + + @FXML + private TreeTableColumn idSpalte01 = new TreeTableColumn<>( + "tableCurrentOrder"); + + @FXML + private TreeTableView jobsTreeTable; + + @FXML + private TreeTableColumn columnJobValue; + + @FXML + private TreeTableColumn columnState; + + @FXML + private TreeTableColumn columnPositions; + + @FXML + private TreeTableColumn columnTime; + + @FXML + private TreeTableColumn columnJobNumber; + + @FXML + private TreeTableColumn idSpalte02 = new TreeTableColumn<>( + "jobsTreeTable"); + + @FXML + private TreeTableView entryTreeTable; + + @FXML + private TreeTableColumn columnColor; + + @FXML + private TreeTableColumn columnCat; + + @FXML + private TreeTableColumn columnPrize; + + @FXML + private TreeTableColumn columnPositionsEdit; + + @FXML + private TreeTableColumn columnPosnumber; + + @FXML + private ChoiceBox colorChoise; + + @FXML + private ChoiceBox catChoise; + + @FXML + private ChoiceBox printerChoise; + + @FXML + private Spinner linesSpinner; + + @FXML + private Spinner offsetHeaderSpinner; + + @FXML + private Spinner offsetFooterSpinner; + + @FXML + private Button ueberbtn; + + @FXML + private Button gridButton01; + + @FXML + private Button gridButton02; + + @FXML + private Button gridButton03; + + @FXML + private Button gridButton04; + + @FXML + private Button gridButton05; + + @FXML + private Button gridButton06; + + @FXML + private Button gridButton07; + + @FXML + private Button gridButton08; + + @FXML + private Button gridButton09; + + @FXML + private Button gridButton10; + + @FXML + private Button gridButton11; + + @FXML + private Button gridButton12; + + @FXML + private Button gridButton13; + + @FXML + private Button gridButton14; + + @FXML + private Button gridButton15; + + @FXML + private Button gridButton16; + + @FXML + private Button gridButton17; + + @FXML + private Button gridButton18; + + @FXML + private Button gridButton19; + + @FXML + private Button gridButton20; + + @FXML + private Button gridButton21; + + @FXML + private Button gridButton22; + + @FXML + private Button gridButton23; + + @FXML + private Button gridButton24; + + @FXML + private Button gridButton25; + + @FXML + public Button btnSavePrinter; + + @FXML + public Button btnDeleteSelectedPosition; + + @FXML + public Button btnPrintBill; + + @FXML + public Button btnLock; + + @FXML + public Button btnReprintJob; + + @FXML + public Button btnCancelJob; + + @FXML + public Button btnCalcStats; + + @FXML + public Button btnSaveEntry; + + @FXML + public Button btnClearEntry; + + @FXML + public Button btnCreateNewDatabase; + + @FXML + private Button btnOpenFolder; + + @FXML + private Label labelCat01; + + @FXML + private Label labelCat02; + + @FXML + private Label labelCat05; + + @FXML + private Label labelCat04; + + @FXML + private Label labelCat03; + + @FXML + private TextField tftfooter; + + @FXML + private TextField tftheader; + + @FXML + private TextField tftKat01; + + @FXML + private TextField tftKat02; + + @FXML + private TextField tftKat03; + + @FXML + private TextField tftKat04; + + @FXML + private TextField tftKat05; + + @FXML + public Button btnSaveCat; + + @FXML + private Label labelAllPrize; + + @FXML + private Label labelJobCounter; + + @FXML + private Label labelTime; + + @FXML + private Label labelJobCount; + + @FXML + private Label labelAvgJob; + + @FXML + private Label labelAllValue; + + @FXML + private Label labelSelectCat; + + @FXML + private Label labelNewPosition; + + @FXML + private Label labelNewValue; + + @FXML + private Label labelNewColor; + + @FXML + private Label labelDBStatus; + + @FXML + private Label labelDBName; + + @FXML + private Label labelFirstStart; + + @FXML + private TitledPane titlePaneStats; + + @FXML + private TitledPane titlePaneCat; + + @FXML + private TitledPane titledPaneEntry; + + @FXML + private TitledPane titlePanePrint; + + @FXML + private TextField tftNewPosition; + + @FXML + private TextField tftNewValue; + + @FXML + private TextField tftNewDBName; + + @FXML + private CheckBox switchSeparate; + + @SuppressWarnings("unused") + private Main main; + + private DBController dbc; + + private XMLController xmlc; + + private PrinterController pc; + + private TimeDate timedate = new TimeDate(); + + private PrintJob pj = new PrintJob(); + + private int idPositionen = 0; + + private String selectedColorName; + + private String selectedCatName; + + private boolean lockState = false; + + private boolean isPrintBtnDisabled = true; + + private Job currentJob = null; + + private String currentOrderPosName; + + private int selectedJobId; + + @FXML + TreeItem rootCurrentJob = new TreeItem<>( + new tableDataCurrentOrder("0", 0)); + + @FXML + TreeItem rootJobs = new TreeItem<>( + new tableDataJob(0, "0", "0", "0", "0")); + + @FXML + TreeItem rootPositionen = new TreeItem<>( + new tableDataPositionen(0, "0", "0", "0", "0")); + + @FXML + public void ueberbtnAction(ActionEvent event) { // Opens the 'About' dialog + + // creates a dialog + Dialog> dialog = new Dialog<>(); + dialog.setTitle("Über jFxKasse"); + dialog.setHeaderText("Informationen und Lizenzen - Version 0.3.2"); + + dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK); + + GridPane grid = new GridPane(); + grid.setHgap(10); + grid.setVgap(10); + grid.setPadding(new Insets(20, 150, 10, 10)); + + grid.add(new Label( + "Einfaches Kassensystem für kleine bis mittel große Veranstaltungen mit Bon-Drucker\n" + + "\nUnter Lizenz GPL-3.0 abrufbar auf https://git.mosad.xyz/localhorst/jFxKasse\n" + + "\nDatenbank: sqlite.org - Public Domain" + + " \nUI Design01: eclipse.org/efxclipse/install.html - Eclipse Public License 1.0" + + " \nUI Design02: http://www.jfoenix.com/ - Apache License 2.0" + + " \nUI - Datenbank Integration: basierend auf Project-HomeFlix - github.com/Seil0/Project-HomeFlix - GPLv3 \n" + + " \nMaintainer: mail@hendrikschutter.com" + + " \n(c) 2026 Hendrik Schutter"), + 0, 0); + + dialog.getDialogPane().setContent(grid); + dialog.setResizable(true); + dialog.showAndWait(); + } + + @FXML + public void btnOpenFolderAction(ActionEvent event) throws IOException { + + if (System.getProperty("os.name").contains("Windows")) { + System.out.println("FCK Windows"); + File file = new File(Main.filepath); + Desktop desktop = Desktop.getDesktop(); + desktop.open(file); + } else { + Runtime.getRuntime().exec("xdg-open " + Main.filepath); + } + } + + @FXML + public void btnCreateNewDatabaseAction(ActionEvent event) throws Exception { + + if (!(tftNewDBName.getText().equals(""))) { + + xmlc.setDatabaseName(tftNewDBName.getText()); + + dbc.setDbname(xmlc.getDatabaseName()); + dbc.connectDatabase(); // Establish DB connection + dbc.createTablePositionen(); // Create new table + dbc.erstelleTabelleJobs(); // Create new table + dbc.createTableCategory(); // Create new table + try { + // saveSettings(getDatabaseName()); + xmlc.saveSettings(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + setDBLabel(); // Set new database labels + blockUI(false); // Unlock UI elements that need DB + if (labelFirstStart != null) { + labelFirstStart.setVisible(false); + } + fillTablePositionen(); // Fill TreeTable 'Positions' + fillCategory(); + fillPrinterSettings(); + initUI(); // Initialize the UI elements + getSelectedCat(); + createNewJob(); + + btnLock.setDisable(false); + } + } + + @FXML + public void btnSaveEntryAction(ActionEvent event) { + dbc.setName_Positionen(idPositionen, tftNewPosition.getText()); + dbc.setValue_Positionen(idPositionen, tftNewValue.getText()); + dbc.setColor_Positionen(idPositionen, getColorCodes(selectedColorName)); + + dbc.setCat_Positionen(idPositionen, getSelectedCat()); + + fillTablePositionen(); // Fill TreeTable 'Positions' + loadGridButtons(); + + } + + @FXML + public void btnClearEntryAction(ActionEvent event) { + // Set default values + dbc.setName_Positionen(idPositionen, "Noch frei"); + dbc.setValue_Positionen(idPositionen, "0.00"); + dbc.setColor_Positionen(idPositionen, "#FAF0E6"); + dbc.setCat_Positionen(idPositionen, 6); + + fillTablePositionen(); // Fill TreeTable 'Positions' + } + + @FXML + public void btnCalcStatsAction(ActionEvent event) { + int allActiveJobs = Integer.valueOf(dbc.getJobCount()); + + if (dbc.getAllJobValue_Job() != null) { + + // Summed up values of all active jobs + float allValue = Float.valueOf(dbc.getAllJobValue_Job()); + + // Count of all active jobs + + float avgJobValue = ((float) allValue / allActiveJobs); + + setJobStatLabel(allActiveJobs, avgJobValue, allValue); + } else { + setJobStatLabel(allActiveJobs, 0, 0); + } + titlePaneStats.setVisible(true); + } + + @FXML + public void btnSavePrinterAction(ActionEvent event) { + System.out.println("btnSavePrinterAction"); + + xmlc.setPrintername( + printerChoise.getSelectionModel().getSelectedItem().toString()); + xmlc.setLinebreak(linesSpinner.getValue()); + xmlc.setOffsetHeader(offsetHeaderSpinner.getValue()); + xmlc.setOffsetFooter(offsetFooterSpinner.getValue()); + xmlc.setHeader(tftheader.getText()); + xmlc.setFooter(tftfooter.getText()); + xmlc.setCategorySplitted(switchSeparate.isSelected()); + + try { + xmlc.saveSettings(); + } catch (Exception e) { + // TODO Auto-generated catch block + // e.printStackTrace(); + } + fillPrinterSettings(); + } + + @FXML + public void btnCancelJobAction(ActionEvent event) { + dbc.setStatus_Jobs(selectedJobId + 1, "storniert"); + fillTableJobs(); + btnCancelJob.setDisable(true); + btnReprintJob.setDisable(true); + } + + @FXML + public void btnLockAction(ActionEvent event) { + lockState = !lockState; + blockUI(lockState); + + if (lockState) { + btnLock.setText("Kasse entsperren"); + } else { + btnLock.setText("Kasse sperren"); + } + } + + @FXML + public void btnSaveCatAction(ActionEvent event) { + dbc.setName_Category(1, tftKat01.getText()); + dbc.setName_Category(2, tftKat02.getText()); + dbc.setName_Category(3, tftKat03.getText()); + dbc.setName_Category(4, tftKat04.getText()); + dbc.setName_Category(5, tftKat05.getText()); + + fillCategory(); + fillTablePositionen(); + getSelectedCat(); + } + + @FXML + public void btnDeleteSelectedPositionAction(ActionEvent event) { + currentJob.deletePosName(currentOrderPosName); + rootCurrentJob.getChildren().remove(0, + rootCurrentJob.getChildren().size()); + + for (int i = 0; i < currentJob.getCurrentJobPositionen().size(); i++) { + rootCurrentJob.getChildren().add(new TreeItem( + currentJob.getCurrentJobPositionen().get(i))); + + } + setJobPrizeLabel(currentJob.getJobValue()); + + if (rootCurrentJob.getChildren().size() == 0) { + btnPrintBill.setDisable(true); + isPrintBtnDisabled = true; + tapPosEdit.setDisable(false); + btnDeleteSelectedPosition.setDisable(true); + } + + if (!currentJob.existsPosName(currentOrderPosName)) { + btnDeleteSelectedPosition.setDisable(true); + } + } + + @FXML + public void btnPrintBillAction(ActionEvent event) { + btnPrintBill.setDisable(true); + tapPosEdit.setDisable(false); + btnDeleteSelectedPosition.setDisable(true); + isPrintBtnDisabled = true; + tapJobs.setDisable(false); + + setJobPrizeLabel(0); + + currentJob.setJobtime( + timedate.getSystemTime() + " " + timedate.getSystemDate()); + + rootCurrentJob.getChildren().remove(0, + rootCurrentJob.getChildren().size()); + + dbc.fillJobs_Jobs(currentJob.getJobnumber(), currentJob.getJobtime(), + currentJob.createPosQuantityDBString(), + currentJob.createPosNameDBString(), + currentJob.createPosValueDBString(), + currentJob.createPosCatDBString(), "verbucht", + String.valueOf(currentJob.getJobValue())); + + pj.printJob(currentJob.getJobnumber(), xmlc, dbc, pc); + + fillTableJobs(); + + currentJob = null; + + createNewJob(); + + } + + @FXML + public void btnReprintJobAction(ActionEvent event) { + System.out.println("reprint job"); + pj.printJob((selectedJobId + 1), xmlc, dbc, pc); + } + + @FXML + public void gridButton01Action(ActionEvent event) { + handleGridButtons(1); + } + + @FXML + public void gridButton02Action(ActionEvent event) { + handleGridButtons(2); + } + + @FXML + public void gridButton03Action(ActionEvent event) { + handleGridButtons(3); + } + + @FXML + public void gridButton04Action(ActionEvent event) { + handleGridButtons(4); + } + + @FXML + public void gridButton05Action(ActionEvent event) { + handleGridButtons(5); + } + + @FXML + public void gridButton06Action(ActionEvent event) { + handleGridButtons(6); + } + + @FXML + public void gridButton07Action(ActionEvent event) { + handleGridButtons(7); + } + + @FXML + public void gridButton08Action(ActionEvent event) { + handleGridButtons(8); + } + + @FXML + public void gridButton09Action(ActionEvent event) { + handleGridButtons(9); + } + + @FXML + public void gridButton10Action(ActionEvent event) { + handleGridButtons(10); + } + + @FXML + public void gridButton11Action(ActionEvent event) { + handleGridButtons(11); + } + + @FXML + public void gridButton12Action(ActionEvent event) { + handleGridButtons(12); + } + + @FXML + public void gridButton13Action(ActionEvent event) { + handleGridButtons(13); + } + + @FXML + public void gridButton14Action(ActionEvent event) { + handleGridButtons(14); + } + + @FXML + public void gridButton15Action(ActionEvent event) { + handleGridButtons(15); + } + + @FXML + public void gridButton16Action(ActionEvent event) { + handleGridButtons(16); + } + + @FXML + public void gridButton17Action(ActionEvent event) { + handleGridButtons(17); + } + + @FXML + public void gridButton18Action(ActionEvent event) { + handleGridButtons(18); + } + + @FXML + public void gridButton19Action(ActionEvent event) { + handleGridButtons(19); + } + + @FXML + public void gridButton20Action(ActionEvent event) { + handleGridButtons(20); + } + + @FXML + public void gridButton21Action(ActionEvent event) { + handleGridButtons(21); + } + + @FXML + public void gridButton22Action(ActionEvent event) { + handleGridButtons(22); + } + + @FXML + public void gridButton23Action(ActionEvent event) { + handleGridButtons(23); + } + + @FXML + public void gridButton24Action(ActionEvent event) { + handleGridButtons(24); + } + + @FXML + public void gridButton25Action(ActionEvent event) { + handleGridButtons(25); + } + + @FXML + public void fillTablePositionen() { // Load positions into the TreeTableView + + rootPositionen.getChildren().remove(0, + rootPositionen.getChildren().size()); + + for (int i = 0; i < dbc.ladeTabellePositionen().size(); i++) { + + float fValue = Float + .valueOf(dbc.ladeTabellePositionen().get(i).getValue()); + + String strValue = String.format("%.02f", fValue); + + strValue.replace('.', ','); + + tableDataPositionen helpTableData = new tableDataPositionen( + dbc.ladeTabellePositionen().get(i).getID(), + dbc.ladeTabellePositionen().get(i).getName(), (strValue + "€"), + dbc.getCategoryNameFromPositionen(i + 1), + getColorNames(dbc.ladeTabellePositionen().get(i).getColor())); + rootPositionen.getChildren() + .add(new TreeItem(helpTableData)); + } + } + + public void initUI() { + System.out.println("initUI"); + for (int i = 0; i < 25; i++) { + getButtonByID(i).setVisible(false); + } + tftNewDBName.setText(xmlc.getDatabaseName()); + tftKat05.setDisable(true); + titlePaneStats.setVisible(false); + btnPrintBill.setDisable(true); + btnReprintJob.setDisable(true); + btnCancelJob.setDisable(true); + btnDeleteSelectedPosition.setDisable(true); + tapJobs.setDisable(true); + btnOpenFolder.setFocusTraversable(false); + ueberbtn.setFocusTraversable(false); + isPrintBtnDisabled = true; + btnPrintBill + .setStyle("-fx-background-color: #2ac8fc; -fx-text-fill: black;"); + btnLock.setFocusTraversable(false); + initPositionen(); + initCurrentOrderTreeTableView(); + initJobTreeTableView(); + + } + + public int getSelectedCat() { + ObservableList cats = FXCollections.observableArrayList(); + + for (int i = 1; i < 5; i++) { + if (dbc.getName_Category(i).equals("Standard")) { + } else { + cats.add(dbc.getName_Category(i)); + } + } + + cats.add(dbc.getName_Category(5)); + + catChoise.setItems(cats); + catChoise.getSelectionModel().selectedIndexProperty() + .addListener(new ChangeListener() { + @Override + public void changed(ObservableValue ov, + Number value, Number new_value) { + try { + selectedCatName = catChoise.getItems().get((int) new_value) + .toString(); + } catch (Exception e) { + } + } + }); + + for (int i = 1; i < 6; i++) { + if (dbc.getName_Category(i).equals(selectedCatName)) { + return i; + } + } + return 5; + } + + public void fillPrinterSettings() { + System.out.println("Fill printer Settings"); + + ObservableList printers = FXCollections + .observableArrayList(pc.getAvailablePrinters()); + printers.add("Drucker auswählen"); + printerChoise.setItems(printers); + + boolean printerFound = false; + int index = 0; + for (String currentPrinter : printers) { + if (xmlc.getPrintername().equals(currentPrinter)) { + // Saved printer is available + printerFound = true; + // Select saved printer in UI + printerChoise.getSelectionModel().select(index); + } + index++; + } + + if (!printerFound) { + // Saved printer is not available + printerChoise.getSelectionModel().select(printers.size() - 1); + System.out.println("no printer found"); + } + + SpinnerValueFactory valueFactoryLines = // + new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 99, + xmlc.getLinebreak()); + + linesSpinner.setValueFactory(valueFactoryLines); + + SpinnerValueFactory valueFactoryHeader = // + new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 99, + xmlc.getOffsetHeader()); + + offsetHeaderSpinner.setValueFactory(valueFactoryHeader); + + SpinnerValueFactory valueFactoryFooter = // + new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 99, + xmlc.getOffsetFooter()); + + offsetFooterSpinner.setValueFactory(valueFactoryFooter); + + tftheader.setText(xmlc.getHeader()); + + tftfooter.setText(xmlc.getFooter()); + + switchSeparate.setSelected(xmlc.getCategorySplitted()); + + } + + public void fillCategory() { + tftKat01.setText(dbc.getName_Category(1)); + tftKat02.setText(dbc.getName_Category(2)); + tftKat03.setText(dbc.getName_Category(3)); + tftKat04.setText(dbc.getName_Category(4)); + tftKat05.setText(dbc.getName_Category(5)); + } + + private void initPositionen() { + entryTreeTable.setRoot(rootPositionen); + entryTreeTable.setShowRoot(false); + entryTreeTable.setEditable(false); + + columnPosnumber + .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + columnPositionsEdit + .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + columnPrize.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + columnCat.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + columnColor.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + + ObservableList color = FXCollections.observableArrayList("Rot", + "Orange", "Braun", "Weiß", "Gelb", "Gr\u00fcn", "Blau", "Indigo"); + colorChoise.setItems(color); + colorChoise.getSelectionModel().selectedIndexProperty() + .addListener(new ChangeListener() { + @Override + public void changed(ObservableValue ov, + Number value, Number new_value) { + selectedColorName = colorChoise.getItems() + .get((int) new_value).toString(); + } + }); + + columnPosnumber.setCellValueFactory( + cellData -> cellData.getValue().getValue().idProperty().asObject()); + + columnPositionsEdit.setCellValueFactory( + cellData -> cellData.getValue().getValue().nameProperty()); + + columnPrize.setCellValueFactory( + cellData -> cellData.getValue().getValue().valueProperty()); + + columnCat.setCellValueFactory( + cellData -> cellData.getValue().getValue().catProperty()); + + columnColor.setCellValueFactory( + cellData -> cellData.getValue().getValue().colorProperty()); + + entryTreeTable.getSelectionModel().selectedItemProperty() + .addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Object oldVal, + Object newVal) { + int selected = entryTreeTable.getSelectionModel() + .getSelectedIndex(); // Get selected item + + try { + idPositionen = columnPosnumber.getCellData(selected); + tftNewPosition + .setText(dbc.getName_Positionen(idPositionen)); + tftNewValue.setText(dbc.getValue_Positionen(idPositionen)); + colorChoise.getSelectionModel().select( + getColorID(dbc.getColor_Positionen(idPositionen))); + + catChoise.getSelectionModel().select( + dbc.getCategoryNameFromPositionen(idPositionen)); + + } catch (Exception e) { + // TODO Auto-generated catch block + // e.printStackTrace(); + } + } + }); + + tftNewValue.textProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, + String oldValue, String newValue) { + if (!newValue.matches("\\d{0,4}([\\.]\\d{0,2})?")) { + tftNewValue.setText(oldValue); + } + } + }); + + final Tooltip tooltipName = new Tooltip(); + tooltipName.setText("Name der neuen Position"); + tooltipName.setStyle("-fx-font: normal bold 20 Cantarell; " + + "-fx-base: #AE3522; " + "-fx-text-fill: orange;"); + tftNewPosition.setTooltip(tooltipName); + + final Tooltip tooltipValue = new Tooltip(); + tooltipValue + .setText("Preis der neuen Position.\nPunkt als Trennzeichen!"); + tooltipValue.setStyle("-fx-font: normal bold 20 Cantarell; " + + "-fx-base: #AE3522; " + "-fx-text-fill: orange;"); + tftNewValue.setTooltip(tooltipValue); + labelNewValue.setTooltip(tooltipValue); + + } + + public void setMain(Main main, DBController dbc, XMLController xmlc, + PrinterController pc) { + this.main = main; + this.dbc = dbc; + this.xmlc = xmlc; + this.pc = pc; + } + + public void setDBLabel() throws Exception { + if (xmlc.loadSettings() == true) { + labelDBStatus.setText( + "Geladene Datenbank: " + xmlc.getDatabaseName() + ".db"); + btnCreateNewDatabase.setDisable(true); + tftNewDBName.setDisable(true); + labelDBName.setTooltip(new Tooltip( + "Um eine neue Datenbank zu erzeugen muss die vorherige config.xml und " + + xmlc.getDatabaseName() + + ".db gelöscht werden! Anwendung danach neustarten!")); + labelDBStatus.setTooltip(new Tooltip( + "Um eine neue Datenbank zu erzeugen muss die vorherige config.xml und " + + xmlc.getDatabaseName() + + ".db gelöscht werden! Anwendung danach neustarten!")); + } else { + labelDBStatus.setText("Keine Datenbank gefunden!"); + } + } + + private String getColorCodes(String pColorName) { + switch (pColorName) { + case "Rot": + return "#ad0000"; + case "Orange": + return "#FF4500"; + case "Braun": + return "#8B4513"; + case "Weiß": + return "#FAF0E6"; + case "Gelb": + return "#FFD700"; + case "Gr\u00fcn": + return "#556B2F"; + case "Blau": + return "#00BFFF"; + case "Indigo": + return "#4B0082"; + + default: + return "#FFFFFF"; + } + } + + private String getColorNames(String pColorCode) { + switch (pColorCode) { + case "#ad0000": + return "Rot"; + case "#FF4500": + return "Orange"; + case "#8B4513": + return "Braun"; + case "#FAF0E6": + return "Weiß"; + case "#FFD700": + return "Gelb"; + case "#556B2F": + return "Gr\u00fcn"; + case "#00BFFF": + return "Blau"; + case "#4B0082": + return "Indigo"; + + default: + return "Farbe"; + } + } + + private Integer getColorID(String pColorCode) { + switch (pColorCode) { + case "#ad0000": + return 0; + case "#FF4500": + return 1; + case "#8B4513": + return 2; + case "#FAF0E6": + return 3; + case "#FFD700": + return 4; + case "#556B2F": + return 5; + case "#00BFFF": + return 6; + case "#4B0082": + return 7; + + default: + return 0; + } + } + + public void blockUI(boolean pState) { + btnCalcStats.setDisable(pState); + btnClearEntry.setDisable(pState); + + if ((!isPrintBtnDisabled) && (!pState)) { + // Print was not disabled and will be enabled again + btnPrintBill.setDisable(pState); + btnDeleteSelectedPosition.setDisable(pState); + } + + if (pState) { + // Always disable + btnPrintBill.setDisable(pState); + btnDeleteSelectedPosition.setDisable(pState); + } + + btnReprintJob.setDisable(pState); + btnSaveEntry.setDisable(pState); + btnCancelJob.setDisable(pState); + + for (int i = 0; i < 25; i++) { + getButtonByID(i).setDisable(pState); + } + + tftNewPosition.setDisable(pState); + tftNewValue.setDisable(pState); + colorChoise.setDisable(pState); + catChoise.setDisable(pState); + + tableCurrentOrder.setDisable(pState); + jobsTreeTable.setDisable(pState); + entryTreeTable.setDisable(pState); + + labelAllPrize.setVisible(!pState); + labelJobCounter.setVisible(!pState); + + if (pState) { + titlePaneStats.setVisible(!pState); + } + + titledPaneEntry.setDisable(pState); + titlePaneCat.setDisable(pState); + titlePanePrint.setDisable(pState); + + } + + public void loadGridButtons() { + for (int i = 0; i < 25; i++) { + getButtonByID(i).setText(dbc.getName_Positionen(i + 1)); + getButtonByID(i).setFocusTraversable(false); + if ((getColorID(dbc.getColor_Positionen(i + 1)) == 0) + || (getColorID(dbc.getColor_Positionen(i + 1)) == 7)) { + getButtonByID(i).setStyle("-fx-background-color: " + + dbc.getColor_Positionen(i + 1) + "; -fx-text-fill: white;"); + } else { + getButtonByID(i).setStyle("-fx-background-color: " + + dbc.getColor_Positionen(i + 1) + "; -fx-text-fill: black;"); + } + } + for (int i = 0; i < 25; i++) { + if (dbc.getName_Positionen(i + 1).equals("Noch frei")) { + getButtonByID(i).setVisible(false); + } else { + getButtonByID(i).setVisible(true); + } + } + } + + public Button getButtonByID(int pID) { + switch (pID) { + case 0: + return gridButton01; + case 1: + return gridButton02; + case 2: + return gridButton03; + case 3: + return gridButton04; + case 4: + return gridButton05; + case 5: + return gridButton06; + case 6: + return gridButton07; + case 7: + return gridButton08; + case 8: + return gridButton09; + case 9: + return gridButton10; + case 10: + return gridButton11; + case 11: + return gridButton12; + case 12: + return gridButton13; + case 13: + return gridButton14; + case 14: + return gridButton15; + case 15: + return gridButton16; + case 16: + return gridButton17; + case 17: + return gridButton18; + case 18: + return gridButton19; + case 19: + return gridButton20; + case 20: + return gridButton21; + case 21: + return gridButton22; + case 22: + return gridButton23; + case 23: + return gridButton24; + case 24: + return gridButton25; + default: + return gridButton01; + } + } + + private void handleGridButtons(int pID) { + + if (!getButtonByID(pID - 1).isVisible()) { + // Button is not visible, no action + return; + } + + currentJob.addPosition(dbc.getName_Positionen(pID), + Float.parseFloat(dbc.getValue_Positionen(pID)), + dbc.getCategoryNameFromPositionen(pID)); + + btnPrintBill.setDisable(false); + isPrintBtnDisabled = false; + tapPosEdit.setDisable(true); + + rootCurrentJob.getChildren().remove(0, + rootCurrentJob.getChildren().size()); + + for (int i = 0; i < currentJob.getCurrentJobPositionen().size(); i++) { + rootCurrentJob.getChildren().add(new TreeItem( + currentJob.getCurrentJobPositionen().get(i))); + } + + setJobPrizeLabel(currentJob.getJobValue()); + + btnPrintBill.setFocusTraversable(false); + + } + + private void initCurrentOrderTreeTableView() { + columnQuantity + .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + columnPosition + .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + + tableCurrentOrder.setRoot(rootCurrentJob); + tableCurrentOrder.setShowRoot(false); + tableCurrentOrder.setEditable(false); + + columnQuantity.setCellValueFactory(cellData -> cellData.getValue() + .getValue().quantityProperty().asObject()); + + columnPosition.setCellValueFactory( + cellData -> cellData.getValue().getValue().positionProperty()); + + tableCurrentOrder.getSelectionModel().selectedItemProperty() + .addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Object oldVal, + Object newVal) { + int selected = tableCurrentOrder.getSelectionModel() + .getSelectedIndex(); // Get selected item + + if (columnPosition.getCellData(selected) != null) { + currentOrderPosName = columnPosition.getCellData(selected); // Selected position + btnDeleteSelectedPosition.setDisable(false); + } + } + }); + + } + + private void initJobTreeTableView() { + columnJobNumber + .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + + columnTime.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + + columnPositions + .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + + columnState.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + + columnJobValue + .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); + + jobsTreeTable.setRoot(rootJobs); + jobsTreeTable.setShowRoot(false); + jobsTreeTable.setEditable(false); + + columnJobNumber.setCellValueFactory(cellData -> cellData.getValue() + .getValue().numberProperty().asObject()); + + columnTime.setCellValueFactory( + cellData -> cellData.getValue().getValue().timeProperty()); + + columnPositions.setCellValueFactory( + cellData -> cellData.getValue().getValue().positionProperty()); + + columnState.setCellValueFactory( + cellData -> cellData.getValue().getValue().statusProperty()); + + columnJobValue.setCellValueFactory( + cellData -> cellData.getValue().getValue().valueProperty()); + + jobsTreeTable.getSelectionModel().selectedItemProperty() + .addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, Object oldVal, + Object newVal) { + selectedJobId = jobsTreeTable.getSelectionModel() + .getSelectedIndex(); // Get selected item + + if (dbc.getState_Job(selectedJobId + 1).equals("storniert")) { + btnCancelJob.setDisable(true); + btnReprintJob.setDisable(true); + } else { + btnCancelJob.setDisable(false); + btnReprintJob.setDisable(false); + } + } + }); + } + + @FXML + public void fillTableJobs() { // Load jobs into the TreeTableView + rootJobs.getChildren().remove(0, rootJobs.getChildren().size()); + + for (int i = 0; i < dbc.loadTableJobs_Job().size(); i++) { + + float fValue = Float + .valueOf(dbc.loadTableJobs_Job().get(i).getValue()); + + String strValue = String.format("%.02f", fValue); + + strValue.replace('.', ','); + + strValue = (strValue + "€"); + + String strJobDescription = createJobDescription( + dbc.loadTableJobs_Job().get(i).getPosition(), + dbc.getQuantity_Job(dbc.loadTableJobs_Job().get(i).getNumber())); + + tableDataJob tmp = new tableDataJob( + dbc.loadTableJobs_Job().get(i).getNumber(), + dbc.loadTableJobs_Job().get(i).getTime(), strJobDescription, + dbc.loadTableJobs_Job().get(i).getStatus(), strValue); + + rootJobs.getChildren().add(new TreeItem(tmp)); + } + + if (!dbc.getJobCount().equals("0")) { + tapJobs.setDisable(false); + } + + } + + public void createNewJob() { + currentJob = new Job(dbc.getLatestJobNumber_Job() + 1); + labelJobCounter.setText("Auftragsnummer: " + + String.valueOf(dbc.getLatestJobNumber_Job() + 1)); + } + + private static String createJobDescription(String pNames, String pQuantities) { + String line = pQuantities; + int size = line.length() - line.replace(";", "").length() + 1; + + String[] namesArray = new String[size]; + String[] quantitiesArray = new String[size]; + + namesArray = pNames.split(";"); + quantitiesArray = pQuantities.split(";"); + + String tmp = quantitiesArray[0] + "x " + namesArray[0]; + + for (int i = 1; i < namesArray.length; i++) { + tmp = tmp + ", " + quantitiesArray[i] + "x " + namesArray[i]; + } + return tmp; + } + + private void setJobPrizeLabel(float pPrize) { + String str = String.format("%.02f", pPrize); + str.replace('.', ','); + labelAllPrize.setText(str + "€"); + } + + private void setJobStatLabel(int pCounter, float pAvgValue, float pAllValue) { + labelJobCount.setText("Anzahl Aufträge: " + pCounter); + + String str = String.format("%.02f", pAvgValue); + + str.replace('.', ','); + + labelAvgJob.setText("Durchschnittlicher Auftragswert: " + str + "€"); + + str = String.format("%.02f", pAllValue); + + str.replace('.', ','); + + labelAllValue.setText("Gesamt: " + str + "€"); + + titlePaneStats.setText("Statistik - " + timedate.getSystemTime() + " " + + timedate.getSystemDate()); + } + + public void updateTimeLabel() { + labelTime.setText("Uhrzeit: " + timedate.getSystemTime()); + + } + + public void blockUnlock() { + btnLock.setDisable(true); + // Show a clear hint to the user that they need to create a database first + if (labelFirstStart != null) { + labelFirstStart.setVisible(true); + } + } + + public int getActiveTab() { + + if (tapNewJob.isSelected()) { + return 0; + } + + if (tapJobs.isSelected()) { + return 1; + } + + if (tapPosEdit.isSelected()) { + return 2; + } + + if (tapSettings.isSelected()) { + return 3; + } + + return 404; + } + +} diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml index 17f48aa..fb54935 100644 --- a/src/main/resources/fxml/MainWindow.fxml +++ b/src/main/resources/fxml/MainWindow.fxml @@ -1,8 +1,8 @@ + + + - - - @@ -40,10 +40,10 @@ - + - + - + - - + + - - + + - - + + - - + + - + - + - + @@ -227,21 +232,21 @@ - + - + - + - +