Update ServiceDialogController.java
This commit is contained in:
@@ -31,9 +31,6 @@ public class ServiceDialogController {
|
||||
@FXML
|
||||
private TextField txtServiceDesc;
|
||||
|
||||
@FXML
|
||||
private TextField txtServiceDuration;
|
||||
|
||||
@FXML
|
||||
private TextField txtServiceName;
|
||||
|
||||
@@ -86,29 +83,37 @@ public class ServiceDialogController {
|
||||
|
||||
String name = txtServiceName.getText();
|
||||
String desc = txtServiceDesc.getText();
|
||||
String durationText = txtServiceDuration.getText();
|
||||
String priceText = txtServicePrice.getText();
|
||||
|
||||
// Empty checks
|
||||
Integer hours = cbHours.getValue();
|
||||
Integer minutes = cbMinutes.getValue();
|
||||
|
||||
// -------- VALIDATION --------
|
||||
if (name == null || name.isBlank()) {
|
||||
showError("Service name is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (priceText == null || priceText.isBlank()) {
|
||||
showError("Price is required.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (hours == null || minutes == null) {
|
||||
showError("Please select hours and minutes.");
|
||||
showError("Please select duration.");
|
||||
return;
|
||||
}
|
||||
|
||||
double price;
|
||||
|
||||
try {
|
||||
price = Double.parseDouble(priceText);
|
||||
} catch (NumberFormatException e) {
|
||||
showError("Price must be numeric.");
|
||||
return;
|
||||
}
|
||||
|
||||
int duration = (hours * 60) + minutes;
|
||||
double price;
|
||||
|
||||
// Number validation
|
||||
try {
|
||||
duration = Integer.parseInt(durationText);
|
||||
price = Double.parseDouble(priceText);
|
||||
} catch (NumberFormatException e) {
|
||||
showError("Duration must be a whole number and Price must be numeric.");
|
||||
return;
|
||||
}
|
||||
|
||||
Service service = new Service(
|
||||
selectedService == null ? 0 : selectedService.getServiceId(),
|
||||
@@ -119,6 +124,7 @@ public class ServiceDialogController {
|
||||
);
|
||||
|
||||
try {
|
||||
|
||||
if (mode.equals("Add")) {
|
||||
ServiceDB.insertService(service);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user