From 5f1b0d9ae10aec8d3c1f34b91b1e215032d89c8c Mon Sep 17 00:00:00 2001 From: localhorst Date: Thu, 4 Oct 2018 23:46:42 +0200 Subject: [PATCH] first steps for currentOrder Tree Table --- src/application/DBController.java | 184 ++++---- src/application/Job.java | 82 ++++ src/application/Main.java | 1 + src/application/MainWindow.fxml | 505 +++++---------------- src/application/MainWindowController.java | 166 +++++-- src/application/tableData.java | 68 --- src/application/tableDataCurrentOrder.java | 51 +++ src/application/tableDataJob.java | 51 +++ 8 files changed, 514 insertions(+), 594 deletions(-) create mode 100644 src/application/Job.java delete mode 100644 src/application/tableData.java create mode 100644 src/application/tableDataCurrentOrder.java create mode 100644 src/application/tableDataJob.java diff --git a/src/application/DBController.java b/src/application/DBController.java index 91b0295..73f51ab 100644 --- a/src/application/DBController.java +++ b/src/application/DBController.java @@ -75,51 +75,7 @@ class DBController return true; } } - - // table Position section - public void createTablePositionen() - { // create table position - System.out.println("Erstelle Tabelle Positionen"); - try { - Statement stmt = connection.createStatement(); - stmt.executeUpdate("DROP TABLE IF EXISTS positionen;"); - stmt.executeUpdate( - "CREATE TABLE positionen (posid, name, value, cat, color);"); - } catch (SQLException e) { - System.err.println("Couldn't handle DB-Query"); - e.printStackTrace(); - } - - // create 25 demo/default data entries - for (int i = 0; i < 25; i++) { - fillPositionen_Positionen(i + 1, "Noch frei", (float) 0.00, 6, - "#ad0000"); - } - } - - public void createTableCategory() - { // create table position - System.out.println("Erstelle Tabelle Kategorie"); - try { - Statement stmt = connection.createStatement(); - stmt.executeUpdate("DROP TABLE IF EXISTS category;"); - stmt.executeUpdate("CREATE TABLE category (catid, catname);"); - } catch (SQLException e) { - System.err.println("Couldn't handle DB-Query"); - e.printStackTrace(); - } - - fillCategory_Category(1, "Essen"); - fillCategory_Category(2, "alkoholische Getränke"); - fillCategory_Category(3, "alkoholfreie Getränke"); - fillCategory_Category(4, "Kuchen"); - fillCategory_Category(5, "Standard"); - - - - } - public String getCategoryNameFromPositionen(int pID) { // System.out.println("getCategoryName: " + pID); @@ -154,36 +110,25 @@ class DBController } - public void setName_Category(int pID, String pName) - { // Setzte den Namen + // table Position section // + public void createTablePositionen() + { // create table position + System.out.println("Erstelle Tabelle Positionen"); try { Statement stmt = connection.createStatement(); - stmt.executeUpdate("UPDATE category SET catname = '" + pName - + "'WHERE catid =" + pID + ";"); - } catch (SQLException e) { - System.err.println("Couldn't handle DB-Query"); - e.printStackTrace(); - } - } - - public void fillCategory_Category(int pID, String pName) - { - - System.out.println("Erstelle neuen Kategorie Eintrag"); - try { - PreparedStatement ps = connection - .prepareStatement("INSERT INTO category VALUES (?, ?);"); - ps.setInt(1, pID); // primary - ps.setString(2, pName); - ps.addBatch(); - connection.setAutoCommit(false); - ps.executeBatch(); // SQL execution - connection.setAutoCommit(true); + stmt.executeUpdate("DROP TABLE IF EXISTS positionen;"); + stmt.executeUpdate( + "CREATE TABLE positionen (posid, name, value, cat, color);"); } catch (SQLException e) { System.err.println("Couldn't handle DB-Query"); e.printStackTrace(); } + // create 25 demo/default data entries + for (int i = 0; i < 25; i++) { + fillPositionen_Positionen(i + 1, "Noch frei", (float) 0.00, 6, + "#ad0000"); + } } public void fillPositionen_Positionen(int pID, String pName, float pValue, @@ -223,21 +168,6 @@ class DBController } } - public String getName_Category(int pID) - { // Gibt das Datum zurück - try { - Statement stmt = connection.createStatement(); - ResultSet rs = stmt.executeQuery( - "SELECT catid, catname FROM category WHERE catid = " + pID - + ";"); - return rs.getString("catname"); - } catch (SQLException e) { - System.err.println("Couldn't handle DB-Query"); - e.printStackTrace(); - return "Error 404"; - } - } - public String getValue_Positionen(int pID) { // Gibt das Konto zurück try { @@ -375,7 +305,76 @@ class DBController } } - // table Jobs section + // table Category section // + public void createTableCategory() + { // create table position + System.out.println("Erstelle Tabelle Kategorie"); + try { + Statement stmt = connection.createStatement(); + stmt.executeUpdate("DROP TABLE IF EXISTS category;"); + stmt.executeUpdate("CREATE TABLE category (catid, catname);"); + } catch (SQLException e) { + System.err.println("Couldn't handle DB-Query"); + e.printStackTrace(); + } + + fillCategory_Category(1, "Essen"); + fillCategory_Category(2, "alkoholische Getränke"); + fillCategory_Category(3, "alkoholfreie Getränke"); + fillCategory_Category(4, "Kuchen"); + fillCategory_Category(5, "Standard"); + + } + + public void setName_Category(int pID, String pName) + { // Setzte den Namen + try { + Statement stmt = connection.createStatement(); + stmt.executeUpdate("UPDATE category SET catname = '" + pName + + "'WHERE catid =" + pID + ";"); + } catch (SQLException e) { + System.err.println("Couldn't handle DB-Query"); + e.printStackTrace(); + } + } + + public void fillCategory_Category(int pID, String pName) + { + + System.out.println("Erstelle neuen Kategorie Eintrag"); + try { + PreparedStatement ps = connection + .prepareStatement("INSERT INTO category VALUES (?, ?);"); + ps.setInt(1, pID); // primary + ps.setString(2, pName); + ps.addBatch(); + connection.setAutoCommit(false); + ps.executeBatch(); // SQL execution + connection.setAutoCommit(true); + } catch (SQLException e) { + System.err.println("Couldn't handle DB-Query"); + e.printStackTrace(); + } + + } + + public String getName_Category(int pID) + { // Gibt das Datum zurück + try { + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery( + "SELECT catid, catname FROM category WHERE catid = " + pID + + ";"); + return rs.getString("catname"); + } catch (SQLException e) { + System.err.println("Couldn't handle DB-Query"); + e.printStackTrace(); + return "Error 404"; + } + } + + + // table Jobs section // public void erstelleTabelleJobs() { // Erstelle Tabelle mit Reihen System.out.println("Erstelle Tabelle Jobs"); @@ -383,11 +382,28 @@ class DBController Statement stmt = connection.createStatement(); stmt.executeUpdate("DROP TABLE IF EXISTS jobs;"); stmt.executeUpdate( - "CREATE TABLE jobs (id, time, positionen, state, value);"); + "CREATE TABLE jobs (jobid, time, positionen_name, positionen_value, positionen_cat, state, jobvalue);"); } catch (SQLException e) { System.err.println("Couldn't handle DB-Query"); e.printStackTrace(); } } + + public int getLatestJobNumber_Job() { + + try { + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery( + "SELECT jobid from jobs ORDER BY jobid DESC LIMIT 1;"); + return rs.getInt("jobid"); + } catch (SQLException e) { + //System.err.println("Couldn't handle DB-Query"); + //e.printStackTrace(); + + } + System.out.println("XXXXXXXXXXX 1 XXXXXXXXXXX"); + return 1; + + } } diff --git a/src/application/Job.java b/src/application/Job.java new file mode 100644 index 0000000..ec35975 --- /dev/null +++ b/src/application/Job.java @@ -0,0 +1,82 @@ +package application; + +import java.util.ArrayList; + +public class Job +{ + + private int jobnumber; + + private int jobvalue; + + private String jobtime; + + private ArrayList positionenQuantity; + + private ArrayList positionenName; + + private ArrayList positionenValue; + + private ArrayList positionenCat; + + public Job(int pJobnumber) + { + this.jobnumber = pJobnumber; + System.out.println("Neuer Job: " + this.jobnumber); + + positionenQuantity = new ArrayList(); + positionenName = new ArrayList(); + positionenValue = new ArrayList(); + positionenCat = new ArrayList(); + + //System.out.println("Größe: " + positionenName.size()); + + } + + public void addPosition(String pPositionenName, float pPositionenValue, + String pPositionenCat) + { + //System.out.println("addName"); + + for (int i = 0; i < positionenName.size(); i++) { + if (positionenName.get(i).equals(pPositionenName)) { + // Item is already in list, increase quantity + positionenQuantity.set(i, positionenQuantity.get(i) + 1); + //System.out.println("Item exists, increasing quantity"); + return; + } + } + + positionenName.add(pPositionenName); + positionenValue.add(pPositionenValue); + positionenCat.add(pPositionenCat); + positionenQuantity.add(1); + } + + public void printJobOnConsole() + { + + System.out.println("---------------------------------------------"); + System.out.println("JobNummer: " + jobnumber); + System.out.println("---------------------------------------------"); + + //System.out.println("Größe: " + positionenName.size()); + + for (int i = 0; i < positionenName.size(); i++) { + + System.out.println( + positionenQuantity.get(i) + " " + positionenName.get(i) + " " + + positionenValue.get(i) + " " + positionenCat.get(i)); +/* + System.out.println("i is: " + i); + System.out.println(positionenName.get(i)); + System.out.println(positionenQuantity.get(i)); + */ + + } + + System.out.println("---------------------------------------------"); + + } + +} diff --git a/src/application/Main.java b/src/application/Main.java index 704df5d..52d4ce2 100644 --- a/src/application/Main.java +++ b/src/application/Main.java @@ -79,6 +79,7 @@ public class Main extends Application mwc.fillCategory(); mwc.loadGridButtons(); mwc.getSelectedCat(); //Load DB entries in Chois Box + mwc.createFirstJob(); } else { // config.xml NOT found, first start of app System.out.println("keine XML gefunden!"); diff --git a/src/application/MainWindow.fxml b/src/application/MainWindow.fxml index 180a7a9..091ab43 100644 --- a/src/application/MainWindow.fxml +++ b/src/application/MainWindow.fxml @@ -17,63 +17,36 @@ - + - + - + - - - - + - + - @@ -281,65 +183,37 @@ - + - + - - - - - + + + + + - - + - + - - - - - diff --git a/src/application/MainWindowController.java b/src/application/MainWindowController.java index cea8c00..790808d 100644 --- a/src/application/MainWindowController.java +++ b/src/application/MainWindowController.java @@ -35,7 +35,6 @@ import javafx.scene.control.Label; import javafx.scene.layout.AnchorPane; import javafx.scene.layout.GridPane; import javafx.util.Pair; -import sun.jvm.hotspot.tools.SysPropsDumper; public class MainWindowController { @@ -51,38 +50,38 @@ public class MainWindowController private AnchorPane paneDB; @FXML - private TreeTableView tableCurrentOrder; + private TreeTableView tableCurrentOrder; @FXML - private TreeTableColumn columnQuantity; + private TreeTableColumn columnQuantity; @FXML - private TreeTableColumn columnPosition; + private TreeTableColumn columnPosition; @FXML - private TreeTableColumn idSpalte01 = new TreeTableColumn<>( + private TreeTableColumn idSpalte01 = new TreeTableColumn<>( "tableCurrentOrder"); @FXML - private TreeTableView jobsTreeTable; + private TreeTableView jobsTreeTable; @FXML - private TreeTableColumn columnJobValue; + private TreeTableColumn columnJobValue; @FXML - private TreeTableColumn columnState; + private TreeTableColumn columnState; @FXML - private TreeTableColumn columnPositions; + private TreeTableColumn columnPositions; @FXML - private TreeTableColumn columnTime; + private TreeTableColumn columnTime; @FXML - private TreeTableColumn columnJobNumber; + private TreeTableColumn columnJobNumber; @FXML - private TreeTableColumn idSpalte02 = new TreeTableColumn<>( + private TreeTableColumn idSpalte02 = new TreeTableColumn<>( "jobsTreeTable"); @FXML @@ -321,13 +320,17 @@ public class MainWindowController private String databaseName; private boolean lockState = false; + + private boolean isPrintBtnDisabled = true; + + private Job currentJob = null; @FXML - TreeItem rootCurrentJob = new TreeItem<>( - new tableData(0, "0", "0")); + TreeItem rootCurrentJob = new TreeItem<>( + new tableDataCurrentOrder("0", 0)); @FXML - TreeItem rootJobs = new TreeItem<>(new tableData(0, "0", "0")); + TreeItem rootJobs = new TreeItem<>(new tableDataCurrentOrder("0", 0)); @FXML TreeItem rootPositionen = new TreeItem<>( @@ -487,158 +490,167 @@ public class MainWindowController @FXML public void btnPrintBillAction(ActionEvent event) { - System.out.println("Button!"); + //System.out.println("Button!"); + + currentJob.printJobOnConsole(); + + currentJob = null; + + currentJob = new Job(dbc.getLatestJobNumber_Job()); + + btnPrintBill.setDisable(true); + isPrintBtnDisabled = true; } @FXML public void gridButton01Action(ActionEvent event) { - System.out.println("Test Button!"); + handelGridButtons(1); } @FXML public void gridButton02Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(2); } @FXML public void gridButton03Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(3); } @FXML public void gridButton04Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(4); } @FXML public void gridButton05Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(5); } @FXML public void gridButton06Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(6); } @FXML public void gridButton07Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(7); } @FXML public void gridButton08Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(8); } @FXML public void gridButton09Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(9); } @FXML public void gridButton10Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(10); } @FXML public void gridButton11Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(11); } @FXML public void gridButton12Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(12); } @FXML public void gridButton13Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(13); } @FXML public void gridButton14Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(14); } @FXML public void gridButton15Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(15); } @FXML public void gridButton16Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(16); } @FXML public void gridButton17Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(17); } @FXML public void gridButton18Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(18); } @FXML public void gridButton19Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(19); } @FXML public void gridButton20Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(20); } @FXML public void gridButton21Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(21); } @FXML public void gridButton22Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(22); } @FXML public void gridButton23Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(23); } @FXML public void gridButton24Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(24); } @FXML public void gridButton25Action(ActionEvent event) { - System.out.println("Button!"); + handelGridButtons(25); } @FXML @@ -665,7 +677,10 @@ public class MainWindowController System.out.println("initUI"); tftNewDBName.setText(getDatabaseName()); tftKat05.setDisable(true); + btnPrintBill.setDisable(true); + isPrintBtnDisabled = true; initPositionen(); + initCurrentOrderTreeTableView(); } @@ -980,7 +995,17 @@ public class MainWindowController btnCalcStats.setDisable(pState); btnClearEntry.setDisable(pState); btnDeleteSelectedPosition.setDisable(pState); - btnPrintBill.setDisable(pState); + + if((!isPrintBtnDisabled) && (!pState)) { + // print was not disabled and will be enabled again + btnPrintBill.setDisable(pState); + } + + if(pState) { + // disable allways + btnPrintBill.setDisable(pState); + } + btnReprintJob.setDisable(pState); btnSaveEntry.setDisable(pState); btnCancelJob.setDisable(pState); @@ -995,7 +1020,7 @@ public class MainWindowController catChoise.setDisable(pState); tableCurrentOrder.setDisable(pState); - jobsTreeTable.setDisable(pState); + //jobsTreeTable.setDisable(pState); entryTreeTable.setDisable(pState); labelAllPrize.setVisible(!pState); @@ -1095,6 +1120,61 @@ public class MainWindowController } } + private void handelGridButtons(int pID) + { + + System.out.println("Button: " + pID); + + currentJob.addPosition(dbc.getName_Positionen(pID), + Float.parseFloat(dbc.getValue_Positionen(pID)), + dbc.getCategoryNameFromPositionen(pID)); + + btnPrintBill.setDisable(false); + isPrintBtnDisabled = false; + + tableDataCurrentOrder test01 = new tableDataCurrentOrder("Test", 42); + + + rootCurrentJob.getChildren().remove(0, + rootCurrentJob.getChildren().size()); + + rootCurrentJob.getChildren().add(new TreeItem(test01)); + + } + + private void initCurrentOrderTreeTableView() { + + + columnQuantity.setStyle("-fx-alignment: CENTER;"); + columnPosition.setStyle("-fx-alignment: CENTER;"); + + tableCurrentOrder.setRoot(rootCurrentJob); + tableCurrentOrder.setShowRoot(false); + tableCurrentOrder.setEditable(false); + + columnQuantity.setCellValueFactory( + cellData -> cellData.getValue().getValue().quantityProperty().asObject()); + + columnPosition.setCellValueFactory( + cellData -> cellData.getValue().getValue().positionProperty()); + + + + + + + + + + } + + + + public void createFirstJob() + { + currentJob = new Job(dbc.getLatestJobNumber_Job()); + } + public void updateTimeLabel() { // System.out.println(getSystemTime()); diff --git a/src/application/tableData.java b/src/application/tableData.java deleted file mode 100644 index e1e2bbc..0000000 --- a/src/application/tableData.java +++ /dev/null @@ -1,68 +0,0 @@ -package application; - -import javafx.beans.property.IntegerProperty; -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; - -public class tableData -{ // Datenobjekt mit der ID, Datum und Konto - - private final IntegerProperty id = new SimpleIntegerProperty(); - - private final StringProperty datum = new SimpleStringProperty(); - - private final StringProperty konto = new SimpleStringProperty(); - - public tableData(final int id, final String datum, final String konto) - { - this.id.set(id); - this.datum.set(datum); - this.konto.set(konto); - } - - public IntegerProperty idProperty() - { - return id; - } - - public StringProperty datumProperty() - { - return datum; - } - - public StringProperty kontoProperty() - { - return konto; - } - - public int getID() - { - return idProperty().get(); - } - - public String getDatum() - { - return datumProperty().get(); - } - - public String getKonto() - { - return kontoProperty().get(); - } - - public final void setID(int id) - { - idProperty().set(id); - } - - public final void setdatum(String datum) - { - datumProperty().set(datum); - } - - public final void setkonto(String konto) - { - kontoProperty().set(konto); - } -} diff --git a/src/application/tableDataCurrentOrder.java b/src/application/tableDataCurrentOrder.java new file mode 100644 index 0000000..7a86a5e --- /dev/null +++ b/src/application/tableDataCurrentOrder.java @@ -0,0 +1,51 @@ +package application; + +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class tableDataCurrentOrder +{ + + private final StringProperty position = new SimpleStringProperty(); + + private final IntegerProperty quantity = new SimpleIntegerProperty(); + + public tableDataCurrentOrder(final String pPosition, final Integer pQuantity) + { + this.position.set(pPosition); + this.quantity.set(pQuantity); + + } + + public StringProperty positionProperty() + { + return position; + } + + public IntegerProperty quantityProperty() + { + return quantity; + } + + public String getPosition() + { + return positionProperty().get(); + } + + public Integer getQuantity() + { + return quantityProperty().get(); + } + + public final void setPosition(String pPosition) + { + positionProperty().set(pPosition); + } + + public final void setQuantity(int pQuantity) + { + quantityProperty().set(pQuantity); + } +} diff --git a/src/application/tableDataJob.java b/src/application/tableDataJob.java new file mode 100644 index 0000000..e4e50ff --- /dev/null +++ b/src/application/tableDataJob.java @@ -0,0 +1,51 @@ +package application; + +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + +public class tableDataJob +{ + + private final StringProperty position = new SimpleStringProperty(); + + private final IntegerProperty quantity = new SimpleIntegerProperty(); + + public tableDataJob(final String pPosition, final Integer pQuantity) + { + this.position.set(pPosition); + this.quantity.set(pQuantity); + + } + + public StringProperty positionProperty() + { + return position; + } + + public IntegerProperty quantityProperty() + { + return quantity; + } + + public String getPosition() + { + return positionProperty().get(); + } + + public Integer getQuantity() + { + return quantityProperty().get(); + } + + public final void setPosition(String pPosition) + { + positionProperty().set(pPosition); + } + + public final void setQuantity(int pQuantity) + { + quantityProperty().set(pQuantity); + } +}