Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package HotelInterface;
- import javafx.application.Platform;
- import javafx.event.ActionEvent;
- import javafx.event.Event;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.*;
- import javafx.scene.web.WebEngine;
- import javafx.scene.web.WebView;
- import javafx.stage.Stage;
- import static HotelInterface.CustomerDetails.customerID;
- import java.io.IOException;
- import java.sql.SQLException;
- import java.text.DateFormat;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import java.util.Locale;
- public class Controller {
- // public VBox vb;
- public TextField cardholderid;
- public ComboBox cardtype;
- public TextField cardnumberid;
- public TextField issuerdate;
- public TextField expirydate;
- public TextField issurenumber;
- public TextField cvvcode;
- public Button logc;
- public Button createacc;
- public Button book;
- public Button staff;
- public Button login;
- public TextField cusfname;
- public TextField cuslname;
- public TextField cusaddress;
- public TextField cusaddress1;
- public TextField cuscity;
- public TextField cuspost;
- public ComboBox cuscoun;
- public TextField cusemail;
- public TextField cuspass;
- public TextField cuspass1;
- public TextField uname;
- public TextField pword;
- public TextField emaillog;
- public TextField passlog;
- public Parent root;
- public DatePicker checkin;
- public DatePicker checkout;
- public Label checkRoom;
- public ComboBox adult;
- public ComboBox children;
- public WebView test;
- public WebView WebViewMap;
- Jdbc db;
- String customeremail;
- String checkInDate, checkOutDate, typeOfRoom;
- public Controller() {
- try {
- db = new Jdbc();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- public void Home(ActionEvent actionEvent) throws IOException {
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("HomePage.fxml"));
- Parent root = (Parent) fxmlLoader.load();
- stage.setScene(new Scene(root));
- stage.show();
- }
- public void Staff(ActionEvent actionEvent) throws IOException {
- Stage stage = (Stage) staff.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("StaffLogin.fxml"));
- Parent root = (Parent) fxmlLoader.load();
- stage.setScene(new Scene(root));
- stage.show();
- }
- public void Login(ActionEvent actionEvent) throws IOException {
- String user = uname.getText();
- String pass = pword.getText();
- Boolean login;
- login = db.StaffLogin(user, pass);
- if (login) {
- Stage stage = (Stage) uname.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("AdminMenu.fxml"));
- Parent root = (Parent) fxmlLoader.load();
- stage.setScene(new Scene(root));
- stage.show();
- }
- }
- public void Logc(ActionEvent actionEvent)throws IOException {
- String user = emaillog.getText();
- String pass = passlog.getText();
- Boolean login;
- login = db.CustomerLogin(user, pass);
- if (login) {
- customeremail = db.getCustomerID();
- Stage stage = (Stage) emaillog.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("BookOnline.fxml"));
- Parent root = (Parent) fxmlLoader.load();
- stage.setScene(new Scene(root));
- stage.show();
- }
- }
- public void Rooms(ActionEvent actionEvent) {
- }
- public void Contact(ActionEvent actionEvent) {
- }
- public void Location(ActionEvent actionEvent) throws IOException {
- Platform.runLater(new Runnable() {
- @Override
- public void run() {
- WebEngine engine = WebViewMap.getEngine();
- engine.load("https://www.google.co.uk/maps/place/University+of+Westminster,+Cavendish/@51.5207356,-0.1424753,17z/data=!4m7!1m4!3m3!1s0x48761b29fa9eaaf7:0x7f3373780309f65f!2s115+New+Cavendish+St,+London+W1W!3b1!3m1!1s0x48761ad51b1e1cf9:0x287c68bedac36d2e");
- System.out.println("testrun");
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("location.fxml"));
- Parent root = null;
- try {
- root = (Parent) fxmlLoader.load();
- } catch (IOException e) {
- e.printStackTrace();
- }
- stage.setScene(new Scene(root));
- stage.show();
- }
- });
- }
- public void Book(ActionEvent actionEvent)throws IOException {
- System.out.println("In Book ActionEvent method");
- if(db.customerEmail == null) {
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("AccountView.fxml"));
- Parent root = (Parent) fxmlLoader.load();
- stage.setScene(new Scene(root));
- stage.show();
- System.out.println("Customer ID = "+customerID);
- }else{
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("BookOnline.fxml"));
- Parent root = (Parent) fxmlLoader.load();
- stage.setScene(new Scene(root));
- stage.show();
- }
- }
- public void Createacc(ActionEvent event)throws IOException{
- //Validates teh name of the user
- //
- String fname = cusfname.getText().toString();
- String lname = cuslname.getText().toString();
- String address = cusaddress.getText().toString() + ", " + cusaddress1.getText().toString();
- String city = cuscity.getText().toString();
- String postcode = cuspost.getText().toString();
- //String country = cuscoun.getValue().toString();
- String email = cusemail.getText().toString();
- String password = cuspass.getText().toString();
- // db.addUserToDB(fname,lname,password,address,email,"HARDCODED",postcode,city);
- }
- public void validatename(String fname, String lname){
- }
- public void CheckroomBook(ActionEvent e){
- }
- public void CheckRoom(ActionEvent actionEvent) throws ParseException {
- if (checkin.getValue() == null || checkout.getValue() == null || adult.getValue() == null) {
- checkRoom.setText("Please fill all details before checking for availability");
- } else {
- if (children.getValue() == null) children.setValue(0);
- int roomSizeInt = Integer.parseInt(adult.getValue().toString()) + Integer.parseInt(children.getValue().toString());
- if (roomSizeInt > 3) {
- checkRoom.setText("No rooms support this many people");
- } else {
- String roomSize = "";
- switch (roomSizeInt) {
- case 1:
- roomSize = "Small";
- break;
- case 2:
- roomSize = "Medium";
- break;
- case 3:
- roomSize = "Large";
- break;
- }
- List startDates = db.RoomCheck("StartDate", roomSize);
- List endDates = db.RoomCheck("EndDate", roomSize);
- List bookRID = db.RoomCheck("Booking.RoomID", roomSize);
- ArrayList<String> bookRIDS = new ArrayList<>(bookRID.size());
- bookRIDS.addAll(bookRID);
- List roomID = db.RoomCheck1("Room.RoomID", roomSize);
- ArrayList<String> roomIDS = new ArrayList<>(roomID.size());
- roomIDS.addAll(roomID);
- Boolean[] roomBooked = new Boolean[roomIDS.size()];
- Date startDate;
- Date endDate;
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
- Date dateA = format.parse(checkin.getValue().toString());
- Date dateD = format.parse(checkout.getValue().toString());
- int availableRooms = 0;
- for (int i = 0; i < startDates.size() - 1; i++) {
- startDate = format.parse(startDates.get(i).toString());
- endDate = format.parse(endDates.get(i).toString());
- if ((startDate.compareTo(dateA) * startDate.compareTo(endDate) > 0)) {
- System.out.println(bookRIDS.get(i) + " is booked");
- roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
- } else availableRooms++;
- if ((startDate.compareTo(dateD) * startDate.compareTo(endDate) > 0)) {
- System.out.println(bookRIDS.get(i) + " is booked");
- roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
- } else availableRooms++;
- }
- for (int i = 0; i < roomBooked.length; i++) {
- if (roomBooked[i] == null) System.out.println(roomID.get(i) + " is free");
- }
- if (availableRooms == 0) checkRoom.setText("No rooms are available");
- else checkRoom.setText("Rooms are available");
- }
- }
- }
- public void webtest(Event event) {
- WebEngine engine = WebViewMap.getEngine();
- engine.load("https://www.google.co.uk/maps/place/University+of+Westminster,+Cavendish/@51.5207356,-0.1424753,17z/data=!4m7!1m4!3m3!1s0x48761b29fa9eaaf7:0x7f3373780309f65f!2s115+New+Cavendish+St,+London+W1W!3b1!3m1!1s0x48761ad51b1e1cf9:0x287c68bedac36d2e");
- System.out.println("fdgkjgfdnjgfdd");
- }
- public void BookRoom(ActionEvent actionEvent) throws ParseException, IOException {
- //GET DATES
- //CHECK IF ROOM IS AVAIL ON DATE
- //IF NOT THEN NOTIFY USER
- //IF AVAIL
- //STORE DATES, CUSTOMERID
- if (checkin.getValue() == null || checkout.getValue() == null || adult.getValue() == null) {
- checkRoom.setText("Please fill all details before checking for availability");
- } else {
- if (children.getValue() == null) children.setValue(0);
- int roomSizeInt = Integer.parseInt(adult.getValue().toString()) + Integer.parseInt(children.getValue().toString());
- if (roomSizeInt > 3) {
- checkRoom.setText("No rooms support this many people");
- } else {
- String roomSize = "";
- switch (roomSizeInt) {
- case 1:
- roomSize = "Small";
- break;
- case 2:
- roomSize = "Medium";
- break;
- case 3:
- roomSize = "Large";
- break;
- }
- List startDates = db.RoomCheck("StartDate", roomSize);
- List endDates = db.RoomCheck("EndDate", roomSize);
- List bookRID = db.RoomCheck("Booking.RoomID", roomSize);
- ArrayList<String> bookRIDS = new ArrayList<>(bookRID.size());
- bookRIDS.addAll(bookRID);
- List roomID = db.RoomCheck1("Room.RoomID", roomSize);
- ArrayList<String> roomIDS = new ArrayList<>(roomID.size());
- roomIDS.addAll(roomID);
- Boolean[] roomBooked = new Boolean[roomIDS.size()];
- Date startDate;
- Date endDate;
- DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
- Date dateA = format.parse(checkin.getValue().toString());
- Date dateD = format.parse(checkout.getValue().toString());
- int availableRooms = 0;
- for (int i = 0; i < startDates.size() - 1; i++) {
- startDate = format.parse(startDates.get(i).toString());
- endDate = format.parse(endDates.get(i).toString());
- if ((startDate.compareTo(dateA) * startDate.compareTo(endDate) > 0)) {
- System.out.println(bookRIDS.get(i) + " is booked");
- roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
- } else availableRooms++;
- if ((startDate.compareTo(dateD) * startDate.compareTo(endDate) > 0)) {
- System.out.println(bookRIDS.get(i) + " is booked");
- roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
- } else availableRooms++;
- }
- for (int i = 0; i < roomBooked.length; i++) {
- if (roomBooked[i] == null) System.out.println(roomID.get(i) + " is free");
- }
- if (availableRooms == 0) checkRoom.setText("No rooms are available");
- else checkRoom.setText("Rooms are available");
- if(checkRoom.getText().toString().equals("Rooms are available")){
- checkInDate = dateA.toString();
- checkOutDate = dateD.toString();
- int roomSizeToBeBooked = Integer.parseInt(adult.getValue().toString()) + Integer.parseInt(children.getValue().toString());
- switch(roomSizeToBeBooked){
- case 1: typeOfRoom = "Small";
- break;
- case 2: typeOfRoom = "Medium";
- break;
- case 3: typeOfRoom = "Large";
- break;
- default: checkRoom.setText("Rooms are too small");
- }
- Stage stage = (Stage) root.getScene().getWindow();
- FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CustomerPayment.fxml"));
- Parent root = (Parent) fxmlLoader.load();
- stage.setScene(new Scene(root));
- stage.show();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement