Advertisement
Guest User

Untitled

a guest
Mar 24th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.82 KB | None | 0 0
  1. package HotelInterface;
  2.  
  3. import javafx.application.Platform;
  4. import javafx.event.ActionEvent;
  5. import javafx.event.Event;
  6. import javafx.fxml.FXMLLoader;
  7. import javafx.scene.Parent;
  8. import javafx.scene.Scene;
  9. import javafx.scene.control.*;
  10. import javafx.scene.web.WebEngine;
  11. import javafx.scene.web.WebView;
  12. import javafx.stage.Stage;
  13. import static HotelInterface.CustomerDetails.customerID;
  14. import java.io.IOException;
  15. import java.sql.SQLException;
  16. import java.text.DateFormat;
  17. import java.text.ParseException;
  18. import java.text.SimpleDateFormat;
  19. import java.util.ArrayList;
  20. import java.util.Date;
  21. import java.util.List;
  22. import java.util.Locale;
  23.  
  24. public class Controller {
  25. // public VBox vb;
  26. public TextField cardholderid;
  27. public ComboBox cardtype;
  28. public TextField cardnumberid;
  29. public TextField issuerdate;
  30. public TextField expirydate;
  31. public TextField issurenumber;
  32. public TextField cvvcode;
  33.  
  34. public Button logc;
  35. public Button createacc;
  36. public Button book;
  37. public Button staff;
  38. public Button login;
  39. public TextField cusfname;
  40. public TextField cuslname;
  41. public TextField cusaddress;
  42. public TextField cusaddress1;
  43. public TextField cuscity;
  44. public TextField cuspost;
  45. public ComboBox cuscoun;
  46. public TextField cusemail;
  47. public TextField cuspass;
  48. public TextField cuspass1;
  49. public TextField uname;
  50. public TextField pword;
  51. public TextField emaillog;
  52. public TextField passlog;
  53. public Parent root;
  54. public DatePicker checkin;
  55. public DatePicker checkout;
  56. public Label checkRoom;
  57. public ComboBox adult;
  58. public ComboBox children;
  59. public WebView test;
  60. public WebView WebViewMap;
  61.  
  62.  
  63. Jdbc db;
  64. String customeremail;
  65. String checkInDate, checkOutDate, typeOfRoom;
  66.  
  67.  
  68.  
  69. public Controller() {
  70. try {
  71. db = new Jdbc();
  72. } catch (SQLException e) {
  73. e.printStackTrace();
  74. }
  75. }
  76.  
  77. public void Home(ActionEvent actionEvent) throws IOException {
  78. Stage stage = (Stage) root.getScene().getWindow();
  79. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("HomePage.fxml"));
  80. Parent root = (Parent) fxmlLoader.load();
  81. stage.setScene(new Scene(root));
  82. stage.show();
  83. }
  84.  
  85. public void Staff(ActionEvent actionEvent) throws IOException {
  86. Stage stage = (Stage) staff.getScene().getWindow();
  87. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("StaffLogin.fxml"));
  88. Parent root = (Parent) fxmlLoader.load();
  89. stage.setScene(new Scene(root));
  90. stage.show();
  91. }
  92.  
  93.  
  94.  
  95. public void Login(ActionEvent actionEvent) throws IOException {
  96. String user = uname.getText();
  97. String pass = pword.getText();
  98. Boolean login;
  99. login = db.StaffLogin(user, pass);
  100. if (login) {
  101.  
  102. Stage stage = (Stage) uname.getScene().getWindow();
  103. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("AdminMenu.fxml"));
  104. Parent root = (Parent) fxmlLoader.load();
  105. stage.setScene(new Scene(root));
  106. stage.show();
  107. }
  108.  
  109. }
  110. public void Logc(ActionEvent actionEvent)throws IOException {
  111. String user = emaillog.getText();
  112. String pass = passlog.getText();
  113. Boolean login;
  114. login = db.CustomerLogin(user, pass);
  115.  
  116. if (login) {
  117. customeremail = db.getCustomerID();
  118. Stage stage = (Stage) emaillog.getScene().getWindow();
  119. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("BookOnline.fxml"));
  120. Parent root = (Parent) fxmlLoader.load();
  121. stage.setScene(new Scene(root));
  122. stage.show();
  123. }
  124.  
  125. }
  126.  
  127. public void Rooms(ActionEvent actionEvent) {
  128.  
  129. }
  130.  
  131. public void Contact(ActionEvent actionEvent) {
  132.  
  133. }
  134.  
  135. public void Location(ActionEvent actionEvent) throws IOException {
  136. Platform.runLater(new Runnable() {
  137. @Override
  138. public void run() {
  139. WebEngine engine = WebViewMap.getEngine();
  140. 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");
  141. System.out.println("testrun");
  142.  
  143. Stage stage = (Stage) root.getScene().getWindow();
  144. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("location.fxml"));
  145. Parent root = null;
  146. try {
  147. root = (Parent) fxmlLoader.load();
  148. } catch (IOException e) {
  149. e.printStackTrace();
  150. }
  151. stage.setScene(new Scene(root));
  152. stage.show();
  153.  
  154.  
  155.  
  156. }
  157. });
  158.  
  159.  
  160.  
  161. }
  162.  
  163. public void Book(ActionEvent actionEvent)throws IOException {
  164. System.out.println("In Book ActionEvent method");
  165. if(db.customerEmail == null) {
  166. Stage stage = (Stage) root.getScene().getWindow();
  167. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("AccountView.fxml"));
  168. Parent root = (Parent) fxmlLoader.load();
  169. stage.setScene(new Scene(root));
  170. stage.show();
  171. System.out.println("Customer ID = "+customerID);
  172. }else{
  173. Stage stage = (Stage) root.getScene().getWindow();
  174. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("BookOnline.fxml"));
  175. Parent root = (Parent) fxmlLoader.load();
  176. stage.setScene(new Scene(root));
  177. stage.show();
  178. }
  179. }
  180.  
  181.  
  182.  
  183.  
  184. public void Createacc(ActionEvent event)throws IOException{
  185.  
  186. //Validates teh name of the user
  187. //
  188. String fname = cusfname.getText().toString();
  189. String lname = cuslname.getText().toString();
  190. String address = cusaddress.getText().toString() + ", " + cusaddress1.getText().toString();
  191. String city = cuscity.getText().toString();
  192. String postcode = cuspost.getText().toString();
  193. //String country = cuscoun.getValue().toString();
  194. String email = cusemail.getText().toString();
  195. String password = cuspass.getText().toString();
  196.  
  197.  
  198.  
  199. // db.addUserToDB(fname,lname,password,address,email,"HARDCODED",postcode,city);
  200.  
  201.  
  202.  
  203. }
  204.  
  205. public void validatename(String fname, String lname){
  206. }
  207.  
  208. public void CheckroomBook(ActionEvent e){
  209.  
  210. }
  211.  
  212. public void CheckRoom(ActionEvent actionEvent) throws ParseException {
  213. if (checkin.getValue() == null || checkout.getValue() == null || adult.getValue() == null) {
  214. checkRoom.setText("Please fill all details before checking for availability");
  215. } else {
  216. if (children.getValue() == null) children.setValue(0);
  217. int roomSizeInt = Integer.parseInt(adult.getValue().toString()) + Integer.parseInt(children.getValue().toString());
  218. if (roomSizeInt > 3) {
  219. checkRoom.setText("No rooms support this many people");
  220. } else {
  221. String roomSize = "";
  222. switch (roomSizeInt) {
  223. case 1:
  224. roomSize = "Small";
  225. break;
  226. case 2:
  227. roomSize = "Medium";
  228. break;
  229. case 3:
  230. roomSize = "Large";
  231. break;
  232. }
  233.  
  234. List startDates = db.RoomCheck("StartDate", roomSize);
  235.  
  236. List endDates = db.RoomCheck("EndDate", roomSize);
  237.  
  238. List bookRID = db.RoomCheck("Booking.RoomID", roomSize);
  239.  
  240. ArrayList<String> bookRIDS = new ArrayList<>(bookRID.size());
  241. bookRIDS.addAll(bookRID);
  242.  
  243. List roomID = db.RoomCheck1("Room.RoomID", roomSize);
  244.  
  245. ArrayList<String> roomIDS = new ArrayList<>(roomID.size());
  246. roomIDS.addAll(roomID);
  247.  
  248. Boolean[] roomBooked = new Boolean[roomIDS.size()];
  249.  
  250. Date startDate;
  251. Date endDate;
  252.  
  253. DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
  254. Date dateA = format.parse(checkin.getValue().toString());
  255.  
  256. Date dateD = format.parse(checkout.getValue().toString());
  257.  
  258. int availableRooms = 0;
  259.  
  260. for (int i = 0; i < startDates.size() - 1; i++) {
  261. startDate = format.parse(startDates.get(i).toString());
  262. endDate = format.parse(endDates.get(i).toString());
  263.  
  264. if ((startDate.compareTo(dateA) * startDate.compareTo(endDate) > 0)) {
  265. System.out.println(bookRIDS.get(i) + " is booked");
  266. roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
  267. } else availableRooms++;
  268.  
  269. if ((startDate.compareTo(dateD) * startDate.compareTo(endDate) > 0)) {
  270. System.out.println(bookRIDS.get(i) + " is booked");
  271. roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
  272. } else availableRooms++;
  273.  
  274. }
  275. for (int i = 0; i < roomBooked.length; i++) {
  276. if (roomBooked[i] == null) System.out.println(roomID.get(i) + " is free");
  277. }
  278. if (availableRooms == 0) checkRoom.setText("No rooms are available");
  279. else checkRoom.setText("Rooms are available");
  280. }
  281. }
  282. }
  283.  
  284.  
  285.  
  286. public void webtest(Event event) {
  287. WebEngine engine = WebViewMap.getEngine();
  288. 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");
  289.  
  290. System.out.println("fdgkjgfdnjgfdd");
  291.  
  292. }
  293.  
  294.  
  295. public void BookRoom(ActionEvent actionEvent) throws ParseException, IOException {
  296. //GET DATES
  297. //CHECK IF ROOM IS AVAIL ON DATE
  298. //IF NOT THEN NOTIFY USER
  299. //IF AVAIL
  300. //STORE DATES, CUSTOMERID
  301.  
  302.  
  303. if (checkin.getValue() == null || checkout.getValue() == null || adult.getValue() == null) {
  304. checkRoom.setText("Please fill all details before checking for availability");
  305. } else {
  306. if (children.getValue() == null) children.setValue(0);
  307. int roomSizeInt = Integer.parseInt(adult.getValue().toString()) + Integer.parseInt(children.getValue().toString());
  308. if (roomSizeInt > 3) {
  309. checkRoom.setText("No rooms support this many people");
  310. } else {
  311. String roomSize = "";
  312. switch (roomSizeInt) {
  313. case 1:
  314. roomSize = "Small";
  315. break;
  316. case 2:
  317. roomSize = "Medium";
  318. break;
  319. case 3:
  320. roomSize = "Large";
  321. break;
  322. }
  323.  
  324. List startDates = db.RoomCheck("StartDate", roomSize);
  325.  
  326. List endDates = db.RoomCheck("EndDate", roomSize);
  327.  
  328. List bookRID = db.RoomCheck("Booking.RoomID", roomSize);
  329.  
  330. ArrayList<String> bookRIDS = new ArrayList<>(bookRID.size());
  331. bookRIDS.addAll(bookRID);
  332.  
  333. List roomID = db.RoomCheck1("Room.RoomID", roomSize);
  334.  
  335. ArrayList<String> roomIDS = new ArrayList<>(roomID.size());
  336. roomIDS.addAll(roomID);
  337.  
  338. Boolean[] roomBooked = new Boolean[roomIDS.size()];
  339.  
  340. Date startDate;
  341. Date endDate;
  342.  
  343. DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
  344. Date dateA = format.parse(checkin.getValue().toString());
  345.  
  346. Date dateD = format.parse(checkout.getValue().toString());
  347.  
  348. int availableRooms = 0;
  349.  
  350. for (int i = 0; i < startDates.size() - 1; i++) {
  351. startDate = format.parse(startDates.get(i).toString());
  352. endDate = format.parse(endDates.get(i).toString());
  353.  
  354. if ((startDate.compareTo(dateA) * startDate.compareTo(endDate) > 0)) {
  355. System.out.println(bookRIDS.get(i) + " is booked");
  356. roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
  357. } else availableRooms++;
  358.  
  359. if ((startDate.compareTo(dateD) * startDate.compareTo(endDate) > 0)) {
  360. System.out.println(bookRIDS.get(i) + " is booked");
  361. roomBooked[Integer.parseInt(bookRIDS.get(i)) - 1] = true;
  362. } else availableRooms++;
  363.  
  364. }
  365. for (int i = 0; i < roomBooked.length; i++) {
  366. if (roomBooked[i] == null) System.out.println(roomID.get(i) + " is free");
  367. }
  368. if (availableRooms == 0) checkRoom.setText("No rooms are available");
  369. else checkRoom.setText("Rooms are available");
  370.  
  371. if(checkRoom.getText().toString().equals("Rooms are available")){
  372.  
  373. checkInDate = dateA.toString();
  374. checkOutDate = dateD.toString();
  375. int roomSizeToBeBooked = Integer.parseInt(adult.getValue().toString()) + Integer.parseInt(children.getValue().toString());
  376. switch(roomSizeToBeBooked){
  377. case 1: typeOfRoom = "Small";
  378. break;
  379. case 2: typeOfRoom = "Medium";
  380. break;
  381. case 3: typeOfRoom = "Large";
  382. break;
  383. default: checkRoom.setText("Rooms are too small");
  384. }
  385. Stage stage = (Stage) root.getScene().getWindow();
  386. FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("CustomerPayment.fxml"));
  387. Parent root = (Parent) fxmlLoader.load();
  388. stage.setScene(new Scene(root));
  389. stage.show();
  390.  
  391. }
  392. }
  393. }
  394. }
  395.  
  396. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement