avgJobValue is now correct

This commit is contained in:
Hendrik Schutter 2018-12-03 21:50:41 +01:00
parent 244243f07a
commit 279f358392
2 changed files with 82 additions and 91 deletions

View File

@ -526,6 +526,24 @@ public class DBController
return "0"; return "0";
} }
} }
public String getJobCount()
{ // Gibt den Nutzernamen zurück
try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery(
"SELECT count(*) AS JOBCOUNT FROM jobs WHERE state = "
+ '"' + "verbucht" + '"' + ";");
return rs.getString("JOBCOUNT");
} catch (SQLException e) {
System.err.println("Couldn't handle DB-Query");
e.printStackTrace();
return "0";
}
}
public void setStatus_Jobs(int pID, String pStatus) public void setStatus_Jobs(int pID, String pStatus)
{ // Setzt das Konto { // Setzt das Konto

View File

@ -24,8 +24,6 @@ import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Properties; import java.util.Properties;
import com.jfoenix.controls.JFXTextField; import com.jfoenix.controls.JFXTextField;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
@ -44,7 +42,6 @@ import com.jFxKasse.datatypes.tableDataCurrentOrder;
import com.jFxKasse.datatypes.tableDataJob; import com.jFxKasse.datatypes.tableDataJob;
import com.jFxKasse.datatypes.tableDataPositionen; import com.jFxKasse.datatypes.tableDataPositionen;
public class MainWindowController public class MainWindowController
{ {
@ -399,34 +396,30 @@ public class MainWindowController
@FXML @FXML
public void btnCreateNewDatabaseAction(ActionEvent event) throws Exception public void btnCreateNewDatabaseAction(ActionEvent event) throws Exception
{ {
if(!(tftNewDBName.getText().equals(""))) {
setDatabaseName(tftNewDBName.getText());
dbc.dbname = getDatabaseName();
dbc.connectDatabase(); // establish DB connection
dbc.createTablePositionen(); // Create new table
dbc.erstelleTabelleJobs(); // Create new table
dbc.createTableCategory(); // Create new table
try {
saveSettings(getDatabaseName());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setDBLabel(); // Set new databese labels
blockUI(false); // unlock UI elements that need DB
fillTablePositionen(); // fill TreeTable 'Positionen'
fillCategory();
initUI(); // Starting the UI elements
getSelectedCat();
createNewJob();
btnLock.setDisable(false); if (!(tftNewDBName.getText().equals(""))) {
setDatabaseName(tftNewDBName.getText());
dbc.dbname = getDatabaseName();
dbc.connectDatabase(); // establish DB connection
dbc.createTablePositionen(); // Create new table
dbc.erstelleTabelleJobs(); // Create new table
dbc.createTableCategory(); // Create new table
try {
saveSettings(getDatabaseName());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
setDBLabel(); // Set new databese labels
blockUI(false); // unlock UI elements that need DB
fillTablePositionen(); // fill TreeTable 'Positionen'
fillCategory();
initUI(); // Starting the UI elements
getSelectedCat();
createNewJob();
btnLock.setDisable(false);
} }
} }
@ -459,27 +452,24 @@ public class MainWindowController
@FXML @FXML
public void btnCalcStatsAction(ActionEvent event) public void btnCalcStatsAction(ActionEvent event)
{ {
// System.out.println(dbc.getAllJobValue_Job());
System.out.println(dbc.getAllJobValue_Job());
int allActiveJobs = Integer.valueOf(dbc.getJobCount());
if(dbc.getAllJobValue_Job() != null) {
if (dbc.getAllJobValue_Job() != null) {
// summed up values of all jobs that are active
float allValue = Float.valueOf(dbc.getAllJobValue_Job()); float allValue = Float.valueOf(dbc.getAllJobValue_Job());
float avgJobValue = ((float) allValue / dbc.getLatestJobNumber_Job()); // count of all jobs that are active
setJobStatLabel(dbc.getLatestJobNumber_Job(), avgJobValue, allValue); float avgJobValue = ((float) allValue / allActiveJobs);
}else {
setJobStatLabel(dbc.getLatestJobNumber_Job(), 0, 0); setJobStatLabel(allActiveJobs, avgJobValue, allValue);
} else {
setJobStatLabel(allActiveJobs, 0, 0);
} }
titlePaneStats.setVisible(true); titlePaneStats.setVisible(true);
} }
@FXML @FXML
@ -742,28 +732,22 @@ public class MainWindowController
rootPositionen.getChildren().size()); rootPositionen.getChildren().size());
for (int i = 0; i < dbc.ladeTabellePositionen().size(); i++) { for (int i = 0; i < dbc.ladeTabellePositionen().size(); i++) {
float fValue = Float
float fValue = Float.valueOf(dbc.ladeTabellePositionen().get(i).getValue()); .valueOf(dbc.ladeTabellePositionen().get(i).getValue());
String strValue = String.format("%.02f", fValue); String strValue = String.format("%.02f", fValue);
strValue.replace('.', ','); strValue.replace('.', ',');
tableDataPositionen helpTableData = new tableDataPositionen( tableDataPositionen helpTableData = new tableDataPositionen(
dbc.ladeTabellePositionen().get(i).getID(), dbc.ladeTabellePositionen().get(i).getID(),
dbc.ladeTabellePositionen().get(i).getName(), dbc.ladeTabellePositionen().get(i).getName(),
(strValue + "") (strValue + "")
, ,
dbc.getCategoryNameFromPositionen(i + 1), dbc.getCategoryNameFromPositionen(i + 1),
getColorNames(dbc.ladeTabellePositionen().get(i).getColor())); getColorNames(dbc.ladeTabellePositionen().get(i).getColor()));
rootPositionen.getChildren() rootPositionen.getChildren()
@ -849,13 +833,14 @@ public class MainWindowController
entryTreeTable.setRoot(rootPositionen); entryTreeTable.setRoot(rootPositionen);
entryTreeTable.setShowRoot(false); entryTreeTable.setShowRoot(false);
entryTreeTable.setEditable(false); entryTreeTable.setEditable(false);
columnPosnumber.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); columnPosnumber
columnPositionsEdit.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); .setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;");
columnPositionsEdit
.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;");
columnPrize.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); columnPrize.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;");
columnCat.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); columnCat.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;");
columnColor.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;"); columnColor.setStyle("-fx-alignment: CENTER; -fx-font: 17px Cantarell;");
ObservableList<String> color = FXCollections.observableArrayList("Rot", ObservableList<String> color = FXCollections.observableArrayList("Rot",
"Orange", "Braun", "Weiß", "Gelb", "Gr\u00fcn", "Blau", "Indigo"); "Orange", "Braun", "Weiß", "Gelb", "Gr\u00fcn", "Blau", "Indigo");
@ -915,21 +900,16 @@ public class MainWindowController
} }
}); });
tftNewValue.textProperty().addListener(new ChangeListener<String>() { tftNewValue.textProperty().addListener(new ChangeListener<String>() {
@Override @Override
public void changed(ObservableValue<? extends String> observable, public void changed(ObservableValue<? extends String> observable,
String oldValue, String newValue) String oldValue, String newValue)
{ {
if (!newValue.matches("\\d{0,4}([\\.]\\d{0,2})?")) { if (!newValue.matches("\\d{0,4}([\\.]\\d{0,2})?")) {
tftNewValue.setText(oldValue); tftNewValue.setText(oldValue);
} }
} }
}); });
@ -1141,10 +1121,10 @@ public class MainWindowController
labelAllPrize.setVisible(!pState); labelAllPrize.setVisible(!pState);
labelJobCounter.setVisible(!pState); labelJobCounter.setVisible(!pState);
if(pState) { if (pState) {
titlePaneStats.setVisible(!pState); titlePaneStats.setVisible(!pState);
} }
titledPaneEntry.setDisable(pState); titledPaneEntry.setDisable(pState);
titlePaneCat.setDisable(pState); titlePaneCat.setDisable(pState);
@ -1179,7 +1159,6 @@ public class MainWindowController
} }
} }
public Button getButtonByID(int pID) public Button getButtonByID(int pID)
{ {
@ -1238,7 +1217,6 @@ public class MainWindowController
return gridButton01; return gridButton01;
} }
} }
private void handelGridButtons(int pID) private void handelGridButtons(int pID)
{ {
@ -1262,7 +1240,6 @@ public class MainWindowController
setJobPrizeLabel(currentJob.getJobValue()); setJobPrizeLabel(currentJob.getJobValue());
} }
private void initCurrentOrderTreeTableView() private void initCurrentOrderTreeTableView()
{ {
@ -1300,7 +1277,6 @@ public class MainWindowController
}); });
} }
private void initJobTreeTableView() private void initJobTreeTableView()
{ {
@ -1345,14 +1321,13 @@ public class MainWindowController
{ {
selectedJobId = jobsTreeTable.getSelectionModel() selectedJobId = jobsTreeTable.getSelectionModel()
.getSelectedIndex(); // get selected item .getSelectedIndex(); // get selected item
if(dbc.getState_Job(selectedJobId+1).equals("storniert")) { if (dbc.getState_Job(selectedJobId + 1).equals("storniert")) {
btnCancelJob.setDisable(true); btnCancelJob.setDisable(true);
}else { } else {
btnCancelJob.setDisable(false); btnCancelJob.setDisable(false);
} }
} }
}); });
@ -1395,7 +1370,6 @@ public class MainWindowController
labelJobCounter.setText("Auftragsnummer: " labelJobCounter.setText("Auftragsnummer: "
+ String.valueOf(dbc.getLatestJobNumber_Job() + 1)); + String.valueOf(dbc.getLatestJobNumber_Job() + 1));
} }
private static String createJobDescription(String pNames, String pQuantities) private static String createJobDescription(String pNames, String pQuantities)
{ {
@ -1415,7 +1389,6 @@ public class MainWindowController
} }
return tmp; return tmp;
} }
private void setJobPrizeLabel(float pPrize) private void setJobPrizeLabel(float pPrize)
{ {
@ -1441,8 +1414,9 @@ public class MainWindowController
str.replace('.', ','); str.replace('.', ',');
labelAllValue.setText("Gesamt: " + str + ""); labelAllValue.setText("Gesamt: " + str + "");
titlePaneStats.setText("Statistik - " + getSystemTime() + " " + getSystemDate()); titlePaneStats
.setText("Statistik - " + getSystemTime() + " " + getSystemDate());
} }
@ -1451,7 +1425,6 @@ public class MainWindowController
labelTime.setText("Uhrzeit: " + getSystemTime()); labelTime.setText("Uhrzeit: " + getSystemTime());
} }
public void blockUnlock() public void blockUnlock()
{ {