xml is now in XMLController

This commit is contained in:
2018-12-05 22:44:15 +01:00
parent 37cfe02c5b
commit 87f9b8786c
5 changed files with 469 additions and 448 deletions

View File

@ -11,14 +11,21 @@ import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.util.Duration;
import com.jFxKasse.controller.MainWindowController;
import com.jFxKasse.controller.XMLController;
import com.jFxKasse.controller.DBController;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
public class Main extends Application
{
private String filepathXMLLinux = System.getProperty("user.home")
+ "/bin/jFxKasse/config.xml"; // Pfad wo die XML liegt
private MainWindowController mwc;
private XMLController xmlc = new XMLController(filepathXMLLinux);
private DBController dbc = new DBController(this);
private Stage primaryStage;
@ -43,7 +50,7 @@ public class Main extends Application
primaryStage.setTitle("jFxKasse"); // Title of window
mwc = loader.getController();
mwc.setMain(this, dbc);
mwc.setMain(this, dbc, xmlc);
firstStart();
@ -75,12 +82,12 @@ public class Main extends Application
*/
private void firstStart() throws Exception
{
if (mwc.loadSettings()) {
if (xmlc.loadSettings()) {
// config.xml found, app starting normal
System.out.println("XML gefunden!");
mwc.initUI(); // Starting the UI elements
mwc.setDBLabel(); // Set databese labels
dbc.dbname = mwc.getDatabaseName(); // handover database name
dbc.setDbname(xmlc.getDatabaseName()); // handover database name
dbc.connectDatabase(); // estabishing DB conection
mwc.fillTablePositionen(); // fill TreeTable 'Positionen'
mwc.fillCategory();
@ -91,10 +98,12 @@ public class Main extends Application
} else {
// config.xml NOT found, first start of app
System.out.println("keine XML gefunden!");
xmlc.initXML(); // set default values
mwc.blockUI(true); // disable UI elements that need DB
mwc.blockUnlock();
File dir = new File(System.getProperty("user.home") + "/bin/jFxKasse");
dir.mkdir(); // Create new Subfolder
}
}
}

View File

@ -21,7 +21,9 @@ public class DBController
private String DB_PATH_Linux = System.getProperty("user.home")
+ "/bin/jFxKasse/";
public String dbname;
private String dbname;
@SuppressWarnings("unused")
private Main main;
@ -41,6 +43,11 @@ public class DBController
{
this.main = main;
}
public void setDbname(String dbname)
{
this.dbname = dbname;
}
public void connectDatabase()
{ // connect to database

View File

@ -22,9 +22,10 @@ import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import com.jfoenix.controls.JFXTextField;
import com.jfoenix.controls.JFXToggleButton;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
@ -32,6 +33,7 @@ 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.Tab;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane;
@ -118,6 +120,18 @@ public class MainWindowController
@FXML
private ChoiceBox<String> catChoise;
@FXML
private ChoiceBox<String> printerChoise;
@FXML
private Spinner<Integer> linesSpinner;
@FXML
private Spinner<Integer> offsetHeaderSpinner;
@FXML
private Spinner<Integer> offsetFooterSpinner;
@FXML
private Button ueberbtn;
@ -196,6 +210,9 @@ public class MainWindowController
@FXML
private Button gridButton25;
@FXML
private Button btnSavePrinter;
@FXML
private Button btnDeleteSelectedPosition;
@ -241,6 +258,12 @@ public class MainWindowController
@FXML
private Label labelCat03;
@FXML
private JFXTextField tftfooter;
@FXML
private JFXTextField tftheader;
@FXML
private JFXTextField tftKat01;
@ -304,6 +327,9 @@ public class MainWindowController
@FXML
private TitledPane titledPaneEntry;
@FXML
private TitledPane titlePanePrint;
@FXML
private TextField tftNewPosition;
@ -313,13 +339,15 @@ public class MainWindowController
@FXML
private TextField tftNewDBName;
@FXML
private JFXToggleButton switchSeparate;
@SuppressWarnings("unused")
private Main main;
private DBController dbc;
private String filepathXMLLinux = System.getProperty("user.home")
+ "/bin/jFxKasse/config.xml"; // Pfad wo die XML liegt
private XMLController xmlc;
private int idPositionen = 0;
@ -327,7 +355,7 @@ public class MainWindowController
private String selectedCatName;
private String databaseName;
private boolean lockState = false;
@ -351,7 +379,7 @@ public class MainWindowController
TreeItem<tableDataPositionen> rootPositionen = new TreeItem<>(
new tableDataPositionen(0, "0", "0", "0", "0"));
Properties props = new Properties();
@FXML
public void ueberbtnAction(ActionEvent event)
@ -400,14 +428,16 @@ public class MainWindowController
if (!(tftNewDBName.getText().equals(""))) {
setDatabaseName(tftNewDBName.getText());
dbc.dbname = getDatabaseName();
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());
//saveSettings(getDatabaseName());
xmlc.saveSettings();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -479,6 +509,12 @@ public class MainWindowController
}
@FXML
public void btnSavePrinterAction(ActionEvent event)
{
System.out.println("btnSavePrinterAction");
}
@FXML
public void btnCancelJobAction(ActionEvent event)
{
@ -568,11 +604,13 @@ public class MainWindowController
System.out.println(currentJob.getJobnumber());
/* TODO */
PrinterController pc = new PrinterController();
pc.searchPrinters();
pc.selectPrinter("CUPS-PDF");
/* TODO */
PrintDataSimple pds = new PrintDataSimple(28, 1, 2,
getSystemTime() + " " + getSystemDate(), "Firma GmbH",
@ -587,7 +625,7 @@ public class MainWindowController
dbc.getJobValue_Job(currentJob.getJobnumber()));
pc.printString(pds.getPrintString());
fillTableJobs();
currentJob = null;
@ -784,7 +822,7 @@ public class MainWindowController
for (int i = 0; i < 25; i++) {
getButtonByID(i).setVisible(false);
}
tftNewDBName.setText(getDatabaseName());
tftNewDBName.setText(xmlc.getDatabaseName());
tftKat05.setDisable(true);
titlePaneStats.setVisible(false);
btnPrintBill.setDisable(true);
@ -952,10 +990,11 @@ public class MainWindowController
}
public void setMain(Main main, DBController dbc)
public void setMain(Main main, DBController dbc, XMLController xmlc)
{
this.main = main;
this.dbc = dbc;
this.xmlc = xmlc;
}
public String getSystemTime()
@ -974,57 +1013,36 @@ public class MainWindowController
return dateStr;
}
public void saveSettings(String databasename) throws Exception
{ // Save settings to config.xml
OutputStream outputStream;
try {
props.setProperty("databasename", databasename);
outputStream = new FileOutputStream(filepathXMLLinux);
props.storeToXML(outputStream, "jFxKasse settings");
outputStream.close();
} catch (IOException e) {
}
}
public boolean loadSettings() throws Exception
{ // reads the settings from config.xml
InputStream inputStream;
try {
inputStream = new FileInputStream(filepathXMLLinux);
props.loadFromXML(inputStream);
setDatabaseName(props.getProperty("databasename"));
inputStream.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
/*
public String getDatabaseName()
{
return databaseName;
return xmlc.getDatabaseName();
}
public void setDatabaseName(String NewDatabaseName)
{
databaseName = NewDatabaseName;
}
*/
public void setDBLabel() throws Exception
{
if (loadSettings() == true) {
if (xmlc.loadSettings() == true) {
labelDBStatus
.setText("Geladene Datenbank: " + getDatabaseName() + ".db");
.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 "
+ getDatabaseName()
+ 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 "
+ getDatabaseName()
+ xmlc.getDatabaseName()
+ ".db gelöscht werden! Anwendung danach neustarten!"));
} else {
labelDBStatus.setText("Keine Datenbank gefunden!");
@ -1150,6 +1168,7 @@ public class MainWindowController
titledPaneEntry.setDisable(pState);
titlePaneCat.setDisable(pState);
titlePanePrint.setDisable(pState);
}

View File

@ -0,0 +1,222 @@
package com.jFxKasse.controller;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
public class XMLController
{
private String databaseName = null;
private String printername = null;
private int linebreak;
private int offsetHeader;
private int offsetFooter;
private String header = null;
private String footer = null;
private boolean categorySplitted;
private String filePath = null;
private Properties props = null;
public XMLController(String filePath)
{
this.filePath = filePath;
props = new Properties();
}
public void saveSettings() throws Exception
{ // Save settings to config.xml
System.out.println("Saving XML");
OutputStream outputStream;
String linebreak = Integer.toString(this.linebreak);
String offsetHeader = Integer.toString(this.offsetHeader);
String offsetFooter = Integer.toString(this.offsetFooter);
String categorySplitted = null;
if (this.categorySplitted) {
categorySplitted = "true";
} else {
categorySplitted = "false";
}
try {
props.setProperty("databasename", this.databaseName);
props.setProperty("printername", this.printername);
props.setProperty("linebreak", linebreak);
props.setProperty("offsetHeader", offsetHeader);
props.setProperty("offsetFooter", offsetFooter);
props.setProperty("header", this.header);
props.setProperty("footer", this.footer);
props.setProperty("categorySplitted", categorySplitted);
outputStream = new FileOutputStream(filePath);
props.storeToXML(outputStream, "jFxKasse settings");
outputStream.close();
} catch (IOException e) {
}
}
public boolean loadSettings() throws Exception
{ // reads the settings from config.xml
InputStream inputStream;
try {
inputStream = new FileInputStream(filePath);
props.loadFromXML(inputStream);
this.databaseName = (props.getProperty("databasename"));
this.printername = (props.getProperty("printername"));
try {
this.linebreak = Integer.valueOf(props.getProperty("linebreak"));
} catch (Exception e) {
this.linebreak = 28;
}
try {
this.offsetHeader = Integer
.valueOf(props.getProperty("offsetHeader"));
} catch (Exception e) {
this.offsetHeader = 1;
}
try {
this.offsetFooter = Integer
.valueOf(props.getProperty("offsetFooter"));
} catch (Exception e) {
this.offsetFooter = 2;
}
this.header = (props.getProperty("header"));
this.footer = (props.getProperty("footer"));
try {
if (props.getProperty("categorySplitted").equals("true")) {
this.categorySplitted = true;
} else {
this.categorySplitted = false;
}
} catch (Exception e) {
this.categorySplitted = false;
}
inputStream.close();
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
public void initXML()
{
this.printername = "CUPS-PDF";
this.offsetHeader = 1;
this.offsetFooter = 2;
this.linebreak = 28;
this.categorySplitted = false;
this.header = "XYZ GmbH";
this.footer = "Vielen Dank für den Einkauf";
}
public String getDatabaseName()
{
return databaseName;
}
public void setDatabaseName(String databaseName)
{
this.databaseName = databaseName;
}
public String getPrintername()
{
return printername;
}
public void setPrintername(String printername)
{
this.printername = printername;
}
public int getLinebreak()
{
return linebreak;
}
public void setLinebreak(int linebreak)
{
this.linebreak = linebreak;
}
public int getOffsetHeader()
{
return offsetHeader;
}
public void setOffsetHeader(int offsetHeader)
{
this.offsetHeader = offsetHeader;
}
public int getOffsetFooter()
{
return offsetFooter;
}
public void setOffsetFooter(int offsetFooter)
{
this.offsetFooter = offsetFooter;
}
public String getHeader()
{
return header;
}
public void setHeader(String header)
{
this.header = header;
}
public String getFooter()
{
return footer;
}
public void setFooter(String footer)
{
this.footer = footer;
}
public boolean getCategorySplitted()
{
return categorySplitted;
}
public void setCategorySplitted(boolean categorySplitted)
{
this.categorySplitted = categorySplitted;
}
}