Customer liked with appointment table
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
package org.example.petshopdesktop.database;
|
||||||
|
|
||||||
|
import javafx.collections.FXCollections;
|
||||||
|
import javafx.collections.ObservableList;
|
||||||
|
import org.example.petshopdesktop.models.Customer;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class CustomerDB {
|
||||||
|
|
||||||
|
//
|
||||||
|
// GET ALL CUSTOMERS
|
||||||
|
//
|
||||||
|
public static ObservableList<Customer> getCustomers()
|
||||||
|
throws SQLException {
|
||||||
|
|
||||||
|
ObservableList<Customer> list =
|
||||||
|
FXCollections.observableArrayList();
|
||||||
|
|
||||||
|
Connection conn = ConnectionDB.getConnection();
|
||||||
|
|
||||||
|
String sql = "SELECT * FROM customer";
|
||||||
|
|
||||||
|
Statement stmt = conn.createStatement();
|
||||||
|
ResultSet rs = stmt.executeQuery(sql);
|
||||||
|
|
||||||
|
while(rs.next()) {
|
||||||
|
|
||||||
|
Customer c = new Customer(
|
||||||
|
rs.getInt("customerId"),
|
||||||
|
rs.getString("firstName"),
|
||||||
|
rs.getString("lastName"),
|
||||||
|
rs.getString("email"),
|
||||||
|
rs.getString("phone")
|
||||||
|
);
|
||||||
|
|
||||||
|
list.add(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
conn.close();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package org.example.petshopdesktop.models;
|
||||||
|
|
||||||
|
import javafx.beans.property.SimpleIntegerProperty;
|
||||||
|
import javafx.beans.property.SimpleStringProperty;
|
||||||
|
|
||||||
|
public class Customer {
|
||||||
|
|
||||||
|
private SimpleIntegerProperty customerId;
|
||||||
|
private SimpleStringProperty firstName;
|
||||||
|
private SimpleStringProperty lastName;
|
||||||
|
private SimpleStringProperty email;
|
||||||
|
private SimpleStringProperty phone;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public Customer(int customerId,
|
||||||
|
String firstName,
|
||||||
|
String lastName,
|
||||||
|
String email,
|
||||||
|
String phone) {
|
||||||
|
|
||||||
|
this.customerId = new SimpleIntegerProperty(customerId);
|
||||||
|
this.firstName = new SimpleStringProperty(firstName);
|
||||||
|
this.lastName = new SimpleStringProperty(lastName);
|
||||||
|
this.email = new SimpleStringProperty(email);
|
||||||
|
this.phone = new SimpleStringProperty(phone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
public int getCustomerId() {
|
||||||
|
return customerId.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhone() {
|
||||||
|
return phone.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Properties (optional but useful later)
|
||||||
|
public SimpleIntegerProperty customerIdProperty() {
|
||||||
|
return customerId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty firstNameProperty() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty lastNameProperty() {
|
||||||
|
return lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty emailProperty() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleStringProperty phoneProperty() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This controls how customer appears in ComboBox
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return getFirstName() + " " + getLastName();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user