Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.gitrekt.resort.controller;

import com.gitrekt.resort.model.services.RoomService;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.control.TextField;
import javafx.stage.Stage;

public class EditPricesDialogController implements Initializable {

@FXML
private Button cancelButton;

@FXML
private Button editButton;

@FXML
private TextField editPriceField;

@Override
public void initialize(URL location, ResourceBundle resources) {

}

public void onCancelButtonClicked() {
Stage dialogStage = (Stage) cancelButton.getScene().getWindow();
dialogStage.close();
ScreenManager.getInstance().switchToScreen("/fxml/EditPricesScreen.fxml");

}

public void onEditButtonClicked() {
boolean isGoodInput = true;
double d = 0;
try {
d = Double.valueOf(editPriceField.getText());
} catch (NumberFormatException e) {
isGoodInput = false;
}
if (isGoodInput == true) {
RoomService roomservice = new RoomService();

Alert a = new Alert(AlertType.CONFIRMATION);
a.setTitle("Price Change Confirmation");
a.setHeaderText("Confirm the Price Change?");
Optional<ButtonType> result = a.showAndWait();
if (result.get() == ButtonType.OK) {
roomservice.editRoomPrice(EditPricesScreenController.service, d);
Stage dialogStage = (Stage) cancelButton.getScene().getWindow();
dialogStage.close();
ScreenManager.getInstance().switchToScreen("/fxml/EditPricesScreen.fxml");
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,48 @@

import com.gitrekt.resort.model.entities.RoomCategory;
import com.gitrekt.resort.model.services.RoomService;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
* The FXML controller class for the edit prices screen.
*/
public class EditPricesScreenController implements Initializable {

@FXML
private Button backButton;
@FXML
private Button editPriceButton;
@FXML
private TableView<RoomCategory> roomTableView;

@FXML
private TableColumn<RoomCategory,String> roomNameColumn;

@FXML
private TableColumn<RoomCategory,String> roomDescriptionColumn;

@FXML
private TableColumn<RoomCategory,Double> roomPriceColumn;

private ObservableList<RoomCategory> room;

/**
* Initializes the FXML controller class.
*
* @param location
* @param resources
*/
static RoomCategory service;


@Override
public void initialize(URL location, ResourceBundle resources) {
room = FXCollections.observableArrayList();
roomTableView.setItems(room);
roomTableView.refresh();

roomNameColumn.setCellValueFactory((param) -> {
return new SimpleStringProperty(
Expand All @@ -58,34 +61,46 @@ public void initialize(URL location, ResourceBundle resources) {
return new SimpleDoubleProperty(
param.getValue().getBasePrice()
).asObject();
});
} );

loadData();

}

/**
* Pops up a dialog that prompts the user to change the price.
*/
@FXML
private void onEditPriceClickedButton() {
// TODO
private void onEditPriceClickedButton() throws IOException {

Stage editPriceDialogStage = new Stage();
Parent editPriceDialogRoot = FXMLLoader.load(
getClass().getResource("/fxml/EditPriceDialog.fxml")
);
service = roomTableView.getSelectionModel().getSelectedItem();
Scene editPriceDialog = new Scene(editPriceDialogRoot);

editPriceDialogStage.getIcons().add(new Image("images/Logo.png"));
editPriceDialogStage.setScene(editPriceDialog);
editPriceDialogStage.initModality(Modality.APPLICATION_MODAL);
editPriceDialogStage.initOwner(editPriceButton.getScene().getWindow());
editPriceDialogStage.setResizable(false);
editPriceDialogStage.setTitle("Edit Price");
editPriceDialogStage.centerOnScreen();
editPriceDialogStage.show();

}

/**
* Returns to the staff home screen.
*/
@FXML
private void onBackButtonClicked() {
ScreenManager.getInstance().switchToScreen("/fxml/StaffHomeScreen.fxml");
}

/**
* Loads the pricing data for the resort.
*/
private void loadData() {
RoomService roomService = new RoomService();
room.addAll(roomService.getAllRoomCategories());
}





}

27 changes: 16 additions & 11 deletions src/main/java/com/gitrekt/resort/model/entities/RoomCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import javax.persistence.Id;

/**
* The type of room, containing properties such as the number of beds, a text description of the
* room, images of the room, etc.
* The type of room, containing properties such as the number of beds, a text
* description of the room, images of the room, etc.
*
* Because all resort rooms in the same category share the same core set of features, there is no
* need to tie these properties to the room object itself.
* Because all resort rooms in the same category share the same core set of
* features, there is no need to tie these properties to the room object itself.
*/
@Entity
public class RoomCategory {
Expand All @@ -37,7 +37,7 @@ public class RoomCategory {
}

public RoomCategory(String name, String description,
String imagePath, String bedsInfo, Double basePrice) {
String imagePath, String bedsInfo, Double basePrice) {

this.name = name;
this.description = description;
Expand All @@ -55,8 +55,8 @@ public String getDescription() {
}

/**
* The image representing this room category, based on the file path string provided when the
* category was created.
* The image representing this room category, based on the file path string
* provided when the category was created.
*/
public Image getImage() {
return new Image(this.imageFilePath);
Expand All @@ -69,18 +69,23 @@ public String getBedsInfo() {
/**
* DANGER!
*
* This method only gives you the base price of a room, which is just a part of what goes into
* the pricing of a room.
* This method only gives you the base price of a room, which is just a part
* of what goes into the pricing of a room.
*
* Other factors like resort capacity, etc. affect this price. This method should only be used
* to calculate the final price of the room within the appropriate service class.
* Other factors like resort capacity, etc. affect this price. This method
* should only be used to calculate the final price of the room within the
* appropriate service class.
*
* @return The base price of the room.
*/
public Double getBasePrice() {
return basePrice;
}

public void setBasePrice(double price) {
this.basePrice = price;
}

/**
* Generated by NetBeans. Compares only the name of the room category.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/gitrekt/resort/model/services/RoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.gitrekt.resort.model.entities.RoomCategory;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

/**
Expand Down Expand Up @@ -49,6 +50,18 @@ public List<Room> getAllRoomsInCategory(String categoryName) {
return q.getResultList();
}

public void editRoomPrice(RoomCategory room, double price) {
room.setBasePrice(price);
try {
entityManager.getTransaction().begin();
entityManager.merge(room);
entityManager.getTransaction().commit();
} catch (PersistenceException e) {
entityManager.getTransaction().rollback();
throw e;
}
}

public List<RoomCategory> getAllRoomCategories() {
return entityManager.createQuery("FROM RoomCategory").getResultList();
}
Expand Down
76 changes: 76 additions & 0 deletions src/main/resources/fxml/EditPriceDialog.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<VBox id="editDialog" alignment="TOP_CENTER" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="200.0" prefWidth="400.0" stylesheets="@../fxcss/Master.css" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.gitrekt.resort.controller.EditPricesDialogController">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<children>
<Label text="Edit Price">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
<font>
<Font size="18.0" />
</font>
</Label>
<Separator prefWidth="200.0">
<VBox.margin>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</Separator>
<GridPane hgap="30.0" vgap="25.0">
<columnConstraints>
<ColumnConstraints halignment="LEFT" hgrow="SOMETIMES" maxWidth="-Infinity" minWidth="10.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<children>
<Label text="Price:" />
<TextField fx:id="editPriceField" promptText="Enter New Price" GridPane.columnIndex="1" />
</children>
</GridPane>
<HBox alignment="CENTER" spacing="20.0">
<VBox.margin>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</VBox.margin>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<children>
<Button fx:id="cancelButton" mnemonicParsing="false" onAction="#onCancelButtonClicked" prefWidth="60.0" text="Cancel">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</Button>
<Button fx:id="editButton" mnemonicParsing="false" onAction="#onEditButtonClicked" prefWidth="60.0" text="Edit">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<HBox.margin>
<Insets />
</HBox.margin>
</Button>
</children>
</HBox>
</children>
</VBox>