completed TabPane 'Positionen'

code cleanup
This commit is contained in:
hendrik 2018-04-02 20:31:47 +02:00
parent 247bd9a20b
commit 4b80f983fb
10 changed files with 191 additions and 330 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -68,18 +68,21 @@
<children>
<TreeTableView fx:id="entryTreeTable" layoutX="11.0" layoutY="10.0" prefHeight="502.0" prefWidth="1346.0">
<columns>
<TreeTableColumn fx:id="columnColor" editable="false" prefWidth="135.0" resizable="false" sortable="false" text="Farbe" />
<TreeTableColumn fx:id="columnPrize" editable="false" prefWidth="117.0" resizable="false" sortable="false" text="Preis" />
<TreeTableColumn fx:id="columnPositionsEdit" editable="false" prefWidth="982.0" resizable="false" sortable="false" text="Positionen" />
<TreeTableColumn fx:id="columnPosnumber" editable="false" maxWidth="3000.0" prefWidth="111.0" resizable="false" sortable="false" text="Nummer" />
<TreeTableColumn fx:id="columnColor" editable="false" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" resizable="false" sortable="false" text="Farbe" />
<TreeTableColumn fx:id="columnPrize" editable="false" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" resizable="false" sortable="false" text="Preis" />
<TreeTableColumn fx:id="columnPositionsEdit" editable="false" maxWidth="800.0" minWidth="800.0" prefWidth="800.0" resizable="false" sortable="false" text="Positionen" />
<TreeTableColumn fx:id="columnPosnumber" editable="false" maxWidth="120.0" minWidth="120.0" prefWidth="120.0" resizable="false" sortable="false" text="Nummer" />
</columns>
<columnResizePolicy>
<TreeTableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TreeTableView>
<Button fx:id="btnSaveEntry" layoutX="66.0" layoutY="620.0" mnemonicParsing="false" onAction="#btnSaveEntryAction" text="Ausgewählten Eintrag speichern">
<Button fx:id="btnSaveEntry" layoutX="494.0" layoutY="631.0" mnemonicParsing="false" onAction="#btnSaveEntryAction" text="Ausgewählten Eintrag speichern">
<font>
<Font name="Cantarell Regular" size="17.0" />
</font>
</Button>
<Button fx:id="btnClearEntry" layoutX="437.0" layoutY="620.0" mnemonicParsing="false" onAction="#btnClearEntryAction" text="Ausgewählten Eintrag zurücksetzten">
<Button fx:id="btnClearEntry" layoutX="462.0" layoutY="525.0" mnemonicParsing="false" onAction="#btnClearEntryAction" text="Ausgewählten Eintrag zurücksetzten">
<font>
<Font name="Cantarell Regular" size="17.0" />
</font>
@ -93,13 +96,19 @@
<Font name="Cantarell Regular" size="18.0" />
</font>
</Label>
<JFXTextField fx:id="tftNewPosition" layoutX="160.0" layoutY="10.0" prefHeight="25.0" prefWidth="279.0" />
<JFXTextField fx:id="tftNewPosition" alignment="CENTER" layoutX="160.0" layoutY="10.0" prefHeight="25.0" prefWidth="279.0">
<font>
<Font name="Cantarell Regular" size="13.0" />
</font></JFXTextField>
<Label fx:id="labelNewValue" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="442.0" layoutY="50.0" prefHeight="34.0" prefWidth="118.0" text="Preis in Euro:">
<font>
<Font name="Cantarell Regular" size="18.0" />
</font>
</Label>
<JFXTextField fx:id="tftNewValue" layoutX="380.0" layoutY="50.0" prefHeight="25.0" prefWidth="58.0" />
<JFXTextField fx:id="tftNewValue" alignment="CENTER" layoutX="380.0" layoutY="50.0" prefHeight="25.0" prefWidth="58.0">
<font>
<Font name="Cantarell Regular" size="13.0" />
</font></JFXTextField>
<Label fx:id="lableNewColor" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="455.0" layoutY="90.0" prefHeight="34.0" prefWidth="105.0" text="Farbe:">
<font>
<Font name="Cantarell Regular" size="18.0" />

View File

@ -12,27 +12,20 @@ import java.io.FileInputStream;
class DBController
{
private Connection connection;
private String DB_PATH_Linux = System.getProperty("user.home")
+ "/bin/jFxKasse/";
public String dbname;
private Main main;
// private Cryption crypo = new Cryption();
private String schluessel; // Für Ver-/Entschlüsselung
boolean databasepresent = false;
private Main main;
public void main()
{
try {
connection = DriverManager
.getConnection("jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db");
connection = DriverManager
.getConnection("jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -44,16 +37,14 @@ class DBController
this.main = main;
}
public void verbindeDatenbank()
{ // Verbinde mit der Datenbank-Datei
public void connectDatabase()
{ // connect to database
System.out.println("Verbinde ... DB name: " + dbname);
try {
if (connection != null)
return;
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db");
connection = DriverManager
.getConnection("jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db");
if (!connection.isClosed())
System.out.println("DB Datei-Verbindung erstellt");
} catch (SQLException e) {
@ -75,63 +66,6 @@ class DBController
});
}
public void fuellenPositionen(int pID, String pName, float pValue,
String pColor)
{ // Neuen Eintrag erstellen
System.out.println("Erstelle neuen positionen eintrag");
try {
PreparedStatement ps = connection.prepareStatement(
"INSERT INTO positionen VALUES (?, ?, ?, ?);");
ps.setInt(1, pID); // Primärschlässel
ps.setString(2, pName);
ps.setFloat(3, pValue);
ps.setString(4, pColor);
ps.addBatch();
connection.setAutoCommit(false);
ps.executeBatch(); // SQL ausführen
connection.setAutoCommit(true);
// connection.close();
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
}
public void erstelleTabellePositionen()
{ // Erstelle Tabelle mit Reihen
System.out.println("Erstelle Tabelle Positionen");
try {
Statement stmt = connection.createStatement();
stmt.executeUpdate("DROP TABLE IF EXISTS positionen;");
stmt.executeUpdate(
"CREATE TABLE positionen (id, name, value, color);");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
for(int i = 0; i < 25; i++) {
fuellenPositionen(i+1, "Noch frei", (float) 0.00, "#FAF0E6");
}
}
public void erstelleTabelleJobs()
{ // Erstelle Tabelle mit Reihen
System.out.println("Erstelle Tabelle Jobs");
try {
Statement stmt = connection.createStatement();
stmt.executeUpdate("DROP TABLE IF EXISTS jobs;");
stmt.executeUpdate(
"CREATE TABLE jobs (id, time, positionen, state, value);");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
}
public boolean existiertDatenbank(String pPfad)
{ // Prüft ob die Datenbank existiert
File varTmpDir = new File(pPfad);
@ -142,20 +76,43 @@ class DBController
}
}
public void ausgebenSysoPositionen()
{ // Debugging Ausgabe der kompletten Tabelle
System.out.println("Print positionen");
// table Position section
public void createTablePositionen()
{ // create table position
System.out.println("Erstelle Tabelle Positionen");
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM positionen;");
while (rs.next()) {
System.out.println("id = " + rs.getString("id"));
System.out.println("name = " + rs.getString("name"));
System.out.println("vale = " + rs.getString("value"));
System.out.println("color = " + rs.getString("color"));
System.out.println(" ");
}
stmt.executeUpdate("DROP TABLE IF EXISTS positionen;");
stmt.executeUpdate(
"CREATE TABLE positionen (id, name, value, 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(i + 1, "Noch frei", (float) 0.00, "#FAF0E6");
}
}
public void fillPositionen(int pID, String pName, float pValue,
String pColor)
{ // create new data in table
System.out.println("Erstelle neuen positionen eintrag");
try {
PreparedStatement ps = connection
.prepareStatement("INSERT INTO positionen VALUES (?, ?, ?, ?);");
ps.setInt(1, pID); // primary
ps.setString(2, pName);
ps.setFloat(3, pValue);
ps.setString(4, pColor);
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();
@ -204,37 +161,6 @@ class DBController
}
}
public String getEmail(int pID)
{ // Gibt die Email zurück
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT id, email FROM konten WHERE id = " + pID + ";");
return rs.getString("email");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
return "Error 404";
}
}
public String getPasswort(int pID)
{ // Gibt das Passwort zurück
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT id, passwort FROM konten WHERE id = " + pID + ";");
return rs.getString("passwort");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
return "Error 404";
}
}
public void setName(int pID, String pName)
{ // Setzt das Datum
try {
@ -271,89 +197,6 @@ class DBController
}
}
public void setEmail(int pID, String pEmail)
{ // Setzt die Email
try {
Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE konten SET email = '" + pEmail
+ "'WHERE id =" + pID + ";");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
}
public void setPasswort(int pID, String pPasswort)
{ // Setzt das Passwort
try {
Statement stmt = connection.createStatement();
stmt.executeUpdate("UPDATE konten SET passwort = '" + pPasswort
+ "'WHERE id =" + pID + ";");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
}
public void loeschenEintrag(int pID)
{ // Löscht den Eintrag
int alteOrdnung = getNeueID(); // Speichert die ID des letzten Eintrags
try {
if (pID == getNeueID() - 1) { // Falls letzter Eintrag gelöscht werden
// soll
PreparedStatement ps = connection
.prepareStatement("DELETE FROM konten WHERE id=?");
ps.setInt(1, pID);
ps.executeUpdate();
} else { // Wenn ein Eintrag in mitten der DB gelöscht wird, dann wird
// hochkopiert
while (!(pID + 1 == alteOrdnung - 1)) {
int pIDneu = pID + 1;
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT id, datum, konto, nutzername, email, passwort FROM konten WHERE id = "
+ pIDneu + ";");
String pDatum = rs.getString("datum");
String pKonto = rs.getString("konto");
String pNutzername = rs.getString("nutzername");
String pEmail = rs.getString("email");
String pPasswort = rs.getString("passwort");
stmt.executeUpdate("UPDATE konten SET datum = '" + pDatum
+ "', konto = '" + pKonto + "', nutzername = '"
+ pNutzername + "', email = '" + pEmail + "', passwort = '"
+ pPasswort + "'WHERE id =" + pID + ";");
pID = pID + 1;
}
PreparedStatement ps = connection
.prepareStatement("DELETE FROM konten WHERE id=?");
ps.setInt(1, alteOrdnung - 1);
ps.executeUpdate();
}
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
}
public int getNeueID()
{ // Gibt die ID des nächsten Eintrags zurück
int neueID = 0;
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM konten;");
while (rs.next()) {
neueID = rs.getInt("id") + 1;
}
rs.close();
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
return neueID;
}
public ArrayList<tableDataPositionen> ladeTabellePositionen()
{ // Gibt ein Objekt daten mit allen Einträgen der DB zurück
ArrayList<tableDataPositionen> daten = new ArrayList<>();
@ -363,7 +206,9 @@ class DBController
while (rs.next()) {
try {
// Entschlüsselte Daten werden als Datenobjekt gespeichert
daten.add(new tableDataPositionen(rs.getInt("id"), rs.getString("name"), rs.getString("value"), rs.getString("color")));
daten.add(new tableDataPositionen(rs.getInt("id"),
rs.getString("name"), rs.getString("value"),
rs.getString("color")));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -375,11 +220,44 @@ class DBController
}
return daten;
}
public void ausgebenSysoPositionen()
{ // Debugging Ausgabe der kompletten Tabelle
System.out.println("Print positionen");
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM positionen;");
while (rs.next()) {
System.out.println("id = " + rs.getString("id"));
System.out.println("name = " + rs.getString("name"));
System.out.println("vale = " + rs.getString("value"));
System.out.println("color = " + rs.getString("color"));
System.out.println(" ");
}
public void setSchluessel(String pSchluessel)
{ // Setzt den Schlüssel für die Ver-/Entschlüsslung
schluessel = pSchluessel;
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
}
// table Jobs section
public void erstelleTabelleJobs()
{ // Erstelle Tabelle mit Reihen
System.out.println("Erstelle Tabelle Jobs");
try {
Statement stmt = connection.createStatement();
stmt.executeUpdate("DROP TABLE IF EXISTS jobs;");
stmt.executeUpdate(
"CREATE TABLE jobs (id, time, positionen, state, value);");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
}
}
}

View File

@ -33,8 +33,6 @@ public class Main extends Application
private DBController dbc = new DBController(this);
private String schluesselNutzer; // Passwort des Nutzers
private Stage primaryStage;
@Override
@ -42,7 +40,6 @@ public class Main extends Application
{
this.primaryStage = primaryStage;
mainWindow();
//this.primaryStage.setResizable(false);
}
private void mainWindow()
@ -51,22 +48,12 @@ public class Main extends Application
FXMLLoader loader = new FXMLLoader(
getClass().getResource("MainWindow.fxml"));
AnchorPane pane = loader.load();
// Test
//Test
//primaryStage.setWidth(1366);
//primaryStage.setHeight(732);
primaryStage.setTitle("jFxKasse"); // Title der Stage
primaryStage.setTitle("jFxKasse"); // Title of window
mwc = loader.getController();
mwc.setMain(this, dbc);
firstStart(); // Prüft ob das Programm zuvor gestartet wurde
// dbc.main(); // Startet die Datenbank
//mwc.fuelleTablle(); // Ladt die Einträge in die Tabelle
firstStart();
Scene scene = new Scene(pane);
scene.getStylesheets()
@ -83,42 +70,26 @@ public class Main extends Application
launch(args);
}
/**
* Checks if the config.xml is preset.
* @author hendrik
*/
private void firstStart() throws Exception
{
if (mwc.loadSettings()) { // Wenn XML gefunden
if (mwc.loadSettings()) {
// config.xml found, app starting normal
System.out.println("XML gefunden!");
mwc.initUI(); // Startet die UI
mwc.setDBLabel();
dbc.dbname = mwc.getDatabaseName();
dbc.verbindeDatenbank(); // Verbindet mit der Datenbank-Datei
mwc.fuelleTabllePositionen();
} else { // Wenn keine XML gefunden --> erster Start
mwc.initUI(); // Starting the UI elements
mwc.setDBLabel(); // Set databese labels
dbc.dbname = mwc.getDatabaseName(); // handover database name
dbc.connectDatabase(); // estabishing DB conection
mwc.fillTablePositionen(); // fill TreeTable 'Positionen'
} else {
// config.xml NOT found, first start of app
System.out.println("keine XML gefunden!");
mwc.blockUI(true);
if (System.getProperty("os.name").equals("Linux")) {
File dir = new File(
System.getProperty("user.home") + "/bin/jFxKasse"); // Erstellt
// den
// Unterordner
dir.mkdir(); // Erstellt den Unterordner
} else {
File dir = new File("C:/ProgramData/jFxKasse/"); // Erstellt den
// Unterordner
dir.mkdir(); // Erstellt den Unterordner
}
// mwc.saveSettings(mwc.getDatabaseName(), "dd"); // speichert das Passwort und
// den Individueller
// Schlüssel für die API in
// der XML
//dbc.verbindeDatenbank(); // Verbindet mit der Datenbank-Datei
//dbc.erstelleDatenbank(); // Neue Datenbank-Datei wird erstellt
//System.exit(0); // Programm wird beendet
mwc.blockUI(true); // disable UI elements that need DB
File dir = new File(System.getProperty("user.home") + "/bin/jFxKasse");
dir.mkdir(); // Create new Subfolder
}
}
}

View File

@ -68,18 +68,21 @@
<children>
<TreeTableView fx:id="entryTreeTable" layoutX="11.0" layoutY="10.0" prefHeight="502.0" prefWidth="1346.0">
<columns>
<TreeTableColumn fx:id="columnColor" editable="false" prefWidth="135.0" resizable="false" sortable="false" text="Farbe" />
<TreeTableColumn fx:id="columnPrize" editable="false" prefWidth="117.0" resizable="false" sortable="false" text="Preis" />
<TreeTableColumn fx:id="columnPositionsEdit" editable="false" prefWidth="982.0" resizable="false" sortable="false" text="Positionen" />
<TreeTableColumn fx:id="columnPosnumber" editable="false" maxWidth="3000.0" prefWidth="111.0" resizable="false" sortable="false" text="Nummer" />
<TreeTableColumn fx:id="columnColor" editable="false" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" resizable="false" sortable="false" text="Farbe" />
<TreeTableColumn fx:id="columnPrize" editable="false" maxWidth="200.0" minWidth="200.0" prefWidth="200.0" resizable="false" sortable="false" text="Preis" />
<TreeTableColumn fx:id="columnPositionsEdit" editable="false" maxWidth="800.0" minWidth="800.0" prefWidth="800.0" resizable="false" sortable="false" text="Positionen" />
<TreeTableColumn fx:id="columnPosnumber" editable="false" maxWidth="120.0" minWidth="120.0" prefWidth="120.0" resizable="false" sortable="false" text="Nummer" />
</columns>
<columnResizePolicy>
<TreeTableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TreeTableView>
<Button fx:id="btnSaveEntry" layoutX="66.0" layoutY="620.0" mnemonicParsing="false" onAction="#btnSaveEntryAction" text="Ausgewählten Eintrag speichern">
<Button fx:id="btnSaveEntry" layoutX="494.0" layoutY="631.0" mnemonicParsing="false" onAction="#btnSaveEntryAction" text="Ausgewählten Eintrag speichern">
<font>
<Font name="Cantarell Regular" size="17.0" />
</font>
</Button>
<Button fx:id="btnClearEntry" layoutX="437.0" layoutY="620.0" mnemonicParsing="false" onAction="#btnClearEntryAction" text="Ausgewählten Eintrag zurücksetzten">
<Button fx:id="btnClearEntry" layoutX="462.0" layoutY="525.0" mnemonicParsing="false" onAction="#btnClearEntryAction" text="Ausgewählten Eintrag zurücksetzten">
<font>
<Font name="Cantarell Regular" size="17.0" />
</font>
@ -93,13 +96,19 @@
<Font name="Cantarell Regular" size="18.0" />
</font>
</Label>
<JFXTextField fx:id="tftNewPosition" layoutX="160.0" layoutY="10.0" prefHeight="25.0" prefWidth="279.0" />
<JFXTextField fx:id="tftNewPosition" alignment="CENTER" layoutX="160.0" layoutY="10.0" prefHeight="25.0" prefWidth="279.0">
<font>
<Font name="Cantarell Regular" size="13.0" />
</font></JFXTextField>
<Label fx:id="labelNewValue" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="442.0" layoutY="50.0" prefHeight="34.0" prefWidth="118.0" text="Preis in Euro:">
<font>
<Font name="Cantarell Regular" size="18.0" />
</font>
</Label>
<JFXTextField fx:id="tftNewValue" layoutX="380.0" layoutY="50.0" prefHeight="25.0" prefWidth="58.0" />
<JFXTextField fx:id="tftNewValue" alignment="CENTER" layoutX="380.0" layoutY="50.0" prefHeight="25.0" prefWidth="58.0">
<font>
<Font name="Cantarell Regular" size="13.0" />
</font></JFXTextField>
<Label fx:id="lableNewColor" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="455.0" layoutY="90.0" prefHeight="34.0" prefWidth="105.0" text="Farbe:">
<font>
<Font name="Cantarell Regular" size="18.0" />

View File

@ -15,11 +15,7 @@ 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 com.sun.java.swing.action.NewAction;
import java.awt.Desktop;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
@ -35,10 +31,8 @@ import java.net.URISyntaxException;
import java.sql.DriverManager;
import java.util.Optional;
import java.util.Properties;
import javax.security.auth.callback.Callback;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane.TitlePaneLayout;
import javafx.application.Platform;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
@ -286,9 +280,6 @@ public class MainWindowController
private String databaseName;
// private ObservableList<String> color =
// FXCollections.observableArrayList("English", "Deutsch");
@FXML
TreeItem<tableData> rootCurrentJob = new TreeItem<>(
new tableData(0, "0", "0"));
@ -304,18 +295,16 @@ public class MainWindowController
@FXML
public void ueberbtnAction(ActionEvent event)
{ // Öffnet den Über-Dialog
{ // opens the 'Über' dialog
// Erstellt einen Dialog
// creates a dialog
Dialog<Pair<String, String>> dialog = new Dialog<>();
dialog.setTitle("Über jFxKasse");
dialog.setHeaderText(
"Informationen und Lizenzen - Version 0.7 - UI Techdemo");
"Informationen und Lizenzen - Version 0.8 - UI Techdemo");
// Erzeugt den Button
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK);
// Erzeugt die Textfelder und Label
GridPane grid = new GridPane();
grid.setHgap(10);
grid.setVgap(10);
@ -343,27 +332,21 @@ public class MainWindowController
@FXML
public void btnCreateNewDatabaseAction(ActionEvent event) throws Exception
{
System.out.println("Button!");
System.out.println(tftNewDBName.getText());
setDatabaseName(tftNewDBName.getText());
dbc.dbname = getDatabaseName();
dbc.verbindeDatenbank(); // Verbindet mit der Datenbank-Datei
dbc.erstelleTabellePositionen();
dbc.erstelleTabelleJobs();
dbc.connectDatabase(); // establish DB connection
dbc.createTablePositionen(); // Create new table
dbc.erstelleTabelleJobs(); // Create new table
try {
saveSettings(getDatabaseName());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setDBLabel();
blockUI(false);
fuelleTabllePositionen();
initUI(); // Startet die UI
setDBLabel(); // Set new databese labels
blockUI(false); // unlock UI elements that need DB
fillTablePositionen(); // fill TreeTable 'Positionen'
initUI(); // Starting the UI elements
}
@ -376,14 +359,19 @@ public class MainWindowController
dbc.setValue(idPositionen, tftNewValue.getText());
dbc.setColor(idPositionen, getColorCodes(selectedColorName));
fuelleTabllePositionen();
fillTablePositionen(); // fill TreeTable 'Positionen'
}
@FXML
public void btnClearEntryAction(ActionEvent event)
{
System.out.println("Button!");
// set default values
dbc.setName(idPositionen, "Noch frei");
dbc.setValue(idPositionen, "0.00");
dbc.setColor(idPositionen, "#FAF0E6");
fillTablePositionen(); // fill TreeTable 'Positionen'
}
@FXML
@ -395,8 +383,7 @@ public class MainWindowController
@FXML
public void btnReprintJobAction(ActionEvent event)
{
// System.out.println("fuelleTabellePositionen");
// fuelleTabllePositionen();
}
@FXML
@ -409,7 +396,6 @@ public class MainWindowController
public void btnLockAction(ActionEvent event)
{
System.out.println("Button!");
dbc.ausgebenSysoPositionen();
}
@FXML
@ -575,12 +561,8 @@ public class MainWindowController
}
@FXML
public void fuelleTabllePositionen()
{ // Lädt die Datenbank in die Tabelle
// dbc.setSchluessel(schluessel);
public void fillTablePositionen()
{ // loads the table in the TreeTableView
rootPositionen.getChildren().remove(0,
rootPositionen.getChildren().size());
@ -588,7 +570,7 @@ public class MainWindowController
tableDataPositionen helpTableData = new tableDataPositionen(
dbc.ladeTabellePositionen().get(i).getID(),
dbc.ladeTabellePositionen().get(i).getName(),
dbc.ladeTabellePositionen().get(i).getValue(),
dbc.ladeTabellePositionen().get(i).getValue() + "",
getColorNames(dbc.ladeTabellePositionen().get(i).getColor()));
rootPositionen.getChildren()
@ -599,12 +581,10 @@ public class MainWindowController
public void initUI()
{
System.out.println("initUI");
tftNewDBName.setText(getDatabaseName());
initPositionen();
}
private void initPositionen()
{
@ -668,51 +648,64 @@ public class MainWindowController
}
});
columnPosnumber.setStyle("-fx-alignment: CENTER;");
columnPositionsEdit.setStyle("-fx-alignment: CENTER;");
columnPrize.setStyle("-fx-alignment: CENTER;");
columnColor.setStyle("-fx-alignment: CENTER;");
tftNewValue.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable,
String oldValue, String newValue)
{
if (!newValue.matches("\\d{0,7}([\\.]\\d{0,2})?")) {
tftNewValue.setText(oldValue);
}
}
});
}
public void setMain(Main main, DBController dbc)
{
this.main = main;
this.dbc = dbc;
}
public String getSystemDatum()
{ // Gibt das System-Datum zurück
{
java.util.Date now = new java.util.Date();
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
"dd.MM.yyyy");
String heutigesDatum = sdf.format(now);
return heutigesDatum;
}
public void saveSettings(String databasename) throws Exception
{
OutputStream outputStream; // new output-stream
{ //Save settings to config.xml
OutputStream outputStream;
try {
props.setProperty("databasename", databasename); // writes dbname into
// property
props.setProperty("databasename", databasename);
outputStream = new FileOutputStream(filepathXMLLinux);
props.storeToXML(outputStream, "jFxKasse settings"); // writes new .xml
props.storeToXML(outputStream, "jFxKasse settings");
outputStream.close();
} catch (IOException e) {
}
}
public boolean loadSettings() throws Exception
{ // Ladt die Daten aus der XML
{ // reads the settings from config.xml
InputStream inputStream;
try {
inputStream = new FileInputStream(filepathXMLLinux);
props.loadFromXML(inputStream);
setDatabaseName(props.getProperty("databasename"));
// = crypo.entschluesseln(props.getProperty("key"),
// crypo.getProgrammSchluessel()); //liest schluessel von property
// base32Secret = crypo.entschluesseln(props.getProperty("TOTPkey"),
// crypo.getProgrammSchluessel()); //liest schluessel von property
inputStream.close();
return true;
} catch (IOException e) {
@ -720,21 +713,21 @@ public class MainWindowController
return false;
}
}
public void starteDB()
{ // Startet die Datenbank
dbc.verbindeDatenbank();
}
public String getDatabaseName()
{
return databaseName;
}
public void setDatabaseName(String NewDatabaseName)
{
databaseName = NewDatabaseName;
}
public void setDBLabel() throws Exception
{
@ -754,8 +747,8 @@ public class MainWindowController
} else {
labelDBStatus.setText("Keine Datenbank gefunden!");
}
}
private String getColorCodes(String pColorName)
{
@ -781,6 +774,8 @@ public class MainWindowController
return "#FFFFFF";
}
}
private String getColorNames(String pColorCode)
{
@ -806,6 +801,7 @@ public class MainWindowController
return "Farbe";
}
}
private Integer getColorID(String pColorCode)
{
@ -830,12 +826,11 @@ public class MainWindowController
default:
return 0;
}
}
public void blockUI(boolean pState)
{
btnCalcStats.setDisable(pState);
btnClearEntry.setDisable(pState);
btnDeleteSelectedPosition.setDisable(pState);
@ -881,7 +876,6 @@ public class MainWindowController
labelJobCounter.setVisible(!pState);
titlePaneStats.setVisible(!pState);
}
}