├── .idea ├── .gitignore ├── vcs.xml ├── libraries │ └── postgresql_42_6_0.xml ├── misc.xml ├── modules.xml └── uiDesigner.xml ├── src ├── postgresql-42.6.0.jar ├── view │ ├── App.java │ ├── LoginGUI.java │ ├── PensionGUI.java │ ├── Layout.java │ ├── UserGUI.java │ ├── SeasonGUI.java │ ├── PensionGUI.form │ ├── UserGUI.form │ ├── ADDRoomGUI.java │ ├── SeasonGUI.form │ ├── LoginGUI.form │ ├── UserManagementGUI.java │ ├── HotelAddGUI.java │ ├── AddReservationGUI.java │ ├── HotelUpdateGUI.java │ ├── UpdateReservationGUI.java │ └── ADDRoomGUI.form ├── entity │ ├── Facility.java │ ├── Pension.java │ ├── Season.java │ ├── User.java │ ├── Hotel.java │ ├── Reservation.java │ └── Room.java ├── business │ ├── FacilityManager.java │ ├── SeasonManager.java │ ├── PensionManager.java │ ├── HotelManager.java │ ├── ReservationManager.java │ ├── UserManager.java │ └── RoomManager.java ├── core │ ├── ComboItem.java │ ├── Db.java │ └── Helper.java └── dao │ ├── FacilityDAO.java │ ├── SeasonDao.java │ ├── HotelDAO.java │ ├── PensionDao.java │ ├── RoomDao.java │ ├── UserDAO.java │ └── ReservationDao.java ├── tourismagencysystem.sql ├── .gitignore ├── Tourism_Agency_System.iml └── README.md /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /src/postgresql-42.6.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmedaliibrahim01/TourismAgencyManagementSystem/HEAD/src/postgresql-42.6.0.jar -------------------------------------------------------------------------------- /tourismagencysystem.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahmedaliibrahim01/TourismAgencyManagementSystem/HEAD/tourismagencysystem.sql -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/view/App.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.UserManager; 4 | import core.Helper; 5 | 6 | public class App { 7 | public static void main(String[] args) { 8 | Helper.setTheme(); 9 | LoginGUI loginGUI = new LoginGUI(); 10 | } 11 | } -------------------------------------------------------------------------------- /.idea/libraries/postgresql_42_6_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### IntelliJ IDEA ### 2 | out/ 3 | !**/src/main/**/out/ 4 | !**/src/test/**/out/ 5 | 6 | ### Eclipse ### 7 | .apt_generated 8 | .classpath 9 | .factorypath 10 | .project 11 | .settings 12 | .springBeans 13 | .sts4-cache 14 | bin/ 15 | !**/src/main/**/bin/ 16 | !**/src/test/**/bin/ 17 | 18 | ### NetBeans ### 19 | /nbproject/private/ 20 | /nbbuild/ 21 | /dist/ 22 | /nbdist/ 23 | /.nb-gradle/ 24 | 25 | ### VS Code ### 26 | .vscode/ 27 | 28 | ### Mac OS ### 29 | .DS_Store -------------------------------------------------------------------------------- /Tourism_Agency_System.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/entity/Facility.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | public class Facility { 4 | private int id; 5 | private String name; 6 | 7 | public Facility(int id, String name) { 8 | this.id = id; 9 | this.name = name; 10 | } 11 | 12 | public Facility() { 13 | } 14 | 15 | public Facility(String name) { 16 | this.name = name; 17 | } 18 | 19 | public int getId() { 20 | return id; 21 | } 22 | 23 | public void setId(int id) { 24 | this.id = id; 25 | } 26 | 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | @Override 36 | public String toString() { 37 | return "Facility{" + 38 | "id=" + id + 39 | ", name='" + name + '\'' + 40 | '}'; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/entity/Pension.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | import core.ComboItem; 4 | 5 | public class Pension { 6 | private int pension_id; 7 | private int hotel_id; 8 | private String pension_type; 9 | 10 | // Boş kurucu metot 11 | public Pension() { 12 | } 13 | 14 | // Parametreli kurucu metot 15 | 16 | public Pension(int pension_id, int hotel_id, String pension_type) { 17 | this.pension_id = pension_id; 18 | this.hotel_id = hotel_id; 19 | this.pension_type = pension_type; 20 | } 21 | 22 | 23 | // Getter ve Setter metotları 24 | 25 | 26 | public int getPension_id() { 27 | return pension_id; 28 | } 29 | 30 | public void setPension_id(int pension_id) { 31 | this.pension_id = pension_id; 32 | } 33 | 34 | public int getHotel_id() { 35 | return hotel_id; 36 | } 37 | 38 | public void setHotel_id(int hotel_id) { 39 | this.hotel_id = hotel_id; 40 | } 41 | 42 | public String getPension_type() { 43 | return pension_type; 44 | } 45 | 46 | public void setPension_type(String pension_type) { 47 | this.pension_type = pension_type; 48 | } 49 | 50 | public ComboItem getComboItem(){ 51 | return new ComboItem(this.getPension_id(),this.getPension_type());} 52 | 53 | @Override 54 | public String toString() { 55 | return pension_type; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/business/FacilityManager.java: -------------------------------------------------------------------------------- 1 | package business; 2 | 3 | import dao.FacilityDAO; 4 | import entity.Facility; 5 | import entity.Hotel; 6 | 7 | import java.util.ArrayList; 8 | 9 | // Manages operations related to facilities 10 | public class FacilityManager { 11 | private FacilityDAO facilityDao; 12 | 13 | public FacilityManager() { 14 | this.facilityDao = new FacilityDAO(); 15 | } 16 | 17 | // Retrieves all facilities 18 | public ArrayList findAll() { 19 | return this.facilityDao.findAll(); 20 | } 21 | 22 | // Retrieves facilities of a specific hotel by ID 23 | public ArrayList getHotelFacilities(int hotelId){ 24 | return this.facilityDao.getHotelFacilities(hotelId); 25 | } 26 | 27 | // Provides information necessary for the table for hotel facilities 28 | public ArrayList getForTableHotelFacility(int size, int hotelId) { 29 | ArrayList facilityRowList = new ArrayList<>(); 30 | for (String facility : this.getHotelFacilities(hotelId)) { 31 | Object[] rowObject = new Object[size]; 32 | rowObject[0] = facility; 33 | facilityRowList.add(rowObject); 34 | } 35 | return facilityRowList; 36 | } 37 | 38 | // Provides information necessary for the table for general facilities 39 | public ArrayList getForTableFacilities(int size) { 40 | ArrayList facilityRowList = new ArrayList<>(); 41 | for (Facility obj : this.findAll()) { 42 | int i = 0; 43 | Object[] rowObject = new Object[size]; 44 | rowObject[i++] = obj.getName(); 45 | facilityRowList.add(rowObject); 46 | } 47 | return facilityRowList; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/core/ComboItem.java: -------------------------------------------------------------------------------- 1 | package core; 2 | 3 | /** 4 | * Represents an item in a combo box, with a key and a value. 5 | */ 6 | public class ComboItem { 7 | private int key; 8 | private String value; 9 | 10 | /** 11 | * Constructs a ComboItem with the specified key and value. 12 | * @param key The key of the combo item. 13 | * @param value The value of the combo item. 14 | */ 15 | public ComboItem(int key, String value) { 16 | this.key = key; 17 | this.value = value; 18 | } 19 | 20 | /** 21 | * Constructs a ComboItem with only a value. 22 | * @param value The value of the combo item. 23 | */ 24 | public ComboItem(String value) { 25 | this.value = value; 26 | } 27 | 28 | /** 29 | * Retrieves the key of the combo item. 30 | * @return The key of the combo item. 31 | */ 32 | public int getKey() { 33 | return key; 34 | } 35 | 36 | /** 37 | * Sets the key of the combo item. 38 | * @param key The key to set. 39 | */ 40 | public void setKey(int key) { 41 | this.key = key; 42 | } 43 | 44 | /** 45 | * Retrieves the value of the combo item. 46 | * @return The value of the combo item. 47 | */ 48 | public String getValue() { 49 | return value; 50 | } 51 | 52 | /** 53 | * Sets the value of the combo item. 54 | * @param value The value to set. 55 | */ 56 | public void setValue(String value) { 57 | this.value = value; 58 | } 59 | 60 | /** 61 | * Returns a string representation of the combo item. 62 | * @return The string representation of the combo item (its value). 63 | */ 64 | public String toString() { 65 | return this.value; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/core/Db.java: -------------------------------------------------------------------------------- 1 | package core; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | import java.sql.Connection; 7 | import java.sql.DriverManager; 8 | import java.sql.SQLException; 9 | import java.util.Properties; 10 | 11 | /** 12 | * Database utility class for managing database connections using Singleton Design Pattern. 13 | */ 14 | public class Db { 15 | 16 | // Singleton Design Pattern 17 | private static Db instance = null; 18 | private Connection connection = null; 19 | 20 | // Database connection parameters 21 | private static final String DB_URL = "jdbc:postgresql://localhost:5432/tourismagencysystem"; 22 | private static final String DB_USERNAME = "postgres"; 23 | private static final String DB_PASS = "postgres"; 24 | 25 | /** 26 | * Private constructor to prevent instantiation from outside. 27 | * Establishes a database connection using the specified parameters. 28 | */ 29 | private Db() { 30 | try { 31 | this.connection = DriverManager.getConnection(DB_URL, DB_USERNAME, DB_PASS); 32 | } catch (SQLException e) { 33 | System.out.println(e.getMessage()); 34 | } 35 | } 36 | 37 | /** 38 | * Returns the established database connection. 39 | * @return The database connection. 40 | */ 41 | public Connection getConnection() { 42 | return connection; 43 | } 44 | 45 | /** 46 | * Provides a singleton instance of the database connection. 47 | * @return The singleton instance of the database connection. 48 | */ 49 | public static Connection getInstance() { 50 | try { 51 | if (instance == null || instance.getConnection().isClosed()) { 52 | instance = new Db(); 53 | } 54 | } catch (SQLException e) { 55 | System.out.println(e.getMessage()); 56 | } 57 | return instance.getConnection(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/entity/Season.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | import core.ComboItem; 4 | 5 | import java.time.LocalDate; 6 | 7 | public class Season { 8 | private int id; 9 | private int hotel_id; 10 | private LocalDate start_date; 11 | private LocalDate finish_date; 12 | private String season_type; 13 | 14 | 15 | // Parametreli kurucu metot 16 | public Season(int id, int hotel_id, String start_date, String finish_date, String season_type) { 17 | this.id = id; 18 | this.hotel_id = hotel_id; 19 | this.start_date = LocalDate.parse(start_date); 20 | this.finish_date = LocalDate.parse(finish_date); 21 | this.season_type = season_type; 22 | } 23 | 24 | public String getSeason_type() { 25 | return season_type; 26 | } 27 | 28 | public void setSeason_type(String season_type) { 29 | this.season_type = season_type; 30 | } 31 | 32 | // Boş kurucu metot 33 | public Season() { 34 | } 35 | 36 | 37 | // Getter ve Setter metotları 38 | 39 | 40 | public int getId() { 41 | return id; 42 | } 43 | 44 | public void setId(int id) { 45 | this.id = id; 46 | } 47 | 48 | public int getHotel_id() { 49 | return hotel_id; 50 | } 51 | 52 | public void setHotel_id(int hotel_id) { 53 | this.hotel_id = hotel_id; 54 | } 55 | 56 | public LocalDate getStart_date() { 57 | return start_date; 58 | } 59 | 60 | public void setStart_date(LocalDate start_date) { 61 | this.start_date = start_date; 62 | } 63 | 64 | public LocalDate getFinish_date() { 65 | return finish_date; 66 | } 67 | 68 | public void setFinish_date(LocalDate finish_date) { 69 | this.finish_date = finish_date; 70 | } 71 | 72 | public ComboItem getComboItem(){ 73 | return new ComboItem(this.getId(), "( Start Date: -> " + this.getStart_date() + " - "+" Finish Date: -> " + this.getFinish_date() + ")"); 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return start_date + " to " + finish_date; 79 | } 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/dao/FacilityDAO.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import core.Db; 4 | import entity.Facility; 5 | 6 | import java.sql.*; 7 | import java.util.ArrayList; 8 | import java.util.Arrays; 9 | 10 | // Class responsible for database operations related to facilities 11 | public class FacilityDAO { 12 | private Connection connection; 13 | 14 | // Constructor 15 | public FacilityDAO() { 16 | this.connection = Db.getInstance(); 17 | } 18 | 19 | // Method to find all facilities 20 | public ArrayList findAll() { 21 | ArrayList facilityList = new ArrayList<>(); 22 | String query = "SELECT * FROM public.facility ORDER BY facility_id ASC"; 23 | try { 24 | ResultSet rs = this.connection.createStatement().executeQuery(query); 25 | while (rs.next()) { 26 | facilityList.add(this.match(rs)); 27 | } 28 | } catch (SQLException e) { 29 | e.printStackTrace(); 30 | } 31 | return facilityList; 32 | } 33 | 34 | // Method to get facilities of a hotel by its ID 35 | public ArrayList getHotelFacilities(int hotelId) { 36 | ArrayList facilitiesList = new ArrayList<>(); 37 | try { 38 | String query = "SELECT hotel_facilities FROM hotel WHERE hotel_id = ?"; 39 | PreparedStatement preparedStatement = connection.prepareStatement(query); 40 | preparedStatement.setInt(1, hotelId); 41 | ResultSet resultSet = preparedStatement.executeQuery(); 42 | 43 | if (resultSet.next()) { 44 | Array facilitiesArray = resultSet.getArray("hotel_facilities"); 45 | 46 | // Extract facilities from the array and add them to the list 47 | String[] facilities = (String[]) facilitiesArray.getArray(); 48 | facilitiesList.addAll(Arrays.asList(facilities)); 49 | } 50 | } catch (SQLException e) { 51 | e.printStackTrace(); 52 | } 53 | return facilitiesList; 54 | } 55 | 56 | // Helper method to map ResultSet to Facility object 57 | public Facility match(ResultSet rs) throws SQLException { 58 | Facility obj = new Facility(); 59 | obj.setName(rs.getString("facility_name")); 60 | return obj; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/entity/User.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | /** 4 | * Represents a user entity in the system. 5 | */ 6 | public class User { 7 | private int id; 8 | private String fullName; 9 | private String userName; 10 | private String password; 11 | private Role role; 12 | 13 | // Constructors and methods... 14 | public User() { 15 | } 16 | 17 | public User(int id, String nameSurname, String user, String password, Role role) { 18 | this.id = id; 19 | this.fullName = nameSurname; 20 | this.userName = user; 21 | this.password = password; 22 | this.role = role; 23 | } 24 | 25 | /** 26 | * Enumeration representing roles of users in the system. 27 | */ 28 | public enum Role{ 29 | ADMIN, 30 | EMPLOYEE 31 | } 32 | 33 | public User(String nameSurname, String user, String password, Role role) { 34 | this.fullName = nameSurname; 35 | this.userName = user; 36 | this.password = password; 37 | this.role = role; 38 | } 39 | 40 | public User(String user, String password) { 41 | this.userName = user; 42 | this.password = password; 43 | } 44 | 45 | public int getId() { 46 | return id; 47 | } 48 | 49 | public void setId(int id) { 50 | this.id = id; 51 | } 52 | 53 | public String getFullName() { 54 | return fullName; 55 | } 56 | 57 | public void setFullName(String fullName) { 58 | this.fullName = fullName; 59 | } 60 | 61 | public String getUserName() { 62 | return userName; 63 | } 64 | 65 | public void setUserName(String userName) { 66 | this.userName = userName; 67 | } 68 | 69 | public String getPassword() { 70 | return password; 71 | } 72 | 73 | public void setPassword(String password) { 74 | this.password = password; 75 | } 76 | 77 | public Role getRole() { 78 | return role; 79 | } 80 | 81 | public void setRole(Role role) { 82 | this.role = role; 83 | } 84 | 85 | @Override 86 | public String toString() { 87 | return "User{" + 88 | "id=" + id + 89 | ", nameSurname='" + fullName + '\'' + 90 | ", user='" + userName + '\'' + 91 | ", password='" + password + '\'' + 92 | ", role=" + role + 93 | '}'; 94 | } 95 | } -------------------------------------------------------------------------------- /src/view/LoginGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.UserManager; 4 | import core.Helper; 5 | import entity.User; 6 | 7 | import javax.swing.*; 8 | 9 | /** 10 | * LoginGUI provides an interface for user login. 11 | * This class presents an interface using Swing components for user authentication. 12 | */ 13 | public class LoginGUI extends Layout { 14 | 15 | private JPanel container; 16 | private JPanel user_login; 17 | private JPanel pnl_top; 18 | private JLabel lbl_rent_a_car; 19 | private JLabel lbl_management; 20 | private JPanel pnl_bottom; 21 | private JTextField textField_username; 22 | private JPasswordField passwordField; 23 | private JButton btn_login; 24 | private JLabel lbl_pass; 25 | private JLabel lbl_user; 26 | private final UserManager userManager; 27 | 28 | /** 29 | * Constructor for LoginGUI class. 30 | * Initializes necessary objects and creates the login interface. 31 | */ 32 | public LoginGUI() { 33 | this.userManager = new UserManager(); 34 | add(container); 35 | this.guiInitialize(400, 400); 36 | 37 | // Action listener for login button 38 | btn_login.addActionListener(e -> { 39 | // Check if username field is empty 40 | if (Helper.isFieldEmpty(textField_username)) { 41 | Helper.showMsg("Enter Username"); 42 | } 43 | // Check if password field is empty 44 | else if (Helper.isFieldEmpty(passwordField)) { 45 | Helper.showMsg("Enter Password"); 46 | } else { 47 | // Find user by login credentials 48 | User loginUser = this.userManager.findByLogin(this.textField_username.getText(), this.passwordField.getText()); 49 | if (loginUser == null) { 50 | Helper.showMsg("User not found"); 51 | } else { 52 | // Check user role and open respective GUI 53 | if (loginUser.getRole().toString().equalsIgnoreCase("Admin")) { 54 | UserManagementGUI userManagementGUI = new UserManagementGUI(loginUser); 55 | userManagementGUI.setVisible(true); 56 | dispose(); 57 | } else { 58 | EmployeeGUI employeeGUI = new EmployeeGUI(loginUser); 59 | employeeGUI.setVisible(true); 60 | dispose(); 61 | } 62 | } 63 | } 64 | }); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/business/SeasonManager.java: -------------------------------------------------------------------------------- 1 | package business; 2 | 3 | import core.Helper; 4 | import dao.SeasonDao; 5 | import entity.Season; 6 | 7 | import java.util.ArrayList; 8 | 9 | // Manages operations related to seasons 10 | public class SeasonManager { 11 | SeasonDao seasonDao = new SeasonDao(); 12 | 13 | // Retrieves a season by its ID 14 | public Season getById(int id){ 15 | return this.seasonDao.getByID(id); 16 | } 17 | 18 | // Retrieves seasons by a specific hotel ID 19 | public ArrayList getSeasonsByOtelId(int id){ 20 | return this.seasonDao.getSeasonsByOtelId(id);} 21 | 22 | // Retrieves all seasons 23 | public ArrayList findAll() { 24 | return this.seasonDao.findAll(); 25 | } 26 | 27 | // Provides information necessary for the table 28 | public ArrayList getForTable(int size, ArrayList seasons){ 29 | ArrayList seasonList = new ArrayList<>(); 30 | for (Season obj : seasons){ 31 | int i = 0; 32 | Object[] rowObject = new Object[size]; 33 | rowObject[i++] = obj.getId(); 34 | rowObject[i++] = obj.getHotel_id(); 35 | rowObject[i++] = obj.getStart_date(); 36 | rowObject[i++] = obj.getFinish_date(); 37 | seasonList.add(rowObject); 38 | } 39 | return seasonList; 40 | } 41 | 42 | // Adds a season record to the database 43 | public boolean save(Season season){ 44 | if(season.getId()!=0){ 45 | Helper.showMsg("error"); 46 | } 47 | return this.seasonDao.save(season); 48 | } 49 | 50 | // Deletes a season with a specific ID 51 | public boolean delete(int id){ 52 | if(this.getById(id) == null){ 53 | Helper.showMsg(id + " ID registered model not found"); 54 | return false; 55 | } 56 | return this.seasonDao.delete(id); 57 | } 58 | 59 | // Retrieves seasons for a specific hotel 60 | public ArrayList getHotelSeasons(int hotelId){ 61 | return this.seasonDao.getHotelSeason(hotelId); 62 | } 63 | 64 | // Provides information necessary for the table of hotel pensions 65 | public ArrayList getForTableHotelPensions(int size, int hotelId) { 66 | ArrayList seasonRowList = new ArrayList<>(); 67 | for (Season season : this.getHotelSeasons(hotelId)){ 68 | Object[] rowObject = new Object[size]; 69 | rowObject[0] = season; 70 | seasonRowList.add(rowObject); 71 | } 72 | return seasonRowList; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/business/PensionManager.java: -------------------------------------------------------------------------------- 1 | package business; 2 | 3 | import core.Helper; 4 | import dao.PensionDao; 5 | import entity.Pension; 6 | 7 | import java.util.ArrayList; 8 | 9 | // Manages operations related to pensions 10 | public class PensionManager { 11 | PensionDao pensionDao = new PensionDao(); 12 | 13 | // Retrieves a pension by a specific ID 14 | public Pension getById(int id){ 15 | return this.pensionDao.getByID(id); 16 | } 17 | 18 | // Retrieves all pensions 19 | public ArrayList findAll() { 20 | return this.pensionDao.findAll(); 21 | } 22 | 23 | // Retrieves pensions by a specific hotel ID 24 | public ArrayList getPensionByOtelId(int id){ 25 | return this.pensionDao.getPensionByOtelId(id); 26 | } 27 | 28 | // Provides information necessary for the table 29 | public ArrayList getForTable(int size, ArrayList pensions){ 30 | ArrayList pensionList = new ArrayList<>(); 31 | for (Pension obj : pensions){ 32 | int i = 0; 33 | Object[] rowObject = new Object[size]; 34 | rowObject[i++] = obj.getPension_id(); 35 | rowObject[i++] = obj.getHotel_id(); 36 | rowObject[i++] = obj.getPension_type(); 37 | pensionList.add(rowObject); 38 | } 39 | return pensionList; 40 | } 41 | 42 | // Adds a pension record to the database 43 | public boolean save(Pension pension){ 44 | if(pension.getPension_id()!=0){ 45 | Helper.showMsg("error"); 46 | } 47 | return this.pensionDao.save(pension); 48 | } 49 | 50 | // Retrieves pension types for a specific hotel ID 51 | public ArrayList getHotelFacilities(int hotelId){ 52 | return this.pensionDao.getHotelPensionTypes(hotelId); 53 | } 54 | 55 | // Provides information necessary for the table for hotel pensions 56 | public ArrayList getForTableHotelPensions(int size, int hotelId) { 57 | ArrayList facilityRowList = new ArrayList<>(); 58 | for (Pension pensionType : this.getHotelFacilities(hotelId)) { 59 | Object[] rowObject = new Object[size]; 60 | rowObject[0] = pensionType; 61 | facilityRowList.add(rowObject); 62 | } 63 | return facilityRowList; 64 | } 65 | 66 | // Deletes a pension by a specific ID 67 | public boolean delete(int id){ 68 | if(this.getById(id) == null){ 69 | Helper.showMsg(id + " ID registered model not found"); 70 | return false; 71 | } 72 | return this.pensionDao.delete(id); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/view/PensionGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.HotelManager; 4 | import business.PensionManager; 5 | import core.ComboItem; 6 | import core.Helper; 7 | import entity.Hotel; 8 | import entity.Pension; 9 | import entity.User; 10 | 11 | import javax.swing.*; 12 | 13 | /** 14 | * PensionGUI class provides a graphical interface for managing pension information. 15 | * This class allows users to save pension data associated with a hotel. 16 | */ 17 | public class PensionGUI extends Layout { 18 | private JPanel wrap; 19 | private JButton btn_save_pension; 20 | private JComboBox cmb_persion; 21 | private JLabel lbl_pan_add_menu; 22 | private JLabel lbl_hotel_id; 23 | private JComboBox cmb_hotel; 24 | private JTextField tf_hotel_name; 25 | private PensionManager pensionManager; 26 | private Pension pension; 27 | private HotelManager hotelManager; 28 | private Hotel hotel; 29 | private User user; 30 | 31 | /** 32 | * Constructs a PensionGUI object. 33 | * Initializes necessary components and sets up the GUI for managing pension data. 34 | * @param hotel The hotel associated with the pension data 35 | */ 36 | public PensionGUI(Hotel hotel) { 37 | // Initialize managers and entities 38 | this.hotelManager = new HotelManager(); 39 | this.hotel = hotel; 40 | this.pensionManager = new PensionManager(); 41 | this.pension = new Pension(); 42 | 43 | // Add components to the layout 44 | this.cmb_persion.getSelectedItem(); 45 | this.add(wrap); 46 | this.guiInitialize(375, 250); 47 | 48 | // Populate hotel combo box if hotel is not null 49 | if (this.hotel != null) { 50 | this.cmb_hotel.addItem(hotel.getComboItem()); 51 | } else { 52 | dispose(); 53 | } 54 | 55 | // Define action for save button 56 | this.btn_save_pension.addActionListener(e -> { 57 | boolean result = false; 58 | ComboItem selectedHotel = (ComboItem) cmb_hotel.getSelectedItem(); 59 | this.pension.setHotel_id(selectedHotel.getKey()); 60 | this.pension.setPension_type(cmb_persion.getSelectedItem().toString()); 61 | 62 | // Save pension data if hotel ID is not zero 63 | if (this.pension.getHotel_id() != 0) { 64 | result = this.pensionManager.save(this.pension); 65 | } 66 | 67 | // Show result message and dispose the window 68 | if (result) { 69 | Helper.showMsg("done"); 70 | dispose(); 71 | } else { 72 | Helper.showMsg("error"); 73 | } 74 | }); 75 | } 76 | } -------------------------------------------------------------------------------- /src/business/HotelManager.java: -------------------------------------------------------------------------------- 1 | package business; 2 | 3 | import core.Helper; 4 | import dao.HotelDAO; 5 | import entity.Hotel; 6 | 7 | import java.util.ArrayList; 8 | 9 | // Manages operations related to hotels 10 | public class HotelManager { 11 | private HotelDAO hotelDao; 12 | 13 | public HotelManager() { 14 | this.hotelDao = new HotelDAO(); 15 | } 16 | 17 | // Retrieves all hotels 18 | public ArrayList findAll() { 19 | return this.hotelDao.findAll(); 20 | } 21 | 22 | // Retrieves a hotel by a specific ID 23 | public Hotel findHotelById(int hotelId){ 24 | return hotelDao.getById(hotelId); 25 | } 26 | 27 | // Updates a hotel 28 | public boolean update(Hotel hotel) { 29 | return this.hotelDao.update(hotel); 30 | } 31 | 32 | // Adds a hotel record to the database 33 | public boolean save(Hotel hotel) { 34 | if (hotel.getId() != 0) { 35 | Helper.showMsg("error"); 36 | } 37 | return this.hotelDao.save(hotel); 38 | } 39 | 40 | // Deletes a hotel by a specific ID 41 | public boolean delete(int id) { 42 | if (this.getById(id) == null) { 43 | Helper.showMsg("Hotel Not found"); 44 | return false; 45 | } 46 | return this.hotelDao.delete(id); 47 | } 48 | 49 | // Provides information necessary for the table 50 | public ArrayList getForTable(int size) { 51 | ArrayList hotelRowList = new ArrayList<>(); 52 | for (Hotel obj : this.findAll()) { 53 | int i = 0; 54 | Object[] rowObject = new Object[size]; 55 | rowObject[i++] = obj.getId(); 56 | rowObject[i++] = obj.getName(); 57 | rowObject[i++] = obj.getCity(); 58 | rowObject[i++] = obj.getRegion(); 59 | rowObject[i++] = obj.getFullAddress(); 60 | rowObject[i++] = obj.getPhone(); 61 | rowObject[i++] = obj.getEmail(); 62 | rowObject[i++] = obj.getStar(); 63 | hotelRowList.add(rowObject); 64 | } 65 | return hotelRowList; 66 | } 67 | 68 | // Provides information necessary for the facilities table 69 | public ArrayList getForTableFacilities(int size) { 70 | ArrayList facilityRowList = new ArrayList<>(); 71 | for (Hotel obj : this.findAll()) { 72 | int i = 0; 73 | Object[] rowObject = new Object[size]; 74 | rowObject[i++] = obj.getFacilities(); 75 | facilityRowList.add(rowObject); 76 | } 77 | return facilityRowList; 78 | } 79 | 80 | // Retrieves a hotel by a specific ID 81 | public Hotel getById(int id) { 82 | return this.hotelDao.getById(id); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/business/ReservationManager.java: -------------------------------------------------------------------------------- 1 | package business; 2 | 3 | import core.Helper; 4 | import dao.ReservationDao; 5 | import entity.Reservation; 6 | 7 | import java.util.ArrayList; 8 | 9 | // Manages operations related to reservations 10 | public class ReservationManager { 11 | ReservationDao reservationDao = new ReservationDao(); 12 | 13 | // Retrieves a reservation by a specific ID 14 | public Reservation getById(int id){ 15 | return this.reservationDao.getByID(id); 16 | } 17 | 18 | // Retrieves reservations by a specific hotel ID 19 | public ArrayList getReservationByOtelId(int id){ 20 | return this.reservationDao.getReservationByOtelId(id); 21 | } 22 | 23 | // Retrieves all reservations 24 | public ArrayList findAll() { 25 | return this.reservationDao.findAll(); 26 | } 27 | 28 | // Provides information necessary for the table 29 | public ArrayList getForTable(int size){ 30 | ArrayList resList = new ArrayList<>(); 31 | for (Reservation obj : this.findAll()){ 32 | int i = 0; 33 | Object[] rowObject = new Object[size]; 34 | rowObject[i++] = obj.getId(); 35 | rowObject[i++] = obj.getRoom_id(); 36 | rowObject[i++] = obj.getGuest_name(); 37 | rowObject[i++] = obj.getGuest_id(); 38 | rowObject[i++] = obj.getGuest_email(); 39 | rowObject[i++] = obj.getGuest_phone(); 40 | rowObject[i++] = obj.getAdult_count(); 41 | rowObject[i++] = obj.getChild_count(); 42 | rowObject[i++] = obj.getCheck_in_date(); 43 | rowObject[i++] = obj.getCheck_out_date(); 44 | rowObject[i++] = obj.getGuest_note(); 45 | rowObject[i++] = obj.getTotal_price(); 46 | rowObject[i++] = obj.getHotel_id(); 47 | resList.add(rowObject); 48 | } 49 | return resList; 50 | } 51 | 52 | // Adds a reservation record to the database 53 | public boolean save(Reservation reservation){ 54 | if(reservation.getId()!=0){ 55 | Helper.showMsg("error"); 56 | } 57 | return this.reservationDao.save(reservation); 58 | } 59 | 60 | // Deletes a reservation by a specific ID 61 | public boolean delete(int id){ 62 | if (this.getById(id)==null){ 63 | Helper.showMsg(" Reservation Not found"); 64 | return false; 65 | } 66 | return this.reservationDao.delete(id); 67 | } 68 | 69 | // Updates reservation information 70 | public boolean update(Reservation reservation){ 71 | if(this.getById(reservation.getId()) == null){ 72 | Helper.showMsg("Reservation " + reservation.getId() + " not found"); 73 | return false; 74 | } 75 | return this.reservationDao.update(reservation); 76 | } 77 | } -------------------------------------------------------------------------------- /src/view/Layout.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import core.Helper; 4 | 5 | import javax.swing.*; 6 | import javax.swing.table.DefaultTableModel; 7 | import java.awt.*; 8 | import java.awt.event.MouseAdapter; 9 | import java.awt.event.MouseEvent; 10 | import java.util.ArrayList; 11 | 12 | // Represents the layout of the application 13 | public class Layout extends JFrame { 14 | 15 | // Initializes the GUI window 16 | public void guiInitialize(int width, int height) { 17 | this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 18 | this.setTitle("Tourism Agency System"); 19 | this.setSize(width, height); 20 | this.setLocation(Helper.getLocationPoint("x", this.getSize()), Helper.getLocationPoint("y", this.getSize())); 21 | this.setVisible(true); 22 | } 23 | 24 | // Creates a table with given model, columns, and rows 25 | public void createTable(DefaultTableModel model, JTable table, Object[] columns, ArrayList rows) { 26 | model.setColumnIdentifiers(columns); 27 | table.setModel(model); 28 | table.getTableHeader().setReorderingAllowed(false); 29 | table.setEnabled(false); 30 | 31 | DefaultTableModel clearModel = (DefaultTableModel) table.getModel(); 32 | clearModel.setRowCount(0); 33 | 34 | if (rows == null) { 35 | rows = new ArrayList<>(); 36 | } 37 | 38 | for (Object[] row : rows) { 39 | model.addRow(row); 40 | } 41 | } 42 | 43 | // Retrieves the ID of the selected row in the table 44 | int getTableSelectedRow(JTable table, int col_index){ 45 | int selectedRow = table.getSelectedRow(); 46 | if (selectedRow != -1) { 47 | return (int) table.getModel().getValueAt(selectedRow, col_index); 48 | } 49 | return -1; 50 | } 51 | 52 | // Selects the entire row when clicked in the table 53 | public void tableRowSelect(JTable table){ 54 | table.addMouseListener(new MouseAdapter() { 55 | @Override 56 | public void mousePressed(MouseEvent e) { 57 | int selected_row = table.rowAtPoint(e.getPoint()); 58 | table.setRowSelectionInterval(selected_row, selected_row); 59 | } 60 | }); 61 | } 62 | 63 | // Prints the size of JFrame 64 | public void printFrameSize(JFrame frame) { 65 | Dimension size = frame.getSize(); 66 | System.out.println("Dimension is: " + size); 67 | } 68 | 69 | // Prints the size of JPanel 70 | public void printFrameSize(JPanel frame) { 71 | Dimension size = frame.getSize(); 72 | System.out.println("Dimension is: " + size); 73 | } 74 | 75 | // Prints the size of JTextField 76 | public void printFrameSize(JTextField frame) { 77 | Dimension size = frame.getSize(); 78 | System.out.println("Dimension is: " + size); 79 | } 80 | 81 | // Prints the size of JTabbedPane 82 | public void printFrameSize(JTabbedPane frame) { 83 | Dimension size = frame.getSize(); 84 | System.out.println("Dimension is: " + size); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/view/UserGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.UserManager; 4 | import core.Helper; 5 | import entity.User; 6 | 7 | import javax.swing.*; 8 | 9 | /** 10 | * UserGUI provides an interface for managing user information. 11 | * This class presents an interface using Swing components for adding or updating user details. 12 | */ 13 | public class UserGUI extends Layout { 14 | 15 | private JPanel container; 16 | private JTextField txtf_username; 17 | private JTextField txtf_password; 18 | private JButton btn_user_save; 19 | private JLabel lbl_update_new; 20 | private JLabel lbl_username; 21 | private JLabel lbl_password; 22 | private JLabel lbl_role; 23 | private JComboBox cmbx_role; 24 | private JTextField txtf_name_surname; 25 | private JLabel lbl_name_surname; 26 | private UserManager userManager; 27 | private User user; 28 | private DefaultComboBoxModel defaultComboBoxModel; 29 | 30 | /** 31 | * Constructor for UserGUI class. 32 | * Initializes necessary objects and creates the interface for managing user information. 33 | * @param user The user for whom the details are being managed (null if adding new user) 34 | */ 35 | public UserGUI(User user){ 36 | this.userManager = new UserManager(); 37 | this.user = user; 38 | this.add(container); 39 | this.guiInitialize(300, 350); 40 | this.defaultComboBoxModel = new DefaultComboBoxModel<>(); 41 | 42 | // If user object is provided, populate fields with user details 43 | if (user != null) { 44 | this.txtf_name_surname.setText(user.getFullName()); 45 | this.txtf_username.setText(user.getUserName()); 46 | this.txtf_password.setText(user.getPassword()); 47 | this.cmbx_role.setToolTipText(user.getRole().toString()); 48 | } 49 | 50 | // ActionListener for save button 51 | btn_user_save.addActionListener(e -> { 52 | if (Helper.isFieldEmpty(this.txtf_username) || Helper.isFieldEmpty(this.txtf_password)) { 53 | Helper.showMsg("fill"); 54 | } else { 55 | boolean result = true; 56 | if (this.user == null) { 57 | // If adding new user, create User object and save it 58 | User newUser = new User(txtf_name_surname.getText(), txtf_username.getText(), txtf_password.getText(), User.Role.valueOf((String) cmbx_role.getSelectedItem())); 59 | result = this.userManager.save(newUser); 60 | } else { 61 | // If updating existing user, update user details 62 | this.user.setFullName(txtf_name_surname.getText()); 63 | this.user.setUserName(txtf_username.getText()); 64 | this.user.setPassword(txtf_password.getText()); 65 | this.user.setRole(User.Role.valueOf((String) cmbx_role.getSelectedItem())); 66 | this.userManager.update(this.user); 67 | } 68 | // Show message based on operation result 69 | if (result) { 70 | Helper.showMsg("done"); 71 | dispose(); 72 | } else { 73 | Helper.showMsg("error"); 74 | } 75 | } 76 | }); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/business/UserManager.java: -------------------------------------------------------------------------------- 1 | package business; 2 | 3 | import core.Helper; 4 | import dao.UserDAO; 5 | import entity.User; 6 | 7 | import java.util.ArrayList; 8 | 9 | /** 10 | * Manages user-related business logic. 11 | */ 12 | public class UserManager { 13 | private UserDAO userDao; 14 | 15 | /** 16 | * Constructs a UserManager object. 17 | */ 18 | public UserManager() { 19 | this.userDao = new UserDAO(); 20 | } 21 | 22 | /** 23 | * Finds a user by login credentials (username and password). 24 | * @param username The username of the user. 25 | * @param password The password of the user. 26 | * @return The user found, or null if not found. 27 | */ 28 | public User findByLogin(String username, String password) { 29 | return this.userDao.findByLogin(username, password); 30 | } 31 | 32 | /** 33 | * Retrieves all users. 34 | * @return A list of all users. 35 | */ 36 | public ArrayList findAll() { 37 | return this.userDao.findAll(); 38 | } 39 | 40 | /** 41 | * Retrieves users with the role of admin. 42 | * @return A list of admin users. 43 | */ 44 | public ArrayList findByAdmin() { 45 | return this.userDao.findByAdmin(); 46 | } 47 | 48 | /** 49 | * Retrieves users with the role of employee. 50 | * @return A list of employee users. 51 | */ 52 | public ArrayList findByEmployee() { 53 | return this.userDao.findByEmployee(); 54 | } 55 | 56 | /** 57 | * Saves a user. 58 | * @param user The user to save. 59 | * @return True if the user is saved successfully, otherwise false. 60 | */ 61 | public boolean save(User user) { 62 | if (user.getId() != 0) { 63 | Helper.showMsg("error"); 64 | } 65 | return this.userDao.save(user); 66 | } 67 | 68 | /** 69 | * Updates a user. 70 | * @param user The user to update. 71 | * @return True if the user is updated successfully, otherwise false. 72 | */ 73 | public boolean update(User user) { 74 | if (this.getById(user.getId()) == null) { 75 | Helper.showMsg("notFound"); 76 | } 77 | return this.userDao.update(user); 78 | } 79 | 80 | /** 81 | * Deletes a user by ID. 82 | * @param id The ID of the user to delete. 83 | * @return True if the user is deleted successfully, otherwise false. 84 | */ 85 | public boolean delete(int id) { 86 | if (this.getById(id) == null) { 87 | Helper.showMsg(id + " ID registered user not found"); 88 | return false; 89 | } 90 | return this.userDao.delete(id); 91 | } 92 | 93 | /** 94 | * Retrieves user data for a table. 95 | * @param size The size of the data to retrieve. 96 | * @return A list of objects representing user data for the table. 97 | */ 98 | public ArrayList getForTable(int size) { 99 | ArrayList userRowList = new ArrayList<>(); 100 | for (User obj : this.findAll()) { 101 | int i = 0; 102 | Object[] rowObject = new Object[size]; 103 | rowObject[i++] = obj.getId(); 104 | rowObject[i++] = obj.getFullName(); 105 | rowObject[i++] = obj.getUserName(); 106 | rowObject[i++] = obj.getPassword(); 107 | rowObject[i++] = obj.getRole(); 108 | userRowList.add(rowObject); 109 | } 110 | return userRowList; 111 | } 112 | 113 | /** 114 | * Retrieves a user by ID. 115 | * @param id The ID of the user to retrieve. 116 | * @return The user with the specified ID, or null if not found. 117 | */ 118 | public User getById(int id) { 119 | return this.userDao.getById(id); 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /src/entity/Hotel.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | import core.ComboItem; 4 | 5 | import java.util.Arrays; 6 | 7 | public class Hotel { 8 | private int id; 9 | private String name; 10 | private String city; 11 | private String region; 12 | private String fullAddress; 13 | private String phone; 14 | private String email; 15 | private String star; 16 | private String[] facilities; 17 | private String[] pensionTypes; 18 | 19 | public Hotel() { 20 | } 21 | 22 | public Hotel(int id, String name, String city, String region, String fullAddress, String phone, String email, String star, String[] facilities, String[] pensionTypes) { 23 | this.id = id; 24 | this.name = name; 25 | this.city = city; 26 | this.region = region; 27 | this.fullAddress = fullAddress; 28 | this.phone = phone; 29 | this.email = email; 30 | this.star = star; 31 | this.facilities = facilities; 32 | this.pensionTypes = pensionTypes; 33 | } 34 | 35 | public Hotel(String name, String city, String region, String fullAddress, String phone, String email, String star, String[] facilities) { 36 | this.name = name; 37 | this.city = city; 38 | this.region = region; 39 | this.fullAddress = fullAddress; 40 | this.phone = phone; 41 | this.email = email; 42 | this.star = star; 43 | this.facilities = facilities; 44 | } 45 | 46 | 47 | public int getId() { 48 | return id; 49 | } 50 | 51 | public void setId(int id) { 52 | this.id = id; 53 | } 54 | 55 | public String getName() { 56 | return name; 57 | } 58 | 59 | public void setName(String name) { 60 | this.name = name; 61 | } 62 | 63 | public String getCity() { 64 | return city; 65 | } 66 | 67 | public void setCity(String city) { 68 | this.city = city; 69 | } 70 | 71 | public String getRegion() { 72 | return region; 73 | } 74 | 75 | public void setRegion(String region) { 76 | this.region = region; 77 | } 78 | 79 | public String getFullAddress() { 80 | return fullAddress; 81 | } 82 | 83 | public void setFullAddress(String fullAddress) { 84 | this.fullAddress = fullAddress; 85 | } 86 | 87 | public String getPhone() { 88 | return phone; 89 | } 90 | 91 | public void setPhone(String phone) { 92 | this.phone = phone; 93 | } 94 | 95 | public String getEmail() { 96 | return email; 97 | } 98 | 99 | public void setEmail(String email) { 100 | this.email = email; 101 | } 102 | 103 | public String getStar() { 104 | return star; 105 | } 106 | 107 | public void setStar(String star) { 108 | this.star = star; 109 | } 110 | 111 | public String[] getFacilities() { 112 | return facilities; 113 | } 114 | 115 | public void setFacilities(String[] facilities) { 116 | this.facilities = facilities; 117 | } 118 | 119 | public String[] getPensionTypes() { 120 | return pensionTypes; 121 | } 122 | 123 | public void setPensionTypes(String[] pensionTypes) { 124 | this.pensionTypes = pensionTypes; 125 | } 126 | public ComboItem getComboItem() { 127 | return new ComboItem(this.getId(), this.getName()); 128 | } 129 | 130 | @Override 131 | public String toString() { 132 | return "Hotel{" + 133 | "id=" + id + 134 | ", name='" + name + '\'' + 135 | ", city='" + city + '\'' + 136 | ", region='" + region + '\'' + 137 | ", fullAddress='" + fullAddress + '\'' + 138 | ", phone='" + phone + '\'' + 139 | ", email='" + email + '\'' + 140 | ", star='" + star + '\'' + 141 | ", facilities=" + Arrays.toString(facilities) + 142 | ", pensionTypes=" + Arrays.toString(pensionTypes) + 143 | '}'; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/view/SeasonGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.HotelManager; 4 | import business.SeasonManager; 5 | import core.ComboItem; 6 | import core.Helper; 7 | import entity.Hotel; 8 | import entity.Season; 9 | 10 | import javax.swing.*; 11 | import javax.swing.text.MaskFormatter; 12 | import java.awt.event.ActionEvent; 13 | import java.awt.event.ActionListener; 14 | import java.text.ParseException; 15 | import java.time.DateTimeException; 16 | import java.time.LocalDate; 17 | import java.time.format.DateTimeFormatter; 18 | 19 | /** 20 | * SeasonGUI provides an interface for managing hotel seasons. 21 | * This class presents an interface using Swing components to add a new season for a hotel. 22 | */ 23 | public class SeasonGUI extends Layout { 24 | private JPanel wrap; 25 | private JButton btn_save_season; 26 | private JComboBox cmb_hotel_season; 27 | private JPanel wrap_season; 28 | private JLabel lbl_hotel_id; 29 | private JFormattedTextField tf_season_start; 30 | private JFormattedTextField tf_season_finish; 31 | private HotelManager hotelManager; 32 | private Hotel hotel; 33 | private SeasonManager seasonManager; 34 | private Season season; 35 | 36 | /** 37 | * Constructor for SeasonGUI class. 38 | * Initializes necessary objects and creates the interface for adding a new season. 39 | * @param hotel The hotel for which the season is being added 40 | */ 41 | public SeasonGUI(Hotel hotel) { 42 | this.hotelManager = new HotelManager(); 43 | this.hotel = hotel; 44 | this.seasonManager = new SeasonManager(); 45 | this.season = new Season(); 46 | this.cmb_hotel_season.getSelectedItem(); 47 | this.add(wrap); 48 | this.guiInitialize(375, 300); 49 | 50 | // Populate hotel combo box with the selected hotel 51 | if (this.hotel != null){ 52 | this.cmb_hotel_season.addItem(hotel.getComboItem()); 53 | } else { 54 | dispose(); // Close the window if no hotel is selected 55 | } 56 | 57 | // Action listener for save button 58 | btn_save_season.addActionListener(new ActionListener() { 59 | @Override 60 | public void actionPerformed(ActionEvent e) { 61 | boolean result = false; 62 | ComboItem selectSeason = (ComboItem) cmb_hotel_season.getSelectedItem(); 63 | season.setHotel_id(selectSeason.getKey()); 64 | season.setSeason_type(cmb_hotel_season.getSelectedItem().toString()); 65 | JFormattedTextField[] checkDateList = {tf_season_start, tf_season_finish}; 66 | if (Helper.isFieldListEmpty(checkDateList)) { 67 | Helper.showMsg("fill"); 68 | } else { 69 | try { 70 | season.setStart_date(LocalDate.parse(tf_season_start.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 71 | season.setFinish_date(LocalDate.parse(tf_season_finish.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 72 | 73 | result = seasonManager.save(season); 74 | 75 | } catch (DateTimeException ex) { 76 | Helper.showMsg("Date Format is Wrong !"); 77 | return; 78 | } 79 | } 80 | if (result) { 81 | Helper.showMsg("done"); 82 | dispose(); // Close the window after saving 83 | } else { 84 | Helper.showMsg("error"); 85 | } 86 | } 87 | }); 88 | } 89 | 90 | /** 91 | * Method to create the UI components. 92 | * @throws ParseException If there's an error parsing the date format 93 | */ 94 | private void createUIComponents() throws ParseException { 95 | this.tf_season_start = new JFormattedTextField(new MaskFormatter("##/##/####")); 96 | this.tf_season_start.setText("01/06/2024"); 97 | this.tf_season_finish = new JFormattedTextField(new MaskFormatter("##/##/####")); 98 | this.tf_season_finish.setText("01/12/2024"); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/business/RoomManager.java: -------------------------------------------------------------------------------- 1 | package business; 2 | 3 | import core.Helper; 4 | import dao.RoomDao; 5 | import entity.Hotel; 6 | import entity.Room; 7 | 8 | import javax.swing.*; 9 | import javax.swing.table.DefaultTableModel; 10 | import java.time.LocalDate; 11 | import java.time.format.DateTimeFormatter; 12 | import java.util.ArrayList; 13 | 14 | // Manages operations related to rooms 15 | public class RoomManager { 16 | RoomDao roomDao = new RoomDao(); 17 | HotelManager hotelManager = new HotelManager(); 18 | 19 | // Adds a room record to the database 20 | public boolean save(Room room) { 21 | if (room.getRoom_id() != 0) { 22 | Helper.showMsg("error"); 23 | } 24 | return this.roomDao.save(room); 25 | } 26 | 27 | // Retrieves all rooms 28 | public ArrayList findAll() { 29 | return this.roomDao.findAll(); 30 | } 31 | 32 | // Provides information necessary for the table 33 | public ArrayList getForTable(int size) { 34 | ArrayList roomList = new ArrayList<>(); 35 | for (Room obj : this.findAll()) { 36 | int i = 0; 37 | Object[] rowObject = new Object[size]; 38 | rowObject[i++] = obj.getRoom_id(); 39 | rowObject[i++] = obj.getHotel_id(); 40 | rowObject[i++] = obj.getHotel_name(); 41 | rowObject[i++] = obj.getHotel_city(); 42 | rowObject[i++] = obj.getType(); 43 | rowObject[i++] = obj.getStock(); 44 | rowObject[i++] = obj.getAdult_price(); 45 | rowObject[i++] = obj.getChild_price(); 46 | rowObject[i++] = obj.getBed_capacity(); 47 | rowObject[i++] = obj.getSquare_meter(); 48 | rowObject[i++] = obj.isTelevision(); 49 | rowObject[i++] = obj.isMinibar(); 50 | rowObject[i++] = obj.isGame_console(); 51 | rowObject[i++] = obj.isCash_box(); 52 | rowObject[i++] = obj.isProjection(); 53 | rowObject[i++] = obj.getPension_id(); 54 | rowObject[i++] = obj.getSeason_id(); 55 | roomList.add(rowObject); 56 | } 57 | return roomList; 58 | } 59 | 60 | // Retrieves the city of the hotel 61 | public String getHotelCity(int hotelId) { 62 | Hotel hotel = hotelManager.findHotelById(hotelId); 63 | if (hotel != null) { 64 | return hotel.getCity(); 65 | } else { 66 | return ""; // Returns an empty string if the hotel is not found or there is no city information 67 | } 68 | } 69 | 70 | // Searches for rooms based on hotel name, city, entry date, and release date 71 | public ArrayList searchRooms(String hotelName, String city, String entryDate, String releaseDate) { 72 | return roomDao.searchRooms(hotelName, city, entryDate, releaseDate); 73 | } 74 | 75 | // Fills the room table with room information 76 | public void fillRoomTable(ArrayList roomList, JTable table) { 77 | DefaultTableModel model = (DefaultTableModel) table.getModel(); 78 | model.setRowCount(0); 79 | for (Room room : roomList) { 80 | Object[] row = { 81 | room.getRoom_id(), 82 | room.getHotel_id(), 83 | room.getHotel_name(), 84 | room.getHotel_city(), 85 | room.getType(), 86 | room.getStock(), 87 | room.getAdult_price(), 88 | room.getChild_price(), 89 | room.getBed_capacity(), 90 | room.getSquare_meter(), 91 | room.isTelevision(), 92 | room.isMinibar(), 93 | room.isGame_console(), 94 | room.isCash_box(), 95 | room.isProjection(), 96 | room.getPension_id(), 97 | room.getSeason_id() 98 | }; 99 | model.addRow(row); 100 | } 101 | } 102 | 103 | // Retrieves a room by its ID 104 | public Room getById(int id) { 105 | return this.roomDao.getById(id); 106 | } 107 | 108 | // Updates the stock of a room 109 | public boolean updateStock(Room room){ 110 | if(this.getById(room.getRoom_id()) == null){ 111 | return false; 112 | } 113 | return this.roomDao.updateStock(room); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Tourism Agency Management System 3 | 4 | ## Description 5 | Tourism Agency Management System Promotional Video 6 | 7 | Link : https://drive.google.com/drive/folders/1v4aX8t81EfQar818K_pRkrHmEdlIcigX?usp=sharing 8 | 9 | This project aims to create a digital management system for Patika Tourism Agency to streamline its daily operations in the hotel sector and optimize customer reservation processes. 10 | 11 | 12 | ## Table of Contents 13 | 14 | - [Description](#description) 15 | - [Technologies](#technologies) 16 | - [Project Overview](#project-overview) 17 | - [Features](#features) 18 | - [Installation](#installation) 19 | - [Clone](#clone) 20 | - [Permission Table](#permission-table) 21 | - [Database Design](#database-design) 22 | - [Coding Practices](#coding-practices) 23 | - [Screenshots](#screenshots) 24 | 25 | ## Technologies 26 | 27 | - Java 21 28 | - Swing Framework 29 | - PostgreSQL 30 | - IntelliJ IDEA 31 | 32 | ## Project Overview 33 | 34 | The project consists of 3 main parts: **Hotel Management**, **User Management** and **Reservation Management**. 35 | 36 | ## Features 37 | 38 | - **User Management:** 39 | - Admin can add, delete, update, and filter users based on their roles (admin, staff). 40 | 41 | - **Hotel Management:** 42 | - List hotels with details such as name, address, star rating, and amenities. 43 | - Add new hotels with information like email, phone, and location. 44 | - Specify accommodation types (pension types) offered by each hotel. 45 | 46 | - **Room Management:** 47 | - List rooms for each hotel with details like type, features, and availability. 48 | - Add new rooms, specifying type, features, and stock quantity. 49 | 50 | - **Season Management:** 51 | - Define historical seasons to adjust room pricing based on periods. 52 | - Specify start and end dates for each season. 53 | 54 | - **Pricing Management:** 55 | - Set dynamic pricing for rooms based on seasons and accommodation types. 56 | - Differentiate prices for adults and children. 57 | 58 | - **Room Search:** 59 | - Search available rooms based on city, date range, and hotel name. 60 | - Display relevant information about hotels and rooms that match the search criteria. 61 | 62 | - **Reservation Operations:** 63 | - List existing reservations with details like check-in/out dates, guests, and total price. 64 | - Add new reservations by selecting available rooms and providing guest information. 65 | - Delete or update existing reservations. 66 | - **Security:** 67 | - Users are required to log in to the system with their credentials. 68 | - 69 | ## Installation 70 | 71 | ### Clone 72 | 73 | 1. Clone the repository: `git clone https://github.com/ahmedaliibrahim01/Tourism_Agency_System.git` 74 | 2. Navigate to the project directory: `cd Tourism_Agency_System` 75 | 3. Open the project in your IDE 76 | 4. Create a database named `tourismagencysystem` in PostgreSQL or change the database name in the `src/main/java/agency/core/Db.java` file 77 | 5. Import the `tourismagencysystem.sql` 78 | 6. Run the project 79 | 80 | ### Permission Table 81 | 82 | ### Admin 83 | 84 | - User Management: Admin can list, add, delete, update, and filter users based on their roles (admin, staff). 85 | 86 | ### Employee (Agency Staff) 87 | 88 | - Hotel Management: List and add hotels. 89 | - Room Management: List and add rooms. 90 | - Season Management: List and add seasons. 91 | - Pricing Management. 92 | - Room Search. 93 | - Reservation Operations: List, add, delete, and update reservations. 94 | 95 | 96 | ## Database Design 97 | 98 | The system uses a relational database with the following tables: 99 | 100 | - `user`: Stores user information. 101 | - `hotel`: Stores hotel information. 102 | - `hotel_season`: Stores seasonal information for hotels. 103 | - `hote_pension`: Stores pension types for hotels. 104 | - `hotel_room`: Stores room information. 105 | - `reservation`: Stores reservation details. 106 | 107 | The project uses Swing for the graphical user interface, providing a user-friendly experience for both admins and employees. 108 | 109 | ### Coding Practices 110 | 111 | - Variable and function names are clear and self-explanatory. 112 | - Code readability and formatting are maintained with proper indentation. 113 | - Comments and documentation are provided for better understanding. 114 | - The code is modular and reusable. 115 | 116 | ## Screenshots 117 | 118 | Include screenshots here to visually showcase the application's interface and features. 119 | -------------------------------------------------------------------------------- /src/entity/Reservation.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | import java.time.LocalDate; 4 | 5 | public class Reservation { 6 | private int id; 7 | private int room_id; 8 | private String guest_name; 9 | private String guest_id; 10 | public String guest_email; 11 | public String guest_phone; 12 | private int adult_count; 13 | private int child_count; 14 | public LocalDate check_in_date; 15 | public LocalDate check_out_date; 16 | private String guest_note; 17 | private double total_price; 18 | private int hotel_id; 19 | 20 | 21 | // Boş kurucu metot 22 | public Reservation() { 23 | } 24 | 25 | 26 | // Parametreli kurucu metot 27 | 28 | public Reservation(int id, int room_id, String guest_name, String guest_id, String guest_mail, String guest_phone, int adult_count, int child_count, LocalDate check_in_date, LocalDate check_out_date, String guest_note, double total_price) { 29 | this.id = id; 30 | this.room_id = room_id; 31 | this.guest_name = guest_name; 32 | this.guest_id = guest_id; 33 | this.guest_email = guest_mail; 34 | this.guest_phone = guest_phone; 35 | this.adult_count = adult_count; 36 | this.child_count = child_count; 37 | this.check_in_date = check_in_date; 38 | this.check_out_date = check_out_date; 39 | this.guest_note = guest_note; 40 | this.total_price = total_price; 41 | } 42 | 43 | public int getId() { 44 | return id; 45 | } 46 | 47 | public void setId(int id) { 48 | this.id = id; 49 | } 50 | 51 | public int getRoom_id() { 52 | return room_id; 53 | } 54 | 55 | public void setRoom_id(int room_id) { 56 | this.room_id = room_id; 57 | } 58 | 59 | public String getGuest_name() { 60 | return guest_name; 61 | } 62 | 63 | public void setGuest_name(String guest_name) { 64 | this.guest_name = guest_name; 65 | } 66 | 67 | public String getGuest_id() { 68 | return guest_id; 69 | } 70 | 71 | public void setGuest_id(String guest_id) { 72 | this.guest_id = guest_id; 73 | } 74 | 75 | public String getGuest_email() { 76 | return guest_email; 77 | } 78 | 79 | public void setGuest_email(String guest_email) { 80 | this.guest_email = guest_email; 81 | } 82 | 83 | public String getGuest_phone() { 84 | return guest_phone; 85 | } 86 | 87 | public void setGuest_phone(String guest_phone) { 88 | this.guest_phone = guest_phone; 89 | } 90 | 91 | public int getAdult_count() { 92 | return adult_count; 93 | } 94 | 95 | public void setAdult_count(int adult_count) { 96 | this.adult_count = adult_count; 97 | } 98 | 99 | public int getChild_count() { 100 | return child_count; 101 | } 102 | 103 | public void setChild_count(int child_count) { 104 | this.child_count = child_count; 105 | } 106 | 107 | public LocalDate getCheck_in_date() { 108 | return check_in_date; 109 | } 110 | 111 | public void setCheck_in_date(LocalDate check_in_date) { 112 | this.check_in_date = check_in_date; 113 | } 114 | 115 | public LocalDate getCheck_out_date() { 116 | return check_out_date; 117 | } 118 | 119 | public void setCheck_out_date(LocalDate check_out_date) { 120 | this.check_out_date = check_out_date; 121 | } 122 | 123 | public String getGuest_note() { 124 | return guest_note; 125 | } 126 | 127 | public void setGuest_note(String guest_note) { 128 | this.guest_note = guest_note; 129 | } 130 | 131 | public double getTotal_price() { 132 | return total_price; 133 | } 134 | 135 | public void setTotal_price(double total_price) { 136 | this.total_price = total_price; 137 | } 138 | 139 | public int getHotel_id() { 140 | return hotel_id; 141 | } 142 | 143 | public void setHotel_id(int hotel_id) { 144 | this.hotel_id = hotel_id; 145 | } 146 | 147 | @Override 148 | public String toString() { 149 | return "Reservation{" + 150 | "id=" + id + 151 | ", room_id=" + room_id + 152 | ", guest_name='" + guest_name + '\'' + 153 | ", guest_id='" + guest_id + '\'' + 154 | ", guest_mail='" + guest_email + '\'' + 155 | ", guess_phone='" + guest_phone + '\'' + 156 | ", adult_count=" + adult_count + 157 | ", child_count=" + child_count + 158 | ", check_in_date=" + check_in_date + 159 | ", check_out_date=" + check_out_date + 160 | ", guest_note='" + guest_note + '\'' + 161 | ", total_price=" + total_price + 162 | '}'; 163 | } 164 | } 165 | -------------------------------------------------------------------------------- /src/view/PensionGUI.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /src/dao/SeasonDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import core.Db; 4 | import entity.Pension; 5 | import entity.Season; 6 | 7 | import java.sql.*; 8 | import java.time.LocalDate; 9 | import java.util.ArrayList; 10 | 11 | // Class responsible for database operations related to seasons 12 | public class SeasonDao { 13 | private final Connection connection; 14 | 15 | // Constructor method 16 | public SeasonDao() { 17 | this.connection = Db.getInstance(); 18 | } 19 | 20 | // Method to retrieve seasons of a specific hotel 21 | public ArrayList getSeasonsByOtelId(int hotelId) { 22 | ArrayList seasons = new ArrayList<>(); 23 | String query = "SELECT * FROM public.hotel_season WHERE hotel_id = ?"; 24 | 25 | try (PreparedStatement pr = connection.prepareStatement(query)) { 26 | pr.setInt(1, hotelId); 27 | ResultSet rs = pr.executeQuery(); 28 | 29 | while (rs.next()) { 30 | Season season = match(rs); 31 | seasons.add(season); 32 | } 33 | } catch (SQLException e) { 34 | e.printStackTrace(); 35 | } 36 | 37 | return seasons; 38 | } 39 | 40 | // Method to get a season by its ID 41 | public Season getByID(int id) { 42 | Season obj = null; 43 | String query = "SELECT * FROM public.hotel_season WHERE season_id = ? "; 44 | try { 45 | PreparedStatement pr = this.connection.prepareStatement(query); 46 | pr.setInt(1, id); 47 | ResultSet rs = pr.executeQuery(); 48 | if (rs.next()) { 49 | obj = this.match(rs); 50 | } 51 | } catch (SQLException e) { 52 | e.printStackTrace(); 53 | } 54 | return obj; 55 | } 56 | 57 | // Helper method to map ResultSet to Season object 58 | public Season match(ResultSet rs) throws SQLException { 59 | Season obj = new Season(); 60 | obj.setId(rs.getInt("season_id")); 61 | obj.setHotel_id(rs.getInt("hotel_id")); 62 | obj.setStart_date(LocalDate.parse(rs.getString("start_date"))); 63 | obj.setFinish_date(LocalDate.parse(rs.getString("finish_date"))); 64 | return obj; 65 | } 66 | 67 | // Method to retrieve all seasons 68 | public ArrayList findAll() { 69 | ArrayList seasonList = new ArrayList<>(); 70 | String sql = "SELECT * FROM public.hotel_season"; 71 | try { 72 | ResultSet rs = this.connection.createStatement().executeQuery(sql); 73 | while (rs.next()) { 74 | seasonList.add(this.match(rs)); 75 | } 76 | } catch (SQLException e) { 77 | e.printStackTrace(); 78 | } 79 | return seasonList; 80 | } 81 | 82 | // Method to save a season 83 | public boolean save(Season season){ 84 | String query = "INSERT INTO public.hotel_season"+ 85 | "("+ 86 | "hotel_id,"+ 87 | "start_date," + 88 | "finish_date"+ 89 | ")"+ 90 | "VALUES (?,?,?)"; 91 | try { 92 | PreparedStatement pr = connection.prepareStatement(query); 93 | pr.setInt(1,season.getHotel_id()); 94 | pr.setDate(2, Date.valueOf(season.getStart_date())); 95 | pr.setDate(3, Date.valueOf(season.getFinish_date())); 96 | return pr.executeUpdate() != -1; 97 | } catch (SQLException throwables) { 98 | throwables.printStackTrace(); 99 | } 100 | return true; 101 | } 102 | 103 | // Method to delete a season 104 | public boolean delete(int hotel_id){ 105 | try{ 106 | String query = "DELETE FROM public.hotel_season WHERE id = ?"; 107 | PreparedStatement pr = connection.prepareStatement(query); 108 | pr.setInt(1,hotel_id); 109 | return pr.executeUpdate() != -1; 110 | }catch (SQLException throwables){ 111 | throwables.printStackTrace(); 112 | } 113 | return true; 114 | } 115 | 116 | // Method to get seasons of a hotel 117 | public ArrayList getHotelSeason(int hotelId) { 118 | ArrayList seasonList = new ArrayList<>(); 119 | try { 120 | String query = "SELECT start_date,finish_date FROM public.hotel_season WHERE hotel_id = ?"; 121 | PreparedStatement preparedStatement = connection.prepareStatement(query); 122 | preparedStatement.setInt(1, hotelId); 123 | ResultSet resultSet = preparedStatement.executeQuery(); 124 | 125 | while (resultSet.next()) { 126 | Season season = new Season(); 127 | season.setStart_date(LocalDate.parse(resultSet.getString("start_date"))); 128 | season.setFinish_date(LocalDate.parse(resultSet.getString("finish_date"))); 129 | seasonList.add(season); 130 | } 131 | }catch (SQLException e){ 132 | e.printStackTrace(); 133 | } 134 | return seasonList; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/view/UserGUI.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /src/dao/HotelDAO.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import core.Db; 4 | import entity.Hotel; 5 | 6 | import java.sql.*; 7 | import java.util.ArrayList; 8 | 9 | // Class responsible for database operations related to hotels 10 | public class HotelDAO { 11 | private Connection connection; 12 | 13 | // Constructor 14 | public HotelDAO() { 15 | this.connection = Db.getInstance(); 16 | } 17 | 18 | // Method to find all hotels 19 | public ArrayList findAll() { 20 | ArrayList hotelList = new ArrayList<>(); 21 | String sql = "SELECT * FROM public.hotel ORDER BY hotel_id ASC"; 22 | try { 23 | ResultSet rs = this.connection.createStatement().executeQuery(sql); 24 | while (rs.next()) { 25 | hotelList.add(this.match(rs)); 26 | } 27 | } catch (SQLException e) { 28 | e.printStackTrace(); 29 | } 30 | return hotelList; 31 | } 32 | 33 | // Method to update a hotel 34 | public boolean update(Hotel hotel) { 35 | String query = "UPDATE public.hotel SET hotel_name = ?, hotel_city = ?, hotel_region = ?, hotel_full_address = ?, hotel_phone = ?, hotel_email = ?, hotel_star = ?, hotel_facilities = ? WHERE hotel_id = ?"; 36 | try { 37 | PreparedStatement pr = this.connection.prepareStatement(query); 38 | pr.setString(1, hotel.getName()); 39 | pr.setString(2, hotel.getCity()); 40 | pr.setString(3, hotel.getRegion()); 41 | pr.setString(4, hotel.getFullAddress()); 42 | pr.setString(5, hotel.getPhone()); 43 | pr.setString(6, hotel.getEmail()); 44 | pr.setString(7, hotel.getStar()); 45 | Array facilitiesArray = this.connection.createArrayOf("text", hotel.getFacilities()); 46 | pr.setArray(8, facilitiesArray); 47 | pr.setInt(9,hotel.getId()); 48 | return pr.executeUpdate() != -1; 49 | } catch (SQLException e) { 50 | e.printStackTrace(); 51 | } 52 | return true; 53 | } 54 | 55 | // Method to save a new hotel 56 | public boolean save(Hotel hotel) { 57 | String query = "INSERT INTO public.hotel (hotel_name, hotel_city, hotel_region, hotel_full_address, hotel_phone, hotel_email, hotel_star, hotel_facilities) VALUES (?,?,?,?,?,?,?,?)"; 58 | try { 59 | PreparedStatement pr = this.connection.prepareStatement(query); 60 | pr.setString(1, hotel.getName()); 61 | pr.setString(2, hotel.getCity()); 62 | pr.setString(3, hotel.getRegion()); 63 | pr.setString(4, hotel.getFullAddress()); 64 | pr.setString(5, hotel.getPhone()); 65 | pr.setString(6, hotel.getEmail()); 66 | pr.setString(7, hotel.getStar()); 67 | Array facilitiesArray = this.connection.createArrayOf("text", hotel.getFacilities()); 68 | pr.setArray(8, facilitiesArray); 69 | return pr.executeUpdate() != -1; 70 | } catch (SQLException e) { 71 | e.printStackTrace(); 72 | } 73 | return true; 74 | } 75 | 76 | // Method to delete a hotel by its ID 77 | public boolean delete(int id) { 78 | String query = "DELETE FROM public.hotel WHERE hotel_id = ?"; 79 | try { 80 | PreparedStatement pr = this.connection.prepareStatement(query); 81 | pr.setInt(1, id); 82 | return pr.executeUpdate() != -1; 83 | } catch (SQLException e) { 84 | e.printStackTrace(); 85 | } 86 | return true; 87 | } 88 | 89 | // Method to get a hotel by its ID 90 | public Hotel getById(int id) { 91 | Hotel obj = null; 92 | String query = "SELECT * FROM public.hotel WHERE hotel_id = ? "; 93 | try { 94 | PreparedStatement pr = this.connection.prepareStatement(query); 95 | pr.setInt(1, id); 96 | ResultSet rs = pr.executeQuery(); 97 | if (rs.next()) { 98 | obj = this.match(rs); 99 | } 100 | } catch (SQLException e) { 101 | e.printStackTrace(); 102 | } 103 | return obj; 104 | } 105 | 106 | // Method to filter hotels (not used in the provided code) 107 | public ArrayList filterByAdmin() { 108 | ArrayList hotelList = new ArrayList<>(); 109 | String sql = "SELECT * FROM public.hotel ORDER BY hotel_id ASC"; 110 | try { 111 | ResultSet rs = this.connection.createStatement().executeQuery(sql); 112 | while (rs.next()) { 113 | hotelList.add(this.match(rs)); 114 | } 115 | } catch (SQLException e) { 116 | e.printStackTrace(); 117 | } 118 | return hotelList; 119 | } 120 | 121 | // Helper method to map ResultSet to Hotel object 122 | public Hotel match(ResultSet rs) throws SQLException { 123 | Hotel obj = new Hotel(); 124 | obj.setId(rs.getInt("hotel_id")); 125 | obj.setName(rs.getString("hotel_name")); 126 | obj.setCity(rs.getString("hotel_city")); 127 | obj.setRegion(rs.getString("hotel_region")); 128 | obj.setFullAddress(rs.getString("hotel_full_address")); 129 | obj.setPhone(rs.getString("hotel_phone")); 130 | obj.setEmail(rs.getString("hotel_email")); 131 | obj.setStar(rs.getString("hotel_star")); 132 | return obj; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/dao/PensionDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import core.Db; 4 | import entity.Hotel; 5 | import entity.Pension; 6 | 7 | import java.sql.*; 8 | import java.util.ArrayList; 9 | import java.util.Arrays; 10 | 11 | // Class responsible for database operations related to pensions 12 | public class PensionDao { 13 | private final Connection connection; 14 | 15 | // Constructor 16 | public PensionDao() { 17 | this.connection = Db.getInstance(); 18 | } 19 | 20 | // Method to get pensions with a specific hotel ID 21 | public ArrayList getPensionByOtelId(int id) { 22 | ArrayList pensions = new ArrayList<>(); 23 | String query = "SELECT * FROM public.hotel_pension WHERE hotel_id = ?"; 24 | try { 25 | PreparedStatement pr = connection.prepareStatement(query); 26 | pr.setInt(1, id); 27 | ResultSet rs = pr.executeQuery(); 28 | 29 | while (rs.next()) { 30 | Pension pension = match(rs); 31 | pensions.add(pension); 32 | } 33 | } catch (SQLException e) { 34 | e.printStackTrace(); 35 | } 36 | 37 | return pensions; 38 | } 39 | 40 | // Method to get a pension by its ID 41 | public Pension getByID(int id) { 42 | Pension obj = null; 43 | String query = "SELECT * FROM public.hotel_pension WHERE pension_id = ? "; 44 | try { 45 | PreparedStatement pr = this.connection.prepareStatement(query); 46 | pr.setInt(1, id); 47 | ResultSet rs = pr.executeQuery(); 48 | if (rs.next()) { 49 | obj = this.match(rs); 50 | } 51 | } catch (SQLException e) { 52 | e.printStackTrace(); 53 | } 54 | return obj; 55 | } 56 | 57 | // Helper method to map ResultSet to Pension object 58 | public Pension match(ResultSet rs) throws SQLException { 59 | Pension obj = new Pension(); 60 | obj.setPension_id(rs.getInt("pension_id")); 61 | obj.setHotel_id(rs.getInt("hotel_id")); 62 | obj.setPension_type(rs.getString("pension_type")); 63 | return obj; 64 | } 65 | 66 | // Method to update a pension 67 | public boolean update(Pension pension) { 68 | try { 69 | String query = "UPDATE public.hotel_pension SET " + 70 | "hotel_id = ?," + 71 | "pension_type = ?" + 72 | "WHERE user_id = ?"; 73 | PreparedStatement pr = connection.prepareStatement(query); 74 | pr.setInt(1,pension.getHotel_id()); 75 | pr.setString(2,pension.getPension_type()); 76 | return pr.executeUpdate() != -1; 77 | 78 | } catch (SQLException throwables) { 79 | throwables.printStackTrace(); 80 | } 81 | return true; 82 | } 83 | 84 | // Method to get all pensions 85 | public ArrayList findAll() { 86 | ArrayList pensionList = new ArrayList<>(); 87 | String sql = "SELECT * FROM public.hotel_pension"; 88 | try { 89 | ResultSet rs = this.connection.createStatement().executeQuery(sql); 90 | while (rs.next()) { 91 | pensionList.add(this.match(rs)); 92 | } 93 | } catch (SQLException e) { 94 | e.printStackTrace(); 95 | } 96 | return pensionList; 97 | } 98 | 99 | // Method to add a pension 100 | public boolean save(Pension pension){ 101 | String query = "INSERT INTO public.hotel_pension"+ 102 | "("+ 103 | "hotel_id,"+ 104 | "pension_type"+ 105 | ")"+ 106 | "VALUES (?,?)"; 107 | try { 108 | PreparedStatement pr = connection.prepareStatement(query); 109 | pr.setInt(1,pension.getHotel_id()); 110 | pr.setString(2,pension.getPension_type()); 111 | return pr.executeUpdate() != -1; 112 | } catch (SQLException throwables) { 113 | throwables.printStackTrace(); 114 | } 115 | return true; 116 | } 117 | 118 | // Method to delete a pension 119 | public boolean delete(int hotel_id){ 120 | try{ 121 | String query = "DELETE FROM public.hotel_pension WHERE pension_id = ?"; 122 | PreparedStatement pr = connection.prepareStatement(query); 123 | pr.setInt(1,hotel_id); 124 | return pr.executeUpdate() != -1; 125 | }catch (SQLException throwables){ 126 | throwables.printStackTrace(); 127 | } 128 | return true; 129 | } 130 | 131 | // Method to get pension types of a hotel 132 | public ArrayList getHotelPensionTypes(int hotelId) { 133 | ArrayList pensionTypeList = new ArrayList<>(); 134 | try { 135 | String query = "SELECT pension_type FROM public.hotel_pension WHERE hotel_id = ?"; 136 | PreparedStatement preparedStatement = connection.prepareStatement(query); 137 | preparedStatement.setInt(1, hotelId); 138 | ResultSet resultSet = preparedStatement.executeQuery(); 139 | 140 | while (resultSet.next()) { 141 | Pension pension = new Pension(); 142 | pension.setPension_type(resultSet.getString("pension_type")); 143 | pensionTypeList.add(pension); 144 | } 145 | } catch (SQLException e) { 146 | e.printStackTrace(); 147 | } 148 | return pensionTypeList; 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/core/Helper.java: -------------------------------------------------------------------------------- 1 | package core; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | /** 7 | * Utility class providing helper methods for Swing applications. 8 | */ 9 | public class Helper { 10 | 11 | /** 12 | * Sets the look and feel of the Swing application to Nimbus, if available. 13 | */ 14 | public static void setTheme() { 15 | for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) { 16 | if ("Nimbus".equals(info.getName())) { 17 | try { 18 | UIManager.setLookAndFeel(info.getClassName()); 19 | } catch (Exception e) { 20 | System.out.println(e.getMessage()); 21 | } 22 | break; 23 | } 24 | } 25 | } 26 | 27 | /** 28 | * Displays a message dialog with a given message string. 29 | * @param str The message string or a predefined message key. 30 | */ 31 | public static void showMsg(String str) { 32 | String message; 33 | String title; 34 | switch (str) { 35 | case "fill" -> { 36 | message = "Please fill in all fields!"; 37 | title = "Error"; 38 | } 39 | case "done" -> { 40 | message = "Successful!"; 41 | title = "Result"; 42 | } 43 | case "notFound" -> { 44 | message = "Not found!"; 45 | title = "Not found"; 46 | } 47 | case "error" -> { 48 | message = "You've made a mistake!"; 49 | title = "Error!"; 50 | } 51 | default -> { 52 | message = str; 53 | title = "Message"; 54 | } 55 | } 56 | JOptionPane.showMessageDialog(null, message, title, JOptionPane.INFORMATION_MESSAGE); 57 | } 58 | 59 | /** 60 | * Displays a confirmation dialog with a given message and title. 61 | * @param str The message string or a predefined message key. 62 | * @param title The title of the dialog. 63 | * @return True if the user selects "Yes", false otherwise. 64 | */ 65 | public static boolean confirm(String str, String title) { 66 | String msg; 67 | if (str.equals("sure")) { 68 | msg = "Are you sure you want to do this?"; 69 | } else { 70 | msg = str; 71 | } 72 | return JOptionPane.showConfirmDialog(null, msg, title, JOptionPane.YES_NO_OPTION) == 0; 73 | } 74 | 75 | /** 76 | * Checks if a JTextField is empty. 77 | * @param field The JTextField to check. 78 | * @return True if the field is empty, false otherwise. 79 | */ 80 | public static boolean isFieldEmpty(JTextField field) { 81 | return field.getText().trim().isEmpty(); 82 | } 83 | 84 | /** 85 | * Checks if a JComboBox is empty. 86 | * @param comboBox The JComboBox to check. 87 | * @return True if the combo box is empty, false otherwise. 88 | */ 89 | public static boolean isComboBoxEmpty(JComboBox comboBox) { 90 | Object selectedItem = comboBox.getSelectedItem(); 91 | if (selectedItem == null) { 92 | return true; 93 | } else { 94 | if (selectedItem instanceof String) { 95 | return ((String) selectedItem).isEmpty(); 96 | } else { 97 | return false; // I didn't handle other cases in the example, returned false here without any action. 98 | } 99 | } 100 | } 101 | 102 | /** 103 | * Checks if a JTable is empty. 104 | * @param table The JTable to check. 105 | * @return True if the table is empty, false otherwise. 106 | */ 107 | public static boolean isTableEmpty(JTable table) { 108 | int rowCount = table.getRowCount(); 109 | int columnCount = table.getColumnCount(); 110 | 111 | for (int row = 0; row < rowCount; row++) { 112 | for (int col = 0; col < columnCount; col++) { 113 | Object value = table.getValueAt(row, col); 114 | if (value != null && !value.toString().isEmpty()) { 115 | return false; 116 | } 117 | } 118 | } 119 | return true; 120 | } 121 | 122 | /** 123 | * Checks if an array of JTextFields contains any empty fields. 124 | * @param fieldList The array of JTextFields to check. 125 | * @return True if any field is empty, false otherwise. 126 | */ 127 | public static boolean isFieldListEmpty(JTextField[] fieldList) { 128 | for (JTextField field : fieldList) { 129 | if (isFieldEmpty(field)) return true; 130 | } 131 | return false; 132 | } 133 | 134 | /** 135 | * Calculates the location point for a window to be centered on the screen. 136 | * @param type The type of location point (x or y). 137 | * @param size The size of the window. 138 | * @return The location point value. 139 | */ 140 | public static int getLocationPoint(String type, Dimension size) { 141 | return switch (type) { 142 | case "x" -> (Toolkit.getDefaultToolkit().getScreenSize().width - size.width) / 2; 143 | case "y" -> (Toolkit.getDefaultToolkit().getScreenSize().height - size.height) / 2; 144 | default -> 0; 145 | }; 146 | } 147 | 148 | /** 149 | * Converts the first character of a string to uppercase. 150 | * @param str The input string. 151 | * @return The string with the first character in uppercase. 152 | */ 153 | public static String firstWordUpper(String str){ 154 | return str.substring(0,1).toUpperCase()+str.substring(1); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /src/view/ADDRoomGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.*; 4 | import core.ComboItem; 5 | import core.Helper; 6 | import entity.*; 7 | 8 | import javax.swing.*; 9 | import java.util.ArrayList; 10 | 11 | // Represents the graphical user interface for adding a room 12 | public class ADDRoomGUI extends Layout { 13 | private JComboBox cmb_room_add_hotel; 14 | private JComboBox cmb_season_add; 15 | private JComboBox cmb_room_type_add; 16 | private JTextField tf_adult_price; 17 | private JRadioButton rbut_projection; 18 | private JButton btn_save_add_room; 19 | private JPanel container; 20 | private JComboBox cmb_pension_add; 21 | private JTextField tf_child_price; 22 | private JTextField tf_bed_capacity; 23 | private JTextField tf_square_meter; 24 | private JRadioButton rbut_television; 25 | private JRadioButton rbut_minibar; 26 | private JRadioButton rbut_game_console; 27 | private JRadioButton rbut_cashbox; 28 | private JTextField tf_stock; 29 | private JLabel lbl_room; 30 | private HotelManager hotelManager; 31 | private SeasonManager seasonManager; 32 | private PensionManager pensionManager; 33 | private Hotel hotel; 34 | private Room room; 35 | private Season season; 36 | private RoomManager roomManager; 37 | 38 | // Constructor for ADDRoomGUI 39 | public ADDRoomGUI() { 40 | this.add(container); 41 | this.guiInitialize(600, 550); 42 | this.hotel = new Hotel(); 43 | this.room = new Room(); 44 | this.season = new Season(); 45 | this.pensionManager = new PensionManager(); 46 | this.seasonManager = new SeasonManager(); 47 | this.hotelManager = new HotelManager(); 48 | this.roomManager = new RoomManager(); 49 | 50 | // Populate hotel combo box 51 | for (Hotel hotel : hotelManager.findAll()) { 52 | this.cmb_room_add_hotel.addItem(hotel.getComboItem()); 53 | } 54 | 55 | // Handle hotel combo box selection change event 56 | cmb_room_add_hotel.addActionListener(e -> { 57 | ComboItem selectedHotelItem = (ComboItem) cmb_room_add_hotel.getSelectedItem(); 58 | 59 | // Populate pension combo box based on selected hotel 60 | ArrayList pensions = pensionManager.getPensionByOtelId(selectedHotelItem.getKey()); 61 | cmb_pension_add.removeAllItems(); 62 | 63 | for (Pension pension : pensions) { 64 | cmb_pension_add.addItem(pension.getComboItem()); 65 | } 66 | 67 | // Populate season combo box based on selected hotel 68 | ArrayList seasons = seasonManager.getSeasonsByOtelId(selectedHotelItem.getKey()); 69 | cmb_season_add.removeAllItems(); 70 | 71 | for (Season season : seasons) { 72 | cmb_season_add.addItem(season.getComboItem()); 73 | } 74 | }); 75 | 76 | // Handle save button click event 77 | btn_save_add_room.addActionListener(e -> { 78 | JTextField[] selectedRoomList = {tf_adult_price, tf_child_price, tf_bed_capacity, tf_bed_capacity, tf_square_meter}; 79 | if (Helper.isComboBoxEmpty(cmb_room_add_hotel) 80 | || Helper.isComboBoxEmpty(cmb_pension_add) 81 | || Helper.isComboBoxEmpty(cmb_season_add) 82 | || Helper.isComboBoxEmpty(cmb_room_type_add) 83 | || Helper.isFieldListEmpty(selectedRoomList)) { 84 | Helper.showMsg("Please fill in all fields."); 85 | } else { 86 | ComboItem selectedHotel = (ComboItem) cmb_room_add_hotel.getSelectedItem(); 87 | ComboItem selectedPension = (ComboItem) cmb_pension_add.getSelectedItem(); 88 | ComboItem selectedSeason = (ComboItem) cmb_season_add.getSelectedItem(); 89 | 90 | ComboItem selectedHotelId = (ComboItem) cmb_room_add_hotel.getSelectedItem(); 91 | int hotelId = selectedHotelId.getKey(); 92 | 93 | // Set room properties 94 | room.setHotel_name(selectedHotel.getValue()); 95 | room.setHotel_city(roomManager.getHotelCity(hotelId)); 96 | room.setType((String) cmb_room_type_add.getSelectedItem()); 97 | room.setStock(Integer.parseInt(tf_stock.getText())); 98 | room.setAdult_price(Double.parseDouble(tf_adult_price.getText())); 99 | room.setChild_price(Double.parseDouble(tf_child_price.getText())); 100 | room.setBed_capacity(Integer.parseInt(tf_bed_capacity.getText())); 101 | room.setSquare_meter(Integer.parseInt(tf_square_meter.getText())); 102 | room.setTelevision(rbut_television.isSelected()); 103 | room.setMinibar(rbut_minibar.isSelected()); 104 | room.setGame_console(rbut_game_console.isSelected()); 105 | room.setCash_box(rbut_cashbox.isSelected()); 106 | room.setProjection(rbut_projection.isSelected()); 107 | room.setHotel_id(selectedHotel.getKey()); 108 | room.setPension_id(selectedPension.getKey()); 109 | room.setSeason_id(selectedSeason.getKey()); 110 | 111 | // Save room 112 | boolean result = false; 113 | if (room.getRoom_id() == 0) { 114 | result = roomManager.save(room); 115 | } 116 | if (result) { 117 | Helper.showMsg("Room added successfully."); 118 | dispose(); 119 | } else { 120 | Helper.showMsg("Error occurred while adding room."); 121 | } 122 | } 123 | }); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/view/SeasonGUI.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /src/entity/Room.java: -------------------------------------------------------------------------------- 1 | package entity; 2 | 3 | public class Room { 4 | private int room_id; 5 | private String hotel_name; 6 | private String type; 7 | private int stock; 8 | private double adult_price; 9 | private double child_price; 10 | private int bed_capacity; 11 | private int square_meter; 12 | private boolean television; 13 | private boolean minibar; 14 | private boolean game_console; 15 | private boolean cash_box; 16 | private boolean projection; 17 | private int hotel_id; 18 | private int pension_id; 19 | private int season_id; 20 | private String hotel_city; 21 | private Hotel hotel; 22 | 23 | 24 | // Boş kurucu metot 25 | public Room() { 26 | } 27 | 28 | public Room(int room_id, String hotel_name, String type, int stock, double adult_price, double child_price, int bed_capacity, int square_meter, boolean television, boolean minibar, boolean game_console, boolean cash_box, boolean projection, int hotel_id, int pension_id, int season_id, String hotel_city) { 29 | this.room_id = room_id; 30 | this.hotel_name = hotel_name; 31 | this.type = type; 32 | this.stock = stock; 33 | this.adult_price = adult_price; 34 | this.child_price = child_price; 35 | this.bed_capacity = bed_capacity; 36 | this.square_meter = square_meter; 37 | this.television = television; 38 | this.minibar = minibar; 39 | this.game_console = game_console; 40 | this.cash_box = cash_box; 41 | this.projection = projection; 42 | this.hotel_id = hotel_id; 43 | this.pension_id = pension_id; 44 | this.season_id = season_id; 45 | this.hotel_city = hotel_city; 46 | } 47 | 48 | public int getRoom_id() { 49 | return room_id; 50 | } 51 | 52 | public void setRoom_id(int room_id) { 53 | this.room_id = room_id; 54 | } 55 | 56 | public String getHotel_name() { 57 | return hotel_name; 58 | } 59 | 60 | public void setHotel_name(String hotel_name) { 61 | this.hotel_name = hotel_name; 62 | } 63 | 64 | public String getType() { 65 | return type; 66 | } 67 | 68 | public void setType(String type) { 69 | this.type = type; 70 | } 71 | 72 | public int getStock() { 73 | return stock; 74 | } 75 | 76 | public void setStock(int stock) { 77 | this.stock = stock; 78 | } 79 | 80 | public double getAdult_price() { 81 | return adult_price; 82 | } 83 | 84 | public void setAdult_price(double adult_price) { 85 | this.adult_price = adult_price; 86 | } 87 | 88 | public double getChild_price() { 89 | return child_price; 90 | } 91 | 92 | public void setChild_price(double child_price) { 93 | this.child_price = child_price; 94 | } 95 | 96 | public int getBed_capacity() { 97 | return bed_capacity; 98 | } 99 | 100 | public void setBed_capacity(int bed_capacity) { 101 | this.bed_capacity = bed_capacity; 102 | } 103 | 104 | public int getSquare_meter() { 105 | return square_meter; 106 | } 107 | 108 | public void setSquare_meter(int square_meter) { 109 | this.square_meter = square_meter; 110 | } 111 | 112 | public boolean isTelevision() { 113 | return television; 114 | } 115 | 116 | public void setTelevision(boolean television) { 117 | this.television = television; 118 | } 119 | 120 | public boolean isMinibar() { 121 | return minibar; 122 | } 123 | 124 | public void setMinibar(boolean minibar) { 125 | this.minibar = minibar; 126 | } 127 | 128 | public boolean isGame_console() { 129 | return game_console; 130 | } 131 | 132 | public void setGame_console(boolean game_console) { 133 | this.game_console = game_console; 134 | } 135 | 136 | public boolean isCash_box() { 137 | return cash_box; 138 | } 139 | 140 | public void setCash_box(boolean cash_box) { 141 | this.cash_box = cash_box; 142 | } 143 | 144 | public boolean isProjection() { 145 | return projection; 146 | } 147 | 148 | public void setProjection(boolean projection) { 149 | this.projection = projection; 150 | } 151 | 152 | public int getHotel_id() { 153 | return hotel_id; 154 | } 155 | 156 | public void setHotel_id(int hotel_id) { 157 | this.hotel_id = hotel_id; 158 | } 159 | 160 | public int getPension_id() { 161 | return pension_id; 162 | } 163 | 164 | public void setPension_id(int pension_id) { 165 | this.pension_id = pension_id; 166 | } 167 | 168 | public int getSeason_id() { 169 | return season_id; 170 | } 171 | 172 | public void setSeason_id(int season_id) { 173 | this.season_id = season_id; 174 | } 175 | 176 | public String getHotel_city() { 177 | return hotel_city; 178 | } 179 | 180 | public void setHotel_city(String hotel_city) { 181 | this.hotel_city = hotel_city; 182 | } 183 | 184 | public Hotel getHotel() { 185 | return hotel; 186 | } 187 | 188 | public void setHotel(Hotel hotel) { 189 | this.hotel = hotel; 190 | } 191 | @Override 192 | public String toString() { 193 | return "Room{" + 194 | "room_id=" + room_id + 195 | ", hotel_name='" + hotel_name + '\'' + 196 | ", type='" + type + '\'' + 197 | ", stock=" + stock + 198 | ", adult_price=" + adult_price + 199 | ", child_price=" + child_price + 200 | ", bed_capacity=" + bed_capacity + 201 | ", square_meter=" + square_meter + 202 | ", television=" + television + 203 | ", minibar=" + minibar + 204 | ", game_console=" + game_console + 205 | ", cash_box=" + cash_box + 206 | ", projection=" + projection + 207 | ", hotel_id=" + hotel_id + 208 | ", pension_id=" + pension_id + 209 | ", season_id=" + season_id + 210 | ", hotel_city='" + hotel_city + '\'' + 211 | '}'; 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /src/view/LoginGUI.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /src/dao/RoomDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import core.Db; 4 | import entity.Room; 5 | 6 | import java.sql.Connection; 7 | import java.sql.PreparedStatement; 8 | import java.sql.ResultSet; 9 | import java.sql.SQLException; 10 | import java.time.LocalDate; 11 | import java.util.ArrayList; 12 | 13 | // Class responsible for database operations related to rooms 14 | public class RoomDao { 15 | private final Connection connection; 16 | 17 | // Constructor method 18 | public RoomDao() { 19 | this.connection = Db.getInstance(); 20 | } 21 | 22 | // Method to retrieve all rooms 23 | public ArrayList findAll() { 24 | ArrayList roomList = new ArrayList<>(); 25 | String sql = "SELECT * FROM public.hotel_room"; 26 | try { 27 | ResultSet rs = this.connection.createStatement().executeQuery(sql); 28 | while (rs.next()) { 29 | roomList.add(this.match(rs)); 30 | } 31 | } catch (SQLException e) { 32 | e.printStackTrace(); 33 | } 34 | return roomList; 35 | } 36 | 37 | // Helper method to map ResultSet to Room object 38 | public Room match(ResultSet rs) throws SQLException { 39 | Room obj = new Room(); 40 | obj.setRoom_id(rs.getInt("room_id")); 41 | obj.setHotel_id(rs.getInt("hotel_id")); 42 | obj.setHotel_name(rs.getString("hotel_name")); 43 | obj.setHotel_city(rs.getString("hotel_city")); 44 | obj.setType(rs.getString("type")); 45 | obj.setStock(rs.getInt("stock")); 46 | obj.setAdult_price(rs.getDouble("adult_price")); 47 | obj.setChild_price(rs.getDouble("child_price")); 48 | obj.setBed_capacity(rs.getInt("bed_capacity")); 49 | obj.setSquare_meter(rs.getInt("square_meter")); 50 | obj.setTelevision(rs.getBoolean("television")); 51 | obj.setMinibar(rs.getBoolean("minibar")); 52 | obj.setGame_console(rs.getBoolean("game_console")); 53 | obj.setCash_box(rs.getBoolean("cash_box")); 54 | obj.setProjection(rs.getBoolean("projection")); 55 | obj.setPension_id(rs.getInt("pension_id")); 56 | obj.setSeason_id(rs.getInt("season_id")); 57 | return obj; 58 | } 59 | 60 | // Method to add a room 61 | public boolean save(Room room) { 62 | String query = "INSERT INTO public.hotel_room" + 63 | "(" + 64 | "hotel_name," + 65 | "hotel_city,"+ 66 | "type," + 67 | "stock," + 68 | "adult_price," + 69 | "child_price," + 70 | "bed_capacity," + 71 | "square_meter," + 72 | "television," + 73 | "minibar," + 74 | "game_console," + 75 | "cash_box," + 76 | "projection," + 77 | "hotel_id," + 78 | "pension_id," + 79 | "season_id" + 80 | ")" + 81 | "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 82 | try { 83 | PreparedStatement pr = connection.prepareStatement(query); 84 | pr.setString(1,room.getHotel_name()); 85 | pr.setString(2,room.getHotel_city()); 86 | pr.setString(3, room.getType()); 87 | pr.setInt(4, room.getStock()); 88 | pr.setDouble(5, room.getAdult_price()); 89 | pr.setDouble(6, room.getChild_price()); 90 | pr.setInt(7, room.getBed_capacity()); 91 | pr.setInt(8, room.getSquare_meter()); 92 | pr.setBoolean(9, room.isTelevision()); 93 | pr.setBoolean(10, room.isMinibar()); 94 | pr.setBoolean(11, room.isGame_console()); 95 | pr.setBoolean(12, room.isCash_box()); 96 | pr.setBoolean(13, room.isProjection()); 97 | pr.setInt(14,room.getHotel_id()); 98 | pr.setInt(15, room.getPension_id()); 99 | pr.setInt(16, room.getSeason_id()); 100 | return pr.executeUpdate() != -1; 101 | } catch (SQLException throwables) { 102 | throwables.printStackTrace(); 103 | } 104 | return true; 105 | } 106 | 107 | // Method to dynamically create and execute a SQL query with necessary parameters 108 | public ArrayList searchRooms(String hotelName, String city, String entryDate, String releaseDate) { 109 | ArrayList roomList = new ArrayList<>(); 110 | StringBuilder sqlBuilder = new StringBuilder("SELECT * FROM public.hotel_room WHERE 1=1"); 111 | 112 | // Add hotel name parameter to the query if provided 113 | if (hotelName != null && !hotelName.isEmpty()) { 114 | sqlBuilder.append(" AND hotel_name = ?"); 115 | } 116 | 117 | // Add city parameter to the query if provided 118 | if (city != null && !city.isEmpty()) { 119 | sqlBuilder.append(" AND hotel_city = ?"); 120 | } 121 | 122 | // Add entry date parameter to the query if provided 123 | if (entryDate != null && !entryDate.isEmpty()) { 124 | sqlBuilder.append(" AND entry_date >= ?"); 125 | } 126 | 127 | // Add release date parameter to the query if provided 128 | if (releaseDate != null && !releaseDate.isEmpty()) { 129 | sqlBuilder.append(" AND release_date <= ?"); 130 | } 131 | 132 | try { 133 | PreparedStatement pr = connection.prepareStatement(sqlBuilder.toString()); 134 | 135 | int parameterIndex = 1; 136 | 137 | // Add parameters to the query 138 | if (hotelName != null && !hotelName.isEmpty()) { 139 | pr.setString(parameterIndex++, hotelName); 140 | } 141 | if (city != null && !city.isEmpty()) { 142 | pr.setString(parameterIndex++, city); 143 | } 144 | if (entryDate != null && !entryDate.isEmpty()) { 145 | pr.setString(parameterIndex++, entryDate); 146 | } 147 | if (releaseDate != null && !releaseDate.isEmpty()) { 148 | pr.setString(parameterIndex++, releaseDate); 149 | } 150 | 151 | ResultSet rs = pr.executeQuery(); 152 | 153 | while (rs.next()) { 154 | roomList.add(match(rs)); 155 | } 156 | } catch (SQLException e) { 157 | e.printStackTrace(); 158 | } 159 | return roomList; 160 | } 161 | 162 | // Method to retrieve a room by its ID 163 | public Room getById(int id) { 164 | Room obj = null; 165 | String query = "SELECT * FROM public.hotel_room WHERE room_id = ? "; 166 | try { 167 | PreparedStatement pr = this.connection.prepareStatement(query); 168 | pr.setInt(1, id); 169 | ResultSet rs = pr.executeQuery(); 170 | if (rs.next()) { 171 | obj = this.match(rs); 172 | } 173 | } catch (SQLException e) { 174 | e.printStackTrace(); 175 | } 176 | return obj; 177 | } 178 | 179 | // Method to update the stock information of a room 180 | public boolean updateStock(Room room){ 181 | String query = "UPDATE public.hotel_room SET stock = ? WHERE room_id = ? "; 182 | try { 183 | PreparedStatement pr = this.connection.prepareStatement(query); 184 | pr.setInt(1, room.getStock()); 185 | pr.setInt(2,room.getRoom_id()); 186 | 187 | pr.executeUpdate(); 188 | }catch (SQLException e){ 189 | e.printStackTrace(); 190 | } 191 | return true; 192 | } 193 | } 194 | -------------------------------------------------------------------------------- /src/dao/UserDAO.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import core.Db; 4 | import entity.User; 5 | 6 | import java.sql.Connection; 7 | import java.sql.PreparedStatement; 8 | import java.sql.ResultSet; 9 | import java.sql.SQLException; 10 | import java.util.ArrayList; 11 | 12 | /** 13 | * Data Access Object (DAO) for User entity. 14 | */ 15 | public class UserDAO { 16 | private final Connection connection; 17 | 18 | /** 19 | * Constructor to initialize the UserDAO with a database connection. 20 | */ 21 | public UserDAO() { 22 | this.connection = Db.getInstance(); 23 | } 24 | 25 | /** 26 | * Retrieves all users from the database. 27 | * 28 | * @return ArrayList of User objects containing all users. 29 | */ 30 | public ArrayList findAll() { 31 | ArrayList userList = new ArrayList<>(); 32 | String sql = "SELECT * FROM public.user ORDER BY user_id ASC"; 33 | try { 34 | ResultSet rs = this.connection.createStatement().executeQuery(sql); 35 | while (rs.next()) { 36 | userList.add(this.match(rs)); 37 | } 38 | } catch (SQLException e) { 39 | e.printStackTrace(); 40 | } 41 | return userList; 42 | } 43 | 44 | /** 45 | * Saves a new user to the database. 46 | * 47 | * @param user The User object to be saved. 48 | * @return True if the user is successfully saved, false otherwise. 49 | */ 50 | public boolean save(User user) { 51 | String query = "INSERT INTO public.user (user_name_surname, user_user, user_password, user_role) VALUES (?,?,?,?)"; 52 | try { 53 | PreparedStatement pr = this.connection.prepareStatement(query); 54 | pr.setString(1, user.getFullName()); 55 | pr.setString(2, user.getUserName()); 56 | pr.setString(3, user.getPassword()); 57 | pr.setString(4, user.getRole().toString()); 58 | return pr.executeUpdate() != -1; 59 | } catch (SQLException e) { 60 | System.out.println(e.getMessage()); 61 | } 62 | return true; 63 | } 64 | 65 | /** 66 | * Updates an existing user in the database. 67 | * 68 | * @param user The User object with updated information. 69 | * @return True if the user is successfully updated, false otherwise. 70 | */ 71 | public boolean update(User user) { 72 | String query = "UPDATE public.user SET user_name_surname = ?,user_user = ?, user_password = ?, user_role = ? WHERE user_id = ?"; 73 | try { 74 | PreparedStatement pr = this.connection.prepareStatement(query); 75 | pr.setString(1, user.getFullName()); 76 | pr.setString(2, user.getUserName()); 77 | pr.setString(3, user.getPassword()); 78 | pr.setString(4, user.getRole().toString()); 79 | pr.setInt(5, user.getId()); 80 | return pr.executeUpdate() != -1; 81 | } catch (SQLException e) { 82 | e.printStackTrace(); 83 | } 84 | return true; 85 | } 86 | 87 | /** 88 | * Deletes a user from the database by their ID. 89 | * 90 | * @param id The ID of the user to be deleted. 91 | * @return True if the user is successfully deleted, false otherwise. 92 | */ 93 | public boolean delete(int id) { 94 | String query = "DELETE FROM public.user WHERE user_id = ?"; 95 | try { 96 | PreparedStatement pr = this.connection.prepareStatement(query); 97 | pr.setInt(1, id); 98 | return pr.executeUpdate() != -1; 99 | } catch (SQLException e) { 100 | e.printStackTrace(); 101 | } 102 | return true; 103 | } 104 | 105 | /** 106 | * Finds a user in the database by their login credentials. 107 | * 108 | * @param username The username of the user. 109 | * @param password The password of the user. 110 | * @return The User object if found, null otherwise. 111 | */ 112 | public User findByLogin(String username, String password) { 113 | User obj = null; 114 | String query = "SELECT * FROM public.user WHERE user_user = ? AND user_password = ?"; 115 | try { 116 | PreparedStatement pr = this.connection.prepareStatement(query); 117 | pr.setString(1, username); 118 | pr.setString(2, password); 119 | ResultSet rs = pr.executeQuery(); 120 | if (rs.next()) { 121 | obj = this.match(rs); 122 | } 123 | } catch (SQLException e) { 124 | System.out.println(e.getMessage()); 125 | } 126 | return obj; 127 | } 128 | 129 | /** 130 | * Finds a user in the database by their ID. 131 | * 132 | * @param id The ID of the user to be found. 133 | * @return The User object if found, null otherwise. 134 | */ 135 | public User getById(int id) { 136 | User obj = null; 137 | String query = "SELECT * FROM public.user WHERE user_id = ? "; 138 | try { 139 | PreparedStatement pr = this.connection.prepareStatement(query); 140 | pr.setInt(1, id); 141 | ResultSet rs = pr.executeQuery(); 142 | if (rs.next()) { 143 | obj = this.match(rs); 144 | } 145 | } catch (SQLException e) { 146 | System.out.println(e.getMessage()); 147 | } 148 | return obj; 149 | } 150 | 151 | /** 152 | * Finds all users in the database with the role 'ADMIN'. 153 | * 154 | * @return ArrayList of User objects with the role 'ADMIN'. 155 | */ 156 | public ArrayList findByAdmin() { 157 | ArrayList userList = new ArrayList<>(); 158 | String query = "SELECT * FROM public.user WHERE user_role = 'ADMIN' ORDER BY user_id ASC"; 159 | try { 160 | ResultSet rs = this.connection.createStatement().executeQuery(query); 161 | while (rs.next()) { 162 | userList.add(this.match(rs)); 163 | } 164 | } catch (SQLException e) { 165 | e.printStackTrace(); 166 | } 167 | return userList; 168 | } 169 | 170 | /** 171 | * Finds all users in the database with the role 'EMPLOYEE'. 172 | * 173 | * @return ArrayList of User objects with the role 'EMPLOYEE'. 174 | */ 175 | public ArrayList findByEmployee() { 176 | ArrayList userList = new ArrayList<>(); 177 | String query = "SELECT * FROM public.user WHERE user_role = 'EMPLOYEE' ORDER BY user_id ASC"; 178 | try { 179 | ResultSet rs = this.connection.createStatement().executeQuery(query); 180 | while (rs.next()) { 181 | userList.add(this.match(rs)); 182 | } 183 | } catch (SQLException e) { 184 | e.printStackTrace(); 185 | } 186 | return userList; 187 | } 188 | 189 | /** 190 | * Maps a ResultSet to a User object. 191 | * 192 | * @param rs The ResultSet containing user data. 193 | * @return User object mapped from the ResultSet. 194 | * @throws SQLException If a database access error occurs. 195 | */ 196 | public User match(ResultSet rs) throws SQLException { 197 | User obj = new User(); 198 | obj.setId(rs.getInt("user_id")); 199 | obj.setFullName(rs.getString("user_name_surname")); 200 | obj.setUserName(rs.getString("user_user")); 201 | obj.setPassword(rs.getString("user_password")); 202 | obj.setRole(User.Role.valueOf(rs.getString("user_role"))); 203 | return obj; 204 | } 205 | } 206 | -------------------------------------------------------------------------------- /src/dao/ReservationDao.java: -------------------------------------------------------------------------------- 1 | package dao; 2 | 3 | import core.Db; 4 | import entity.Reservation; 5 | 6 | import java.sql.*; 7 | import java.time.LocalDate; 8 | import java.util.ArrayList; 9 | 10 | // Class responsible for database operations related to reservations 11 | public class ReservationDao { 12 | 13 | private final Connection connection; 14 | 15 | public ReservationDao() { 16 | this.connection = Db.getInstance(); 17 | } 18 | 19 | // Method to retrieve reservations with a specific hotel ID 20 | public ArrayList getReservationByOtelId(int otelId) { 21 | ArrayList reservations = new ArrayList<>(); 22 | String query = "SELECT * FROM public.reservation WHERE room_id = ?"; 23 | 24 | try (PreparedStatement pr = connection.prepareStatement(query)) { 25 | pr.setInt(1, otelId); 26 | ResultSet rs = pr.executeQuery(); 27 | 28 | while (rs.next()) { 29 | Reservation reservation = match(rs); 30 | reservations.add(reservation); 31 | } 32 | } catch (SQLException e) { 33 | e.printStackTrace(); 34 | } 35 | 36 | return reservations; 37 | } 38 | 39 | // Method to retrieve a reservation by its ID 40 | public Reservation getByID(int id) { 41 | Reservation obj = null; 42 | String query = "SELECT * FROM public.reservation WHERE reservation_id = ?"; 43 | try { 44 | PreparedStatement pr = this.connection.prepareStatement(query); 45 | pr.setInt(1, id); 46 | ResultSet rs = pr.executeQuery(); 47 | if (rs.next()) { 48 | obj = this.match(rs); 49 | } 50 | } catch (SQLException e) { 51 | e.printStackTrace(); 52 | } 53 | return obj; 54 | } 55 | 56 | // Helper method to map ResultSet to Reservation object 57 | public Reservation match(ResultSet rs) throws SQLException { 58 | Reservation obj = new Reservation(); 59 | obj.setId(rs.getInt("reservation_id")); 60 | obj.setRoom_id(rs.getInt("room_id")); 61 | obj.setGuest_name(rs.getString("guest_name")); 62 | obj.setGuest_id(rs.getString("guest_id")); 63 | obj.setGuest_email(rs.getString("guest_email")); 64 | obj.setGuest_phone(rs.getString("guest_phone")); 65 | obj.setAdult_count(rs.getInt("adult_count")); 66 | obj.setChild_count(rs.getInt("child_count")); 67 | obj.setCheck_in_date(LocalDate.parse(rs.getString("check_in_date"))); 68 | obj.setCheck_out_date(LocalDate.parse(rs.getString("check_out_date"))); 69 | obj.setGuest_note(rs.getString("guest_note")); 70 | obj.setTotal_price(rs.getDouble("total_price")); 71 | obj.setHotel_id(rs.getInt("hotel_id")); 72 | return obj; 73 | } 74 | 75 | // Method to retrieve all reservations 76 | public ArrayList findAll() { 77 | ArrayList resList = new ArrayList<>(); 78 | String sql = "SELECT * FROM public.reservation"; 79 | try { 80 | ResultSet rs = this.connection.createStatement().executeQuery(sql); 81 | while (rs.next()) { 82 | 83 | resList.add(this.match(rs)); 84 | } 85 | } catch (SQLException e) { 86 | e.printStackTrace(); 87 | } 88 | return resList; 89 | } 90 | 91 | // Method to add a reservation 92 | public boolean save(Reservation reservation){ 93 | String query = "INSERT INTO public.reservation" + 94 | "(room_id," + 95 | "guest_name," + 96 | "guest_id," + 97 | "guest_email," + 98 | "guest_phone," + 99 | "adult_count," + 100 | "child_count," + 101 | "check_in_date," + 102 | "check_out_date," + 103 | "guest_note," + 104 | "total_price," + 105 | "hotel_id)" + 106 | "VALUES (?,?,?,?,?,?,?,?,?,?,?,?)"; 107 | try { 108 | PreparedStatement pr = connection.prepareStatement(query); 109 | 110 | pr.setInt(1,reservation.getRoom_id()); 111 | pr.setString(2,reservation.getGuest_name()); 112 | pr.setString(3,reservation.getGuest_id()); 113 | pr.setString(4,reservation.getGuest_email()); 114 | pr.setString(5,reservation.getGuest_phone()); 115 | pr.setInt(6,reservation.getAdult_count()); 116 | pr.setInt(7,reservation.getChild_count()); 117 | pr.setDate(8,Date.valueOf(reservation.getCheck_in_date())); 118 | pr.setDate(9,Date.valueOf(reservation.getCheck_out_date())); 119 | pr.setString(10,reservation.getGuest_note()); 120 | pr.setDouble(11,reservation.getTotal_price()); 121 | pr.setInt(12,reservation.getHotel_id()); 122 | return pr.executeUpdate() != -1; 123 | } catch (SQLException throwables) { 124 | throwables.printStackTrace(); 125 | } 126 | return true; 127 | } 128 | 129 | // Method to delete a reservation 130 | public boolean delete(int reservation_id){ 131 | try{ 132 | String query = "DELETE FROM public.reservation WHERE reservation_id = ?"; 133 | PreparedStatement pr = connection.prepareStatement(query); 134 | pr.setInt(1,reservation_id); 135 | return pr.executeUpdate() != -1; 136 | }catch (SQLException throwables){ 137 | throwables.printStackTrace(); 138 | } 139 | return true; 140 | } 141 | 142 | // Method to retrieve reservations by a specific reservation ID 143 | public ArrayList getByListReservationId(int id){ 144 | return this.selectByQuery("SELECT * FROM public.reservation WHERE id="+id); 145 | } 146 | 147 | // Method to retrieve reservations with a specific query 148 | public ArrayList selectByQuery(String query){ 149 | ArrayList resList=new ArrayList<>(); 150 | try { 151 | ResultSet rs=this.connection.createStatement().executeQuery(query); 152 | while (rs.next()){ 153 | resList.add(this.match(rs)); 154 | } 155 | } catch (SQLException e) { 156 | e.printStackTrace(); 157 | } 158 | return resList; 159 | } 160 | 161 | // Method to update a reservation 162 | public boolean update (Reservation reservation){ 163 | try{ 164 | String query = "UPDATE public.reservation SET " + 165 | "room_id = ?,"+ 166 | "check_in_date = ?," + 167 | "total_price = ?,"+ 168 | "guest_count = ?,"+ 169 | "guest_name = ?,"+ 170 | "guest_citizen_id = ?,"+ 171 | "guest_mail = ?,"+ 172 | "guest_phone = ?,"+ 173 | "check_out_date = ?"+ 174 | "WHERE id = ?"; 175 | 176 | PreparedStatement pr = connection.prepareStatement(query); 177 | pr.setInt(1,reservation.getRoom_id()); 178 | pr.setString(5,reservation.getGuest_name()); 179 | pr.setString(6,reservation.getGuest_id()); 180 | pr.setString(7,reservation.getGuest_email()); 181 | pr.setString(8,reservation.getGuest_phone()); 182 | pr.setInt(4,reservation.getAdult_count()); 183 | pr.setInt(4,reservation.getChild_count()); 184 | pr.setDate(2,Date.valueOf(reservation.getCheck_in_date())); 185 | pr.setDate(9,Date.valueOf(reservation.getCheck_out_date())); 186 | pr.setString(4,reservation.getGuest_note()); 187 | pr.setDouble(3,reservation.getTotal_price()); 188 | pr.setInt(10,reservation.getId()); 189 | 190 | return pr.executeUpdate() != -1; 191 | }catch (SQLException throwables){ 192 | throwables.printStackTrace(); 193 | } 194 | return true; 195 | } 196 | } 197 | -------------------------------------------------------------------------------- /src/view/UserManagementGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.UserManager; 4 | import core.Helper; 5 | import entity.User; 6 | 7 | import javax.swing.*; 8 | import javax.swing.table.DefaultTableModel; 9 | import java.awt.*; 10 | import java.awt.event.*; 11 | import java.util.ArrayList; 12 | 13 | /** 14 | * UserManagementGUI provides an interface for managing users. 15 | * This class presents an interface for viewing, adding, updating, and deleting user information. 16 | */ 17 | public class UserManagementGUI extends Layout { 18 | private JPanel container; 19 | private JTabbedPane tabbedPane_table_user; 20 | private JButton btn_update; 21 | private JButton btn_delete; 22 | private JButton btn_add; 23 | private JLabel lbl_admin_panel; 24 | private JComboBox cmbx_user_filter; 25 | private JLabel lbl_welcome; 26 | private JTable tbl_users; 27 | private JButton btn_logout; 28 | private JPanel pnl_admin; 29 | private JPanel pnl_welcome; 30 | private JPanel pnl_table_user; 31 | private JScrollPane scrl_table; 32 | private JLabel lbl_filter; 33 | private JTextField txtf_selected_id; 34 | private JPanel pnl_selected; 35 | private JPopupMenu user_menu; 36 | private Object[] col_model; 37 | private User user; 38 | private DefaultTableModel tmdl_users = new DefaultTableModel(); 39 | private UserManager userManager; 40 | 41 | /** 42 | * Constructs a UserManagementGUI object. 43 | * Initializes necessary objects and creates the user management interface. 44 | * @param user The user who is currently logged in 45 | */ 46 | public UserManagementGUI(User user) { 47 | this.userManager = new UserManager(); 48 | this.add(container); 49 | this.guiInitialize(1000, 500); 50 | container.setPreferredSize(new Dimension(1000, 500)); 51 | pnl_selected.setPreferredSize(new Dimension(100, pnl_selected.getPreferredSize().height)); 52 | this.user = user; 53 | if (this.user == null) { 54 | dispose(); 55 | } 56 | this.lbl_welcome.setText("Welcome : " + Helper.firstWordUpper(this.user.getFullName())); 57 | 58 | // Load user table and components 59 | loadUsersTable(); 60 | loadUserComponent(); 61 | this.tbl_users.setComponentPopupMenu(user_menu); 62 | logout(); 63 | } 64 | 65 | /** 66 | * Loads the user table with user data. 67 | */ 68 | private void loadUsersTable() { 69 | Object[] col_user_list = {"ID", "Name Surname", "User", "Password", "Role"}; 70 | ArrayList userList = this.userManager.getForTable(col_user_list.length); 71 | this.createTable(this.tmdl_users, this.tbl_users, col_user_list, userList); 72 | } 73 | 74 | /** 75 | * Loads components related to user management and sets up their functionality. 76 | */ 77 | private void loadUserComponent() { 78 | btn_update.addActionListener(e -> { 79 | int selectedUserId = this.getTableSelectedRow(tbl_users,0); 80 | if (selectedUserId != -1) { 81 | UserGUI userView = new UserGUI(this.userManager.getById(selectedUserId)); 82 | userView.addWindowListener(new WindowAdapter() { 83 | @Override 84 | public void windowClosed(WindowEvent e) { 85 | loadUsersTable(); 86 | } 87 | }); 88 | } else { 89 | JOptionPane.showMessageDialog(UserManagementGUI.this, "Please select a user.", "No User Selected", JOptionPane.WARNING_MESSAGE); 90 | } 91 | }); 92 | 93 | btn_delete.addActionListener(e -> { 94 | int selectedUserId = this.getTableSelectedRow(tbl_users,0); 95 | if (selectedUserId != -1){ 96 | if (Helper.confirm("sure","Delete")){ 97 | if (this.userManager.delete(selectedUserId)){ 98 | Helper.showMsg("done"); 99 | loadUsersTable(); 100 | }else { 101 | Helper.showMsg("error"); 102 | } 103 | } 104 | } else { 105 | JOptionPane.showMessageDialog(UserManagementGUI.this, "Please select a user.", "No User Selected", JOptionPane.WARNING_MESSAGE); 106 | } 107 | }); 108 | 109 | btn_add.addActionListener(e -> { 110 | UserGUI userView = new UserGUI(null); 111 | userView.addWindowListener(new WindowAdapter() { 112 | @Override 113 | public void windowClosed(WindowEvent e) { 114 | loadUsersTable(); 115 | } 116 | }); 117 | }); 118 | 119 | this.tbl_users.addMouseListener(new MouseAdapter() { 120 | @Override 121 | public void mousePressed(MouseEvent e) { 122 | int selectedRow = tbl_users.rowAtPoint(e.getPoint()); 123 | tbl_users.setRowSelectionInterval(selectedRow, selectedRow); 124 | int selectedUserId = (int) tbl_users.getValueAt(selectedRow, 0); 125 | if (selectedUserId != -1){ 126 | txtf_selected_id.setText(String.valueOf(selectedUserId)); 127 | } 128 | } 129 | }); 130 | 131 | this.user_menu = new JPopupMenu(); 132 | this.user_menu.add("Add").addActionListener(e -> { 133 | UserGUI userView = new UserGUI(null); 134 | userView.addWindowListener(new WindowAdapter() { 135 | @Override 136 | public void windowClosed(WindowEvent e) { 137 | loadUsersTable(); 138 | } 139 | }); 140 | }); 141 | 142 | this.user_menu.add("Update").addActionListener(e -> { 143 | int selectedUserId = getTableSelectedRow(tbl_users, 0); 144 | if (selectedUserId != -1) { 145 | UserGUI userView = new UserGUI(userManager.getById(selectedUserId)); 146 | userView.addWindowListener(new WindowAdapter() { 147 | @Override 148 | public void windowClosed(WindowEvent e) { 149 | loadUsersTable(); 150 | } 151 | }); 152 | } else { 153 | JOptionPane.showMessageDialog(UserManagementGUI.this, "Please select a row.", "No Row Selected", JOptionPane.WARNING_MESSAGE); 154 | } 155 | }); 156 | 157 | this.user_menu.add("Delete").addActionListener(e -> { 158 | int selectedUserId = this.getTableSelectedRow(tbl_users,0); 159 | if (selectedUserId != -1){ 160 | if (Helper.confirm("sure","Delete")){ 161 | if (this.userManager.delete(selectedUserId)){ 162 | Helper.showMsg("done"); 163 | loadUsersTable(); 164 | }else { 165 | Helper.showMsg("error"); 166 | } 167 | } 168 | }else { 169 | JOptionPane.showMessageDialog(UserManagementGUI.this, "Please select a row.", "No Row Selected", JOptionPane.WARNING_MESSAGE); 170 | } 171 | }); 172 | 173 | this.cmbx_user_filter.addActionListener(e -> { 174 | String selectedRole = (String) cmbx_user_filter.getSelectedItem(); 175 | if(selectedRole != null ){ 176 | if (selectedRole.equals("ADMIN")) { 177 | ArrayList userList = this.userManager.findByAdmin(); 178 | loadUsersByRole(userList); 179 | }else if (selectedRole.equals("EMPLOYEE")){ 180 | ArrayList userList = this.userManager.findByEmployee(); 181 | loadUsersByRole(userList); 182 | }else { 183 | ArrayList userList = this.userManager.findAll(); 184 | loadUsersByRole(userList); 185 | } 186 | } 187 | }); 188 | } 189 | 190 | /** 191 | * Loads users based on their role and updates the user table. 192 | * @param userList List of users to be loaded 193 | */ 194 | private void loadUsersByRole(ArrayList userList) { 195 | tmdl_users.setRowCount(0); 196 | for (User user : userList) { 197 | Object[] rowData = {user.getId(), user.getFullName(), user.getUserName(), user.getPassword(), user.getRole()}; 198 | tmdl_users.addRow(rowData); 199 | } 200 | tbl_users.setModel(tmdl_users); 201 | txtf_selected_id.setText("No selected ID"); 202 | } 203 | 204 | /** 205 | * Logs out the current user. 206 | */ 207 | public void logout(){ 208 | btn_logout.addActionListener(e -> { 209 | dispose(); 210 | LoginGUI loginView = new LoginGUI(); 211 | }); 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/view/HotelAddGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.FacilityManager; 4 | import business.HotelManager; 5 | import core.Helper; 6 | import entity.Hotel; 7 | 8 | import javax.swing.*; 9 | import javax.swing.table.DefaultTableModel; 10 | import java.awt.*; 11 | import java.awt.event.MouseAdapter; 12 | import java.awt.event.MouseEvent; 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * HotelAddGUI provides an interface for adding a hotel. 17 | * This class presents an interface using Swing components to input and save hotel information. 18 | */ 19 | public class HotelAddGUI extends Layout { 20 | // UI components 21 | private JPanel container; 22 | private JTextField txtf_hotel_name; 23 | private JTextField txtf_hotel_city; 24 | private JTextField txtf_hotel_region; 25 | private JTextField txtf_hotel_full_address; 26 | private JTextField txtf_hotel_email; 27 | private JTextField txtf_hotel_phone; 28 | private JTextField txtf_hotel_star; 29 | private JButton btn_add_facility; 30 | private JButton btn_remove_facility; 31 | private JTable tbl_facilities; 32 | private JPanel hotel_lbls; 33 | private JPanel hotel_txtfs; 34 | private JLabel lbl_hotel_name; 35 | private JLabel lbl_hotel_city; 36 | private JLabel lbl_hotel_region; 37 | private JLabel lbl_hotel_full_address; 38 | private JLabel lbl_hotel_email; 39 | private JLabel lbl_hotel_add_update; // Typo: should be "address" instead of "add_update" 40 | private JLabel lbl_hotel_phone; 41 | private JLabel lbl_hotel_star; 42 | private JTabbedPane tabbedPane_unFacilities; 43 | private JTabbedPane tabbedPane_selected_Facilities; 44 | private JTable tbl_uns_facility; 45 | private JPanel unf_panel; 46 | private JButton btn_save_hotel; 47 | DefaultTableModel unselectedFacilitiesMdl = new DefaultTableModel(); 48 | private String[] unselectedFacilities = {}; 49 | DefaultTableModel selectedFacilitiesMdl = new DefaultTableModel(); 50 | private String[] selectedFacilities = {}; 51 | private final Hotel hotel; 52 | private final FacilityManager facilityManager; 53 | private final HotelManager hotelManager; 54 | 55 | /** 56 | * Constructor for HotelAddGUI class. 57 | * Initializes necessary objects and creates the interface for adding a new hotel. 58 | */ 59 | public HotelAddGUI() { 60 | // Initialize objects 61 | this.hotel = new Hotel(); 62 | this.facilityManager = new FacilityManager(); 63 | this.hotelManager = new HotelManager(); 64 | 65 | // Add container to layout and set initial size 66 | this.add(container); 67 | this.guiInitialize(500, 530); // Typo: should be "initialize" instead of "initilaze" 68 | container.setPreferredSize(new Dimension(500, 530)); 69 | 70 | // Facilities Management 71 | loadLeftFacilityTable(); 72 | loadRightFacilityTable(); 73 | loadAddHotelComponent(); 74 | reSizeComponent(); 75 | } 76 | 77 | // Facilities 78 | /** 79 | * Loads the left facility table. 80 | * Lists all facilities for user selection. 81 | */ 82 | private void loadLeftFacilityTable() { 83 | Object[] col_facility_list = {"Facility Name"}; 84 | ArrayList facilityList = this.facilityManager.getForTableFacilities(col_facility_list.length); 85 | this.createTable(this.unselectedFacilitiesMdl, this.tbl_facilities, col_facility_list, facilityList); 86 | } 87 | 88 | /** 89 | * Loads the right facility table. 90 | * Displays selected facilities for user review. 91 | */ 92 | private void loadRightFacilityTable() { 93 | selectedFacilitiesMdl.addColumn("Facility Name"); 94 | for(String facility : selectedFacilities){ 95 | selectedFacilitiesMdl.addRow(new Object[]{facility}); 96 | } 97 | tbl_uns_facility.setModel(selectedFacilitiesMdl); 98 | } 99 | 100 | // Add Table 101 | 102 | /** 103 | * Loads the components for adding a hotel. 104 | * Defines necessary button listeners. 105 | */ 106 | private void loadAddHotelComponent() { 107 | // Add mouse listener to facilities table 108 | this.tbl_facilities.addMouseListener(new MouseAdapter() { 109 | @Override 110 | public void mousePressed(MouseEvent e) { 111 | int selectedRow = tbl_facilities.rowAtPoint(e.getPoint()); 112 | if (selectedRow != -1 && selectedRow < tbl_facilities.getRowCount()) { 113 | tbl_facilities.setRowSelectionInterval(selectedRow, selectedRow); 114 | } 115 | } 116 | }); 117 | 118 | // Save hotel button action listener 119 | btn_save_hotel.addActionListener(e -> { 120 | if (Helper.isFieldEmpty(this.txtf_hotel_name) 121 | || Helper.isFieldEmpty(this.txtf_hotel_city) 122 | || Helper.isFieldEmpty(this.txtf_hotel_region) 123 | || Helper.isFieldEmpty(this.txtf_hotel_full_address) 124 | || Helper.isFieldEmpty(this.txtf_hotel_email) 125 | || Helper.isFieldEmpty(this.txtf_hotel_phone) 126 | || Helper.isFieldEmpty(this.txtf_hotel_star) 127 | || Helper.isTableEmpty(tbl_uns_facility)) { 128 | Helper.showMsg("fill"); 129 | } else { 130 | Hotel hotel = new Hotel( 131 | txtf_hotel_name.getText(), 132 | txtf_hotel_city.getText(), 133 | txtf_hotel_region.getText(), 134 | txtf_hotel_full_address.getText(), 135 | txtf_hotel_email.getText(), 136 | txtf_hotel_phone.getText(), 137 | txtf_hotel_star.getText(), 138 | selectedFacilities 139 | ); 140 | 141 | if (hotelManager.save(hotel)) { 142 | Helper.showMsg("done"); 143 | dispose(); 144 | } else { 145 | Helper.showMsg("error"); 146 | } 147 | } 148 | }); 149 | 150 | // Facility Add and Remove button action listeners 151 | btn_add_facility.addActionListener(e -> { 152 | int selectedRow = tbl_facilities.getSelectedRow(); 153 | if (selectedRow != -1){ 154 | Object[] rowData = {tbl_facilities.getValueAt(selectedRow,0)}; 155 | selectedFacilitiesMdl.addRow(rowData); 156 | String facilityName = (String) rowData[0]; 157 | selectedFacilities = addFacilityToArray(selectedFacilities, facilityName); 158 | unselectedFacilitiesMdl.removeRow(selectedRow); 159 | } 160 | }); 161 | btn_remove_facility.addActionListener(e -> { 162 | int selectedRow = tbl_uns_facility.getSelectedRow(); 163 | if (selectedRow != -1) { 164 | Object[] rowData = {tbl_uns_facility.getValueAt(selectedRow, 0)}; 165 | unselectedFacilitiesMdl.addRow(rowData); 166 | String facilityName = (String) rowData[0]; 167 | unselectedFacilities = addFacilityToArray(unselectedFacilities, facilityName); 168 | selectedFacilitiesMdl.removeRow(selectedRow); 169 | selectedFacilities = removeHotelFromArray(selectedFacilities, facilityName); 170 | } 171 | }); 172 | } 173 | 174 | /** 175 | * Adds a facility to the array of selected facilities. 176 | * @param selectedFacilities current array of selected facilities 177 | * @param facilityName facility to be added 178 | * @return reference to the new array 179 | */ 180 | private String[] addFacilityToArray(String[] selectedFacilities, String facilityName) { 181 | String[] newFacilities = new String[selectedFacilities.length + 1]; 182 | System.arraycopy(selectedFacilities, 0, newFacilities, 0, selectedFacilities.length); 183 | newFacilities[newFacilities.length - 1] = facilityName; 184 | return newFacilities; 185 | } 186 | 187 | /** 188 | * Removes a facility from the array of selected facilities. 189 | * @param selectedFacilities current array of selected facilities 190 | * @param facilityName facility to be removed 191 | * @return reference to the new array 192 | */ 193 | private String[] removeHotelFromArray(String[] selectedFacilities, String facilityName) { 194 | String[] newFacilities = new String[selectedFacilities.length - 1]; 195 | int index = 0; 196 | for (String facility : selectedFacilities) { 197 | if (!facility.equals(facilityName)) { 198 | newFacilities[index++] = facility; 199 | } 200 | } 201 | return newFacilities; 202 | } 203 | 204 | /** 205 | * Resizes components for proper display. 206 | */ 207 | public void reSizeComponent() { 208 | this.tbl_facilities.getColumnModel().getColumn(0).setMaxWidth(200); 209 | this.tbl_facilities.setPreferredSize(new Dimension(tbl_facilities.getWidth(), 119)); 210 | this.tbl_facilities.revalidate(); 211 | this.tbl_facilities.repaint(); 212 | 213 | this.tbl_uns_facility.setPreferredSize(new Dimension(tbl_facilities.getWidth(), 119)); 214 | this.tbl_uns_facility.revalidate(); 215 | this.tbl_uns_facility.repaint(); 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/view/AddReservationGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.FacilityManager; 4 | import business.ReservationManager; 5 | import business.RoomManager; 6 | import business.SeasonManager; 7 | import core.Helper; 8 | import entity.*; 9 | 10 | import javax.swing.*; 11 | import javax.swing.table.DefaultTableModel; 12 | import javax.swing.text.MaskFormatter; 13 | import java.text.ParseException; 14 | import java.time.LocalDate; 15 | import java.time.format.DateTimeFormatter; 16 | import java.time.temporal.ChronoUnit; 17 | import java.util.ArrayList; 18 | 19 | // Represents the graphical user interface for adding a reservation 20 | public class AddReservationGUI extends Layout { 21 | private JPanel container; 22 | private JTextField tf_res_hotel_name; 23 | private JTextField tf_res_city; 24 | private JTextField tf_res_star; 25 | private JTextField tf_res_roomtype; 26 | private JTextField tf_res_room_field; 27 | private JTextField tf_res_bed_capacity; 28 | private JTextField tf_res_start_date; 29 | private JTextField tf_res_end_date1; 30 | private JRadioButton rbut_television; 31 | private JRadioButton rbut_game_console; 32 | private JRadioButton rbut_cash_vault; 33 | private JRadioButton rbut_res_projection; 34 | private JRadioButton rbut_res_minibar; 35 | private JTextField tf_res_pension; 36 | private JTable tbl_facilities1; 37 | private JButton btn; 38 | private JFormattedTextField star_date; 39 | private JFormattedTextField end_date; 40 | private JTextField txtf_region; 41 | private JTextField txtf_address; 42 | private JTextField txtf_phne; 43 | private JTabbedPane tabbedPane1; 44 | private JTextField txtf_season; 45 | private JTabbedPane tabbedPane3; 46 | private JButton btn_calculate; 47 | private JTextField txtf_total_amount; 48 | private JTextField txtf_guest_name; 49 | private JTextField txtf_guest_phone; 50 | private JTextField txtf_guest_email; 51 | private JTextField txtf_guest_id; 52 | private JTextField txtf_guest_note; 53 | private JButton btn_save; 54 | private JComboBox cmbx_adult; 55 | private JComboBox cmbx_children; 56 | private JTextField txtf_adult_price; 57 | private JTextField txtf_children_price; 58 | private ReservationManager reservationManager = new ReservationManager(); 59 | private Season season; 60 | private Pension pension; 61 | private SeasonManager seasonManager; 62 | private RoomManager roomManager; 63 | private String check_in_date; 64 | private String check_out_date; 65 | private Double adult_price; 66 | private Double child_price; 67 | private double totalAmount; 68 | private FacilityManager facilityManager; 69 | private Hotel hotel; 70 | DefaultTableModel mdl_FacilitiesMdl1 = new DefaultTableModel(); 71 | private Room room; 72 | public DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); 73 | private Reservation reservation; 74 | 75 | // Constructor for AddReservationGUI 76 | public AddReservationGUI(Room room, Hotel hotel, Pension pension, Season season){ 77 | this.add(container); 78 | this.guiInitialize(1000, 700); 79 | this.facilityManager = new FacilityManager(); 80 | this.hotel = hotel; 81 | this.pension = pension; 82 | this.season = season; 83 | this.room = room; 84 | this.reservation = new Reservation(); 85 | this.roomManager = new RoomManager(); 86 | 87 | loadReservationComponent(); 88 | 89 | // Setting initial values based on room, hotel, and season data 90 | this.tf_res_hotel_name.setText(room.getHotel_name()); 91 | this.tf_res_city.setText(room.getHotel_city()); 92 | this.txtf_region.setText(hotel.getRegion()); 93 | this.txtf_address.setText(hotel.getFullAddress()); 94 | this.txtf_phne.setText(hotel.getPhone()); 95 | this.tf_res_star.setText(hotel.getStar()); 96 | 97 | facilityTable(); 98 | 99 | this.tf_res_roomtype.setText(room.getType()); 100 | this.tf_res_pension.setText(pension.getPension_type()); 101 | this.tf_res_bed_capacity.setText(String.valueOf(room.getBed_capacity())); 102 | this.tf_res_room_field.setText(String.valueOf(room.getSquare_meter())); 103 | this.txtf_season.setText(String.valueOf(season.getStart_date()) + " to " + String.valueOf(season.getFinish_date())); 104 | this.txtf_adult_price.setText(String.valueOf(this.room.getAdult_price())); 105 | this.txtf_children_price.setText(String.valueOf(this.room.getChild_price())); 106 | this.rbut_television.setSelected(room.isTelevision()); 107 | this.rbut_game_console.setSelected(room.isGame_console()); 108 | this.rbut_cash_vault.setSelected(room.isCash_box()); 109 | this.rbut_res_projection.setSelected(room.isProjection()); 110 | this.rbut_res_minibar.setSelected(room.isMinibar()); 111 | 112 | int adult = room.getBed_capacity(); 113 | for (int i = 1; i <= adult; i++){ 114 | this.cmbx_adult.addItem(i); 115 | } 116 | String type = room.getType(); 117 | int child; 118 | if (type.equals("Single Room")){ 119 | child = 1; 120 | for (int i = 0; i <= child; i++){ 121 | this.cmbx_children.addItem(i); 122 | } 123 | } else if (type.equals("Double Room")){ 124 | child = 2; 125 | for (int i = 0; i <= child; i++){ 126 | this.cmbx_children.addItem(i); 127 | } 128 | } else if (type.equals("Junior Suite Room")) { 129 | child = 3; 130 | for (int i = 0; i <= child; i++) { 131 | this.cmbx_children.addItem(i); 132 | } 133 | } else if (type.equals("Suite Room")) { 134 | child = 5; 135 | for (int i = 0; i <= child; i++) { 136 | this.cmbx_children.addItem(i); 137 | } 138 | } 139 | 140 | LocalDate checkInDate = LocalDate.parse(star_date.getText(), this.formatter); 141 | LocalDate checkOutDate = LocalDate.parse(end_date.getText(), formatter); 142 | long dayCount = ChronoUnit.DAYS.between(checkInDate, checkOutDate); 143 | 144 | double adultPrice = this.room.getAdult_price(); 145 | double childrenPrice = this.room.getChild_price(); 146 | int adultCount = Integer.parseInt(this.cmbx_adult.getSelectedItem().toString()); 147 | int childCount = Integer.parseInt(cmbx_children.getSelectedItem().toString()); 148 | 149 | totalAmount = ((adultPrice * adultCount) + (childrenPrice * childCount)) * dayCount; 150 | 151 | this.txtf_total_amount.setText(String.valueOf(totalAmount)); 152 | } 153 | 154 | // Load reservation components and set up event listeners 155 | private void loadReservationComponent() { 156 | btn_save.addActionListener(e -> { 157 | JTextField[] checkField = {this.txtf_guest_name, this.txtf_guest_phone, this.txtf_guest_email, this.txtf_guest_id}; 158 | if (Helper.isFieldListEmpty(checkField)) { 159 | Helper.showMsg("Please fill in all fields."); 160 | } else { 161 | // Assign reservation details 162 | this.reservation.setRoom_id(this.room.getRoom_id()); 163 | this.reservation.setGuest_name(this.txtf_guest_name.getText()); 164 | this.reservation.setGuest_id(this.txtf_guest_id.getText()); 165 | this.reservation.setGuest_email(this.txtf_guest_email.getText()); 166 | this.reservation.setGuest_phone(this.txtf_guest_phone.getText()); 167 | this.reservation.setAdult_count(this.cmbx_adult.getItemCount()); 168 | this.reservation.setChild_count(this.cmbx_children.getItemCount()); 169 | this.reservation.setCheck_in_date(LocalDate.parse(this.star_date.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 170 | this.reservation.setCheck_out_date(LocalDate.parse(this.end_date.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 171 | this.reservation.setGuest_note(this.txtf_guest_note.getText()); 172 | this.reservation.setTotal_price(Double.parseDouble(this.txtf_total_amount.getText())); 173 | this.reservation.setHotel_id(this.hotel.getId()); 174 | 175 | // Save reservation 176 | boolean result = this.reservationManager.save(this.reservation); 177 | if (result) { 178 | Helper.showMsg("Reservation saved successfully."); 179 | this.room.setStock(this.room.getStock()-1); 180 | this.roomManager.updateStock(this.room); 181 | dispose(); 182 | } else { 183 | Helper.showMsg("Error occurred while saving reservation."); 184 | } 185 | } 186 | }); 187 | 188 | btn_calculate.addActionListener(e -> { 189 | LocalDate checkInDate = LocalDate.parse(star_date.getText(), formatter); 190 | LocalDate checkOutDate = LocalDate.parse(end_date.getText(), formatter); 191 | long dayCount = ChronoUnit.DAYS.between(checkInDate, checkOutDate); 192 | 193 | double adultPrice = this.room.getAdult_price(); 194 | double childrenPrice = this.room.getChild_price(); 195 | int adultCount = Integer.parseInt(this.cmbx_adult.getSelectedItem().toString()); 196 | int childCount = Integer.parseInt(cmbx_children.getSelectedItem().toString()); 197 | 198 | totalAmount = ((adultPrice * adultCount) + (childrenPrice * childCount)) * dayCount; 199 | 200 | this.txtf_total_amount.setText(String.valueOf(totalAmount)); 201 | }); 202 | } 203 | 204 | // Facility Table 205 | private void facilityTable(){ 206 | Object[] col_facility_list = {"Facility Name"}; 207 | int selectedHotelId = hotel.getId(); 208 | if (selectedHotelId != -1) { 209 | ArrayList facilityList = this.facilityManager.getForTableHotelFacility(col_facility_list.length, selectedHotelId); 210 | this.createTable(this.mdl_FacilitiesMdl1, this.tbl_facilities1, col_facility_list, facilityList); 211 | this.tbl_facilities1.getColumnModel().getColumn(0).setMaxWidth(200); 212 | } else { 213 | this.mdl_FacilitiesMdl1.setRowCount(0); 214 | } 215 | } 216 | 217 | // Create UI components 218 | private void createUIComponents() throws ParseException{ 219 | LocalDate today = LocalDate.now(); 220 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); 221 | LocalDate tomorrow = today.plusDays(1); 222 | 223 | this.star_date = new JFormattedTextField(new MaskFormatter("##/##/####")); 224 | this.star_date.setText(LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 225 | this.end_date = new JFormattedTextField(new MaskFormatter("##/##/####")); 226 | end_date.setText(tomorrow.format(formatter)); 227 | } 228 | } 229 | -------------------------------------------------------------------------------- /src/view/HotelUpdateGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.FacilityManager; 4 | import business.HotelManager; 5 | import core.Helper; 6 | import entity.Hotel; 7 | 8 | import javax.swing.*; 9 | import javax.swing.table.DefaultTableModel; 10 | import java.awt.*; 11 | import java.awt.event.MouseAdapter; 12 | import java.awt.event.MouseEvent; 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * HotelUpdateGUI class provides an interface for updating hotel information. 17 | * This class presents an interface using Swing components to modify hotel details and facilities. 18 | */ 19 | public class HotelUpdateGUI extends Layout { 20 | // UI components 21 | private JLabel lbl_hotel_name; 22 | private JLabel lbl_hotel_city; 23 | private JLabel lbl_hotel_region; 24 | private JLabel lbl_hotel_full_address; 25 | private JLabel lbl_hotel_email; 26 | private JLabel lbl_hotel_phone; 27 | private JLabel lbl_hotel_star; 28 | private JPanel hotel_txtfs1; 29 | private JTextField txtf_hotel_name; 30 | private JTextField txtf_hotel_city; 31 | private JTextField txtf_hotel_region; 32 | private JTextField txtf_hotel_full_address; 33 | private JTextField txtf_hotel_email; 34 | private JTextField txtf_hotel_phone; 35 | private JTextField txtf_hotel_star; 36 | private JPanel unf_panel; 37 | private JTabbedPane tabbedPane_unFclty; 38 | private JTable tbl_facilities; 39 | private JTabbedPane tabbedPane2; 40 | private JTable tbl_uns_facility; 41 | private JButton btn_add_facility; 42 | private JButton btn_remove_facility; 43 | private JButton btn_save_hotel; 44 | private JLabel lbl_hotel_add_update; 45 | private JPanel container; 46 | private JPanel hotel_lbls; 47 | private JPanel hotel_lbls2; 48 | private FacilityManager facilityManager; 49 | DefaultTableModel unselectedFacilitiesMdl = new DefaultTableModel(); 50 | private String[] unselectedFacilities = {}; 51 | DefaultTableModel selectedFacilitiesMdl = new DefaultTableModel(); 52 | private String[] selectedFacilities = {}; 53 | private final Hotel hotel; 54 | private final HotelManager hotelManager; 55 | 56 | /** 57 | * Constructor for HotelUpdateGUI class. 58 | * Initializes necessary objects and creates the interface for updating a hotel. 59 | * @param hotel The hotel object to be updated. 60 | */ 61 | public HotelUpdateGUI(Hotel hotel) { 62 | // Initialize objects 63 | this.facilityManager = new FacilityManager(); 64 | this.hotelManager = new HotelManager(); 65 | this.add(container); 66 | this.guiInitialize(500, 530); 67 | container.setPreferredSize(new Dimension(500, 530)); 68 | this.hotel = hotel; 69 | 70 | // Populate fields with existing hotel information 71 | if (this.hotel != null) { 72 | this.txtf_hotel_name.setText(hotel.getName()); 73 | this.txtf_hotel_city.setText(hotel.getCity()); 74 | this.txtf_hotel_region.setText(hotel.getRegion()); 75 | this.txtf_hotel_full_address.setText(hotel.getFullAddress()); 76 | this.txtf_hotel_email.setText(hotel.getEmail()); 77 | this.txtf_hotel_phone.setText(hotel.getPhone()); 78 | this.txtf_hotel_star.setText(hotel.getStar()); 79 | 80 | // Set tooltip for facilities table with existing facility names 81 | String[] facilities = hotel.getFacilities(); 82 | if (facilities != null && facilities.length > 0) { 83 | StringBuilder tooltipText = new StringBuilder(); 84 | for (String facility : facilities) { 85 | tooltipText.append(facility).append("\n"); 86 | } 87 | tbl_uns_facility.setToolTipText(tooltipText.toString()); 88 | } 89 | } 90 | // Load UI components and data 91 | loadHotelComponent(); 92 | loadLeftFacilityTable(); 93 | loadRightFacilityTable(); 94 | reSizeComponent(); 95 | } 96 | 97 | // Facilities Table 98 | private void loadLeftFacilityTable() { 99 | // Load available facilities into the left table 100 | Object[] col_facility_list = {"Facility Name"}; 101 | ArrayList facilityList = this.facilityManager.getForTableFacilities(col_facility_list.length); 102 | this.createTable(this.unselectedFacilitiesMdl, this.tbl_facilities, col_facility_list, facilityList); 103 | } 104 | 105 | private void loadRightFacilityTable() { 106 | // Load selected facilities of the hotel into the right table 107 | Object[] col_facility_list = {"Facility Name"}; 108 | int hotelId = hotel.getId(); // Get hotel ID 109 | ArrayList facilityList = this.facilityManager.getForTableHotelFacility(col_facility_list.length, hotelId); 110 | this.createTable(this.selectedFacilitiesMdl, this.tbl_uns_facility, col_facility_list, facilityList); 111 | } 112 | 113 | private void loadHotelComponent() { 114 | // Add mouse listener to facilities table 115 | this.tbl_facilities.addMouseListener(new MouseAdapter() { 116 | @Override 117 | public void mousePressed(MouseEvent e) { 118 | int selectedRow = tbl_facilities.rowAtPoint(e.getPoint()); 119 | tbl_facilities.setRowSelectionInterval(selectedRow, selectedRow); 120 | } 121 | }); 122 | 123 | // Add mouse listener to selected facilities table 124 | this.tbl_uns_facility.addMouseListener(new MouseAdapter() { 125 | @Override 126 | public void mousePressed(MouseEvent e) { 127 | int selectedRow = tbl_uns_facility.rowAtPoint(e.getPoint()); 128 | tbl_uns_facility.setRowSelectionInterval(selectedRow, selectedRow); 129 | } 130 | }); 131 | 132 | // Add action listener to save hotel button 133 | this.btn_save_hotel.addActionListener(e -> { 134 | if (Helper.isFieldEmpty(txtf_hotel_name) 135 | || Helper.isFieldEmpty(txtf_hotel_city) 136 | || Helper.isFieldEmpty(txtf_hotel_region) 137 | || Helper.isFieldEmpty(txtf_hotel_full_address) 138 | || Helper.isFieldEmpty(txtf_hotel_email) 139 | || Helper.isFieldEmpty(txtf_hotel_phone) 140 | || Helper.isFieldEmpty(txtf_hotel_star) 141 | || Helper.isTableEmpty(tbl_uns_facility)) { 142 | Helper.showMsg("fill"); 143 | } else { 144 | String[] selectedFacilities = getSelectedFacilities(); 145 | 146 | // Update hotel information with new values 147 | hotel.setName(txtf_hotel_name.getText()); 148 | hotel.setCity(txtf_hotel_city.getText()); 149 | hotel.setRegion(txtf_hotel_region.getText()); 150 | hotel.setFullAddress(txtf_hotel_full_address.getText()); 151 | hotel.setEmail(txtf_hotel_email.getText()); 152 | hotel.setPhone(txtf_hotel_phone.getText()); 153 | hotel.setStar(txtf_hotel_star.getText()); 154 | hotel.setFacilities(selectedFacilities); 155 | 156 | // Update the hotel in the database 157 | if (hotelManager.update(hotel)) { 158 | Helper.showMsg("done"); 159 | dispose(); 160 | } else { 161 | Helper.showMsg("error"); 162 | } 163 | } 164 | }); 165 | 166 | // Add action listener to add facility button 167 | btn_add_facility.addActionListener(e -> { 168 | int selectedRow = tbl_facilities.getSelectedRow(); 169 | if (selectedRow != -1) { 170 | Object[] rowData = {tbl_facilities.getValueAt(selectedRow, 0)}; 171 | String facilityName = (String) rowData[0]; 172 | if (isFacilityAlreadySelected(facilityName)) { 173 | JOptionPane.showMessageDialog(container, "This facility is already selected.", "Notice", JOptionPane.WARNING_MESSAGE); 174 | } else { 175 | selectedFacilitiesMdl.addRow(rowData); 176 | selectedFacilities = addFacilityToArray(selectedFacilities, facilityName); 177 | unselectedFacilitiesMdl.removeRow(selectedRow); 178 | } 179 | } 180 | }); 181 | 182 | // Add action listener to remove facility button 183 | btn_remove_facility.addActionListener(e -> { 184 | int selectedRow = tbl_uns_facility.getSelectedRow(); 185 | if (selectedRow != -1) { 186 | Object[] rowData = {tbl_uns_facility.getValueAt(selectedRow, 0)}; 187 | unselectedFacilitiesMdl.addRow(rowData); 188 | String facilityName = (String) rowData[0]; 189 | unselectedFacilities = addFacilityToArray(unselectedFacilities, facilityName); 190 | selectedFacilitiesMdl.removeRow(selectedRow); 191 | selectedFacilities = addFacilityToArray(selectedFacilities, facilityName); 192 | } 193 | }); 194 | } 195 | 196 | /** 197 | * Add a facility name to the selected facilities array. 198 | * @param selectedFacilities Array of selected facilities 199 | * @param facilityName Name of the facility to add 200 | * @return Updated array of selected facilities 201 | */ 202 | private String[] addFacilityToArray(String[] selectedFacilities, String facilityName) { 203 | String[] newFacilities = new String[selectedFacilities.length + 1]; 204 | System.arraycopy(selectedFacilities, 0, newFacilities, 0, selectedFacilities.length); 205 | newFacilities[newFacilities.length - 1] = facilityName; 206 | return newFacilities; 207 | } 208 | 209 | /** 210 | * Get the selected facilities from the table. 211 | * @return Array of selected facilities 212 | */ 213 | private String[] getSelectedFacilities() { 214 | DefaultTableModel model = (DefaultTableModel) tbl_uns_facility.getModel(); 215 | ArrayList selectedFacilitiesList = new ArrayList<>(); 216 | for (int i = 0; i < model.getRowCount(); i++) { 217 | selectedFacilitiesList.add((String) model.getValueAt(i, 0)); 218 | } 219 | return selectedFacilitiesList.toArray(new String[0]); 220 | } 221 | 222 | /** 223 | * Check if a facility is already selected. 224 | * @param facilityName Name of the facility to check 225 | * @return True if facility is already selected, otherwise false 226 | */ 227 | private boolean isFacilityAlreadySelected(String facilityName) { 228 | for (int i = 0; i < selectedFacilitiesMdl.getRowCount(); i++) { 229 | if (facilityName.equals(selectedFacilitiesMdl.getValueAt(i, 0))) { 230 | return true; 231 | } 232 | } 233 | return false; 234 | } 235 | 236 | /** 237 | * Resize components to fit properly within the UI. 238 | */ 239 | public void reSizeComponent() { 240 | // Resize facilities tables 241 | this.tbl_facilities.getColumnModel().getColumn(0).setMaxWidth(200); 242 | this.tbl_facilities.setPreferredSize(new Dimension(tbl_facilities.getWidth(), 119)); 243 | this.tbl_facilities.revalidate(); 244 | this.tbl_facilities.repaint(); 245 | 246 | this.tbl_uns_facility.getColumnModel().getColumn(0).setMaxWidth(200); 247 | this.tbl_uns_facility.setPreferredSize(new Dimension(tbl_facilities.getWidth(), 119)); 248 | this.tbl_uns_facility.revalidate(); 249 | this.tbl_uns_facility.repaint(); 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /src/view/UpdateReservationGUI.java: -------------------------------------------------------------------------------- 1 | package view; 2 | 3 | import business.FacilityManager; 4 | import business.ReservationManager; 5 | import business.RoomManager; 6 | import business.SeasonManager; 7 | import core.Helper; 8 | import entity.*; 9 | 10 | import javax.swing.*; 11 | import javax.swing.table.DefaultTableModel; 12 | import javax.swing.text.MaskFormatter; 13 | import java.text.ParseException; 14 | import java.time.LocalDate; 15 | import java.time.format.DateTimeFormatter; 16 | import java.time.temporal.ChronoUnit; 17 | import java.util.ArrayList; 18 | 19 | /** 20 | * UpdateReservationGUI provides an interface for updating a reservation. 21 | * This class presents an interface using Swing components to update reservation details. 22 | */ 23 | public class UpdateReservationGUI extends Layout { 24 | private JPanel container; 25 | private JTextField tf_res_hotel_name; 26 | private JTextField tf_res_city; 27 | private JTextField tf_res_star; 28 | private JTextField tf_res_roomtype; 29 | private JTextField tf_res_room_field; 30 | private JTextField tf_res_bed_capacity; 31 | private JTextField tf_res_start_date; 32 | private JTextField tf_res_end_date1; 33 | private JRadioButton rbut_television; 34 | private JRadioButton rbut_game_console; 35 | private JRadioButton rbut_cash_vault; 36 | private JRadioButton rbut_res_projection; 37 | private JRadioButton rbut_res_minibar; 38 | private JTextField tf_res_pension; 39 | private JTable tbl_facilities1; 40 | private JButton btn; 41 | private JFormattedTextField star_date; 42 | private JFormattedTextField end_date; 43 | private JTextField txtf_region; 44 | private JTextField txtf_address; 45 | private JTextField txtf_phne; 46 | private JTabbedPane tabbedPane1; 47 | private JTextField txtf_season; 48 | private JTabbedPane tabbedPane3; 49 | private JButton btn_calculate; 50 | private JTextField txtf_total_amount; 51 | private JTextField txtf_guest_name; 52 | private JTextField txtf_guest_phone; 53 | private JTextField txtf_guest_email; 54 | private JTextField txtf_guest_id; 55 | private JTextField txtf_guest_note; 56 | private JButton btn_save; 57 | private JComboBox cmbx_adult; 58 | private JComboBox cmbx_children; 59 | private JTextField txtf_adult_price; 60 | private JTextField txtf_children_price; 61 | private ReservationManager reservationManager = new ReservationManager(); 62 | private Season season; 63 | private Pension pension; 64 | private SeasonManager seasonManager; 65 | private RoomManager roomManager; 66 | private String check_in_date; 67 | private String check_out_date; 68 | private Double adult_price; 69 | private Double child_price; 70 | private double totalAmount; 71 | private FacilityManager facilityManager; 72 | private Hotel hotel; 73 | DefaultTableModel mdl_FacilitiesMdl1 = new DefaultTableModel(); 74 | private Room room; 75 | public DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); 76 | private Reservation reservation; 77 | 78 | /** 79 | * Constructor for UpdateReservationGUI class. 80 | * Initializes necessary objects and creates the interface for updating a reservation. 81 | * @param room The room for which the reservation is being updated 82 | * @param hotel The hotel associated with the reservation 83 | * @param pension The pension associated with the reservation 84 | * @param season The season associated with the reservation 85 | * @param reservation The reservation being updated 86 | */ 87 | public UpdateReservationGUI(Room room, Hotel hotel, Pension pension, Season season, Reservation reservation) { 88 | this.add(container); 89 | this.guiInitialize(1000, 700); 90 | this.facilityManager = new FacilityManager(); 91 | this.hotel = hotel; 92 | this.pension = pension; 93 | this.season = season; 94 | this.room = room; 95 | this.reservation = reservation; 96 | this.roomManager = new RoomManager(); 97 | 98 | loadReservationComponent(); 99 | 100 | // Populate fields with reservation details 101 | this.tf_res_hotel_name.setText(room.getHotel_name()); 102 | this.tf_res_city.setText(room.getHotel_city()); 103 | this.txtf_region.setText(hotel.getRegion()); 104 | this.txtf_address.setText(hotel.getFullAddress()); 105 | this.txtf_phne.setText(hotel.getPhone()); 106 | this.tf_res_star.setText(hotel.getStar()); 107 | 108 | facilityTable(); 109 | 110 | this.tf_res_roomtype.setText(room.getType()); 111 | this.tf_res_pension.setText(pension.getPension_type()); 112 | this.tf_res_bed_capacity.setText(String.valueOf(room.getBed_capacity())); 113 | this.tf_res_room_field.setText(String.valueOf(room.getSquare_meter())); 114 | this.txtf_season.setText(String.valueOf(season.getStart_date()) + " to " + String.valueOf(season.getFinish_date())); 115 | this.txtf_adult_price.setText(String.valueOf(this.room.getAdult_price())); 116 | this.txtf_children_price.setText(String.valueOf(this.room.getChild_price())); 117 | this.rbut_television.setSelected(room.isTelevision()); 118 | this.rbut_game_console.setSelected(room.isGame_console()); 119 | this.rbut_cash_vault.setSelected(room.isCash_box()); 120 | this.rbut_res_projection.setSelected(room.isProjection()); 121 | this.rbut_res_minibar.setSelected(room.isMinibar()); 122 | 123 | // Populate adult count dropdown 124 | int adult = room.getBed_capacity(); 125 | for (int i = 0; i <= adult; i++){ 126 | this.cmbx_adult.addItem(i); 127 | } 128 | 129 | // Populate children count dropdown based on room type 130 | String type = room.getType(); 131 | int child; 132 | if (type.equals("Single Room")){ 133 | child = 1; 134 | for (int i = 0; i <= child; i++){ 135 | this.cmbx_children.addItem(i); 136 | } 137 | }else if (type.equals("Double Room")){ 138 | child = 2; 139 | for (int i = 0; i <= child; i++){ 140 | this.cmbx_children.addItem(i); 141 | } 142 | }else if (type.equals("Junior Suite Room")) { 143 | child = 3; 144 | for (int i = 0; i <= child; i++) { 145 | this.cmbx_children.addItem(i); 146 | } 147 | }else if (type.equals("Suite Room")) { 148 | child = 5; 149 | for (int i = 0; i <= child; i++) { 150 | this.cmbx_children.addItem(i); 151 | } 152 | } 153 | 154 | // Calculate total amount based on selected dates and guest counts 155 | LocalDate checkInDate = LocalDate.parse(star_date.getText(), this.formatter); 156 | LocalDate checkOutDate = LocalDate.parse(end_date.getText(), formatter); 157 | long dayCount = ChronoUnit.DAYS.between(checkInDate, checkOutDate); 158 | 159 | double adultPrice = this.room.getAdult_price(); 160 | double childrenPrice = this.room.getChild_price(); 161 | int adultCount = Integer.parseInt(this.cmbx_adult.getSelectedItem().toString()); 162 | int childCount = Integer.parseInt(cmbx_children.getSelectedItem().toString()); 163 | 164 | totalAmount = ((adultPrice * adultCount) + (childrenPrice * childCount)) * dayCount; 165 | 166 | this.txtf_total_amount.setText(String.valueOf(totalAmount)); 167 | } 168 | 169 | /** 170 | * Loads components for updating a reservation. 171 | */ 172 | private void loadReservationComponent() { 173 | btn_save.addActionListener(e -> { 174 | JTextField[] checkField = {this.txtf_guest_name, this.txtf_guest_phone, this.txtf_guest_email, this.txtf_guest_id}; 175 | if (Helper.isFieldListEmpty(checkField)) { 176 | Helper.showMsg("Lütfen tüm alanları doldurun."); 177 | } else { 178 | // Set reservation details 179 | this.reservation.setRoom_id(this.room.getRoom_id()); 180 | this.txtf_guest_name.setText(reservation.getGuest_name()); 181 | this.reservation.setGuest_name(this.txtf_guest_name.getText()); 182 | this.reservation.setGuest_id(this.txtf_guest_id.getText()); 183 | this.reservation.setGuest_email(this.txtf_guest_email.getText()); 184 | this.reservation.setGuest_phone(this.txtf_guest_phone.getText()); 185 | this.reservation.setAdult_count(this.cmbx_adult.getItemCount()); 186 | this.reservation.setChild_count(this.cmbx_children.getItemCount()); 187 | this.reservation.setCheck_in_date(LocalDate.parse(this.star_date.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 188 | this.reservation.setCheck_out_date(LocalDate.parse(this.end_date.getText(), DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 189 | this.reservation.setGuest_note(this.txtf_guest_note.getText()); 190 | this.reservation.setTotal_price(Double.parseDouble(this.txtf_total_amount.getText())); 191 | this.reservation.setHotel_id(this.hotel.getId()); 192 | 193 | // Save the reservation 194 | boolean result = this.reservationManager.save(this.reservation); 195 | if (result) { 196 | Helper.showMsg("Rezervasyon başarıyla kaydedildi."); 197 | dispose(); 198 | } else { 199 | Helper.showMsg("Rezervasyon kaydedilirken bir hata oluştu."); 200 | } 201 | } 202 | }); 203 | 204 | btn_calculate.addActionListener(e -> { 205 | LocalDate checkInDate = LocalDate.parse(star_date.getText(), formatter); 206 | LocalDate checkOutDate = LocalDate.parse(end_date.getText(), formatter); 207 | long dayCount = ChronoUnit.DAYS.between(checkInDate, checkOutDate); 208 | 209 | double adultPrice = this.room.getAdult_price(); 210 | double childrenPrice = this.room.getChild_price(); 211 | int adultCount = Integer.parseInt(this.cmbx_adult.getSelectedItem().toString()); 212 | int childCount = Integer.parseInt(cmbx_children.getSelectedItem().toString()); 213 | 214 | totalAmount = ((adultPrice * adultCount) + (childrenPrice * childCount)) * dayCount; 215 | 216 | this.txtf_total_amount.setText(String.valueOf(totalAmount)); 217 | }); 218 | } 219 | 220 | /** 221 | * Creates the UI components. 222 | * @throws ParseException If there's an error parsing the date format 223 | */ 224 | private void createUIComponents() throws ParseException{ 225 | LocalDate today = LocalDate.now(); 226 | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); 227 | LocalDate tomorrow = today.plusDays(1); 228 | 229 | // Set default start and end dates 230 | this.star_date = new JFormattedTextField(new MaskFormatter("##/##/####")); 231 | this.star_date.setText(LocalDate.now().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); 232 | this.end_date = new JFormattedTextField(new MaskFormatter("##/##/####")); 233 | end_date.setText(tomorrow.format(formatter)); 234 | } 235 | 236 | // Facility Table 237 | private void facilityTable(){ 238 | Object[] col_facility_list = {"Facility Name"}; 239 | int selectedHotelId = hotel.getId(); 240 | if (selectedHotelId != -1) { 241 | ArrayList facilityList = this.facilityManager.getForTableHotelFacility(col_facility_list.length, selectedHotelId); 242 | this.createTable(this.mdl_FacilitiesMdl1, this.tbl_facilities1, col_facility_list, facilityList); 243 | this.tbl_facilities1.getColumnModel().getColumn(0).setMaxWidth(200); 244 | } else { 245 | this.mdl_FacilitiesMdl1.setRowCount(0); 246 | } 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /src/view/ADDRoomGUI.form: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | --------------------------------------------------------------------------------