Appointment page
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package org.example.petshopdesktop.DTOs;
|
||||
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
public class AppointmentDTO {
|
||||
|
||||
private SimpleIntegerProperty appointmentId;
|
||||
|
||||
private SimpleIntegerProperty customerId;
|
||||
private SimpleStringProperty customerName;
|
||||
|
||||
private SimpleIntegerProperty petId;
|
||||
private SimpleStringProperty petName;
|
||||
|
||||
private SimpleIntegerProperty serviceId;
|
||||
private SimpleStringProperty serviceName;
|
||||
|
||||
private SimpleStringProperty appointmentDate;
|
||||
private SimpleStringProperty appointmentTime;
|
||||
private SimpleStringProperty appointmentStatus;
|
||||
|
||||
// Constructor
|
||||
public AppointmentDTO(int appointmentId,
|
||||
int customerId, String customerName,
|
||||
int petId, String petName,
|
||||
int serviceId, String serviceName,
|
||||
String appointmentDate,
|
||||
String appointmentTime,
|
||||
String appointmentStatus) {
|
||||
|
||||
this.appointmentId = new SimpleIntegerProperty(appointmentId);
|
||||
this.customerId = new SimpleIntegerProperty(customerId);
|
||||
this.customerName = new SimpleStringProperty(customerName);
|
||||
this.petId = new SimpleIntegerProperty(petId);
|
||||
this.petName = new SimpleStringProperty(petName);
|
||||
this.serviceId = new SimpleIntegerProperty(serviceId);
|
||||
this.serviceName = new SimpleStringProperty(serviceName);
|
||||
this.appointmentDate = new SimpleStringProperty(appointmentDate);
|
||||
this.appointmentTime = new SimpleStringProperty(appointmentTime);
|
||||
this.appointmentStatus = new SimpleStringProperty(appointmentStatus);
|
||||
}
|
||||
|
||||
// Getters
|
||||
public int getAppointmentId() { return appointmentId.get(); }
|
||||
|
||||
public int getCustomerId() { return customerId.get(); }
|
||||
public String getCustomerName() { return customerName.get(); }
|
||||
|
||||
public int getPetId() { return petId.get(); }
|
||||
public String getPetName() { return petName.get(); }
|
||||
|
||||
public int getServiceId() { return serviceId.get(); }
|
||||
public String getServiceName() { return serviceName.get(); }
|
||||
|
||||
public String getAppointmentDate() { return appointmentDate.get(); }
|
||||
public String getAppointmentTime() { return appointmentTime.get(); }
|
||||
public String getAppointmentStatus() { return appointmentStatus.get(); }
|
||||
}
|
||||
@@ -1,138 +1,135 @@
|
||||
package org.example.petshopdesktop.controllers;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.stage.Modality;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.example.petshopdesktop.DTOs.AppointmentDTO;
|
||||
import org.example.petshopdesktop.controllers.dialogcontrollers.AppointmentDialogController;
|
||||
import org.example.petshopdesktop.database.AppointmentDB;
|
||||
import org.example.petshopdesktop.models.Appointment;
|
||||
|
||||
|
||||
public class AppointmentController {
|
||||
|
||||
@FXML private TableView<AppointmentDTO> tvAppointments;
|
||||
|
||||
private ObservableList<Appointment> appointments =
|
||||
FXCollections.observableArrayList();
|
||||
@FXML private TableColumn<AppointmentDTO,Integer> colAppointmentId;
|
||||
@FXML private TableColumn<AppointmentDTO,String> colPetName;
|
||||
@FXML private TableColumn<AppointmentDTO,String> colServiceName;
|
||||
@FXML private TableColumn<AppointmentDTO,String> colAppointmentDate;
|
||||
@FXML private TableColumn<AppointmentDTO,String> colAppointmentTime;
|
||||
@FXML private TableColumn<AppointmentDTO,String> colCustomerName;
|
||||
@FXML private TableColumn<AppointmentDTO,String> colAppointmentStatus;
|
||||
|
||||
@FXML private Button btnAdd;
|
||||
@FXML private Button btnEdit;
|
||||
@FXML private Button btnDelete;
|
||||
|
||||
@FXML private TextField txtSearch;
|
||||
|
||||
private ObservableList<AppointmentDTO> data = FXCollections.observableArrayList();
|
||||
|
||||
@FXML
|
||||
public void initialize(){
|
||||
|
||||
colAppointmentId.setCellValueFactory(new PropertyValueFactory<>("appointmentId"));
|
||||
colPetName.setCellValueFactory(new PropertyValueFactory<>("petName"));
|
||||
colServiceName.setCellValueFactory(new PropertyValueFactory<>("serviceName"));
|
||||
colAppointmentDate.setCellValueFactory(new PropertyValueFactory<>("appointmentDate"));
|
||||
colAppointmentTime.setCellValueFactory(new PropertyValueFactory<>("appointmentTime"));
|
||||
colCustomerName.setCellValueFactory(new PropertyValueFactory<>("customerName"));
|
||||
colAppointmentStatus.setCellValueFactory(new PropertyValueFactory<>("appointmentStatus"));
|
||||
|
||||
public void initialize() {
|
||||
loadAppointments();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void loadAppointments() {
|
||||
appointments.setAll(AppointmentDB.getAllAppointments());
|
||||
tvAppointments.setItems(appointments);
|
||||
private void loadAppointments(){
|
||||
try{
|
||||
data = AppointmentDB.getAppointmentDTOs();
|
||||
tvAppointments.setItems(data);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private Button btnAdd;
|
||||
void btnAddClicked(ActionEvent event){
|
||||
openDialog(null, "Add");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private Button btnDelete;
|
||||
void btnEditClicked(ActionEvent event){
|
||||
|
||||
AppointmentDTO selected =
|
||||
tvAppointments.getSelectionModel().getSelectedItem();
|
||||
|
||||
if(selected == null){
|
||||
showAlert("Select Appointment", "Please select appointment to edit.");
|
||||
return;
|
||||
}
|
||||
|
||||
openDialog(selected, "Edit");
|
||||
}
|
||||
|
||||
@FXML
|
||||
private Button btnEdit;
|
||||
void btnDeleteClicked(ActionEvent event){
|
||||
|
||||
@FXML
|
||||
private TableColumn<?, ?> colAppointmentDate;
|
||||
AppointmentDTO selected =
|
||||
tvAppointments.getSelectionModel().getSelectedItem();
|
||||
|
||||
@FXML
|
||||
private TableColumn<?, ?> colAppointmentId;
|
||||
if(selected == null) return;
|
||||
|
||||
@FXML
|
||||
private TableColumn<?, ?> colAppointmentStatus;
|
||||
try{
|
||||
AppointmentDB.deleteAppointment(selected.getAppointmentId());
|
||||
loadAppointments();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
private TableColumn<?, ?> colAppointmentTime;
|
||||
private void openDialog(AppointmentDTO appt, String mode){
|
||||
|
||||
@FXML
|
||||
private TableColumn<?, ?> colCustomerName;
|
||||
|
||||
@FXML
|
||||
private TableColumn<?, ?> colPetName;
|
||||
|
||||
@FXML
|
||||
private TableColumn<?, ?> colServiceName;
|
||||
|
||||
@FXML
|
||||
private TableView<Appointment> tvAppointments;
|
||||
|
||||
@FXML
|
||||
private TextField txtSearch;
|
||||
|
||||
@FXML
|
||||
void btnAddClicked(ActionEvent event) {
|
||||
|
||||
try {
|
||||
try{
|
||||
FXMLLoader loader = new FXMLLoader(
|
||||
getClass().getResource("/appointment-dialog-view.fxml")
|
||||
getClass().getResource(
|
||||
"/org/example/petshopdesktop/dialogviews/appointment-dialog-view.fxml"
|
||||
)
|
||||
);
|
||||
|
||||
Scene scene = new Scene(loader.load());
|
||||
|
||||
AppointmentDialogController controller =
|
||||
loader.getController();
|
||||
|
||||
controller.setMode(mode);
|
||||
|
||||
if(mode.equals("Edit")){
|
||||
controller.displayAppointmentDetails(appt);
|
||||
}
|
||||
|
||||
Stage stage = new Stage();
|
||||
stage.setScene(new Scene(loader.load()));
|
||||
stage.initModality(Modality.APPLICATION_MODAL);
|
||||
stage.setScene(scene);
|
||||
stage.showAndWait();
|
||||
|
||||
loadAppointments();
|
||||
|
||||
} catch (Exception e) {
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
void btnDeleteClicked(ActionEvent event) {
|
||||
|
||||
Appointment selected = tvAppointments.getSelectionModel().getSelectedItem();
|
||||
|
||||
if (selected == null) return;
|
||||
|
||||
try {
|
||||
AppointmentDB.deleteAppointment(
|
||||
selected.getAppointmentId()
|
||||
);
|
||||
loadAppointments();
|
||||
} 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();
|
||||
}
|
||||
|
||||
@FXML
|
||||
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,110 +2,208 @@ 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.control.*;
|
||||
import javafx.scene.input.MouseEvent;
|
||||
import javafx.stage.Stage;
|
||||
import javafx.scene.control.ListCell;
|
||||
|
||||
import org.example.petshopdesktop.database.AppointmentDB;
|
||||
import org.example.petshopdesktop.models.Appointment;
|
||||
import org.example.petshopdesktop.DTOs.AppointmentDTO;
|
||||
import org.example.petshopdesktop.database.*;
|
||||
import org.example.petshopdesktop.models.*;
|
||||
|
||||
import java.sql.Time;
|
||||
|
||||
public class AppointmentDialogController {
|
||||
|
||||
@FXML
|
||||
private Button btnCancel;
|
||||
// ============================
|
||||
// FXML
|
||||
// ============================
|
||||
|
||||
@FXML
|
||||
private Button btnSave;
|
||||
@FXML private Button btnCancel;
|
||||
@FXML private Button btnSave;
|
||||
|
||||
@FXML
|
||||
private ComboBox<String> cbAppointmentStatus;
|
||||
@FXML private ComboBox<Service> cbService;
|
||||
@FXML private ComboBox<Customer> cbCustomer;
|
||||
@FXML private ComboBox<Pet> cbPet;
|
||||
|
||||
@FXML
|
||||
private ComboBox<Time> cbAppointmentTime;
|
||||
@FXML private ComboBox<Integer> cbHour;
|
||||
@FXML private ComboBox<Integer> cbMinute;
|
||||
|
||||
@FXML
|
||||
private ComboBox<?> cbCustomer;
|
||||
@FXML private ComboBox<String> cbAppointmentStatus;
|
||||
@FXML private DatePicker dpAppointmentDate;
|
||||
|
||||
@FXML private Label lblAppointmentId;
|
||||
@FXML private Label lblMode;
|
||||
|
||||
@FXML
|
||||
private ComboBox<?> cbService;
|
||||
// ============================
|
||||
// DATA
|
||||
// ============================
|
||||
|
||||
@FXML
|
||||
private DatePicker dpAppointmentDate;
|
||||
private String mode = null; // Add | Edit
|
||||
private AppointmentDTO selectedAppointment = null;
|
||||
|
||||
@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()
|
||||
private ObservableList<String> statusList =
|
||||
FXCollections.observableArrayList(
|
||||
"Booked", "Completed", "Cancelled"
|
||||
);
|
||||
|
||||
AppointmentDB.addAppointment(appointment);
|
||||
//
|
||||
// MODE
|
||||
//
|
||||
|
||||
closeStage(mouseEvent);
|
||||
public void setMode(String mode) {
|
||||
this.mode = mode;
|
||||
lblMode.setText(mode + " Appointment");
|
||||
lblAppointmentId.setVisible(!mode.equals("Add"));
|
||||
}
|
||||
|
||||
//
|
||||
// INITIALIZE
|
||||
//
|
||||
|
||||
@FXML
|
||||
public void initialize() {
|
||||
|
||||
try {
|
||||
cbService.setItems(ServiceDB.getServices());
|
||||
cbCustomer.setItems(CustomerDB.getCustomers());
|
||||
cbPet.setItems(PetDB.getPets());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
cbAppointmentStatus.setItems(statusList);
|
||||
|
||||
// Hours 9 AM - 5 PM
|
||||
for (int i = 9; i <= 17; i++) {
|
||||
cbHour.getItems().add(i);
|
||||
}
|
||||
|
||||
cbMinute.getItems().addAll(0, 15, 30, 45);
|
||||
|
||||
// Show pet name
|
||||
cbPet.setCellFactory(param -> new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(Pet pet, boolean empty) {
|
||||
super.updateItem(pet, empty);
|
||||
setText(empty || pet == null ? null : pet.getPetName());
|
||||
}
|
||||
});
|
||||
|
||||
cbPet.setButtonCell(new ListCell<>() {
|
||||
@Override
|
||||
protected void updateItem(Pet pet, boolean empty) {
|
||||
super.updateItem(pet, empty);
|
||||
setText(empty || pet == null ? null : pet.getPetName());
|
||||
}
|
||||
});
|
||||
|
||||
btnSave.setOnMouseClicked(this::buttonSaveClicked);
|
||||
btnCancel.setOnMouseClicked(this::closeStage);
|
||||
}
|
||||
|
||||
private void closeStage(MouseEvent mouseEvent) {
|
||||
Node node = (Node) mouseEvent.getSource();
|
||||
Stage stage = (Stage) node.getScene().getWindow();
|
||||
//
|
||||
// DISPLAY FOR EDIT
|
||||
//
|
||||
|
||||
public void displayAppointmentDetails(AppointmentDTO appt) {
|
||||
|
||||
selectedAppointment = appt;
|
||||
lblAppointmentId.setText("ID: " + appt.getAppointmentId());
|
||||
|
||||
dpAppointmentDate.setValue(
|
||||
java.time.LocalDate.parse(appt.getAppointmentDate())
|
||||
);
|
||||
|
||||
cbAppointmentStatus.setValue(appt.getAppointmentStatus());
|
||||
|
||||
Time time = Time.valueOf(appt.getAppointmentTime());
|
||||
cbHour.setValue(time.toLocalTime().getHour());
|
||||
cbMinute.setValue(time.toLocalTime().getMinute());
|
||||
|
||||
cbService.getItems().forEach(s -> {
|
||||
if (s.getServiceId() == appt.getServiceId()) cbService.setValue(s);
|
||||
});
|
||||
|
||||
cbCustomer.getItems().forEach(c -> {
|
||||
if (c.getCustomerId() == appt.getCustomerId()) cbCustomer.setValue(c);
|
||||
});
|
||||
|
||||
cbPet.getItems().forEach(p -> {
|
||||
if (p.getPetId() == appt.getPetId()) cbPet.setValue(p);
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// SAVE
|
||||
//
|
||||
|
||||
private void buttonSaveClicked(MouseEvent e) {
|
||||
|
||||
if (cbService.getValue() == null ||
|
||||
cbCustomer.getValue() == null ||
|
||||
cbPet.getValue() == null ||
|
||||
dpAppointmentDate.getValue() == null ||
|
||||
cbHour.getValue() == null ||
|
||||
cbMinute.getValue() == null ||
|
||||
cbAppointmentStatus.getValue() == null) {
|
||||
|
||||
showError("All fields are required");
|
||||
return;
|
||||
}
|
||||
|
||||
Time appointmentTime =
|
||||
Time.valueOf(String.format(
|
||||
"%02d:%02d:00",
|
||||
cbHour.getValue(),
|
||||
cbMinute.getValue()
|
||||
));
|
||||
|
||||
Appointment appt = new Appointment(
|
||||
selectedAppointment == null ? 0 : selectedAppointment.getAppointmentId(),
|
||||
cbService.getValue().getServiceId(),
|
||||
cbCustomer.getValue().getCustomerId(),
|
||||
dpAppointmentDate.getValue().toString(),
|
||||
appointmentTime.toString(),
|
||||
cbAppointmentStatus.getValue()
|
||||
);
|
||||
|
||||
try {
|
||||
|
||||
if (mode.equals("Add")) {
|
||||
int newId = AppointmentDB.insertAppointment(appt);
|
||||
AppointmentDB.insertAppointmentPet(newId, cbPet.getValue().getPetId());
|
||||
} else {
|
||||
AppointmentDB.updateAppointment(
|
||||
selectedAppointment.getAppointmentId(),
|
||||
appt,
|
||||
cbPet.getValue().getPetId()
|
||||
);
|
||||
}
|
||||
|
||||
closeStage(e);
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
showError("Error saving appointment");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// UTIL
|
||||
//
|
||||
|
||||
private void closeStage(MouseEvent e) {
|
||||
Stage stage = (Stage) ((Node) e.getSource()).getScene().getWindow();
|
||||
stage.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void showError(String msg) {
|
||||
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||
alert.setHeaderText("Input Error");
|
||||
alert.setContentText(msg);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
@@ -2,72 +2,192 @@ package org.example.petshopdesktop.database;
|
||||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
import org.example.petshopdesktop.DTOs.AppointmentDTO;
|
||||
import org.example.petshopdesktop.models.Appointment;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class AppointmentDB {
|
||||
|
||||
public static ObservableList<Appointment> getAllAppointments() {
|
||||
// ============================
|
||||
// GET ALL APPOINTMENTS
|
||||
// ============================
|
||||
public static ObservableList<AppointmentDTO> getAppointmentDTOs()
|
||||
throws SQLException {
|
||||
|
||||
ObservableList<Appointment> list = FXCollections.observableArrayList();
|
||||
String sql = "SELECT * FROM appointment";
|
||||
ObservableList<AppointmentDTO> list =
|
||||
FXCollections.observableArrayList();
|
||||
|
||||
try (Connection conn = ConnectionDB.getConnection();
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql)) {
|
||||
Connection conn = ConnectionDB.getConnection();
|
||||
|
||||
while (rs.next()) {
|
||||
String sql = """
|
||||
SELECT a.appointmentId,
|
||||
c.customerId,
|
||||
CONCAT(c.firstName,' ',c.lastName) AS customerName,
|
||||
p.petId,
|
||||
p.petName,
|
||||
s.serviceId,
|
||||
s.serviceName,
|
||||
a.appointmentDate,
|
||||
a.appointmentTime,
|
||||
a.appointmentStatus
|
||||
FROM appointment a
|
||||
JOIN customer c ON a.customerId = c.customerId
|
||||
JOIN appointmentPet ap ON a.appointmentId = ap.appointmentId
|
||||
JOIN pet p ON ap.petId = p.petId
|
||||
JOIN service s ON a.serviceId = s.serviceId
|
||||
""";
|
||||
|
||||
Appointment a = new Appointment(
|
||||
rs.getInt("appointmentId"),
|
||||
rs.getInt("serviceId"),
|
||||
rs.getInt("customerId"),
|
||||
rs.getDate("appointmentDate").toLocalDate(),
|
||||
rs.getTime("appointmentTime"),
|
||||
rs.getString("appointmentStatus")
|
||||
);
|
||||
Statement stmt = conn.createStatement();
|
||||
ResultSet rs = stmt.executeQuery(sql);
|
||||
|
||||
list.add(a);
|
||||
}
|
||||
while (rs.next()) {
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
AppointmentDTO dto = new AppointmentDTO(
|
||||
rs.getInt("appointmentId"),
|
||||
|
||||
rs.getInt("customerId"),
|
||||
rs.getString("customerName"),
|
||||
|
||||
rs.getInt("petId"),
|
||||
rs.getString("petName"),
|
||||
|
||||
rs.getInt("serviceId"),
|
||||
rs.getString("serviceName"),
|
||||
|
||||
rs.getString("appointmentDate"),
|
||||
rs.getString("appointmentTime"),
|
||||
rs.getString("appointmentStatus")
|
||||
);
|
||||
|
||||
list.add(dto);
|
||||
}
|
||||
|
||||
conn.close();
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void addAppointment(Appointment a) throws SQLException {
|
||||
// ============================
|
||||
// INSERT APPOINTMENT
|
||||
// ============================
|
||||
public static int insertAppointment(Appointment appt)
|
||||
throws SQLException {
|
||||
|
||||
Connection conn = ConnectionDB.getConnection();
|
||||
|
||||
String sql = """
|
||||
INSERT INTO appointment
|
||||
(serviceId, customerId, appointmentDate,
|
||||
appointmentTime, appointmentStatus)
|
||||
VALUES (?,?,?,?,?)
|
||||
""";
|
||||
|
||||
PreparedStatement ps =
|
||||
conn.prepareStatement(sql,
|
||||
Statement.RETURN_GENERATED_KEYS);
|
||||
|
||||
ps.setInt(1, appt.getServiceId());
|
||||
ps.setInt(2, appt.getCustomerId());
|
||||
ps.setString(3, appt.getAppointmentDate());
|
||||
ps.setString(4, appt.getAppointmentTime());
|
||||
ps.setString(5, appt.getAppointmentStatus());
|
||||
|
||||
ps.executeUpdate();
|
||||
|
||||
ResultSet keys = ps.getGeneratedKeys();
|
||||
int newId = 0;
|
||||
|
||||
if (keys.next()) {
|
||||
newId = keys.getInt(1);
|
||||
}
|
||||
|
||||
conn.close();
|
||||
return newId;
|
||||
}
|
||||
|
||||
//
|
||||
// LINK PET TO APPOINTMENT
|
||||
//
|
||||
public static void insertAppointmentPet(int appointmentId,
|
||||
int petId)
|
||||
throws SQLException {
|
||||
|
||||
Connection conn = ConnectionDB.getConnection();
|
||||
|
||||
String sql =
|
||||
"INSERT INTO appointment " +
|
||||
"(petId, serviceId, customerId, appointmentDate, appointmentTime, appointmentStatus) " +
|
||||
"VALUES (?, ?, ?, ?, ?, ?)";
|
||||
"INSERT INTO appointmentPet (appointmentId, petId) VALUES (?,?)";
|
||||
|
||||
try (Connection conn = ConnectionDB.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
PreparedStatement ps = conn.prepareStatement(sql);
|
||||
ps.setInt(1, appointmentId);
|
||||
ps.setInt(2, petId);
|
||||
ps.executeUpdate();
|
||||
|
||||
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();
|
||||
}
|
||||
conn.close();
|
||||
}
|
||||
|
||||
public static void deleteAppointment(int id) throws SQLException {
|
||||
//
|
||||
// UPDATE APPOINTMENT
|
||||
//
|
||||
public static int updateAppointment(int id,
|
||||
Appointment appt,
|
||||
int petId)
|
||||
throws SQLException {
|
||||
|
||||
String sql = "DELETE FROM appointment WHERE appointmentId=?";
|
||||
Connection conn = ConnectionDB.getConnection();
|
||||
|
||||
try (Connection conn = ConnectionDB.getConnection();
|
||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||
String sql =
|
||||
"UPDATE appointment SET serviceId=?, customerId=?, " +
|
||||
"appointmentDate=?, appointmentTime=?, appointmentStatus=? " +
|
||||
"WHERE appointmentId=?";
|
||||
|
||||
stmt.setInt(1, id);
|
||||
stmt.executeUpdate();
|
||||
}
|
||||
PreparedStatement ps = conn.prepareStatement(sql);
|
||||
|
||||
ps.setInt(1, appt.getServiceId());
|
||||
ps.setInt(2, appt.getCustomerId());
|
||||
ps.setString(3, appt.getAppointmentDate());
|
||||
ps.setString(4, appt.getAppointmentTime());
|
||||
ps.setString(5, appt.getAppointmentStatus());
|
||||
ps.setInt(6, id);
|
||||
|
||||
ps.executeUpdate();
|
||||
|
||||
String sql2 =
|
||||
"UPDATE appointmentPet SET petId=? WHERE appointmentId=?";
|
||||
|
||||
PreparedStatement ps2 = conn.prepareStatement(sql2);
|
||||
ps2.setInt(1, petId);
|
||||
ps2.setInt(2, id);
|
||||
ps2.executeUpdate();
|
||||
|
||||
conn.close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
//
|
||||
// DELETE APPOINTMENT
|
||||
//
|
||||
public static int deleteAppointment(int id)
|
||||
throws SQLException {
|
||||
|
||||
Connection conn = ConnectionDB.getConnection();
|
||||
|
||||
PreparedStatement ps1 =
|
||||
conn.prepareStatement(
|
||||
"DELETE FROM appointmentPet WHERE appointmentId=?"
|
||||
);
|
||||
ps1.setInt(1, id);
|
||||
ps1.executeUpdate();
|
||||
|
||||
PreparedStatement ps2 =
|
||||
conn.prepareStatement(
|
||||
"DELETE FROM appointment WHERE appointmentId=?"
|
||||
);
|
||||
ps2.setInt(1, id);
|
||||
|
||||
int rows = ps2.executeUpdate();
|
||||
|
||||
conn.close();
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,46 @@
|
||||
package org.example.petshopdesktop.models;
|
||||
|
||||
import javafx.beans.property.*;
|
||||
import java.sql.Time;
|
||||
import java.time.LocalDate;
|
||||
import javafx.beans.property.SimpleIntegerProperty;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
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;
|
||||
private SimpleIntegerProperty appointmentId;
|
||||
private SimpleIntegerProperty serviceId;
|
||||
private SimpleIntegerProperty customerId;
|
||||
private SimpleStringProperty appointmentDate;
|
||||
private SimpleStringProperty appointmentTime;
|
||||
private SimpleStringProperty appointmentStatus;
|
||||
|
||||
// Constructor
|
||||
public Appointment(int appointmentId,
|
||||
int serviceId,
|
||||
int customerId,
|
||||
LocalDate date,
|
||||
Time time,
|
||||
String status) {
|
||||
String appointmentDate,
|
||||
String appointmentTime,
|
||||
String appointmentStatus) {
|
||||
|
||||
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);
|
||||
this.appointmentDate = new SimpleStringProperty(appointmentDate);
|
||||
this.appointmentTime = new SimpleStringProperty(appointmentTime);
|
||||
this.appointmentStatus = new SimpleStringProperty(appointmentStatus);
|
||||
}
|
||||
|
||||
// Getters
|
||||
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 getAppointmentDate() { return appointmentDate.get(); }
|
||||
public String getAppointmentTime() { return appointmentTime.get(); }
|
||||
public String getAppointmentStatus() { return appointmentStatus.get(); }
|
||||
}
|
||||
|
||||
// Properties
|
||||
public SimpleIntegerProperty appointmentIdProperty() { return appointmentId; }
|
||||
public SimpleIntegerProperty serviceIdProperty() { return serviceId; }
|
||||
public SimpleIntegerProperty customerIdProperty() { return customerId; }
|
||||
public SimpleStringProperty appointmentDateProperty() { return appointmentDate; }
|
||||
public SimpleStringProperty appointmentTimeProperty() { return appointmentTime; }
|
||||
public SimpleStringProperty appointmentStatusProperty() { return appointmentStatus; }
|
||||
}
|
||||
@@ -12,6 +12,8 @@
|
||||
<?import javafx.scene.layout.RowConstraints?>
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.text.Font?>
|
||||
<?import javafx.scene.control.ComboBox?>
|
||||
<?import javafx.scene.layout.HBox?>
|
||||
|
||||
<VBox minHeight="-Infinity" minWidth="-Infinity" prefHeight="523.0" prefWidth="790.0"
|
||||
spacing="20.0" style="-fx-font-size: 14px;"
|
||||
@@ -46,7 +48,8 @@
|
||||
</HBox.margin>
|
||||
</VBox>
|
||||
<Region prefHeight="93.0" prefWidth="151.0" HBox.hgrow="ALWAYS" />
|
||||
<Button fx:id="btnCancel" layoutX="391.0" layoutY="38.0" mnemonicParsing="false" style="-fx-background-color: #E74c3c; -fx-cursor: hand; -fx-background-radius: 8;" text="Cancel" textFill="WHITE">
|
||||
<Button fx:id="btnCancel" layoutX="391.0" layoutY="38.0"
|
||||
mnemonicParsing="false" style="-fx-background-color: #E74c3c; -fx-cursor: hand; -fx-background-radius: 8;" text="Cancel" textFill="WHITE">
|
||||
<font>
|
||||
<Font name="System Bold" size="14.0" />
|
||||
</font>
|
||||
@@ -54,7 +57,8 @@
|
||||
<Insets bottom="12.0" left="24.0" right="24.0" top="12.0" />
|
||||
</padding>
|
||||
</Button>
|
||||
<Button fx:id="btnSave" layoutX="520.0" layoutY="38.0" mnemonicParsing="false" style="-fx-background-color: #3fe06a; -fx-cursor: hand; -fx-background-radius: 8;" text="Save" textFill="WHITE">
|
||||
<Button fx:id="btnSave" layoutX="520.0" layoutY="38.0" mnemonicParsing="false"
|
||||
style="-fx-background-color: #3fe06a; -fx-cursor: hand; -fx-background-radius: 8;" text="Save" textFill="WHITE">
|
||||
<font>
|
||||
<Font name="System Bold" size="14.0" />
|
||||
</font>
|
||||
@@ -67,7 +71,8 @@
|
||||
<Insets left="15.0" right="15.0" />
|
||||
</padding>
|
||||
</HBox>
|
||||
<VBox prefHeight="370.0" prefWidth="750.0" style="-fx-background-color: white; -fx-background-radius: 14; -fx-border-width: 2; -fx-border-color: #5580b5; -fx-border-radius: 14;">
|
||||
<VBox prefHeight="370.0" prefWidth="750.0"
|
||||
style="-fx-background-color: white; -fx-background-radius: 14; -fx-border-width: 2; -fx-border-color: #5580b5; -fx-border-radius: 14;">
|
||||
<children>
|
||||
<GridPane hgap="25.0" VBox.vgrow="ALWAYS">
|
||||
<columnConstraints>
|
||||
@@ -136,19 +141,54 @@
|
||||
</ComboBox>
|
||||
</children>
|
||||
</VBox>
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
|
||||
<VBox prefHeight="200.0"
|
||||
prefWidth="100.0"
|
||||
spacing="8.0"
|
||||
GridPane.columnIndex="1"
|
||||
GridPane.rowIndex="1">
|
||||
|
||||
<children>
|
||||
|
||||
<Label text="Appointment Time:" textFill="#2c3e50">
|
||||
<font>
|
||||
<Font name="System Bold" size="16.0" />
|
||||
</font>
|
||||
</Label>
|
||||
<ComboBox fx:id="cbAppointmentTime" prefHeight="29.0" prefWidth="336.0" promptText="Select Time" style="-fx-border-color: #E8EBED; -fx-border-width: 2; -fx-border-radius: 10; -fx-background-radius: 10; -fx-background-color: white;">
|
||||
<padding>
|
||||
<Insets bottom="3.0" left="10.0" right="10.0" top="3.0" />
|
||||
</padding>
|
||||
</ComboBox>
|
||||
|
||||
<HBox spacing="10">
|
||||
|
||||
<!-- Hour -->
|
||||
<ComboBox fx:id="cbHour"
|
||||
promptText="Hour"
|
||||
prefWidth="160"
|
||||
style="-fx-border-color: #E8EBED;
|
||||
-fx-border-width: 2;
|
||||
-fx-border-radius: 10;
|
||||
-fx-background-radius: 10;
|
||||
-fx-background-color: white;">
|
||||
<padding>
|
||||
<Insets bottom="3.0" left="10.0" right="10.0" top="3.0" />
|
||||
</padding>
|
||||
</ComboBox>
|
||||
|
||||
<!-- Minute -->
|
||||
<ComboBox fx:id="cbMinute"
|
||||
promptText="Minute"
|
||||
prefWidth="160"
|
||||
style="-fx-border-color: #E8EBED;
|
||||
-fx-border-width: 2;
|
||||
-fx-border-radius: 10;
|
||||
-fx-background-radius: 10;
|
||||
-fx-background-color: white;">
|
||||
<padding>
|
||||
<Insets bottom="3.0" left="10.0" right="10.0" top="3.0" />
|
||||
</padding>
|
||||
</ComboBox>
|
||||
|
||||
</HBox>
|
||||
|
||||
</children>
|
||||
|
||||
</VBox>
|
||||
<VBox prefHeight="200.0" prefWidth="100.0" spacing="8.0" GridPane.rowIndex="2">
|
||||
<children>
|
||||
|
||||
Reference in New Issue
Block a user