Update ServiceDialogController.java
This commit is contained in:
@@ -31,9 +31,6 @@ public class ServiceDialogController {
|
|||||||
@FXML
|
@FXML
|
||||||
private TextField txtServiceDesc;
|
private TextField txtServiceDesc;
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TextField txtServiceDuration;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField txtServiceName;
|
private TextField txtServiceName;
|
||||||
|
|
||||||
@@ -86,29 +83,37 @@ public class ServiceDialogController {
|
|||||||
|
|
||||||
String name = txtServiceName.getText();
|
String name = txtServiceName.getText();
|
||||||
String desc = txtServiceDesc.getText();
|
String desc = txtServiceDesc.getText();
|
||||||
String durationText = txtServiceDuration.getText();
|
|
||||||
String priceText = txtServicePrice.getText();
|
String priceText = txtServicePrice.getText();
|
||||||
|
|
||||||
// Empty checks
|
|
||||||
Integer hours = cbHours.getValue();
|
Integer hours = cbHours.getValue();
|
||||||
Integer minutes = cbMinutes.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) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int duration = (hours * 60) + minutes;
|
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(
|
Service service = new Service(
|
||||||
selectedService == null ? 0 : selectedService.getServiceId(),
|
selectedService == null ? 0 : selectedService.getServiceId(),
|
||||||
@@ -119,6 +124,7 @@ public class ServiceDialogController {
|
|||||||
);
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (mode.equals("Add")) {
|
if (mode.equals("Add")) {
|
||||||
ServiceDB.insertService(service);
|
ServiceDB.insertService(service);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user