Summary Report + Import Map Bugfixes

This commit is contained in:
Georg Reisinger 2021-04-17 01:41:43 +02:00
parent c261652ce6
commit f4e9b16792
6 changed files with 76 additions and 21 deletions

View File

@ -37,13 +37,14 @@ public class Exporter {
/**
* Führt den Imput aus -> File holen, Daten in db erstellen
* @throws FileNotFoundException Fehler beim File öffnen
* @throws IOException Fehler beim File öffnen
*/
public void doImport() throws FileNotFoundException {
public void doImport() throws IOException {
this.touren = JsonHelper.getTourenFromJson(new FileReader(this.path));
DbConnect dbConnect = new DbConnect();
dbConnect.delAllData();
for (Tour tour:this.touren) {
new DirectionMap(tour.getStart(), tour.getZiel(), tour.getName());
dbConnect.addTour(tour);
ArrayList<Log> logs = tour.getLogs();
for (Log log:logs) {

View File

@ -3,6 +3,7 @@ package tourplaner.business;
import com.itextpdf.text.*;
import com.itextpdf.text.Font;
import com.itextpdf.text.Image;
import tourplaner.data.DbConnect;
import tourplaner.object.Log;
import tourplaner.object.Tour;
@ -36,6 +37,59 @@ public class Reporter {
private static Font smallBold = new Font(Font.TIMES_ROMAN, 12,
Font.BOLD);
/**
* Erstellt den Summary Report
*/
public static void sumReport(){
ArrayList<Tour> tours = TourPlaner.getAllTours();
String file = ConfigHelper.getIniString(ConfigHelper.getStandartConfig(), "report", "path") + "summary.pdf";
try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(file));
document.open();
addSumRepo(document, tours);
document.close();
} catch (DocumentException | FileNotFoundException e) {
LogHelper.error(e.getMessage(), e.getClass().getName());
}
FileHelper.openDefault(file);
}
/**
* Content des Sumary reports
* @param document Document auf das geschrieben wird
* @param touren Touren die berechnet werden
* @throws DocumentException Fehler beim schreiben auf das Dokument
*/
private static void addSumRepo(Document document, ArrayList<Tour> touren) throws DocumentException {
double dauer = 0;
double strecke = 0;
double calDauer = 0;
double calStecke = 0;
for (Tour tour:touren) {
calStecke += tour.getStrecke();
calDauer += Double.parseDouble(tour.getDauer());
ArrayList<Log> logs = tour.getLogs();
for (Log log:logs) {
dauer += log.getDauer();
strecke += log.getStrecke();
}
}
Anchor anchor = new Anchor("Zusammengefasster Report", catFont);
anchor.setName("Zusammengefasster Report");
// Second parameter is the number of the chapter
Chapter catPart = new Chapter(new Paragraph(anchor), 1);
Paragraph subPara = new Paragraph("Daten", subFont);
Section subCatPart = catPart.addSection(subPara);
subCatPart.add(new Paragraph(ConfigHelper.getLangIniString("reportvon") + System.getProperty("user.name") + ", " + new Date()));
subCatPart.add(new Paragraph("Gesammte Zeit aller Logs: " + dauer));
subCatPart.add(new Paragraph("gesammte Strecke aller Logs: " + strecke));
subCatPart.add(new Paragraph("Berechnete Zeit aller Logs: " + calDauer));
subCatPart.add(new Paragraph("Berechnete Strecke aller Touren: " + calStecke));
document.add(catPart);
}
/**
* Erstellt einen Tour Report
* @param tourname Name der Tour die Gereportet werden soll

View File

@ -175,13 +175,4 @@ public class TourPlaner{
FileHelper.openDefault(path);
}
/**
* Importiert daten
* @param path Path zu den Daten
* @throws FileNotFoundException File konnte nicht geöffnet werden
*/
public static void importData(String path) throws FileNotFoundException {
Exporter exporter = new Exporter(path);
exporter.doImport();
}
}

View File

@ -52,12 +52,12 @@
<items>
<MenuItem mnemonicParsing="false" onAction="#importBtn" text="Import" />
<MenuItem mnemonicParsing="false" onAction="#exportBtn" text="Export" />
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
<MenuItem mnemonicParsing="false" onAction="#reportSum" text="Report alles" />
<MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Optionen">
<items>
<MenuItem mnemonicParsing="false" onAction="#tourReport" text="Tour Report erstellen" />
<MenuItem mnemonicParsing="false" onAction="#nimpButton" text="Keine Funktion" />
</items>
</Menu>

View File

@ -230,17 +230,22 @@ public class TourplanerController implements Initializable {
}
@FXML
public void exportBtn(){
private void exportBtn(){
this.viewModel.exportData();
}
@FXML
public void importBtn(){
private void importBtn(){
deselectAll();
this.viewModel.importData();
syncTourNamen();
}
@FXML
private void reportSum(){
this.viewModel.sumReport();
}
/**
* Funktion für noch nicht implementierte sachen wie im Menu der 'Bearbeiten' und 'Optionen' Knopf
*/

View File

@ -3,11 +3,8 @@ package tourplaner.viewmodels;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.image.Image;
import tourplaner.business.Exporter;
import tourplaner.business.TourPlaner;
import tourplaner.business.*;
import tourplaner.ui.AlertHelper;
import tourplaner.business.ConfigHelper;
import tourplaner.business.LogHelper;
import tourplaner.object.Log;
import tourplaner.object.Tour;
@ -604,17 +601,24 @@ public class ViewModel {
/**
* Importiert alle daten von einem File das hier gewählt wird
*/
public void importData(){
public void importData() {
String file = AlertHelper.fileChooser("Importiere");
System.out.println("IMPORT: " + file);
if (file != null){
try {
this.tourNamen = FXCollections.observableArrayList();
new Exporter(file).doImport();
} catch (FileNotFoundException e) {
} catch (IOException e) {
AlertHelper.error("Error", "Import Error", "Fehler beim Importieren");
LogHelper.error(e);
}
}
}
/**
* Erstellt einen Summary Report
*/
public void sumReport(){
Reporter.sumReport();
}
}