mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
User is now asked before creating or updating a working day in SQLite database
This commit is contained in:
parent
295f73c4b0
commit
41cfc06b24
@ -10,6 +10,7 @@ import org.nanoboot.utils.timecalc.persistence.api.WorkingDayRepositoryApi;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||||
|
import org.nanoboot.utils.timecalc.utils.common.Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
@ -27,6 +28,9 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi {
|
|||||||
public void create(WorkingDay workingDay) {
|
public void create(WorkingDay workingDay) {
|
||||||
System.out.println("Going to create: " + workingDay.toString());
|
System.out.println("Going to create: " + workingDay.toString());
|
||||||
|
|
||||||
|
if(!Utils.askYesNo(null, "Do you want to create new Working Day? " + workingDay, "Creation of newWorking Day")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb
|
sb
|
||||||
.append("INSERT INTO ")
|
.append("INSERT INTO ")
|
||||||
@ -124,8 +128,12 @@ public class WorkingDayRepositorySQLiteImpl implements WorkingDayRepositoryApi {
|
|||||||
create(workingDay);
|
create(workingDay);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Going to update: " + workingDay.toString());
|
System.out.println("Going to update: " + workingDay.toString());
|
||||||
|
|
||||||
|
if(!Utils.askYesNo(null, "Do you want to update this Working Day? " + workingDay, "Update of Working Day")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb
|
sb
|
||||||
.append("UPDATE ")
|
.append("UPDATE ")
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package org.nanoboot.utils.timecalc.utils.common;
|
package org.nanoboot.utils.timecalc.utils.common;
|
||||||
|
|
||||||
import org.nanoboot.utils.timecalc.app.Main;
|
import org.nanoboot.utils.timecalc.app.Main;
|
||||||
|
import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
||||||
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
import org.nanoboot.utils.timecalc.swing.common.Toaster;
|
||||||
|
|
||||||
|
import javax.swing.JOptionPane;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Component;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -26,8 +29,8 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.Attributes;
|
import java.util.jar.Attributes;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.nanoboot.utils.timecalc.app.TimeCalcException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Robert Vokac
|
* @author Robert Vokac
|
||||||
@ -179,7 +182,7 @@ public class Utils {
|
|||||||
try ( FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap());Stream<Path> stream = Files.walk(fs.getPath(folder))) {
|
try ( FileSystem fs = FileSystems.newFileSystem(uri, Collections.emptyMap());Stream<Path> stream = Files.walk(fs.getPath(folder))) {
|
||||||
result = stream
|
result = stream
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.toList();
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -228,4 +231,19 @@ public class Utils {
|
|||||||
public static void showNotification(Exception e) {
|
public static void showNotification(Exception e) {
|
||||||
showNotification("Error: " + e, 15000, 200);
|
showNotification("Error: " + e, 15000, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean askYesNo(Component frame, String question, String title) {
|
||||||
|
int result = JOptionPane
|
||||||
|
.showConfirmDialog(frame, question,
|
||||||
|
title,
|
||||||
|
JOptionPane.YES_NO_OPTION,
|
||||||
|
JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (result == JOptionPane.YES_OPTION) {
|
||||||
|
return true;
|
||||||
|
} else if (result == JOptionPane.NO_OPTION) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user