appionmeent,service
This commit is contained in:
110
src/main/java/org/example/petshopdesktop/DTOs/ServiceDTO.java
Normal file
110
src/main/java/org/example/petshopdesktop/DTOs/ServiceDTO.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package org.example.petshopdesktop.DTOs;
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleDoubleProperty;
|
||||||
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
import org.example.petshopdesktop.models.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class for ServiceDTO, all service data stored here
|
||||||
|
*/
|
||||||
|
public class ServiceDTO {
|
||||||
|
|
||||||
|
private SimpleIntegerProperty serviceId;
|
||||||
|
private SimpleStringProperty serviceName;
|
||||||
|
private SimpleStringProperty serviceDesc;
|
||||||
|
private SimpleIntegerProperty serviceDuration;
|
||||||
|
private SimpleDoubleProperty servicePrice;
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
public ServiceDTO(int serviceId,
|
||||||
|
String serviceName,
|
||||||
|
String serviceDesc,
|
||||||
|
int serviceDuration,
|
||||||
|
double servicePrice) {
|
||||||
|
|
||||||
|
this.serviceId = new SimpleIntegerProperty(serviceId);
|
||||||
|
this.serviceName = new SimpleStringProperty(serviceName);
|
||||||
|
this.serviceDesc = new SimpleStringProperty(serviceDesc);
|
||||||
|
this.serviceDuration = new SimpleIntegerProperty(serviceDuration);
|
||||||
|
this.servicePrice = new SimpleDoubleProperty(servicePrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
// getters & setters
|
||||||
|
|
||||||
|
public int getServiceId() {
|
||||||
|
return serviceId.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleIntegerProperty serviceIdProperty() {
|
||||||
|
return serviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceId(int serviceId) {
|
||||||
|
this.serviceId.set(serviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceName() {
|
||||||
|
return serviceName.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty serviceNameProperty() {
|
||||||
|
return serviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceName(String serviceName) {
|
||||||
|
this.serviceName.set(serviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceDesc() {
|
||||||
|
return serviceDesc.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty serviceDescProperty() {
|
||||||
|
return serviceDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceDesc(String serviceDesc) {
|
||||||
|
this.serviceDesc.set(serviceDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getServiceDuration() {
|
||||||
|
return serviceDuration.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleIntegerProperty serviceDurationProperty() {
|
||||||
|
return serviceDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceDuration(int serviceDuration) {
|
||||||
|
this.serviceDuration.set(serviceDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getServicePrice() {
|
||||||
|
return servicePrice.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleDoubleProperty servicePriceProperty() {
|
||||||
|
return servicePrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServicePrice(double servicePrice) {
|
||||||
|
this.servicePrice.set(servicePrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts DTO into Service model (for edit/delete)
|
||||||
|
*/
|
||||||
|
public Service toService() {
|
||||||
|
|
||||||
|
Service service = new Service(
|
||||||
|
getServiceId(),
|
||||||
|
getServiceName(),
|
||||||
|
getServiceDesc(),
|
||||||
|
getServiceDuration(),
|
||||||
|
getServicePrice()
|
||||||
|
);
|
||||||
|
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,9 +6,39 @@ import javafx.scene.control.Button;
|
|||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import org.example.petshopdesktop.database.AppointmentDB;
|
||||||
|
import org.example.petshopdesktop.models.Appointment;
|
||||||
|
|
||||||
|
|
||||||
public class AppointmentController {
|
public class AppointmentController {
|
||||||
|
|
||||||
|
|
||||||
|
private ObservableList<Appointment> appointments =
|
||||||
|
FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
|
||||||
|
|
||||||
|
public void initialize() {
|
||||||
|
loadAppointments();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private void loadAppointments() {
|
||||||
|
appointments.setAll(AppointmentDB.getAllAppointments());
|
||||||
|
tvAppointments.setItems(appointments);
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button btnAdd;
|
private Button btnAdd;
|
||||||
|
|
||||||
@@ -40,7 +70,7 @@ public class AppointmentController {
|
|||||||
private TableColumn<?, ?> colServiceName;
|
private TableColumn<?, ?> colServiceName;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TableView<?> tvAppointments;
|
private TableView<Appointment> tvAppointments;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private TextField txtSearch;
|
private TextField txtSearch;
|
||||||
@@ -48,16 +78,61 @@ public class AppointmentController {
|
|||||||
@FXML
|
@FXML
|
||||||
void btnAddClicked(ActionEvent event) {
|
void btnAddClicked(ActionEvent event) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
FXMLLoader loader = new FXMLLoader(
|
||||||
|
getClass().getResource("/appointment-dialog-view.fxml")
|
||||||
|
);
|
||||||
|
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.setScene(new Scene(loader.load()));
|
||||||
|
stage.showAndWait();
|
||||||
|
|
||||||
|
loadAppointments();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void btnDeleteClicked(ActionEvent event) {
|
void btnDeleteClicked(ActionEvent event) {
|
||||||
|
|
||||||
|
Appointment selected = tvAppointments.getSelectionModel().getSelectedItem();
|
||||||
|
|
||||||
|
if (selected == null) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
AppointmentDB.deleteAppointment(
|
||||||
|
selected.getAppointmentId()
|
||||||
|
);
|
||||||
|
loadAppointments();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void btnEditClicked(ActionEvent event) {
|
void btnEditClicked(ActionEvent event) {
|
||||||
|
|
||||||
|
Appointment selected = tvAppointments.getSelectionModel().getSelectedItem();
|
||||||
|
|
||||||
|
if (selected == null) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
FXMLLoader loader = new FXMLLoader(
|
||||||
|
getClass().getResource("/appointment-dialog-view.fxml")
|
||||||
|
);
|
||||||
|
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.setScene(new Scene(loader.load()));
|
||||||
|
stage.showAndWait();
|
||||||
|
|
||||||
|
loadAppointments();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,56 +2,123 @@ package org.example.petshopdesktop.controllers;
|
|||||||
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.control.Button;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.TextField;
|
import javafx.scene.control.*;
|
||||||
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import org.example.petshopdesktop.database.ServiceDB;
|
||||||
|
import org.example.petshopdesktop.models.Service;
|
||||||
|
import org.example.petshopdesktop.controllers.dialogcontrollers.ServiceDialogController;
|
||||||
|
|
||||||
public class ServiceController {
|
public class ServiceController {
|
||||||
|
|
||||||
@FXML
|
@FXML private Button btnAdd;
|
||||||
private Button btnAdd;
|
@FXML private Button btnDelete;
|
||||||
|
@FXML private Button btnEdit;
|
||||||
|
|
||||||
|
@FXML private TableColumn<Service, Integer> colServiceId;
|
||||||
|
@FXML private TableColumn<Service, String> colServiceName;
|
||||||
|
@FXML private TableColumn<Service, String> colServiceDesc;
|
||||||
|
@FXML private TableColumn<Service, Integer> colServiceDuration;
|
||||||
|
@FXML private TableColumn<Service, Double> colServicePrice;
|
||||||
|
|
||||||
|
@FXML private TableView<Service> tvServices;
|
||||||
|
|
||||||
|
@FXML private TextField txtSearch;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private Button btnDelete;
|
public void initialize() {
|
||||||
|
|
||||||
@FXML
|
colServiceId.setCellValueFactory(new PropertyValueFactory<>("serviceId"));
|
||||||
private Button btnEdit;
|
colServiceName.setCellValueFactory(new PropertyValueFactory<>("serviceName"));
|
||||||
|
colServiceDesc.setCellValueFactory(new PropertyValueFactory<>("serviceDesc"));
|
||||||
|
colServiceDuration.setCellValueFactory(new PropertyValueFactory<>("serviceDuration"));
|
||||||
|
colServicePrice.setCellValueFactory(new PropertyValueFactory<>("servicePrice"));
|
||||||
|
|
||||||
@FXML
|
loadServices();
|
||||||
private TableColumn<?, ?> colServiceDesc;
|
}
|
||||||
|
|
||||||
@FXML
|
private void loadServices() {
|
||||||
private TableColumn<?, ?> colServiceDuration;
|
try {
|
||||||
|
tvServices.setItems(ServiceDB.getServices());
|
||||||
|
} catch (Exception e) {
|
||||||
|
showAlert("Database Error", "Unable to load services.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TableColumn<?, ?> colServiceId;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TableColumn<?, ?> colServiceName;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TableColumn<?, ?> colServicePrice;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TableView<?> tvServices;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private TextField txtSearch;
|
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void btnAddClicked(ActionEvent event) {
|
void btnAddClicked(ActionEvent event) {
|
||||||
|
openDialog(null);
|
||||||
}
|
loadServices();
|
||||||
|
|
||||||
@FXML
|
|
||||||
void btnDeleteClicked(ActionEvent event) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
void btnEditClicked(ActionEvent event) {
|
void btnEditClicked(ActionEvent event) {
|
||||||
|
|
||||||
|
Service selected = tvServices.getSelectionModel().getSelectedItem();
|
||||||
|
|
||||||
|
if (selected == null) {
|
||||||
|
showAlert("Select Service", "Please select a service to edit.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
openDialog(selected);
|
||||||
|
loadServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@FXML
|
||||||
|
void btnDeleteClicked(ActionEvent event) {
|
||||||
|
|
||||||
|
Service selected = tvServices.getSelectionModel().getSelectedItem();
|
||||||
|
|
||||||
|
if (selected == null) {
|
||||||
|
showAlert("Select Service", "Please select a service to delete.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
ServiceDB.deleteService(selected.getServiceId());
|
||||||
|
loadServices();
|
||||||
|
} catch (Exception e) {
|
||||||
|
showAlert("Database Error", "Unable to delete service.");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openDialog(Service service) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
FXMLLoader loader = new FXMLLoader(
|
||||||
|
getClass().getResource(
|
||||||
|
"/org.example.petshopdesktop/dialogviews/ServiceDialogView.fxml"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
Parent root = loader.load();
|
||||||
|
|
||||||
|
// IMPORTANT: specify controller type
|
||||||
|
ServiceDialogController controller =
|
||||||
|
loader.getController();
|
||||||
|
|
||||||
|
controller.setService(service);
|
||||||
|
|
||||||
|
Stage stage = new Stage();
|
||||||
|
stage.setScene(new Scene(root));
|
||||||
|
stage.showAndWait();
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void showAlert(String title, String msg) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.INFORMATION);
|
||||||
|
alert.setTitle(title);
|
||||||
|
alert.setHeaderText(null);
|
||||||
|
alert.setContentText(msg);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package org.example.petshopdesktop.controllers.dialogcontrollers;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.DatePicker;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import org.example.petshopdesktop.database.AppointmentDB;
|
||||||
|
import org.example.petshopdesktop.models.Appointment;
|
||||||
|
|
||||||
|
import java.sql.Time;
|
||||||
|
|
||||||
|
public class AppointmentDialogController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button btnCancel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button btnSave;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ComboBox<String> cbAppointmentStatus;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ComboBox<Time> cbAppointmentTime;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ComboBox<?> cbCustomer;
|
||||||
|
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ComboBox<?> cbService;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private DatePicker dpAppointmentDate;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label lblAppointmentId;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label lblMode;
|
||||||
|
|
||||||
|
private String mode = null; //Used to determine add or edit mode
|
||||||
|
|
||||||
|
//Used to populate status combo box
|
||||||
|
private ObservableList<String> statusList = FXCollections.observableArrayList(
|
||||||
|
"Booked", "Completed", "Cancelled"
|
||||||
|
);
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
void initialize() {
|
||||||
|
cbAppointmentStatus.setItems(statusList); //populate status combo box
|
||||||
|
|
||||||
|
//Set up mouse handlers for buttons
|
||||||
|
btnSave.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(MouseEvent mouseEvent) {
|
||||||
|
buttonSaveClicked(mouseEvent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
btnCancel.setOnMouseClicked(new EventHandler<MouseEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(MouseEvent mouseEvent) {
|
||||||
|
closeStage(mouseEvent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSaveClicked(MouseEvent mouseEvent) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
int serviceId = 1; // temporary
|
||||||
|
int customerId = 1; // temporary
|
||||||
|
int petId = 1; // temporary
|
||||||
|
|
||||||
|
Appointment appointment = new Appointment(
|
||||||
|
serviceId,
|
||||||
|
customerId,
|
||||||
|
petId,
|
||||||
|
dpAppointmentDate.getValue(),
|
||||||
|
cbAppointmentTime.getValue(),
|
||||||
|
cbAppointmentStatus.getValue()
|
||||||
|
);
|
||||||
|
|
||||||
|
AppointmentDB.addAppointment(appointment);
|
||||||
|
|
||||||
|
closeStage(mouseEvent);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeStage(MouseEvent mouseEvent) {
|
||||||
|
Node node = (Node) mouseEvent.getSource();
|
||||||
|
Stage stage = (Stage) node.getScene().getWindow();
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package org.example.petshopdesktop.controllers.dialogcontrollers;
|
||||||
|
|
||||||
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.Node;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.Label;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import org.example.petshopdesktop.database.ServiceDB;
|
||||||
|
import org.example.petshopdesktop.models.Service;
|
||||||
|
|
||||||
|
public class ServiceDialogController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button btnCancel;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button btnSave;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label lblMode;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Label lblServiceId;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField txtServiceDesc;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField txtServiceDuration;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField txtServiceName;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField txtServicePrice;
|
||||||
|
|
||||||
|
private Service service; // holds selected service
|
||||||
|
|
||||||
|
// This method is called from ServiceController
|
||||||
|
public void setService(Service service) {
|
||||||
|
|
||||||
|
this.service = service;
|
||||||
|
|
||||||
|
if (service == null) {
|
||||||
|
lblMode.setText("Add Service");
|
||||||
|
lblServiceId.setText("New");
|
||||||
|
} else {
|
||||||
|
lblMode.setText("Edit Service");
|
||||||
|
lblServiceId.setText("ID: " + service.getServiceId());
|
||||||
|
|
||||||
|
txtServiceName.setText(service.getServiceName());
|
||||||
|
txtServiceDesc.setText(service.getServiceDesc());
|
||||||
|
txtServiceDuration.setText(
|
||||||
|
String.valueOf(service.getServiceDuration()));
|
||||||
|
txtServicePrice.setText(
|
||||||
|
String.valueOf(service.getServicePrice()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void buttonSaveClicked(MouseEvent mouseEvent) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (service == null) {
|
||||||
|
service = new Service(0, "", "", 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
service.setServiceName(txtServiceName.getText());
|
||||||
|
service.setServiceDesc(txtServiceDesc.getText());
|
||||||
|
service.setServiceDuration(
|
||||||
|
Integer.parseInt(txtServiceDuration.getText()));
|
||||||
|
service.setServicePrice(
|
||||||
|
Double.parseDouble(txtServicePrice.getText()));
|
||||||
|
|
||||||
|
if (service.getServiceId() == 0) {
|
||||||
|
ServiceDB.insertService(service);
|
||||||
|
} else {
|
||||||
|
ServiceDB.updateService(service.getServiceId(), service);
|
||||||
|
}
|
||||||
|
|
||||||
|
closeStage(mouseEvent);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void closeStage(MouseEvent mouseEvent) {
|
||||||
|
Node node = (Node) mouseEvent.getSource();
|
||||||
|
Stage stage = (Stage) node.getScene().getWindow();
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
package org.example.petshopdesktop.database;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import org.example.petshopdesktop.models.Appointment;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class AppointmentDB {
|
||||||
|
|
||||||
|
public static ObservableList<Appointment> getAllAppointments() {
|
||||||
|
|
||||||
|
ObservableList<Appointment> list = FXCollections.observableArrayList();
|
||||||
|
String sql = "SELECT * FROM appointment";
|
||||||
|
|
||||||
|
try (Connection conn = ConnectionDB.getConnection();
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery(sql)) {
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
|
||||||
|
Appointment a = new Appointment(
|
||||||
|
rs.getInt("appointmentId"),
|
||||||
|
rs.getInt("serviceId"),
|
||||||
|
rs.getInt("customerId"),
|
||||||
|
rs.getDate("appointmentDate").toLocalDate(),
|
||||||
|
rs.getTime("appointmentTime"),
|
||||||
|
rs.getString("appointmentStatus")
|
||||||
|
);
|
||||||
|
|
||||||
|
list.add(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void addAppointment(Appointment a) throws SQLException {
|
||||||
|
|
||||||
|
String sql =
|
||||||
|
"INSERT INTO appointment " +
|
||||||
|
"(petId, serviceId, customerId, appointmentDate, appointmentTime, appointmentStatus) " +
|
||||||
|
"VALUES (?, ?, ?, ?, ?, ?)";
|
||||||
|
|
||||||
|
try (Connection conn = ConnectionDB.getConnection();
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
|
||||||
|
stmt.setInt(1, a.getPetId());
|
||||||
|
stmt.setInt(2, a.getServiceId());
|
||||||
|
stmt.setInt(3, a.getCustomerId());
|
||||||
|
stmt.setDate(4, Date.valueOf(a.getAppointmentDate()));
|
||||||
|
stmt.setTime(5, a.getAppointmentTime());
|
||||||
|
stmt.setString(6, a.getAppointmentStatus());
|
||||||
|
|
||||||
|
stmt.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteAppointment(int id) throws SQLException {
|
||||||
|
|
||||||
|
String sql = "DELETE FROM appointment WHERE appointmentId=?";
|
||||||
|
|
||||||
|
try (Connection conn = ConnectionDB.getConnection();
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
|
||||||
|
stmt.setInt(1, id);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
120
src/main/java/org/example/petshopdesktop/database/ServiceDB.java
Normal file
120
src/main/java/org/example/petshopdesktop/database/ServiceDB.java
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
package org.example.petshopdesktop.database;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import org.example.petshopdesktop.models.Service;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A class containing all the methods relating to CRUD on Services table
|
||||||
|
*/
|
||||||
|
public class ServiceDB {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets all the services into an observable list
|
||||||
|
* @return a list of all the services
|
||||||
|
* @throws SQLException if failed to find services in the database
|
||||||
|
*/
|
||||||
|
public static ObservableList<Service> getServices() throws SQLException {
|
||||||
|
|
||||||
|
ObservableList<Service> services = FXCollections.observableArrayList();
|
||||||
|
Connection conn = ConnectionDB.getConnection();
|
||||||
|
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery("SELECT * FROM services");
|
||||||
|
|
||||||
|
while (rs.next()) {
|
||||||
|
|
||||||
|
Service service = new Service(
|
||||||
|
rs.getInt(1), // service_id
|
||||||
|
rs.getString(2),// service_name
|
||||||
|
rs.getString(3),// description
|
||||||
|
rs.getInt(4), // duration
|
||||||
|
rs.getDouble(5)// price
|
||||||
|
);
|
||||||
|
|
||||||
|
services.add(service);
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.close();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a new service to the database
|
||||||
|
*/
|
||||||
|
public static int insertService(Service service) throws SQLException {
|
||||||
|
|
||||||
|
int numRows;
|
||||||
|
|
||||||
|
Connection conn = ConnectionDB.getConnection();
|
||||||
|
|
||||||
|
String sql =
|
||||||
|
"INSERT INTO services (service_name, description, duration, price) " +
|
||||||
|
"VALUES (?, ?, ?, ?)";
|
||||||
|
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||||
|
|
||||||
|
stmt.setString(1, service.getServiceName());
|
||||||
|
stmt.setString(2, service.getServiceDesc());
|
||||||
|
stmt.setInt(3, service.getServiceDuration());
|
||||||
|
stmt.setDouble(4, service.getServicePrice());
|
||||||
|
|
||||||
|
numRows = stmt.executeUpdate();
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
return numRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update existing service
|
||||||
|
*/
|
||||||
|
public static int updateService(int serviceId, Service service) throws SQLException {
|
||||||
|
|
||||||
|
int numRows;
|
||||||
|
|
||||||
|
Connection conn = ConnectionDB.getConnection();
|
||||||
|
|
||||||
|
String sql =
|
||||||
|
"UPDATE services SET " +
|
||||||
|
" service_name = ?, " +
|
||||||
|
" description = ?, " +
|
||||||
|
" duration = ?, " +
|
||||||
|
" price = ? " +
|
||||||
|
" WHERE service_id = ?";
|
||||||
|
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||||
|
|
||||||
|
stmt.setString(1, service.getServiceName());
|
||||||
|
stmt.setString(2, service.getServiceDesc());
|
||||||
|
stmt.setInt(3, service.getServiceDuration());
|
||||||
|
stmt.setDouble(4, service.getServicePrice());
|
||||||
|
stmt.setInt(5, serviceId);
|
||||||
|
|
||||||
|
numRows = stmt.executeUpdate();
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
return numRows;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a service
|
||||||
|
*/
|
||||||
|
public static int deleteService(int serviceId) throws SQLException {
|
||||||
|
|
||||||
|
int numRows;
|
||||||
|
|
||||||
|
Connection conn = ConnectionDB.getConnection();
|
||||||
|
|
||||||
|
String sql = "DELETE FROM services WHERE service_id = ?";
|
||||||
|
|
||||||
|
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||||
|
stmt.setInt(1, serviceId);
|
||||||
|
|
||||||
|
numRows = stmt.executeUpdate();
|
||||||
|
conn.close();
|
||||||
|
|
||||||
|
return numRows;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package org.example.petshopdesktop.models;
|
||||||
|
|
||||||
|
import javafx.beans.property.*;
|
||||||
|
import java.sql.Time;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
public class Appointment {
|
||||||
|
|
||||||
|
private final SimpleIntegerProperty appointmentId;
|
||||||
|
private final SimpleIntegerProperty serviceId;
|
||||||
|
private final SimpleIntegerProperty customerId;
|
||||||
|
private SimpleIntegerProperty petId = null;
|
||||||
|
private final ObjectProperty<LocalDate> appointmentDate;
|
||||||
|
private final ObjectProperty<Time> appointmentTime;
|
||||||
|
private final SimpleStringProperty appointmentStatus;
|
||||||
|
|
||||||
|
public Appointment(int appointmentId,
|
||||||
|
int serviceId,
|
||||||
|
int customerId,
|
||||||
|
LocalDate date,
|
||||||
|
Time time,
|
||||||
|
String status) {
|
||||||
|
|
||||||
|
this.appointmentId = new SimpleIntegerProperty(appointmentId);
|
||||||
|
this.serviceId = new SimpleIntegerProperty(serviceId);
|
||||||
|
this.customerId = new SimpleIntegerProperty(customerId);
|
||||||
|
this.petId = new SimpleIntegerProperty();
|
||||||
|
this.appointmentDate = new SimpleObjectProperty<>(date);
|
||||||
|
this.appointmentTime = new SimpleObjectProperty<>(time);
|
||||||
|
this.appointmentStatus = new SimpleStringProperty(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAppointmentId() { return appointmentId.get(); }
|
||||||
|
public int getServiceId() { return serviceId.get(); }
|
||||||
|
public int getCustomerId() { return customerId.get(); }
|
||||||
|
public int getPetId() { return petId.get(); }
|
||||||
|
public LocalDate getAppointmentDate() { return appointmentDate.get(); }
|
||||||
|
public Time getAppointmentTime() { return appointmentTime.get(); }
|
||||||
|
public String getAppointmentStatus() { return appointmentStatus.get(); }
|
||||||
|
}
|
||||||
98
src/main/java/org/example/petshopdesktop/models/Service.java
Normal file
98
src/main/java/org/example/petshopdesktop/models/Service.java
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
package org.example.petshopdesktop.models;
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleDoubleProperty;
|
||||||
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The class for the entity of services (contains all data relating to services)
|
||||||
|
*/
|
||||||
|
public class Service {
|
||||||
|
|
||||||
|
private SimpleIntegerProperty serviceId;
|
||||||
|
private SimpleStringProperty serviceName;
|
||||||
|
private SimpleStringProperty serviceDesc;
|
||||||
|
private SimpleIntegerProperty serviceDuration;
|
||||||
|
private SimpleDoubleProperty servicePrice;
|
||||||
|
|
||||||
|
// constructor
|
||||||
|
public Service(int serviceId,
|
||||||
|
String serviceName,
|
||||||
|
String serviceDesc,
|
||||||
|
int serviceDuration,
|
||||||
|
double servicePrice) {
|
||||||
|
|
||||||
|
this.serviceId = new SimpleIntegerProperty(serviceId);
|
||||||
|
this.serviceName = new SimpleStringProperty(serviceName);
|
||||||
|
this.serviceDesc = new SimpleStringProperty(serviceDesc);
|
||||||
|
this.serviceDuration = new SimpleIntegerProperty(serviceDuration);
|
||||||
|
this.servicePrice = new SimpleDoubleProperty(servicePrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
// getters & setters
|
||||||
|
|
||||||
|
public int getServiceId() {
|
||||||
|
return serviceId.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleIntegerProperty serviceIdProperty() {
|
||||||
|
return serviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceId(int serviceId) {
|
||||||
|
this.serviceId.set(serviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceName() {
|
||||||
|
return serviceName.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty serviceNameProperty() {
|
||||||
|
return serviceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceName(String serviceName) {
|
||||||
|
this.serviceName.set(serviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServiceDesc() {
|
||||||
|
return serviceDesc.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty serviceDescProperty() {
|
||||||
|
return serviceDesc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceDesc(String serviceDesc) {
|
||||||
|
this.serviceDesc.set(serviceDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getServiceDuration() {
|
||||||
|
return serviceDuration.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleIntegerProperty serviceDurationProperty() {
|
||||||
|
return serviceDuration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServiceDuration(int serviceDuration) {
|
||||||
|
this.serviceDuration.set(serviceDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getServicePrice() {
|
||||||
|
return servicePrice.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleDoubleProperty servicePriceProperty() {
|
||||||
|
return servicePrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServicePrice(double servicePrice) {
|
||||||
|
this.servicePrice.set(servicePrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getServiceName();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,13 +13,18 @@
|
|||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
<?import javafx.scene.text.Font?>
|
<?import javafx.scene.text.Font?>
|
||||||
|
|
||||||
<VBox minHeight="-Infinity" minWidth="-Infinity" prefHeight="523.0" prefWidth="790.0" spacing="20.0" style="-fx-font-size: 14px;" xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.example.petshopdesktop.controllers.dialogcontrollers.AppointmentDialogController">
|
<VBox minHeight="-Infinity" minWidth="-Infinity" prefHeight="523.0" prefWidth="790.0"
|
||||||
|
spacing="20.0" style="-fx-font-size: 14px;"
|
||||||
|
xmlns="http://javafx.com/javafx/25" xmlns:fx="http://javafx.com/fxml/1"
|
||||||
|
fx:controller="org.example.petshopdesktop.controllers.dialogcontrollers.AppointmentDialogController">
|
||||||
<children>
|
<children>
|
||||||
<HBox alignment="CENTER_LEFT" prefHeight="79.0" prefWidth="727.0" spacing="20.0" style="-fx-background-color: #2C3E50; -fx-background-radius: 14;">
|
<HBox alignment="CENTER_LEFT" prefHeight="79.0" prefWidth="727.0" spacing="20.0"
|
||||||
|
style="-fx-background-color: #2C3E50; -fx-background-radius: 14;">
|
||||||
<children>
|
<children>
|
||||||
<VBox alignment="CENTER_LEFT" prefHeight="93.0" prefWidth="299.0">
|
<VBox alignment="CENTER_LEFT" prefHeight="93.0" prefWidth="299.0">
|
||||||
<children>
|
<children>
|
||||||
<Label fx:id="lblMode" prefHeight="42.0" prefWidth="275.0" text="Mode Appointment" textFill="WHITE">
|
<Label fx:id="lblMode" prefHeight="42.0" prefWidth="275.0" text="Mode Appointment"
|
||||||
|
textFill="WHITE">
|
||||||
<font>
|
<font>
|
||||||
<Font name="Comic Sans MS Bold" size="30.0" />
|
<Font name="Comic Sans MS Bold" size="30.0" />
|
||||||
</font>
|
</font>
|
||||||
|
|||||||
Reference in New Issue
Block a user