dbcontroller and mainwindowcontroller changes
This commit is contained in:
parent
1c6c5ba72e
commit
5244a615ca
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -26,6 +26,38 @@
|
|||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<Button fx:id="ueberbtn" layoutX="664.0" layoutY="325.0" mnemonicParsing="false" onAction="#ueberbtnAction" text="Über" />
|
||||
<TitledPane alignment="CENTER" animated="false" collapsible="false" contentDisplay="CENTER" layoutX="790.0" layoutY="10.0" prefHeight="163.0" prefWidth="566.0" text="Datenbank">
|
||||
<content>
|
||||
<AnchorPane fx:id="paneDB" minHeight="0.0" minWidth="0.0" prefHeight="135.0" prefWidth="547.0">
|
||||
<children>
|
||||
<Label fx:id="labelDBName" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="329.0" layoutY="10.0" prefHeight="34.0" prefWidth="229.0" text="Datenbankname:">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<JFXTextField fx:id="tftNewDBName" alignment="CENTER" layoutX="25.0" layoutY="10.0" prefHeight="25.0" prefWidth="376.0" />
|
||||
<Label fx:id="labelDBStatus" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="7.0" layoutY="50.0" prefHeight="34.0" prefWidth="551.0" text="Keine Datenbank gefunden!">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button fx:id="btnCreateNewDatabase" layoutX="297.0" layoutY="90.0" mnemonicParsing="false" onAction="#btnCreateNewDatabaseAction" text="Neue Datenbank anlegen">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="13.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="btnOpenFolder" layoutX="39.0" layoutY="90.0" mnemonicParsing="false" onAction="#btnOpenFolderAction" text="Speicherort öffnen">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="13.0" />
|
||||
</font>
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="13.0" />
|
||||
</font>
|
||||
</TitledPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
|
|
Binary file not shown.
|
@ -15,26 +15,24 @@ class DBController
|
|||
|
||||
private Connection connection;
|
||||
|
||||
private String DB_PATH_Win = "C:/ProgramData/PWMaster/datenbank.db";
|
||||
|
||||
private String DB_PATH_Linux = System.getProperty("user.home")
|
||||
+ "/bin/PWMaster/datenbank.db";
|
||||
+ "/bin/jFxKasse/";
|
||||
|
||||
public String dbname;
|
||||
|
||||
private Main main;
|
||||
|
||||
// private Cryption crypo = new Cryption();
|
||||
private String schluessel; // Für Ver-/Entschlüsselung
|
||||
|
||||
boolean databasepresent = false;
|
||||
|
||||
public void main()
|
||||
{
|
||||
try {
|
||||
if (System.getProperty("os.name").equals("Linux")) {
|
||||
connection = DriverManager
|
||||
.getConnection("jdbc:sqlite:" + DB_PATH_Linux);
|
||||
} else {
|
||||
connection = DriverManager
|
||||
.getConnection("jdbc:sqlite:" + DB_PATH_Win);
|
||||
}
|
||||
.getConnection("jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db");
|
||||
|
||||
} catch (SQLException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -48,18 +46,16 @@ class DBController
|
|||
|
||||
public void verbindeDatenbank()
|
||||
{ // Verbinde mit der Datenbank-Datei
|
||||
System.out.println("Verbinde ... DB name: " + dbname);
|
||||
try {
|
||||
if (connection != null)
|
||||
return;
|
||||
if (System.getProperty("os.name").equals("Linux")) {
|
||||
connection = DriverManager
|
||||
.getConnection("jdbc:sqlite:" + DB_PATH_Linux);
|
||||
} else {
|
||||
connection = DriverManager
|
||||
.getConnection("jdbc:sqlite:" + DB_PATH_Win);
|
||||
}
|
||||
|
||||
connection = DriverManager.getConnection("jdbc:sqlite:" + DB_PATH_Linux + dbname + ".db");
|
||||
|
||||
|
||||
if (!connection.isClosed())
|
||||
System.out.println();
|
||||
System.out.println("DB Datei-Verbindung erstellt");
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -103,13 +99,29 @@ class DBController
|
|||
}
|
||||
}
|
||||
|
||||
public void erstelleDatenbank()
|
||||
public void erstelleTabellePositionen()
|
||||
{ // Erstelle Tabelle mit Reihen
|
||||
System.out.println("Erstelle Tabelle Positionen");
|
||||
try {
|
||||
Statement stmt = connection.createStatement();
|
||||
stmt.executeUpdate("DROP TABLE IF EXISTS konten;");
|
||||
stmt.executeUpdate("DROP TABLE IF EXISTS positionen;");
|
||||
stmt.executeUpdate(
|
||||
"CREATE TABLE konten (id, datum, konto, nutzername, email, passwort);");
|
||||
"CREATE TABLE positionen (id, name, value, color);");
|
||||
} catch (SQLException e) {
|
||||
System.err.println("Couldn't handle DB-Query");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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();
|
||||
|
@ -366,5 +378,13 @@ class DBController
|
|||
{ // Setzt den Schlüssel für die Ver-/Entschlüsslung
|
||||
schluessel = pSchluessel;
|
||||
}
|
||||
|
||||
public boolean getDatabasePresent() {
|
||||
return databasepresent;
|
||||
}
|
||||
|
||||
public void setDatabasePresent(boolean status) {
|
||||
databasepresent = status;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -61,10 +61,12 @@ public class Main extends Application
|
|||
mwc.setMain(this, dbc);
|
||||
|
||||
firstStart(); // Prüft ob das Programm zuvor gestartet wurde
|
||||
|
||||
dbc.main(); // Startet die Datenbank
|
||||
mwc.initUI(); // Startet die UI
|
||||
mwc.fuelleTablle(); // Ladt die Einträge in die Tabelle
|
||||
|
||||
|
||||
|
||||
// dbc.main(); // Startet die Datenbank
|
||||
|
||||
//mwc.fuelleTablle(); // Ladt die Einträge in die Tabelle
|
||||
|
||||
Scene scene = new Scene(pane);
|
||||
scene.getStylesheets()
|
||||
|
@ -85,30 +87,35 @@ public class Main extends Application
|
|||
{
|
||||
|
||||
if (mwc.loadSettings()) { // Wenn XML gefunden
|
||||
System.out.println("XML gefunden!");
|
||||
mwc.initUI(); // Startet die UI
|
||||
mwc.setDBLabel();
|
||||
dbc.dbname = mwc.getDatabaseName();
|
||||
dbc.verbindeDatenbank(); // Verbindet mit der Datenbank-Datei
|
||||
|
||||
|
||||
|
||||
} else { // Wenn keine XML gefunden --> erster Start
|
||||
System.out.println("keine XML gefunden!");
|
||||
if (System.getProperty("os.name").equals("Linux")) {
|
||||
|
||||
File dir = new File(
|
||||
System.getProperty("user.home") + "/bin/PWMaster"); // Erstellt
|
||||
System.getProperty("user.home") + "/bin/jFxKasse"); // Erstellt
|
||||
// den
|
||||
// Unterordner
|
||||
dir.mkdir(); // Erstellt den Unterordner
|
||||
} else {
|
||||
File dir = new File("C:/ProgramData/PWMaster/"); // Erstellt den
|
||||
File dir = new File("C:/ProgramData/jFxKasse/"); // Erstellt den
|
||||
// Unterordner
|
||||
dir.mkdir(); // Erstellt den Unterordner
|
||||
}
|
||||
|
||||
mwc.saveSettings(schluesselNutzer, "dd"); // speichert das Passwort und
|
||||
// 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
|
||||
//dbc.verbindeDatenbank(); // Verbindet mit der Datenbank-Datei
|
||||
//dbc.erstelleDatenbank(); // Neue Datenbank-Datei wird erstellt
|
||||
//System.exit(0); // Programm wird beendet
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,38 @@
|
|||
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
|
||||
<children>
|
||||
<Button fx:id="ueberbtn" layoutX="664.0" layoutY="325.0" mnemonicParsing="false" onAction="#ueberbtnAction" text="Über" />
|
||||
<TitledPane alignment="CENTER" animated="false" collapsible="false" contentDisplay="CENTER" layoutX="790.0" layoutY="10.0" prefHeight="163.0" prefWidth="566.0" text="Datenbank">
|
||||
<content>
|
||||
<AnchorPane fx:id="paneDB" minHeight="0.0" minWidth="0.0" prefHeight="135.0" prefWidth="547.0">
|
||||
<children>
|
||||
<Label fx:id="labelDBName" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="329.0" layoutY="10.0" prefHeight="34.0" prefWidth="229.0" text="Datenbankname:">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<JFXTextField fx:id="tftNewDBName" alignment="CENTER" layoutX="25.0" layoutY="10.0" prefHeight="25.0" prefWidth="376.0" />
|
||||
<Label fx:id="labelDBStatus" alignment="TOP_RIGHT" contentDisplay="RIGHT" layoutX="7.0" layoutY="50.0" prefHeight="34.0" prefWidth="551.0" text="Keine Datenbank gefunden!">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="18.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<Button fx:id="btnCreateNewDatabase" layoutX="297.0" layoutY="90.0" mnemonicParsing="false" onAction="#btnCreateNewDatabaseAction" text="Neue Datenbank anlegen">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="13.0" />
|
||||
</font>
|
||||
</Button>
|
||||
<Button fx:id="btnOpenFolder" layoutX="39.0" layoutY="90.0" mnemonicParsing="false" onAction="#btnOpenFolderAction" text="Speicherort öffnen">
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="13.0" />
|
||||
</font>
|
||||
</Button>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
<font>
|
||||
<Font name="Cantarell Regular" size="13.0" />
|
||||
</font>
|
||||
</TitledPane>
|
||||
</children>
|
||||
</AnchorPane>
|
||||
</content>
|
||||
|
|
|
@ -14,7 +14,11 @@ 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 com.jfoenix.controls.JFXColorPicker;
|
||||
//import com.sun.java.swing.action.NewAction;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
|
@ -51,6 +55,9 @@ public class MainWindowController
|
|||
@FXML
|
||||
private AnchorPane mainAnchorpane;
|
||||
|
||||
@FXML
|
||||
private AnchorPane paneDB;
|
||||
|
||||
@FXML
|
||||
private TreeTableView<tableData> tableCurrentOrder;
|
||||
|
||||
|
@ -207,6 +214,12 @@ public class MainWindowController
|
|||
@FXML
|
||||
private Button btnClearEntry;
|
||||
|
||||
@FXML
|
||||
private Button btnCreateNewDatabase;
|
||||
|
||||
@FXML
|
||||
private Button btnOpenFolder;
|
||||
|
||||
@FXML
|
||||
private Label labelAllPrize;
|
||||
|
||||
|
@ -234,6 +247,12 @@ public class MainWindowController
|
|||
@FXML
|
||||
private Label lableNewColor;
|
||||
|
||||
@FXML
|
||||
private Label labelDBStatus;
|
||||
|
||||
@FXML
|
||||
private Label labelDBName;
|
||||
|
||||
@FXML
|
||||
private TitledPane titlePaneStats;
|
||||
|
||||
|
@ -243,6 +262,9 @@ public class MainWindowController
|
|||
@FXML
|
||||
private TextField tftNewValue;
|
||||
|
||||
@FXML
|
||||
private TextField tftNewDBName;
|
||||
|
||||
@FXML
|
||||
private JFXColorPicker colorChooser;
|
||||
|
||||
|
@ -250,14 +272,13 @@ public class MainWindowController
|
|||
|
||||
private DBController dbc;
|
||||
|
||||
// Pfad wo die XML liegt
|
||||
private String filepathXMLWin = "C:/ProgramData/PWMaster/config.xml";
|
||||
|
||||
private String filepathXMLLinux = System.getProperty("user.home")
|
||||
+ "/bin/PWMaster/config.xml"; // Pfad wo die XML liegt
|
||||
+ "/bin/jFxKasse/config.xml"; // Pfad wo die XML liegt
|
||||
|
||||
private int id;
|
||||
|
||||
private String databaseName;
|
||||
|
||||
@FXML
|
||||
TreeItem<tableData> root = new TreeItem<>(new tableData(0, "0", "0"));
|
||||
|
||||
|
@ -270,7 +291,8 @@ public class MainWindowController
|
|||
// Erstellt einen Dialog
|
||||
Dialog<Pair<String, String>> dialog = new Dialog<>();
|
||||
dialog.setTitle("Über jFxKasse");
|
||||
dialog.setHeaderText("Informationen und Lizenzen - Version 0.7 - UI Techdemo");
|
||||
dialog.setHeaderText(
|
||||
"Informationen und Lizenzen - Version 0.7 - UI Techdemo");
|
||||
|
||||
// Erzeugt den Button
|
||||
dialog.getDialogPane().getButtonTypes().addAll(ButtonType.OK);
|
||||
|
@ -288,10 +310,42 @@ public class MainWindowController
|
|||
+ " \n(c) 2018 Hendrik Schutter"), 0, 0);
|
||||
|
||||
dialog.getDialogPane().setContent(grid); // Setzt die GridPane auf die
|
||||
dialog.setResizable(true); // DialogPane
|
||||
dialog.setResizable(true); // DialogPane
|
||||
dialog.showAndWait();
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void btnOpenFolderAction(ActionEvent event) throws IOException
|
||||
{
|
||||
Runtime.getRuntime().exec("xdg-open " + System.getProperty("user.home") + "/bin/jFxKasse" );
|
||||
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
try {
|
||||
saveSettings(getDatabaseName());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
setDBLabel();
|
||||
initUI(); // Startet die UI
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
public void btnSaveEntryAction(ActionEvent event)
|
||||
{
|
||||
|
@ -507,11 +561,16 @@ public class MainWindowController
|
|||
|
||||
public void initUI()
|
||||
{
|
||||
System.out.println("initUI");
|
||||
|
||||
tftNewDBName.setText(getDatabaseName());
|
||||
|
||||
tableCurrentOrder.setRoot(root);
|
||||
tableCurrentOrder.setShowRoot(false);
|
||||
tableCurrentOrder.setEditable(false);
|
||||
// Setzt die Textfelder
|
||||
|
||||
/*
|
||||
idSpalte01.setCellValueFactory(
|
||||
cellData -> cellData.getValue().getValue().idProperty().asObject());
|
||||
columnQuantity.setCellValueFactory(
|
||||
|
@ -547,6 +606,8 @@ public class MainWindowController
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
public void setMain(Main main, DBController dbc)
|
||||
|
@ -564,21 +625,16 @@ public class MainWindowController
|
|||
return heutigesDatum;
|
||||
}
|
||||
|
||||
public void saveSettings(String schluessel, String base32Secret)
|
||||
throws Exception
|
||||
public void saveSettings(String databasename) throws Exception
|
||||
{
|
||||
OutputStream outputStream; // new output-stream
|
||||
try {
|
||||
// props.setProperty("key", crypo.verschluesseln(schluessel,
|
||||
// crypo.getProgrammSchluessel())); //writes path into property
|
||||
// props.setProperty("TOTPkey", crypo.verschluesseln(base32Secret,
|
||||
// crypo.getProgrammSchluessel())); //writes path into property
|
||||
if (System.getProperty("os.name").equals("Linux")) {
|
||||
props.setProperty("databasename", databasename); // writes dbname into
|
||||
// property
|
||||
|
||||
outputStream = new FileOutputStream(filepathXMLLinux);
|
||||
} else {
|
||||
outputStream = new FileOutputStream(filepathXMLWin);
|
||||
}
|
||||
props.storeToXML(outputStream, "PWMaster settings"); // writes new .xml
|
||||
|
||||
props.storeToXML(outputStream, "jFxKasse settings"); // writes new .xml
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
@ -588,13 +644,12 @@ public class MainWindowController
|
|||
{ // Ladt die Daten aus der XML
|
||||
InputStream inputStream;
|
||||
try {
|
||||
if (System.getProperty("os.name").equals("Linux")) {
|
||||
|
||||
inputStream = new FileInputStream(filepathXMLLinux);
|
||||
} else {
|
||||
inputStream = new FileInputStream(filepathXMLWin);
|
||||
}
|
||||
|
||||
props.loadFromXML(inputStream);
|
||||
// schluessel = crypo.entschluesseln(props.getProperty("key"),
|
||||
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
|
||||
|
@ -611,10 +666,35 @@ public class MainWindowController
|
|||
dbc.verbindeDatenbank();
|
||||
}
|
||||
|
||||
public void erzeugeDB()
|
||||
{ // Erzeuge die Datenbank
|
||||
dbc.erstelleDatenbank();
|
||||
dbc.verbindeDatenbank();
|
||||
|
||||
|
||||
public String getDatabaseName()
|
||||
{
|
||||
return databaseName;
|
||||
}
|
||||
|
||||
public void setDatabaseName(String NewDatabaseName)
|
||||
{
|
||||
databaseName = NewDatabaseName;
|
||||
}
|
||||
|
||||
public void setDBLabel() throws Exception
|
||||
{
|
||||
if (loadSettings() == true) {
|
||||
labelDBStatus
|
||||
.setText("Geladene Datenbank: " + getDatabaseName() + ".db");
|
||||
btnCreateNewDatabase.setDisable(true);
|
||||
tftNewDBName.setDisable(true);
|
||||
labelDBName.setTooltip(new Tooltip(
|
||||
"Um eine neue Datenbank zu erzeugen muss die vorherige config.xml und "
|
||||
+ getDatabaseName() + ".db gelöscht werden! Anwendung danach neustarten!"));
|
||||
labelDBStatus.setTooltip(new Tooltip(
|
||||
"Um eine neue Datenbank zu erzeugen muss die vorherige config.xml und "
|
||||
+ getDatabaseName() + ".db gelöscht werden! Anwendung danach neustarten!"));
|
||||
} else {
|
||||
labelDBStatus.setText("Keine Datenbank gefunden!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue