Advertisement
Guest User

Untitled

a guest
Dec 4th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 61.20 KB | None | 0 0
  1. package DogHouse;
  2.  
  3. import java.net.URL;
  4. import java.sql.Connection;
  5. import java.sql.DriverManager;
  6. import java.sql.PreparedStatement;
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.sql.Statement;
  10. import java.time.LocalDate;
  11. import java.util.ArrayList;
  12. import java.util.HashSet;
  13. import java.util.Optional;
  14. import javafx.application.Application;
  15. import javafx.collections.FXCollections;
  16. import javafx.collections.ObservableList;
  17. import javafx.geometry.Insets;
  18. import javafx.geometry.Pos;
  19. import javafx.scene.Group;
  20. import javafx.scene.Scene;
  21. import javafx.scene.control.Alert;
  22. import javafx.scene.control.Alert.AlertType;
  23. import javafx.scene.image.Image;
  24. import javafx.scene.image.ImageView;
  25. import javafx.scene.control.Button;
  26. import javafx.scene.control.ChoiceBox;
  27. import javafx.scene.control.DatePicker;
  28. import javafx.scene.control.Label;
  29. import javafx.scene.control.TableColumn;
  30. import javafx.scene.control.TableView;
  31. import javafx.scene.control.TextField;
  32. import javafx.scene.control.TextInputDialog;
  33. import javafx.scene.control.cell.PropertyValueFactory;
  34. import javafx.scene.layout.AnchorPane;
  35. import javafx.scene.layout.Background;
  36. import javafx.scene.layout.BackgroundFill;
  37. import javafx.scene.layout.Border;
  38. import javafx.scene.layout.BorderPane;
  39. import javafx.scene.layout.BorderStroke;
  40. import javafx.scene.layout.BorderStrokeStyle;
  41. import javafx.scene.layout.BorderWidths;
  42. import javafx.scene.layout.GridPane;
  43. import javafx.scene.layout.HBox;
  44. import javafx.scene.layout.VBox;
  45. import javafx.scene.media.Media;
  46. import javafx.scene.media.MediaPlayer;
  47. import javafx.scene.paint.Color;
  48. import javafx.scene.text.Font;
  49. import javafx.scene.text.Text;
  50. import javafx.stage.Stage;
  51. import javafx.util.Duration;
  52.  
  53. public class UserInputPane extends Application {
  54.  
  55. private static MediaPlayer welcomeMessage;
  56. private static MediaPlayer welcomeBGM;
  57. private static MediaPlayer userInputSpeak;
  58. private static MediaPlayer informationSaved;
  59. private static MediaPlayer readyed;
  60. private static MediaPlayer error;
  61. private static MediaPlayer saved;
  62. private static MediaPlayer deleted;
  63. private static MediaPlayer properWeightOrHeight;
  64. private static MediaPlayer entryExisted;
  65. private static MediaPlayer properPhoneNumber;
  66.  
  67.  
  68. public static TableView<Dog> table = new TableView<Dog>();
  69.  
  70. public static TableView<Dog> table1 = new TableView<Dog>();
  71.  
  72. public static ArrayList<Dog> dogInformation = new ArrayList<>();
  73.  
  74. public static ObservableList<Dog> data = FXCollections.observableArrayList();
  75.  
  76. public boolean unique = true;
  77.  
  78. public Dog dog;
  79.  
  80. @Override
  81. public void start(Stage primaryStage) throws Exception {
  82.  
  83. /*
  84. * line 102
  85. * and removed some mp3 please check
  86. * line 288
  87. * line 465
  88. */
  89.  
  90.  
  91. /////////////////////First Pane That Has Dog House Logo/////////////////////
  92.  
  93. BorderPane border = new BorderPane();
  94. border.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  95. border.setPadding(new Insets(25, 25, 25, 25));
  96.  
  97. /////////////////////Buttons for first pane /////////////////////
  98.  
  99. Button button = new Button("OK");
  100. // Button backToJavaFXPane = new Button("Back");
  101.  
  102.  
  103. // backToJavaFXPane.setOnAction(value ->{
  104. // javaFXPane js = new javaFXPane();
  105. // Stage jsStage = new Stage();
  106. // try {
  107. // js.start(jsStage);
  108. // primaryStage.close();
  109. // welcomeMessage.stop();
  110. // welcomeBGM.stop();
  111. // }catch (Exception e3) {
  112. // // TODO Auto-generated catch block
  113. // e3.printStackTrace();
  114. // }
  115. // });
  116.  
  117. /////////////////////Buttons needed after entering the information/////////////////////
  118.  
  119. Button ready = new Button("Ready");
  120. Button notReady = new Button("Clear");
  121. Button viewInfor = new Button("View");
  122. Button AddPet = new Button("Add");
  123.  
  124. /////////////////////Buttons for entering the information /////////////////////
  125.  
  126. Button save = new Button("Save");
  127. Button proceed = new Button("Proceed");
  128. Button back = new Button("Back");
  129. Button backToPrimary = new Button("Back");
  130. Button viewDatabase = new Button("View");
  131.  
  132. button.setTextFill(Color.WHITE);
  133. button.setStyle("-fx-background-color: Black");
  134. button.setOnAction(e->{
  135.  
  136. /////////////////////Entering Dog information /////////////////////
  137.  
  138. primaryStage.close();
  139. welcomeMessage.stop();
  140. final URL resource2 = getClass().getResource("userInput.mp3");
  141. final Media media2 = new Media(resource2.toString());
  142. userInputSpeak = new MediaPlayer(media2);
  143. userInputSpeak.play();
  144. userInputSpeak.setVolume(0.1);
  145. Stage secondaryStage = new Stage();
  146. GridPane pane = new GridPane();
  147.  
  148. pane.setAlignment(Pos.CENTER);
  149. pane.setHgap(5);
  150. pane.setVgap(5);
  151. pane.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  152. //The user input fields
  153. Label name = new Label("name: ");
  154. name.setFont(new Font("Times New Roman",17));
  155. pane.add(name, 0, 1);
  156. TextField nameText = new TextField();
  157. nameText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  158. pane.add(nameText, 1 ,1);
  159.  
  160.  
  161. Label breed = new Label("breed: ");
  162. breed.setFont(new Font("Times New Roman",17));
  163. pane.add(breed, 0, 2);
  164. ChoiceBox<String> breedChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  165. "Retrievers (Labrador) ", "German Shepherds", "Retrievers (Golden) ","French Bulldogs "
  166. ,"Bulldogs","Beagles","Poodles","Rottweilers","Yorkshire Terriers","Pointers (German Shorthaired)"
  167. , "Boxers","Siberian Huskies", "Great Danes","Pomeranians","Pugs","Huskies","Chihuahua"
  168. , "Corgis","Doberman Pinschers","Shih Tzu","Boston Terriers","Havanese","Shetland Sheepdogs","Maltese"
  169. ,"Weimaraners","Collies","Shiba Inu","Retrievers (Chesapeake Bay)","Akitas","Papillons","Dalmatians"
  170. ,"Italian Greyhounds","Mixed","Other")
  171. );
  172. breedChoice.setStyle("-fx-background-color: WHITE");
  173. breedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  174. breedChoice.getSelectionModel().select(0);
  175. pane.add(breedChoice, 1, 2);
  176.  
  177.  
  178. Label gender = new Label("gender: ");
  179. gender.setFont(new Font("Times New Roman",17));
  180. pane.add(gender, 0, 3);
  181. ChoiceBox<String> genderChoice= new ChoiceBox<>();
  182. genderChoice.setStyle("-fx-background-color: WHITE");
  183. genderChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  184. genderChoice.getItems().addAll("Male", "Female");
  185. genderChoice.getSelectionModel().select(0);
  186. pane.add(genderChoice, 1 ,3);
  187.  
  188.  
  189. Label furColor = new Label("fur color: ");
  190. furColor.setFont(new Font("Times New Roman",17));
  191. pane.add(furColor, 0, 4);
  192. ChoiceBox<String> furColorChoice= new ChoiceBox<>();
  193. furColorChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  194. furColorChoice.setStyle("-fx-background-color: WHITE");
  195. furColorChoice.getItems().addAll("Brown", "Red","Gold","Yellow","Cream","Blue","Gray","Two color striped","Three color striped","Dotted","Beige","Tan","Orange","Light Brown"
  196. ,"Dark Brown","Apricot","Fawn","Chestnut","Black","Rust","Wheaten","White","Other");
  197. furColorChoice.getSelectionModel().select(0);
  198. pane.add(furColorChoice, 1, 4);
  199.  
  200.  
  201. Label weight = new Label("weight(in lb): ");
  202. weight.setFont(new Font("Times New Roman",17));
  203. pane.add(weight, 0, 5);
  204. TextField weightText = new TextField();
  205. weightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  206. pane.add(weightText, 1 ,5);
  207.  
  208.  
  209. Label height = new Label("height(in inches): ");
  210. height.setFont(new Font("Times New Roman",17));
  211. pane.add(height, 0, 6);
  212. TextField heightText = new TextField();
  213. heightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  214. pane.add(heightText, 1, 6);
  215.  
  216.  
  217. Label birthday = new Label("birthday: ");
  218. birthday.setFont(new Font("Times New Roman",17));
  219. pane.add(birthday, 0, 7);
  220. DatePicker datePicker = new DatePicker();
  221. datePicker.setStyle("-fx-control-inner-background: WHITE;");
  222. datePicker.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  223. pane.add(datePicker, 1, 7);
  224.  
  225.  
  226. Label neutorSpay= new Label("Is your pet neutored or spayed? ");
  227. neutorSpay.setFont(new Font("Times New Roman",17));
  228. pane.add(neutorSpay, 0, 8);
  229. ChoiceBox<String> neutorSpayChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  230. "Yes", "No")
  231. );
  232. neutorSpayChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  233. neutorSpayChoice.setStyle("-fx-background-color: WHITE");
  234. neutorSpayChoice.getSelectionModel().select(0);
  235. pane.add(neutorSpayChoice, 1 ,8);
  236.  
  237.  
  238. Label microchipped = new Label("Does your pet have microchip? ");
  239. microchipped.setFont(new Font("Times New Roman",17));
  240. pane.add(microchipped, 0, 9);
  241. ChoiceBox<String> microchippedChoice= new ChoiceBox<>();
  242. microchippedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  243. microchippedChoice.setStyle("-fx-background-color: WHITE");
  244. microchippedChoice.getItems().addAll("Yes","No");
  245. microchippedChoice.getSelectionModel().select(0);
  246. pane.add(microchippedChoice, 1, 9);
  247.  
  248. Label phoneNumber = new Label("phone number: ");
  249. phoneNumber.setFont(new Font("Times New Roman",17));
  250. pane.add(phoneNumber, 0, 10);
  251. TextField phoneNumberText = new TextField();
  252. phoneNumberText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  253. pane.add(phoneNumberText, 1 ,10);
  254.  
  255.  
  256. Label provider = new Label("provider: ");
  257. provider.setFont(new Font("Times New Roman",17));
  258. pane.add(provider, 0, 11);
  259. ChoiceBox<String> providerChoice= new ChoiceBox<>();
  260. providerChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  261. providerChoice.setStyle("-fx-background-color: WHITE");
  262. providerChoice.getItems().addAll("Metropcs","ATT","TMobile","Sprint","Cricket");
  263. providerChoice.getSelectionModel().select(0);
  264. pane.add(providerChoice, 1, 11);
  265.  
  266. save.setOnAction(e3->{
  267.  
  268. /////////////////////Save the information /////////////////////
  269.  
  270. String option = genderChoice.getValue().toString();
  271. String neutorSpayOption = neutorSpayChoice.getValue().toString();
  272. String breedOption = breedChoice.getValue().toString();
  273. String furColorOption = furColorChoice.getValue().toString();
  274. String providerOption = providerChoice.getValue().toString();
  275. String microchippedOption = microchippedChoice.getValue().toString();
  276. LocalDate value = datePicker.getValue();
  277. String breedSpecify = "";
  278. String furColorSpecify = "";
  279.  
  280.  
  281. if(!nameText.getText().trim().isEmpty()&&!option.trim().isEmpty() &&
  282. !neutorSpayOption.trim().isEmpty()&& !breedOption.trim().isEmpty()
  283. &&!furColorOption.trim().isEmpty()&& !microchippedOption.trim().isEmpty()
  284. &&value!=null&&!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()
  285. &&!phoneNumberText.getText().trim().isEmpty()
  286. &&!providerOption.trim().isEmpty()
  287. ) {
  288.  
  289. ///////////////////// Specify when choose "Other" /////////////////////
  290.  
  291. if(breedOption.equalsIgnoreCase("Other") || breedOption.equalsIgnoreCase("Mixed")) {
  292. userInputSpeak.stop();
  293.  
  294.  
  295. TextInputDialog dialog = new TextInputDialog("Golden Retriever");
  296. dialog.setTitle("Specify breed");
  297. dialog.setHeaderText(null);
  298. dialog.setContentText("Please specify breed:");
  299. Optional<String> result = dialog.showAndWait();
  300. if(result.isPresent())
  301. breedSpecify = result.get();
  302.  
  303. }else {
  304. breedSpecify = breedOption;
  305. }
  306.  
  307. if(furColorOption.equalsIgnoreCase("Other")) {
  308. userInputSpeak.stop();
  309.  
  310. TextInputDialog dialog = new TextInputDialog("Brown");
  311. dialog.setTitle("Specify fur color");
  312. dialog.setHeaderText(null);
  313. dialog.setContentText("Please specify fur color:");
  314. Optional<String> result = dialog.showAndWait();
  315. if(result.isPresent())
  316. furColorSpecify = result.get();
  317.  
  318. }else {
  319. furColorSpecify = furColorOption;
  320.  
  321. }
  322.  
  323. /////////////////////Numerical validation /////////////////////
  324.  
  325. if(isValidWeight(weightText.getText())==false||isValidHeight(heightText.getText())==false) {
  326. userInputSpeak.stop();
  327. final URL properWOHUrl = getClass().getResource("properWeightOrHeight.mp3");
  328. final Media properWOHMedia = new Media(properWOHUrl.toString());
  329. properWeightOrHeight = new MediaPlayer(properWOHMedia);
  330. properWeightOrHeight.play();
  331. properWeightOrHeight.setVolume(0.1);
  332. Alert alert = new Alert(AlertType.ERROR);
  333. alert.setTitle("Error!");
  334. alert.setContentText("Please enter the proper weight or height!");
  335. alert.showAndWait();
  336. properWeightOrHeight.stop();
  337.  
  338.  
  339. if(isValidWeight(weightText.getText())==false) {
  340. weightText.setText("");
  341. }
  342. if(isValidHeight(heightText.getText())==false) {
  343. heightText.setText("");
  344. }
  345. }
  346. if(isValidPhoneNumber(phoneNumberText.getText())==false) {
  347. userInputSpeak.stop();
  348. final URL phoneRe = getClass().getResource("properPhoneNumber.mp3");
  349. final Media phoneMe = new Media(phoneRe.toString());
  350. properPhoneNumber = new MediaPlayer(phoneMe);
  351. properPhoneNumber.play();
  352. properPhoneNumber.setVolume(0.1);
  353. Alert alert = new Alert(AlertType.ERROR);
  354. alert.setTitle("Error!");
  355. alert.setContentText("Please enter the proper phone number!");
  356. alert.showAndWait();
  357. properPhoneNumber.stop();
  358. phoneNumberText.setText("");
  359. }
  360.  
  361.  
  362. }
  363.  
  364.  
  365.  
  366. if(!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()) {
  367. dog = new Dog(nameText.getText(),breedSpecify,option,
  368. furColorOption,Double.parseDouble(weightText.getText()),Double.parseDouble(heightText.getText()),
  369. value,convertToBoolean(neutorSpayOption),convertToBoolean(microchippedOption),phoneNumberText.getText(),providerOption);
  370. }
  371.  
  372.  
  373.  
  374. if(!weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()&&!option.trim().isEmpty()
  375. && !breedSpecify.trim().isEmpty() && !furColorSpecify.trim().isEmpty()
  376. && !neutorSpayOption.trim().isEmpty()
  377. && !microchippedOption.trim().isEmpty() && !nameText.getText().trim().isEmpty() &&
  378. !phoneNumberText.getText().trim().isEmpty()&& !providerOption.trim().isEmpty()
  379. && dogInformation.contains(dog)==false ) {
  380.  
  381.  
  382.  
  383.  
  384. dogInformation.add(dog);
  385.  
  386. /////////////////////Add the information to MySQL database /////////////////////
  387.  
  388. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  389. String username = "cs3220stu55";
  390. String password = "zWpa0NxR";
  391.  
  392. Connection conn;
  393.  
  394. try{
  395.  
  396. //STEP 2: Register JDBC driver
  397. Class.forName("com.mysql.cj.jdbc.Driver");
  398.  
  399. //STEP 3: Open a connection
  400.  
  401. conn = DriverManager.getConnection(url, username, password);
  402.  
  403. Statement statement = conn.createStatement() ;
  404. ResultSet resultset = statement.executeQuery("SELECT * FROM pet") ;
  405. while(resultset.next()){
  406. if(resultset.getString("name").equalsIgnoreCase(dog.getName())
  407. && resultset.getString("breed").equalsIgnoreCase(dog.getBreed())
  408. && resultset.getString("gender").equalsIgnoreCase(dog.getGender())
  409. && resultset.getString("furColor").equalsIgnoreCase(dog.getFurColor())
  410. && resultset.getDouble("weight") == dog.getWeight()
  411. && resultset.getDouble("height") == dog.getHeight()
  412. && resultset.getBoolean("neutorSpay") == dog.getNeuterSpay()
  413. && resultset.getBoolean("microchipped") == dog.getMicrochip()
  414. && resultset.getString("phoneNumber").equalsIgnoreCase(dog.getPhoneNumber())
  415. && resultset.getString("provider").equalsIgnoreCase(dog.getProvider())
  416.  
  417. ){
  418.  
  419. ///////////////////// for preventing duplicates added to the database /////////////////////
  420. unique = false;
  421. final URL entryExistedR = getClass().getResource("entryExisted.mp3");
  422. final Media entryExistedM = new Media(entryExistedR.toString());
  423. entryExisted = new MediaPlayer(entryExistedM);
  424. entryExisted.play();
  425. entryExisted.setVolume(0.1);
  426. Alert alert = new Alert(AlertType.ERROR);
  427. alert.setTitle("Error!");
  428. alert.setContentText("Entry: " + dog.getName() + " already existed in our database!");
  429. alert.showAndWait();
  430. entryExisted.stop();
  431. weightText.clear();
  432. heightText.clear();
  433. nameText.clear();
  434. phoneNumberText.clear();
  435.  
  436. providerChoice.getSelectionModel().select(0);
  437. breedChoice.getSelectionModel().select(0);
  438. furColorChoice.getSelectionModel().select(0);
  439. neutorSpayChoice.getSelectionModel().select(0);
  440. microchippedChoice.getSelectionModel().select(0);
  441.  
  442. datePicker.setValue(null);
  443. unique = true;
  444. }
  445. }
  446. if(unique == true
  447. && !weightText.getText().trim().isEmpty()&&!heightText.getText().trim().isEmpty()) {
  448. String query = " insert into pet (name, breed,gender,furColor, weight, height,birthday, neutorSpay, microchipped, phoneNumber, provider)"
  449. + " values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  450. PreparedStatement preparedStmt = conn.prepareStatement(query);
  451. preparedStmt.setString (1, nameText.getText());
  452. preparedStmt.setString (2, breedSpecify);
  453. preparedStmt.setString (3, option);
  454. preparedStmt.setString (4, furColorSpecify);
  455. preparedStmt.setDouble (5, Double.parseDouble(weightText.getText()));
  456. preparedStmt.setDouble (6, Double.parseDouble(heightText.getText()));
  457. preparedStmt.setDate (7, java.sql.Date.valueOf(value));
  458. preparedStmt.setBoolean(8, convertToBoolean(neutorSpayOption));
  459. preparedStmt.setBoolean(9, convertToBoolean(microchippedOption));
  460. preparedStmt.setString (10, phoneNumberText.getText());
  461. preparedStmt.setString (11, providerOption);
  462.  
  463.  
  464.  
  465.  
  466. // execute the preparedstatement
  467. preparedStmt.execute();
  468.  
  469. conn.close();
  470.  
  471. userInputSpeak.stop();
  472.  
  473. /////////////////////information saved /////////////////////
  474.  
  475. final URL resource3 = getClass().getResource("informationSaved.mp3");
  476. final Media media3 = new Media(resource3.toString());
  477. informationSaved = new MediaPlayer(media3);
  478. informationSaved.play();
  479. informationSaved.setVolume(0.1);
  480. Alert alert1 = new Alert(AlertType.INFORMATION);
  481. alert1.setTitle("Saved");
  482. alert1.setContentText(dog.getName() + "' Information saved!");
  483. alert1.showAndWait();
  484. informationSaved.stop();
  485.  
  486.  
  487. }
  488. }catch(SQLException se) {
  489. se.printStackTrace();
  490. } catch (ClassNotFoundException e2) {
  491. e2.printStackTrace();
  492. }
  493.  
  494.  
  495. }
  496.  
  497. if(nameText.getText()==null || nameText.getText().trim().isEmpty()
  498. ||breedSpecify==null || breedSpecify.trim().isEmpty()
  499. ||option==null || option.trim().isEmpty()
  500. ||furColorChoice.getValue().toString()==null || furColorChoice.getValue().toString().trim().isEmpty()
  501. ||weightText.getText()==null || weightText.getText().trim().isEmpty()
  502. ||heightText.getText()==null || heightText.getText().trim().isEmpty()
  503. ||value == null
  504. ||neutorSpayOption==null || neutorSpayOption.trim().isEmpty()
  505. ||microchippedOption==null || microchippedOption.trim().isEmpty()
  506. || phoneNumberText.getText().trim().isEmpty() || phoneNumberText.getText() == null ||
  507. providerOption.trim().isEmpty()|| providerOption==null
  508. ) {
  509.  
  510.  
  511. userInputSpeak.stop();
  512. final URL resource5 = getClass().getResource("error.mp3");
  513. final Media media5 = new Media(resource5.toString());
  514. error = new MediaPlayer(media5);
  515. error.play();
  516. error.setVolume(0.1);
  517. Alert alert = new Alert(AlertType.ERROR);
  518. alert.setTitle("Error!");
  519. alert.setContentText("Please fill in all the fields!!");
  520. alert.showAndWait();
  521. error.stop();
  522.  
  523.  
  524.  
  525.  
  526.  
  527. }
  528. else{
  529.  
  530.  
  531. }
  532. });
  533.  
  534.  
  535. backToPrimary.setOnAction(event->{
  536. secondaryStage.close();
  537. primaryStage.show();
  538. userInputSpeak.stop();
  539. welcomeMessage.play();
  540. });
  541.  
  542.  
  543. proceed.setOnAction(e1->{
  544.  
  545. /////////////////////proceed only works after saved /////////////////////
  546.  
  547. if(nameText.getText()==null || nameText.getText().trim().isEmpty()
  548. ||breedChoice.getValue()==null || breedChoice.getValue().toString().trim().isEmpty()
  549. ||genderChoice.getValue().toString()==null || genderChoice.getValue().toString().trim().isEmpty()
  550. ||furColorChoice.getValue().toString()==null || furColorChoice.getValue().toString().trim().isEmpty()
  551. ||weightText.getText()==null || weightText.getText().trim().isEmpty()
  552. ||heightText.getText()==null || heightText.getText().trim().isEmpty()
  553. || datePicker.getValue() == null
  554. ||neutorSpayChoice.getValue().toString()==null || neutorSpayChoice.getValue().toString().trim().isEmpty()
  555. ||microchippedChoice.getValue().toString()==null || microchippedChoice.getValue().toString().trim().isEmpty()
  556. ||phoneNumberText.getText().trim().isEmpty()||phoneNumberText.getText()==null
  557. ||providerChoice.getValue().toString().trim().isEmpty() || providerChoice.getValue().toString()==null
  558. ) {
  559.  
  560.  
  561. userInputSpeak.stop();
  562. final URL resource5 = getClass().getResource("error.mp3");
  563. final Media media5 = new Media(resource5.toString());
  564. error = new MediaPlayer(media5);
  565. error.play();
  566. error.setVolume(0.1);
  567. Alert alert = new Alert(AlertType.ERROR);
  568. alert.setTitle("Error!");
  569. alert.setContentText("Please fill in all the fields!!");
  570. alert.showAndWait();
  571. error.stop();
  572. // userInputSpeak.play();
  573.  
  574.  
  575.  
  576.  
  577.  
  578. }
  579.  
  580. /////////////////////ArrayList dogInformation only add entries when save button is pressed /////////////////////
  581.  
  582. else if(dogInformation.isEmpty()) {
  583.  
  584. userInputSpeak.stop();
  585. final URL resource6 = getClass().getResource("saveAlert.mp3");
  586. final Media media6 = new Media(resource6.toString());
  587. saved = new MediaPlayer(media6);
  588. saved.play();
  589. saved.setVolume(0.1);
  590. Alert alert = new Alert(AlertType.ERROR);
  591. alert.setTitle("Error!");
  592. alert.setContentText("Please save the information to proceed!!");
  593. alert.showAndWait();
  594. }
  595. else {
  596.  
  597. userInputSpeak.stop();
  598.  
  599. final URL resource4 = getClass().getResource("ready.mp3");
  600. final Media media4 = new Media(resource4.toString());
  601. readyed = new MediaPlayer(media4);
  602. readyed.play();
  603. readyed.setVolume(0.1);
  604. secondaryStage.close();
  605. Stage tertiaryStage = new Stage();
  606. GridPane gridPane = new GridPane();
  607. gridPane.setAlignment(Pos.CENTER);
  608. gridPane.setHgap(10);
  609. gridPane.setVgap(10);
  610. gridPane.setPadding(new Insets(25, 25, 25, 25));
  611. Label message = new Label("Are you ready for the ADH? ");
  612. message.setFont(new Font("Times New Roman", 30));
  613. Image image = new Image("cuteDoggy.gif");
  614. ImageView imageView = new ImageView();
  615. imageView.setImage(image);
  616. imageView.setFitHeight(150);
  617. imageView.setFitWidth(90);
  618. message.setGraphic(imageView);
  619. gridPane.add(message, 0, 1);
  620.  
  621.  
  622. ready.setOnAction(e2->{
  623. welcomeBGM.stop();
  624. readyed.stop();
  625. tertiaryStage.close();
  626. javaFXPane jp1 = new javaFXPane();
  627. Stage stage = new Stage();
  628. try {
  629. jp1.start(stage);
  630. } catch (Exception e3) {
  631. // TODO Auto-generated catch block
  632. e3.printStackTrace();
  633. }
  634. });
  635.  
  636. viewInfor.setOnAction(e6->{
  637. data.clear();
  638. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  639. String username = "cs3220stu55";
  640. String password = "zWpa0NxR";
  641.  
  642.  
  643.  
  644.  
  645. try {
  646. Connection c = DriverManager
  647. .getConnection( url, username, password );
  648. Statement stmt = c.createStatement();
  649.  
  650. ResultSet rs = stmt.executeQuery( "select * from pet" );
  651.  
  652. while( rs.next() )
  653. {
  654. LocalDate today = rs.getDate("birthday").toLocalDate();
  655. LocalDate tomorrow = today.plusDays(1);
  656. data.add(new Dog(rs.getString("name"),rs.getString("breed"),
  657. rs.getString("gender"),rs.getString("furColor"),rs.getInt("weight"),rs.getInt("height"),
  658. tomorrow,rs.getBoolean("neutorSpay"),rs.getBoolean("microchipped"), rs.getString("phoneNumber"),rs.getString("provider")));
  659.  
  660. }
  661.  
  662. c.close();
  663.  
  664.  
  665.  
  666.  
  667.  
  668. } catch (Exception exception) {
  669. exception.printStackTrace();
  670. //System.out.println("Error on Building Data");
  671. }
  672. table.getColumns().clear();
  673.  
  674.  
  675. Stage fifthStage = new Stage();
  676.  
  677. Scene scene = new Scene(new Group());
  678.  
  679. final Label label = new Label("Dog Information");
  680. label.setFont(new Font("Arial", 20));
  681.  
  682. table.setEditable(true);
  683.  
  684. TableColumn NameCol = new TableColumn("name");
  685. NameCol.setMaxWidth(100);
  686. NameCol.setCellValueFactory(
  687. new PropertyValueFactory<Dog, String>("name"));
  688.  
  689. TableColumn breedCol = new TableColumn("breed");
  690. breedCol.setMaxWidth(200);
  691. breedCol.setCellValueFactory(
  692. new PropertyValueFactory<Dog, String>("breed"));
  693.  
  694. TableColumn genderCol = new TableColumn("gender");
  695. genderCol.setMaxWidth(100);
  696. genderCol.setCellValueFactory(
  697. new PropertyValueFactory<Dog, String>("gender"));
  698.  
  699. TableColumn furColorCol = new TableColumn("furColor");
  700. furColorCol.setMaxWidth(200);
  701. furColorCol.setCellValueFactory(
  702. new PropertyValueFactory<Dog, String>("furColor"));
  703.  
  704. TableColumn weightCol = new TableColumn("weight(in lbs)");
  705. weightCol.setMaxWidth(100);
  706. weightCol.setCellValueFactory(
  707. new PropertyValueFactory<Dog, String>("weight"));
  708.  
  709. TableColumn heightCol = new TableColumn("height(in inches)");
  710. heightCol.setMaxWidth(150);
  711. heightCol.setCellValueFactory(
  712. new PropertyValueFactory<Dog, String>("height"));
  713.  
  714. TableColumn birthdayCol = new TableColumn("birthday");
  715. birthdayCol.setMaxWidth(100);
  716. birthdayCol.setCellValueFactory(
  717. new PropertyValueFactory<Dog, String>("birthday"));
  718.  
  719. TableColumn spayCol = new TableColumn("neuterSpay");
  720. spayCol.setMaxWidth(100);
  721. spayCol.setCellValueFactory(
  722. new PropertyValueFactory<Dog, String>("neuterSpay"));
  723.  
  724. TableColumn microchippedCol = new TableColumn("microchip");
  725. microchippedCol.setMaxWidth(100);
  726. microchippedCol.setCellValueFactory(
  727. new PropertyValueFactory<Dog, String>("microchip"));
  728.  
  729. TableColumn phoneNumberCol = new TableColumn("phone number");
  730. phoneNumberCol.setMaxWidth(120);
  731. phoneNumberCol.setCellValueFactory(
  732. new PropertyValueFactory<Dog, String>("phoneNumber"));
  733.  
  734. TableColumn providerCol = new TableColumn("provider");
  735. providerCol.setMaxWidth(120);
  736. providerCol.setCellValueFactory(
  737. new PropertyValueFactory<Dog, String>("provider"));
  738.  
  739.  
  740.  
  741. // ObservableList<Dog> list = FXCollections.observableArrayList(dogInformation);
  742. ObservableList<Dog> list = removeDuplicates(data);
  743.  
  744. table.setItems(list);
  745. table.getColumns().addAll(NameCol, breedCol, genderCol,furColorCol, weightCol,
  746. heightCol, birthdayCol, spayCol, microchippedCol,phoneNumberCol,providerCol);
  747.  
  748.  
  749. back.setOnAction(e8->{
  750. fifthStage.close();
  751.  
  752. tertiaryStage.show();
  753. });
  754. notReady.setOnAction(e5->{
  755. fifthStage.close();
  756. readyed.stop();
  757. tertiaryStage.close();
  758. final URL resource5 = getClass().getResource("deleted.mp3");
  759. final Media media5 = new Media(resource5.toString());
  760. deleted = new MediaPlayer(media5);
  761. deleted.play();
  762. deleted.setVolume(0.1);
  763. dogInformation.clear();
  764.  
  765.  
  766. Connection conn = null;
  767. Statement stmte = null;
  768. try{
  769.  
  770.  
  771. Class.forName("com.mysql.cj.jdbc.Driver");
  772.  
  773. conn = DriverManager.getConnection(url, username, password);
  774.  
  775. stmte = conn.createStatement();
  776.  
  777. String sql = "DELETE FROM pet;";
  778.  
  779. stmte.executeUpdate(sql);
  780. }catch(Exception exc) {
  781. exc.printStackTrace();
  782. }
  783. secondaryStage.show();
  784.  
  785. nameText.setText(null);
  786. breedChoice.getSelectionModel().select(0);
  787. genderChoice.getSelectionModel().select(0);
  788. weightText.setText(null);
  789. heightText.setText(null);
  790. furColorChoice.getSelectionModel().select(0);
  791. datePicker.setValue(null);
  792. neutorSpayChoice.getSelectionModel().select(0);
  793. microchippedChoice.getSelectionModel().select(0);
  794.  
  795.  
  796. Alert alert = new Alert(AlertType.INFORMATION);
  797. alert.setTitle("Information");
  798. alert.setHeaderText(null);
  799. alert.setContentText("Please fill in the following!");
  800.  
  801. alert.showAndWait();
  802. deleted.stop();
  803. // userInputSpeak.play();
  804.  
  805. });
  806. Button delete = new Button("Delete This");
  807. delete.setStyle("-fx-background-color: black");
  808. delete.setTextFill(Color.WHITE);
  809. delete.setOnAction(ee->{
  810. Dog selectedItem = table.getSelectionModel().getSelectedItem();
  811. table.getItems().remove(selectedItem);
  812. Connection conn = null;
  813. try{
  814.  
  815.  
  816. Class.forName("com.mysql.cj.jdbc.Driver");
  817.  
  818. conn = DriverManager.getConnection(url, username, password);
  819.  
  820.  
  821. String sql = "DELETE FROM pet where name = ?";
  822.  
  823. PreparedStatement preparedStmt = conn.prepareStatement(sql);
  824. preparedStmt.setString(1,selectedItem.getName());
  825. preparedStmt.execute();
  826. conn.close();
  827.  
  828. }catch(Exception exc) {
  829. exc.printStackTrace();
  830. }
  831. });
  832.  
  833. Button edit = new Button("Edit");
  834. edit.setStyle("-fx-background-color: black");
  835. edit.setTextFill(Color.WHITE);
  836.  
  837. edit.setOnAction(ee->{
  838.  
  839. Dog selectedItem = table.getSelectionModel().getSelectedItem();
  840.  
  841.  
  842.  
  843. Stage editStage = new Stage();
  844. Button editSave = new Button("Save");
  845. editSave.setStyle("-fx-background-color: black");
  846. editSave.setTextFill(Color.WHITE);
  847. GridPane editPane = new GridPane();
  848.  
  849. editPane.setAlignment(Pos.CENTER);
  850. editPane.setHgap(5);
  851. editPane.setVgap(5);
  852. editPane.setBackground(new Background(new BackgroundFill(Color.WHITE, null, null)));
  853. //The user input fields
  854. Label editName = new Label("name: ");
  855. editName.setFont(new Font("Times New Roman",17));
  856. editPane.add(editName, 0, 1);
  857. TextField editNameText = new TextField();
  858. //editNameText.setText(selectedItem.getName());
  859. editNameText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  860. editPane.add(editNameText, 1 ,1);
  861.  
  862.  
  863. Label editBreed = new Label("breed: ");
  864. editBreed.setFont(new Font("Times New Roman",17));
  865. editPane.add(editBreed, 0, 2);
  866. ChoiceBox<String> editBreedChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  867. "Retrievers (Labrador) ", "German Shepherds", "Retrievers (Golden) ","French Bulldogs "
  868. ,"Bulldogs","Beagles","Poodles","Rottweilers","Yorkshire Terriers","Pointers (German Shorthaired)"
  869. , "Boxers","Siberian Huskies", "Great Danes","Pomeranians","Pugs","Huskies","Chihuahua"
  870. , "Pembroke Welsh Corgis","Doberman Pinschers","Shih Tzu","Boston Terriers","Havanese","Shetland Sheepdogs","Maltese"
  871. ,"Weimaraners","Collies","Shiba Inu","Retrievers (Chesapeake Bay)","Akitas","Papillons","Dalmatians"
  872. ,"Italian Greyhounds","Mixed","Other")
  873. );
  874. editBreedChoice.setStyle("-fx-background-color: WHITE");
  875. editBreedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  876. //editBreedChoice.setValue(selectedItem.getBreed());
  877. editPane.add(editBreedChoice, 1, 2);
  878.  
  879.  
  880. Label editGender = new Label("gender: ");
  881. editGender.setFont(new Font("Times New Roman",17));
  882. editPane.add(editGender, 0, 3);
  883. ChoiceBox<String> editGenderChoice= new ChoiceBox<>();
  884. editGenderChoice.setStyle("-fx-background-color: WHITE");
  885. editGenderChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  886. editGenderChoice.getItems().addAll("Male", "Female");
  887. //editGenderChoice.setValue(selectedItem.getGender());
  888. editPane.add(editGenderChoice, 1 ,3);
  889.  
  890.  
  891. Label editFurColor = new Label("fur color: ");
  892. editFurColor.setFont(new Font("Times New Roman",17));
  893. editPane.add(editFurColor, 0, 4);
  894. ChoiceBox<String> editFurColorChoice= new ChoiceBox<>();
  895. editFurColorChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  896. editFurColorChoice.setStyle("-fx-background-color: WHITE");
  897. editFurColorChoice.getItems().addAll("Brown", "Red","Gold","Yellow","Cream","Blue","Gray","Two color striped","Three color striped","Dotted","Beige","Tan","Orange","Light Brown"
  898. ,"Dark Brown","Apricot","Fawn","Chestnut","Rust","Wheaten","White","Other");
  899. //editFurColorChoice.setValue(selectedItem.getFurColor());;
  900. editPane.add(editFurColorChoice, 1, 4);
  901.  
  902.  
  903. Label editWeight = new Label("weight(in lb): ");
  904. editWeight.setFont(new Font("Times New Roman",17));
  905. editPane.add(editWeight, 0, 5);
  906. TextField editWeightText = new TextField();
  907. //editWeightText.setText(String.valueOf(selectedItem.getWeight()));
  908. editWeightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  909. editPane.add(editWeightText, 1 ,5);
  910.  
  911.  
  912. Label editHeight = new Label("height(in cm): ");
  913. editHeight.setFont(new Font("Times New Roman",17));
  914. editPane.add(editHeight, 0, 6);
  915. TextField editHeightText = new TextField();
  916. //editHeightText.setText(String.valueOf(selectedItem.getHeight()));
  917. editHeightText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  918. editPane.add(editHeightText, 1, 6);
  919.  
  920.  
  921. Label editBirthday = new Label("birthday: ");
  922. editBirthday.setFont(new Font("Times New Roman",17));
  923. editPane.add(editBirthday, 0, 7);
  924. DatePicker editDatePicker = new DatePicker();
  925. editDatePicker.setStyle("-fx-control-inner-background: WHITE;");
  926. //editDatePicker.setValue(selectedItem.getBirthday());
  927. editDatePicker.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  928. editPane.add(editDatePicker, 1, 7);
  929.  
  930.  
  931. Label editNeutorSpay= new Label("Is your pet neutored or spayed? ");
  932. editNeutorSpay.setFont(new Font("Times New Roman",17));
  933. editPane.add(editNeutorSpay, 0, 8);
  934. ChoiceBox<String> editNeutorSpayChoice = new ChoiceBox<String>(FXCollections.observableArrayList(
  935. "Yes", "No")
  936. );
  937. editNeutorSpayChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  938. editNeutorSpayChoice.setStyle("-fx-background-color: WHITE");
  939. //editNeutorSpayChoice.setValue(String.valueOf(selectedItem.getNeuterSpay()));
  940. editPane.add(editNeutorSpayChoice, 1 ,8);
  941.  
  942.  
  943. Label editMicrochipped = new Label("Does your pet have microchip? ");
  944. editMicrochipped.setFont(new Font("Times New Roman",17));
  945. editPane.add(editMicrochipped, 0, 9);
  946. ChoiceBox<String> editMicrochippedChoice= new ChoiceBox<>();
  947. editMicrochippedChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  948. editMicrochippedChoice.setStyle("-fx-background-color: WHITE");
  949. editMicrochippedChoice.getItems().addAll("Yes","No");
  950. //editMicrochippedChoice.setValue(String.valueOf(selectedItem.getMicrochip()));;
  951. editPane.add(editMicrochippedChoice, 1, 9);
  952.  
  953. Label editPhoneNumber = new Label("phone number: ");
  954. editPhoneNumber.setFont(new Font("Times New Roman",17));
  955. editPane.add(editPhoneNumber, 0, 10);
  956. TextField editPhoneNumberText = new TextField();
  957. //editNameText.setText(selectedItem.getName());
  958. editPhoneNumberText.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  959. editPane.add(editPhoneNumberText, 1 ,10);
  960.  
  961.  
  962. Label editProvider = new Label("provider: ");
  963. editProvider.setFont(new Font("Times New Roman",17));
  964. editPane.add(editProvider, 0, 11);
  965. ChoiceBox<String> editProviderChoice= new ChoiceBox<>();
  966. editProviderChoice.setBorder(new Border(new BorderStroke(Color.BLACK, BorderStrokeStyle.SOLID, null, new BorderWidths(2))));
  967. editProviderChoice.setStyle("-fx-background-color: WHITE");
  968. editProviderChoice.getItems().addAll("Metropcs","ATT","TMobile","Verizon","Sprint","BoostMobile","Cricket");
  969. //editMicrochippedChoice.setValue(String.valueOf(selectedItem.getMicrochip()));;
  970. editPane.add(editProviderChoice, 1, 11);
  971.  
  972.  
  973. editNameText.setText(selectedItem.getName());
  974. editBreedChoice.setValue(selectedItem.getBreed());
  975. editGenderChoice.setValue(selectedItem.getGender());;
  976. editWeightText.setText(String.valueOf(selectedItem.getWeight()));
  977. editHeightText.setText(String.valueOf(selectedItem.getHeight()));
  978. editFurColorChoice.setValue(selectedItem.getFurColor());
  979. editDatePicker.setValue(selectedItem.getBirthday());
  980. editNeutorSpayChoice.setValue(String.valueOf(selectedItem.getNeuterSpay()));;
  981. editMicrochippedChoice.setValue(String.valueOf(selectedItem.getMicrochip()));;
  982. editPhoneNumberText.setText(selectedItem.getPhoneNumber());
  983. editProviderChoice.setValue(selectedItem.getProvider());
  984.  
  985. editPane.add(editSave, 0, 12);
  986.  
  987. editSave.setOnAction(eee->{
  988.  
  989. String editSpecifyBreed = "";
  990. String editSpecifyColor = "";
  991. Connection conn = null;
  992. try{
  993.  
  994.  
  995. if
  996. (isValidWeight(editWeightText.getText())&&isValidHeight(editHeightText.getText())&&isValidPhoneNumber(editPhoneNumberText.getText())) {
  997.  
  998. if(editBreedChoice.getValue().equalsIgnoreCase("Other")) {
  999. TextInputDialog dialog = new TextInputDialog("Golden Retriever");
  1000. dialog.setTitle("Specify breed");
  1001. dialog.setHeaderText(null);
  1002. dialog.setContentText("Please specify breed:");
  1003. Optional<String> result = dialog.showAndWait();
  1004. if(result.isPresent())
  1005. editSpecifyBreed = result.get();
  1006. }else {
  1007. editSpecifyBreed = editBreedChoice.getValue();
  1008. }
  1009. if(editFurColorChoice.getValue().equalsIgnoreCase("Other")) {
  1010. TextInputDialog dialog = new TextInputDialog("Brown");
  1011. dialog.setTitle("Specify fur color");
  1012. dialog.setHeaderText(null);
  1013. dialog.setContentText("Please specify fur color:");
  1014. Optional<String> result = dialog.showAndWait();
  1015. if(result.isPresent())
  1016. editSpecifyColor = result.get();
  1017. }else {
  1018. editSpecifyColor = editFurColorChoice.getValue();
  1019. }
  1020.  
  1021.  
  1022.  
  1023.  
  1024.  
  1025. Class.forName("com.mysql.cj.jdbc.Driver");
  1026.  
  1027. conn = DriverManager.getConnection(url, username, password);
  1028.  
  1029. String sql = "update pet set breed = ?,"
  1030. + "gender = ?,"
  1031. + "furColor = ?,"
  1032. + "weight = ?,"
  1033. + "height = ?,"
  1034. + "birthday = ?,"
  1035. + "neutorSpay = ?,"
  1036. + "microchipped = ?, "
  1037. + "phoneNumber = ?, "
  1038. + "provider = ?"
  1039. + "where name = ?";
  1040.  
  1041. PreparedStatement preparedStmt = conn.prepareStatement(sql);
  1042. preparedStmt.setString(1,editSpecifyBreed);
  1043. preparedStmt.setString(2,editGenderChoice.getValue());
  1044. preparedStmt.setString(3,editSpecifyColor);
  1045. preparedStmt.setDouble(4, Double.parseDouble(editWeightText.getText()));
  1046. preparedStmt.setDouble(5, Double.parseDouble(editHeightText.getText()));
  1047. preparedStmt.setDate(6, java.sql.Date.valueOf(editDatePicker.getValue()));
  1048. preparedStmt.setBoolean(7, convertToBoolean(editNeutorSpayChoice.getValue()));
  1049. preparedStmt.setBoolean(8, convertToBoolean(editMicrochippedChoice.getValue()));
  1050. preparedStmt.setString(9, editPhoneNumberText.getText());
  1051. preparedStmt.setString(10, editProviderChoice.getValue());
  1052. preparedStmt.setString(11, selectedItem.getName());
  1053.  
  1054.  
  1055. preparedStmt.executeUpdate();
  1056. conn.close();
  1057.  
  1058. Alert alert = new Alert(AlertType.INFORMATION);
  1059. alert.setHeaderText(null);
  1060. alert.setContentText("Edited information has been saved.");
  1061. alert.showAndWait();
  1062.  
  1063. editStage.close();
  1064. }else {
  1065. Alert alert = new Alert(AlertType.ERROR);
  1066. alert.setHeaderText(null);
  1067. alert.setContentText("Please enter proper values!.");
  1068. alert.showAndWait();
  1069.  
  1070. editWeightText.clear();
  1071. editHeightText.clear();
  1072. editPhoneNumberText.clear();
  1073.  
  1074. }
  1075. refreshTable();
  1076.  
  1077. }catch(Exception exc) {
  1078. exc.printStackTrace();
  1079. }
  1080.  
  1081. });
  1082.  
  1083. editStage.setScene(new Scene(editPane,500,500));
  1084. editStage.show();
  1085.  
  1086. });
  1087. final VBox vbox = new VBox();
  1088. vbox.setSpacing(5);
  1089. vbox.setPadding(new Insets(10, 0, 0, 10));
  1090. back.setTextFill(Color.WHITE);
  1091. back.setStyle("-fx-background-color: Black");
  1092. notReady.setTextFill(Color.WHITE);
  1093. notReady.setStyle("-fx-background-color: Black");
  1094. vbox.getChildren().addAll(label, table, back, notReady, delete,edit);
  1095.  
  1096. ((Group) scene.getRoot()).getChildren().addAll(vbox);
  1097.  
  1098. fifthStage.setScene(scene);
  1099. fifthStage.show();
  1100. readyed.stop();
  1101. tertiaryStage.close();
  1102. });
  1103. AddPet.setOnAction(e7->{
  1104. tertiaryStage.close();
  1105. readyed.stop();
  1106. secondaryStage.show();
  1107. // userInputSpeak.play();
  1108. nameText.setText(dog.getName());
  1109. breedChoice.setValue(dog.getBreed());
  1110. genderChoice.setValue(dog.getGender());;
  1111. weightText.setText(String.valueOf(dog.getWeight()));
  1112. heightText.setText(String.valueOf(dog.getHeight()));
  1113. furColorChoice.setValue(dog.getFurColor());
  1114. datePicker.setValue(dog.getBirthday());
  1115. neutorSpayChoice.setValue(String.valueOf(dog.getNeuterSpay()));;
  1116. microchippedChoice.setValue(String.valueOf(dog.getMicrochip()));;
  1117. phoneNumberText.setText(dog.getPhoneNumber());
  1118. providerChoice.setValue(dog.getProvider());
  1119. });
  1120. ready.setTextFill(Color.WHITE);
  1121. ready.setStyle("-fx-background-color: Black");
  1122. viewInfor.setTextFill(Color.WHITE);
  1123. viewInfor.setStyle("-fx-background-color: Black");
  1124. AddPet.setTextFill(Color.WHITE);
  1125. AddPet.setStyle("-fx-background-color: Black");
  1126. gridPane.add(ready, 0, 2);
  1127. // gridPane.add(notReady, 0, 3);
  1128. gridPane.add(viewInfor, 0, 3);
  1129. gridPane.add(AddPet, 0, 4);
  1130.  
  1131. tertiaryStage.setScene(new Scene(gridPane,550,300));
  1132. tertiaryStage.show();
  1133. }
  1134. });
  1135.  
  1136.  
  1137. viewDatabase.setStyle("-fx-background-color: Black");
  1138. viewDatabase.setTextFill(Color.WHITE);
  1139. viewDatabase.setOnAction(event1 ->{
  1140. data.clear();
  1141. userInputSpeak.stop();
  1142. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  1143. String username = "cs3220stu55";
  1144. String password = "zWpa0NxR";
  1145.  
  1146. ObservableList<Dog> data = FXCollections.observableArrayList();
  1147.  
  1148.  
  1149. try {
  1150. Connection c = DriverManager
  1151. .getConnection( url, username, password );
  1152. Statement stmt = c.createStatement();
  1153.  
  1154. ResultSet rs = stmt.executeQuery( "select * from pet" );
  1155.  
  1156. while( rs.next() )
  1157. {
  1158. LocalDate today = rs.getDate("birthday").toLocalDate();
  1159. LocalDate tomorrow = today.plusDays(1);
  1160. data.add(new Dog(rs.getString("name"),rs.getString("breed"),
  1161. rs.getString("gender"),rs.getString("furColor"),rs.getInt("weight"),rs.getInt("height"),
  1162. tomorrow,rs.getBoolean("neutorSpay"),rs.getBoolean("microchipped"),rs.getString("phoneNumber"),rs.getString("provider")));
  1163.  
  1164. }
  1165.  
  1166. c.close();
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172. } catch (Exception exception) {
  1173. exception.printStackTrace();
  1174. //System.out.println("Error on Building Data");
  1175. }
  1176. table1.getColumns().clear();
  1177.  
  1178.  
  1179. Stage sixthStage = new Stage();
  1180.  
  1181. Scene sceneSix = new Scene(new Group());
  1182.  
  1183. final Label label1 = new Label("Dog Information");
  1184. label1.setFont(new Font("Arial", 20));
  1185.  
  1186. table1.setEditable(true);
  1187.  
  1188. TableColumn NameCol = new TableColumn("name");
  1189. NameCol.setMaxWidth(100);
  1190. NameCol.setCellValueFactory(
  1191. new PropertyValueFactory<Dog, String>("name"));
  1192.  
  1193. TableColumn breedCol = new TableColumn("breed");
  1194. breedCol.setMaxWidth(200);
  1195. breedCol.setCellValueFactory(
  1196. new PropertyValueFactory<Dog, String>("breed"));
  1197.  
  1198. TableColumn genderCol = new TableColumn("gender");
  1199. genderCol.setMaxWidth(100);
  1200. genderCol.setCellValueFactory(
  1201. new PropertyValueFactory<Dog, String>("gender"));
  1202.  
  1203. TableColumn furColorCol = new TableColumn("furColor");
  1204. furColorCol.setMaxWidth(200);
  1205. furColorCol.setCellValueFactory(
  1206. new PropertyValueFactory<Dog, String>("furColor"));
  1207.  
  1208. TableColumn weightCol = new TableColumn("weight(in lbs)");
  1209. weightCol.setMaxWidth(100);
  1210. weightCol.setCellValueFactory(
  1211. new PropertyValueFactory<Dog, String>("weight"));
  1212.  
  1213. TableColumn heightCol = new TableColumn("height(in inches)");
  1214. heightCol.setMaxWidth(150);
  1215. heightCol.setCellValueFactory(
  1216. new PropertyValueFactory<Dog, String>("height"));
  1217.  
  1218. TableColumn birthdayCol = new TableColumn("birthday");
  1219. birthdayCol.setMaxWidth(100);
  1220. birthdayCol.setCellValueFactory(
  1221. new PropertyValueFactory<Dog, String>("birthday"));
  1222.  
  1223. TableColumn spayCol = new TableColumn("neuterSpay");
  1224. spayCol.setMaxWidth(100);
  1225. spayCol.setCellValueFactory(
  1226. new PropertyValueFactory<Dog, String>("neuterSpay"));
  1227.  
  1228. TableColumn microchippedCol = new TableColumn("microchip");
  1229. microchippedCol.setMaxWidth(100);
  1230. microchippedCol.setCellValueFactory(
  1231. new PropertyValueFactory<Dog, String>("microchip"));
  1232.  
  1233. TableColumn phoneNumberCol = new TableColumn("phone number");
  1234. phoneNumberCol.setMaxWidth(100);
  1235. phoneNumberCol.setCellValueFactory(
  1236. new PropertyValueFactory<Dog, String>("phoneNumber"));
  1237.  
  1238. TableColumn providerCol = new TableColumn("provider");
  1239. providerCol.setMaxWidth(100);
  1240. providerCol.setCellValueFactory(
  1241. new PropertyValueFactory<Dog, String>("provider"));
  1242.  
  1243.  
  1244. // ObservableList<Dog> list = FXCollections.observableArrayList(dogInformation);
  1245. ObservableList<Dog> list = removeDuplicates(data);
  1246.  
  1247. table1.setItems(list);
  1248. table1.getColumns().addAll(NameCol, breedCol, genderCol,furColorCol, weightCol,
  1249. heightCol, birthdayCol, spayCol, microchippedCol,phoneNumberCol,providerCol);
  1250.  
  1251. Button backToInput = new Button("Back");
  1252. backToInput.setStyle("-fx-background-color: Black");
  1253. backToInput.setTextFill(Color.WHITE);
  1254. backToInput.setOnAction(e8->{
  1255. sixthStage.close();
  1256. // readyed.play();
  1257. secondaryStage.show();
  1258. });
  1259. Button delete = new Button("Delete This");
  1260. delete.setStyle("-fx-background-color: black");
  1261. delete.setTextFill(Color.WHITE);
  1262. delete.setOnAction(ee->{
  1263. Dog selectedItem = table1.getSelectionModel().getSelectedItem();
  1264. table1.getItems().remove(selectedItem);
  1265. Connection conn = null;
  1266. try{
  1267. Class.forName("com.mysql.cj.jdbc.Driver");
  1268.  
  1269. conn = DriverManager.getConnection(url, username, password);
  1270.  
  1271. String sql = "DELETE FROM pet where name = ?";
  1272.  
  1273. PreparedStatement preparedStmt = conn.prepareStatement(sql);
  1274. preparedStmt.setString(1,selectedItem.getName());
  1275. preparedStmt.execute();
  1276. conn.close();
  1277.  
  1278. }catch(Exception exc) {
  1279. exc.printStackTrace();
  1280. }
  1281. });
  1282. Button clearInfor = new Button("Clear");
  1283. clearInfor.setStyle("-fx-background-color: Black");
  1284. clearInfor.setTextFill(Color.WHITE);
  1285. clearInfor.setOnAction(event2->{
  1286.  
  1287. ObservableList<Dog> items = table1.getItems();
  1288.  
  1289. if(!items.isEmpty()) {
  1290. Connection conn = null;
  1291. Statement stmte = null;
  1292. try{
  1293. Class.forName("com.mysql.cj.jdbc.Driver");
  1294.  
  1295. conn = DriverManager.getConnection(url, username, password);
  1296.  
  1297. stmte = conn.createStatement();
  1298.  
  1299. String sql = "DELETE FROM pet;";
  1300.  
  1301. stmte.executeUpdate(sql);
  1302.  
  1303. Alert alert = new Alert(AlertType.INFORMATION);
  1304. alert.setTitle(null);
  1305. alert.setContentText("Deleted!");
  1306. alert.showAndWait();
  1307.  
  1308. sixthStage.close();
  1309. secondaryStage.show();
  1310. //userInputSpeak.play();
  1311.  
  1312. }catch(Exception exc) {
  1313. exc.printStackTrace();
  1314. }
  1315. }else {
  1316. Alert alert = new Alert(AlertType.ERROR);
  1317. alert.setTitle("Error!");
  1318. alert.setContentText("Database is empty, nothing to delete!");
  1319. alert.showAndWait();
  1320. }
  1321. });
  1322.  
  1323. VBox box = new VBox();
  1324. box.setPadding(new Insets(10));
  1325.  
  1326. box.getChildren().addAll(label1,table1,backToInput,clearInfor, delete);
  1327. box.setSpacing(5);
  1328. ((Group) sceneSix.getRoot()).getChildren().addAll(box);
  1329. sixthStage.setScene(sceneSix);
  1330. sixthStage.show();
  1331.  
  1332. });
  1333. save.setTextFill(Color.WHITE);
  1334. save.setStyle("-fx-background-color: Black");
  1335. proceed.setTextFill(Color.WHITE);
  1336. proceed.setStyle("-fx-background-color: Black");
  1337. backToPrimary.setTextFill(Color.WHITE);
  1338. backToPrimary.setStyle("-fx-background-color: Black");
  1339. pane.add(proceed, 1, 12);
  1340. pane.add(save, 0, 12);
  1341. pane.add(backToPrimary, 0, 13);
  1342. pane.add(viewDatabase, 1, 13);
  1343. //pane.add(viewInfor, 0, 12);
  1344. secondaryStage.setScene(new Scene(pane,500,500));
  1345. secondaryStage.show();
  1346.  
  1347. });
  1348.  
  1349. Image image = new Image("Logo.png");
  1350. ImageView imageView = new ImageView();
  1351. imageView.setImage(image);
  1352. imageView.setFitHeight(200);
  1353. imageView.setFitWidth(250);
  1354. // backToJavaFXPane.setTextFill(Color.WHITE);
  1355. // backToJavaFXPane.setStyle("-fx-background-color: Black");
  1356. border.setCenter(imageView);
  1357. // border.setLeft(backToJavaFXPane);
  1358. border.setRight(button);
  1359. // BorderPane.setAlignment(backToJavaFXPane, Pos.BOTTOM_LEFT);
  1360. BorderPane.setAlignment(button, Pos.BOTTOM_RIGHT);
  1361.  
  1362. primaryStage.setScene(new Scene(border,500,500));
  1363. primaryStage.show();
  1364. final URL resource = getClass().getResource("speak.mp3");
  1365. final Media media = new Media(resource.toString());
  1366. final URL resource1 = getClass().getResource("welcomeBGM.mp3");
  1367. final Media media1 = new Media(resource1.toString());
  1368. welcomeBGM = new MediaPlayer(media1);
  1369. welcomeBGM.setVolume(0.1);
  1370. welcomeBGM.setOnEndOfMedia(new Runnable() {
  1371. public void run() {
  1372. welcomeBGM.seek(Duration.ZERO);
  1373. }
  1374. });
  1375. welcomeBGM.play();
  1376. welcomeMessage = new MediaPlayer(media);
  1377. welcomeMessage.play();
  1378. welcomeMessage.setVolume(0.1);
  1379. }
  1380. public static void main(String[] args) {
  1381. launch(args);
  1382. }
  1383. public ArrayList<Dog> getList() {
  1384.  
  1385. return dogInformation;
  1386. }
  1387. boolean convertToBoolean(String value) {
  1388. boolean returnValue = false;
  1389. if ("yes".equalsIgnoreCase(value) ||
  1390. "true".equalsIgnoreCase(value))
  1391. returnValue = true;
  1392. return returnValue;
  1393. }
  1394. static ObservableList<Dog> removeDuplicates(ObservableList<Dog> list) {
  1395.  
  1396. // Store unique items in result.
  1397. ObservableList<Dog> result = FXCollections.observableArrayList();
  1398.  
  1399. // Record encountered Strings in HashSet.
  1400. HashSet<Dog> set = new HashSet<>();
  1401.  
  1402. // Loop over argument list.
  1403. for (Dog item : list) {
  1404.  
  1405. // If String is not in set, add it to the list and the set.
  1406. if (!set.contains(item)) {
  1407. result.add(item);
  1408. set.add(item);
  1409. }
  1410. }
  1411. return result;
  1412. }
  1413. //validating whether an input is numeric
  1414. public static boolean isValidHeight(String input)
  1415. {
  1416. double num;
  1417.  
  1418.  
  1419. try
  1420. {
  1421. num = Double.parseDouble(input);
  1422. if(num<0)
  1423. return false;
  1424. if(num>45)
  1425. return false;
  1426. }
  1427. catch(NumberFormatException ex)
  1428. {
  1429. return false;
  1430. }
  1431. return true;
  1432.  
  1433. }
  1434. public static boolean isValidWeight(String input) {
  1435. double num;
  1436. try
  1437. {
  1438. num = Double.parseDouble(input);
  1439. if(num<0)
  1440. return false;
  1441. if(num>343)
  1442. return false;
  1443. }
  1444. catch(NumberFormatException ex)
  1445. {
  1446. return false;
  1447. }
  1448. return true;
  1449. }
  1450. public void refreshTable() {
  1451. data.clear();
  1452. String url = "jdbc:mysql://localhost/cs3220stu55?useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";
  1453. String username = "cs3220stu55";
  1454. String password = "zWpa0NxR";
  1455.  
  1456. try {
  1457. Connection c = DriverManager
  1458. .getConnection( url, username, password );
  1459. Statement stmt = c.createStatement();
  1460.  
  1461. ResultSet rs = stmt.executeQuery( "select * from pet" );
  1462.  
  1463. while( rs.next() )
  1464. {
  1465. LocalDate today = rs.getDate("birthday").toLocalDate();
  1466. LocalDate tomorrow = today.plusDays(1);
  1467. data.add(new Dog(rs.getString("name"),rs.getString("breed"),
  1468. rs.getString("gender"),rs.getString("furColor"),rs.getInt("weight"),rs.getInt("height"),
  1469. tomorrow,rs.getBoolean("neutorSpay"),rs.getBoolean("microchipped"),rs.getString("phoneNumber"),rs.getString("provider")));
  1470.  
  1471. }
  1472. c.close();
  1473. } catch (Exception exception) {
  1474. exception.printStackTrace();
  1475. //System.out.println("Error on Building Data");
  1476. }
  1477.  
  1478. table.setItems(data);
  1479.  
  1480. }
  1481. private static boolean isValidPhoneNumber(String phoneNo) {
  1482. //validate phone numbers of format "1234567890"
  1483. if (phoneNo.matches("\\d{10}")) return true;
  1484. // //validating phone number with -, . or spaces
  1485. // else if(phoneNo.matches("\\d{3}[-\\.\\s]\\d{3}[-\\.\\s]\\d{4}")) return true;
  1486. // //validating phone number with extension length from 3 to 5
  1487. // else if(phoneNo.matches("\\d{3}-\\d{3}-\\d{4}\\s(x|(ext))\\d{3,5}")) return true;
  1488. // //validating phone number where area code is in braces ()
  1489. // else if(phoneNo.matches("\\(\\d{3}\\)-\\d{3}-\\d{4}")) return true;
  1490. // //return false if nothing matches the input
  1491. else return false;
  1492.  
  1493. }
  1494.  
  1495.  
  1496. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement