From 606b879fb9ff8830ab4a0750cf5b754eb62b063f Mon Sep 17 00:00:00 2001 From: localhorst Date: Wed, 3 Oct 2018 21:53:26 +0200 Subject: [PATCH] Finished the categories --- src/application/DBController.java | 34 +- src/application/MainWindow.fxml | 724 +++++++++++++++------- src/application/MainWindowController.java | 39 +- 3 files changed, 561 insertions(+), 236 deletions(-) diff --git a/src/application/DBController.java b/src/application/DBController.java index a527374..f3c5a8b 100644 --- a/src/application/DBController.java +++ b/src/application/DBController.java @@ -92,8 +92,8 @@ class DBController // create 25 demo/default data entries for (int i = 0; i < 25; i++) { - fillPositionen_Positionen(i + 1, "Noch frei", (float) 0.00, - ((int) (i / 5)) + 1, "#ad0000"); + fillPositionen_Positionen(i + 1, "Noch frei", (float) 0.00, 6, + "#ad0000"); } } @@ -110,25 +110,41 @@ class DBController } for (int i = 1; i < 6; i++) { - fillCategory_Category(i, "Cat: " + (i)); + fillCategory_Category(i, "Standard"); } } public String getCategoryNameFromPositionen(int pID) { - //System.out.println("getCategoryName: " + pID); + // System.out.println("getCategoryName: " + pID); + + int catInPos = 0; try { Statement stmt = connection.createStatement(); - ResultSet rs = stmt.executeQuery( - "SELECT posid, cat, catid, catname FROM positionen, category " - + "WHERE posid = " + pID + " AND cat = catid;"); + ResultSet rs = stmt.executeQuery("SELECT posid, cat FROM positionen " + + "WHERE posid = " + pID + ";"); + catInPos = rs.getInt("cat"); + } catch (SQLException e) { + System.err.println("Couldn't handle DB-Query"); + e.printStackTrace(); + + } + + if (catInPos == 6) { + return "keine Kategorie"; + } + + try { + Statement stmt = connection.createStatement(); + ResultSet rs = stmt.executeQuery("SELECT catid, catname FROM category " + + "WHERE catid = " + catInPos + ";"); return rs.getString("catname"); } catch (SQLException e) { System.err.println("Couldn't handle DB-Query"); e.printStackTrace(); - return "Error 404"; + return "keine Kategorie"; } } @@ -291,7 +307,7 @@ class DBController try { Statement stmt = connection.createStatement(); stmt.executeUpdate("UPDATE positionen SET cat = '" + pCat - + "'WHERE catid =" + pID + ";"); + + "'WHERE posid =" + pID + ";"); } catch (SQLException e) { System.err.println("Couldn't handle DB-Query"); e.printStackTrace(); diff --git a/src/application/MainWindow.fxml b/src/application/MainWindow.fxml index bc6dc8d..180a7a9 100644 --- a/src/application/MainWindow.fxml +++ b/src/application/MainWindow.fxml @@ -17,200 +17,329 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - - - - - + + + + + + + + - - + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - diff --git a/src/application/MainWindowController.java b/src/application/MainWindowController.java index 4a64aba..d419ff7 100644 --- a/src/application/MainWindowController.java +++ b/src/application/MainWindowController.java @@ -35,6 +35,7 @@ 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 { @@ -342,7 +343,7 @@ public class MainWindowController Dialog> dialog = new Dialog<>(); dialog.setTitle("Über jFxKasse"); dialog.setHeaderText( - "Informationen und Lizenzen - Version 0.9.3 - Techdemo"); + "Informationen und Lizenzen - Version 0.9.4 - Techdemo"); dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK); @@ -395,6 +396,7 @@ public class MainWindowController fillTablePositionen(); // fill TreeTable 'Positionen' fillCategory(); initUI(); // Starting the UI elements + getSelectedCat(); } @@ -407,7 +409,8 @@ public class MainWindowController dbc.setValue_Positionen(idPositionen, tftNewValue.getText()); dbc.setColor_Positionen(idPositionen, getColorCodes(selectedColorName)); - System.out.println("refill pos"); + dbc.setCat_Positionen(idPositionen, getSelectedCat()); + fillTablePositionen(); // fill TreeTable 'Positionen' loadGridButtons(); @@ -649,23 +652,18 @@ public class MainWindowController dbc.ladeTabellePositionen().get(i).getID(), dbc.ladeTabellePositionen().get(i).getName(), dbc.ladeTabellePositionen().get(i).getValue() + " €", - - // dbc.ladeTabellePositionen().get(i).getCat(), - // dbc.getCategoryName(dbc.ladeTabellePositionen().get(i).getCat())) dbc.getCategoryNameFromPositionen(i + 1), - getColorNames(dbc.ladeTabellePositionen().get(i).getColor())); - rootPositionen.getChildren() .add(new TreeItem(helpTableData)); } - } public void initUI() { System.out.println("initUI"); tftNewDBName.setText(getDatabaseName()); + tftKat05.setDisable(true); initPositionen(); } @@ -675,6 +673,16 @@ public class MainWindowController ObservableList cats = FXCollections.observableArrayList(); + /* + * for(int i = 1; i < 6; i++) { + * + * if(dbc.getName_Category(i).equals("Standard")) { + * + * }else { cats.add(dbc.getName_Category(i)); } + * + * } + */ + cats.add(dbc.getName_Category(1)); cats.add(dbc.getName_Category(2)); cats.add(dbc.getName_Category(3)); @@ -691,17 +699,18 @@ public class MainWindowController selectedCatName = catChoise.getItems().get((int) new_value) .toString(); - System.out.println("Ausgewählte Cat: " + selectedCatName); + // System.out.println("Ausgewählte Cat: " + selectedCatName); } }); - for (int i = 1; i < 5; i++) { - if (selectedCatName == dbc.getName_Category(i)) { + for (int i = 1; i < 6; i++) { + + if (dbc.getName_Category(i).equals(selectedCatName)) { return i; } } - return -1; + return 5; } public void fillCategory() @@ -730,7 +739,8 @@ public class MainWindowController { selectedColorName = colorChoise.getItems() .get((int) new_value).toString(); - System.out.println("Ausgewählte Farbe: " + selectedColorName); + // System.out.println("Ausgewählte Farbe: " + + // selectedColorName); } }); @@ -773,6 +783,9 @@ public class MainWindowController colorChoise.getSelectionModel().select( getColorID(dbc.getColor_Positionen(idPositionen))); + catChoise.getSelectionModel().select( + dbc.getCategoryNameFromPositionen(idPositionen)); + } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace();