job in DB

This commit is contained in:
Hendrik Schutter 2018-10-05 13:01:42 +02:00
parent 5f1b0d9ae1
commit 1c640de416
4 changed files with 256 additions and 77 deletions

View File

@ -75,7 +75,7 @@ class DBController
return true; return true;
} }
} }
public String getCategoryNameFromPositionen(int pID) public String getCategoryNameFromPositionen(int pID)
{ {
// System.out.println("getCategoryName: " + pID); // System.out.println("getCategoryName: " + pID);
@ -373,7 +373,6 @@ class DBController
} }
} }
// table Jobs section // // table Jobs section //
public void erstelleTabelleJobs() public void erstelleTabelleJobs()
{ // Erstelle Tabelle mit Reihen { // Erstelle Tabelle mit Reihen
@ -382,28 +381,57 @@ class DBController
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
stmt.executeUpdate("DROP TABLE IF EXISTS jobs;"); stmt.executeUpdate("DROP TABLE IF EXISTS jobs;");
stmt.executeUpdate( stmt.executeUpdate(
"CREATE TABLE jobs (jobid, time, positionen_name, positionen_value, positionen_cat, state, jobvalue);"); "CREATE TABLE jobs (jobid, time, positionen_quantity, positionen_name, positionen_value, positionen_cat, state, jobvalue);");
} catch (SQLException e) { } catch (SQLException e) {
System.err.println("Couldn't handle DB-Query"); System.err.println("Couldn't handle DB-Query");
e.printStackTrace(); e.printStackTrace();
} }
} }
public int getLatestJobNumber_Job() { public int getLatestJobNumber_Job()
{
try { try {
Statement stmt = connection.createStatement(); Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery( ResultSet rs = stmt.executeQuery(
"SELECT jobid from jobs ORDER BY jobid DESC LIMIT 1;"); "SELECT jobid from jobs ORDER BY jobid DESC LIMIT 1;");
return rs.getInt("jobid"); return rs.getInt("jobid");
} catch (SQLException e) { } catch (SQLException e) {
//System.err.println("Couldn't handle DB-Query"); // System.err.println("Couldn't handle DB-Query");
//e.printStackTrace(); // e.printStackTrace();
} }
System.out.println("XXXXXXXXXXX 1 XXXXXXXXXXX"); System.out.println("XXXXXXXXXXX 0 XXXXXXXXXXX");
return 1; return 0;
}
public void fillJobs_Jobs(int pID, String pTime, String pPositionen_quantity, String pPositionen_name,
String pPositionen_value, String pPositionen_cat, String pState,
String pJobvalue)
{
System.out.println("Create new Job Entry");
try {
PreparedStatement ps = connection
.prepareStatement("INSERT INTO jobs VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
ps.setInt(1, pID); // primary
ps.setString(2, pTime);
ps.setString(3, pPositionen_quantity);
ps.setString(4, pPositionen_name);
ps.setString(5, pPositionen_value);
ps.setString(6, pPositionen_cat);
ps.setString(7, pState);
ps.setString(8, pJobvalue);
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();
}
} }
} }

View File

@ -7,7 +7,7 @@ public class Job
private int jobnumber; private int jobnumber;
private int jobvalue; private float jobvalue;
private String jobtime; private String jobtime;
@ -19,30 +19,49 @@ public class Job
private ArrayList<String> positionenCat; private ArrayList<String> positionenCat;
public Job(int pJobnumber) public Job(int pJobnumber, String pTime)
{ {
this.jobnumber = pJobnumber; this.jobnumber = pJobnumber;
System.out.println("Neuer Job: " + this.jobnumber); this.jobtime = pTime;
System.out
.println("Neuer Job: " + this.jobnumber + " Time: " + this.jobtime);
positionenQuantity = new ArrayList<Integer>(); positionenQuantity = new ArrayList<Integer>();
positionenName = new ArrayList<String>(); positionenName = new ArrayList<String>();
positionenValue = new ArrayList<Float>(); positionenValue = new ArrayList<Float>();
positionenCat = new ArrayList<String>(); positionenCat = new ArrayList<String>();
//System.out.println("Größe: " + positionenName.size()); // System.out.println("Größe: " + positionenName.size());
}
public int getJobnumber()
{
return this.jobnumber;
}
public String getJobtime()
{
return this.jobtime;
}
public float getJobValue()
{
return this.jobvalue;
} }
public void addPosition(String pPositionenName, float pPositionenValue, public void addPosition(String pPositionenName, float pPositionenValue,
String pPositionenCat) String pPositionenCat)
{ {
//System.out.println("addName"); // System.out.println("addName");
for (int i = 0; i < positionenName.size(); i++) { for (int i = 0; i < positionenName.size(); i++) {
if (positionenName.get(i).equals(pPositionenName)) { if (positionenName.get(i).equals(pPositionenName)) {
// Item is already in list, increase quantity // Item is already in list, increase quantity
positionenQuantity.set(i, positionenQuantity.get(i) + 1); positionenQuantity.set(i, positionenQuantity.get(i) + 1);
//System.out.println("Item exists, increasing quantity"); // System.out.println("Item exists, increasing quantity");
return; return;
} }
} }
@ -51,6 +70,8 @@ public class Job
positionenValue.add(pPositionenValue); positionenValue.add(pPositionenValue);
positionenCat.add(pPositionenCat); positionenCat.add(pPositionenCat);
positionenQuantity.add(1); positionenQuantity.add(1);
calcJobValue();
} }
public void printJobOnConsole() public void printJobOnConsole()
@ -60,23 +81,92 @@ public class Job
System.out.println("JobNummer: " + jobnumber); System.out.println("JobNummer: " + jobnumber);
System.out.println("---------------------------------------------"); System.out.println("---------------------------------------------");
//System.out.println("Größe: " + positionenName.size()); // System.out.println("Größe: " + positionenName.size());
for (int i = 0; i < positionenName.size(); i++) { for (int i = 0; i < positionenName.size(); i++) {
System.out.println( System.out.println(
positionenQuantity.get(i) + " " + positionenName.get(i) + " " positionenQuantity.get(i) + " " + positionenName.get(i) + " "
+ positionenValue.get(i) + " " + positionenCat.get(i)); + positionenValue.get(i) + " " + positionenCat.get(i));
/* /*
System.out.println("i is: " + i); * System.out.println("i is: " + i);
System.out.println(positionenName.get(i)); * System.out.println(positionenName.get(i));
System.out.println(positionenQuantity.get(i)); * System.out.println(positionenQuantity.get(i));
*/ */
} }
System.out.println("---------------------------------------------"); System.out.println("---------------------------------------------");
} }
public ArrayList<tableDataCurrentOrder> getCurrentJobPositionen()
{
ArrayList<tableDataCurrentOrder> jobitems = new ArrayList<tableDataCurrentOrder>();
for (int i = 0; i < positionenName.size(); i++) {
tableDataCurrentOrder tmp = new tableDataCurrentOrder(
positionenName.get(i), positionenQuantity.get(i));
jobitems.add(tmp);
}
return jobitems;
}
private void calcJobValue()
{
for (int i = 0; i < positionenValue.size(); i++) {
jobvalue = jobvalue
+ (positionenQuantity.get(i) * positionenValue.get(i));
}
}
public String createPosQuantityDBString()
{
String tmp = "";
for (int i = 0; i < positionenName.size(); i++) {
tmp = tmp + ";" + positionenQuantity.get(i);
}
return tmp;
}
public String createPosNameDBString()
{
String tmp = "";
for (int i = 0; i < positionenName.size(); i++) {
tmp = tmp + ";" + positionenName.get(i);
}
return tmp;
}
public String createPosValueDBString()
{
String tmp = "";
for (int i = 0; i < positionenName.size(); i++) {
tmp = tmp + ";" + positionenValue.get(i);
}
return tmp;
}
public String createPosCatDBString()
{
String tmp = "";
for (int i = 0; i < positionenName.size(); i++) {
tmp = tmp + ";" + positionenCat.get(i);
}
return tmp;
}
} }

View File

@ -79,7 +79,7 @@ public class Main extends Application
mwc.fillCategory(); mwc.fillCategory();
mwc.loadGridButtons(); mwc.loadGridButtons();
mwc.getSelectedCat(); //Load DB entries in Chois Box mwc.getSelectedCat(); //Load DB entries in Chois Box
mwc.createFirstJob(); mwc.createNewJob();
} else { } else {
// config.xml NOT found, first start of app // config.xml NOT found, first start of app
System.out.println("keine XML gefunden!"); System.out.println("keine XML gefunden!");

View File

@ -320,7 +320,7 @@ public class MainWindowController
private String databaseName; private String databaseName;
private boolean lockState = false; private boolean lockState = false;
private boolean isPrintBtnDisabled = true; private boolean isPrintBtnDisabled = true;
private Job currentJob = null; private Job currentJob = null;
@ -330,7 +330,8 @@ public class MainWindowController
new tableDataCurrentOrder("0", 0)); new tableDataCurrentOrder("0", 0));
@FXML @FXML
TreeItem<tableDataCurrentOrder> rootJobs = new TreeItem<>(new tableDataCurrentOrder("0", 0)); TreeItem<tableDataCurrentOrder> rootJobs = new TreeItem<>(
new tableDataCurrentOrder("0", 0));
@FXML @FXML
TreeItem<tableDataPositionen> rootPositionen = new TreeItem<>( TreeItem<tableDataPositionen> rootPositionen = new TreeItem<>(
@ -490,16 +491,27 @@ public class MainWindowController
@FXML @FXML
public void btnPrintBillAction(ActionEvent event) public void btnPrintBillAction(ActionEvent event)
{ {
//System.out.println("Button!"); // System.out.println("Button!");
currentJob.printJobOnConsole(); currentJob.printJobOnConsole();
currentJob = null; currentJob = null;
currentJob = new Job(dbc.getLatestJobNumber_Job()); createNewJob();
btnPrintBill.setDisable(true); btnPrintBill.setDisable(true);
isPrintBtnDisabled = true; isPrintBtnDisabled = true;
rootCurrentJob.getChildren().remove(0,
rootCurrentJob.getChildren().size());
dbc.fillJobs_Jobs(currentJob.getJobnumber(), currentJob.getJobtime(),
currentJob.createPosQuantityDBString(),
currentJob.createPosNameDBString(),
currentJob.createPosValueDBString(),
currentJob.createPosCatDBString(), "verbucht",
String.valueOf(currentJob.getJobValue()));
} }
@FXML @FXML
@ -675,12 +687,21 @@ public class MainWindowController
public void initUI() public void initUI()
{ {
System.out.println("initUI"); System.out.println("initUI");
for (int i = 0; i < 25; i++) {
getButtonByID(i).setVisible(false);
}
tftNewDBName.setText(getDatabaseName()); tftNewDBName.setText(getDatabaseName());
tftKat05.setDisable(true); tftKat05.setDisable(true);
btnPrintBill.setDisable(true); btnPrintBill.setDisable(true);
isPrintBtnDisabled = true; isPrintBtnDisabled = true;
initPositionen(); initPositionen();
initCurrentOrderTreeTableView(); initCurrentOrderTreeTableView();
} }
@ -854,8 +875,16 @@ public class MainWindowController
{ {
DateFormat dateFormat = new SimpleDateFormat("HH:mm"); DateFormat dateFormat = new SimpleDateFormat("HH:mm");
Date date = new Date(); Date date = new Date();
String heutigesDatum = dateFormat.format(date); String time = dateFormat.format(date);
return heutigesDatum; return time;
}
public String getSystemDate()
{
DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
Date date = new Date();
String dateStr = dateFormat.format(date);
return dateStr;
} }
public void saveSettings(String databasename) throws Exception public void saveSettings(String databasename) throws Exception
@ -995,17 +1024,17 @@ public class MainWindowController
btnCalcStats.setDisable(pState); btnCalcStats.setDisable(pState);
btnClearEntry.setDisable(pState); btnClearEntry.setDisable(pState);
btnDeleteSelectedPosition.setDisable(pState); btnDeleteSelectedPosition.setDisable(pState);
if((!isPrintBtnDisabled) && (!pState)) { if ((!isPrintBtnDisabled) && (!pState)) {
// print was not disabled and will be enabled again // print was not disabled and will be enabled again
btnPrintBill.setDisable(pState); btnPrintBill.setDisable(pState);
} }
if(pState) { if (pState) {
// disable allways // disable allways
btnPrintBill.setDisable(pState); btnPrintBill.setDisable(pState);
} }
btnReprintJob.setDisable(pState); btnReprintJob.setDisable(pState);
btnSaveEntry.setDisable(pState); btnSaveEntry.setDisable(pState);
btnCancelJob.setDisable(pState); btnCancelJob.setDisable(pState);
@ -1020,7 +1049,7 @@ public class MainWindowController
catChoise.setDisable(pState); catChoise.setDisable(pState);
tableCurrentOrder.setDisable(pState); tableCurrentOrder.setDisable(pState);
//jobsTreeTable.setDisable(pState); // jobsTreeTable.setDisable(pState);
entryTreeTable.setDisable(pState); entryTreeTable.setDisable(pState);
labelAllPrize.setVisible(!pState); labelAllPrize.setVisible(!pState);
@ -1131,48 +1160,80 @@ public class MainWindowController
btnPrintBill.setDisable(false); btnPrintBill.setDisable(false);
isPrintBtnDisabled = false; isPrintBtnDisabled = false;
tableDataCurrentOrder test01 = new tableDataCurrentOrder("Test", 42); rootCurrentJob.getChildren().remove(0,
rootCurrentJob.getChildren().size());
rootCurrentJob.getChildren().remove(0, for (int i = 0; i < currentJob.getCurrentJobPositionen().size(); i++) {
rootCurrentJob.getChildren().size()); rootCurrentJob.getChildren().add(new TreeItem<tableDataCurrentOrder>(
currentJob.getCurrentJobPositionen().get(i)));
rootCurrentJob.getChildren().add(new TreeItem<tableDataCurrentOrder>(test01)); }
} }
private void initCurrentOrderTreeTableView() { private void initCurrentOrderTreeTableView()
{
columnQuantity.setStyle("-fx-alignment: CENTER;"); columnQuantity.setStyle("-fx-alignment: CENTER;");
columnPosition.setStyle("-fx-alignment: CENTER;"); columnPosition.setStyle("-fx-alignment: CENTER;");
tableCurrentOrder.setRoot(rootCurrentJob); tableCurrentOrder.setRoot(rootCurrentJob);
tableCurrentOrder.setShowRoot(false); tableCurrentOrder.setShowRoot(false);
tableCurrentOrder.setEditable(false); tableCurrentOrder.setEditable(false);
columnQuantity.setCellValueFactory( columnQuantity.setCellValueFactory(cellData -> cellData.getValue()
cellData -> cellData.getValue().getValue().quantityProperty().asObject()); .getValue().quantityProperty().asObject());
columnPosition.setCellValueFactory( columnPosition.setCellValueFactory(
cellData -> cellData.getValue().getValue().positionProperty()); cellData -> cellData.getValue().getValue().positionProperty());
tableCurrentOrder.getSelectionModel().selectedItemProperty()
.addListener(new ChangeListener<Object>() {
@Override
public void changed(ObservableValue<?> observable, Object oldVal,
Object newVal)
{
// last = selected; //for auto-play
int selected = tableCurrentOrder.getSelectionModel()
.getSelectedIndex(); // get selected item
// String currentOrderPosNamr =
// columnPosition.getCellData(selected); // Ausgewählte
// Spalte
System.out.println(
"CurrentOrder - Ausgewaehlte Spalte: " + selected);
try { // Setzt den Inhalt in die Textfelder
/*
*
* tftNewPosition
* .setText(dbc.getName_Positionen(idPositionen));
* tftNewValue.setText(dbc.getValue_Positionen(idPositionen
* )); colorChoise.getSelectionModel().select(
* getColorID(dbc.getColor_Positionen(idPositionen)));
*
* catChoise.getSelectionModel().select(
* dbc.getCategoryNameFromPositionen(idPositionen));
*
*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
} }
public void createNewJob()
public void createFirstJob()
{ {
currentJob = new Job(dbc.getLatestJobNumber_Job()); currentJob = new Job(dbc.getLatestJobNumber_Job() + 1,
getSystemTime() + " " + getSystemDate());
labelJobCounter.setText("Auftragsnummer: "
+ String.valueOf(dbc.getLatestJobNumber_Job() + 1));
} }
public void updateTimeLabel() public void updateTimeLabel()