diff --git a/data/bookSceneAssets/Status_icons/borrowButton.png b/data/bookSceneAssets/Status_icons/borrowButton.png new file mode 100644 index 0000000..888e23b Binary files /dev/null and b/data/bookSceneAssets/Status_icons/borrowButton.png differ diff --git a/data/covers/1.jpg b/data/covers/1.jpg new file mode 100644 index 0000000..6eea682 Binary files /dev/null and b/data/covers/1.jpg differ diff --git a/data/covers/11.jpg b/data/covers/11.jpg index 5e7bb32..f67ac1a 100644 Binary files a/data/covers/11.jpg and b/data/covers/11.jpg differ diff --git a/data/covers/12.jpg b/data/covers/12.jpg new file mode 100644 index 0000000..1818948 Binary files /dev/null and b/data/covers/12.jpg differ diff --git a/data/covers/2.jpg b/data/covers/2.jpg new file mode 100644 index 0000000..1818948 Binary files /dev/null and b/data/covers/2.jpg differ diff --git a/data/covers/3.jpg b/data/covers/3.jpg new file mode 100644 index 0000000..7ea1ef8 Binary files /dev/null and b/data/covers/3.jpg differ diff --git a/data/covers/4.jpg b/data/covers/4.jpg new file mode 100644 index 0000000..ec45449 Binary files /dev/null and b/data/covers/4.jpg differ diff --git a/src/main/java/com/asu/librarysystem/AdminController.java b/src/main/java/com/asu/librarysystem/AdminController.java index a4c3e80..c78b162 100644 --- a/src/main/java/com/asu/librarysystem/AdminController.java +++ b/src/main/java/com/asu/librarysystem/AdminController.java @@ -19,76 +19,54 @@ public class AdminController { private Parent adminViewNodes; @FXML - public void switchToManagingBooks(ActionEvent event)throws IOException { - - try { - adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("CRUDBooks.fxml")); - adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); - adminScene =new Scene(adminViewNodes); - adminStage.setScene(adminScene); - adminStage.show(); - - }catch (Exception e){ - System.out.println(e.getMessage()); - } - + public void switchToManagingBooks(ActionEvent event) throws IOException { + adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("CRUDBooks.fxml")); + adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + adminScene =new Scene(adminViewNodes); + adminStage.setScene(adminScene); + adminStage.show(); } @FXML - public void switchToManagingBorrowers(ActionEvent event)throws IOException { - - try { - adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("ManagingBorrowers.fxml")); - adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); - adminScene =new Scene(adminViewNodes); - adminStage.setScene(adminScene); - adminStage.show(); - - }catch (Exception e){ - System.out.println(e.getMessage()); - } - + public void switchToManagingBorrowers(ActionEvent event) throws IOException { + adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("CRUD_Borrower-view.fxml")); + adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + adminScene =new Scene(adminViewNodes); + adminStage.setScene(adminScene); + adminStage.show(); } @FXML - public void switchToManagingProfile(ActionEvent event)throws IOException { - - try { - adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("ManagingAdminProfile.fxml")); - adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); - adminScene =new Scene(adminViewNodes); - adminStage.setScene(adminScene); - adminStage.show(); - - }catch (Exception e){ - System.out.println(e.getMessage()); - } + public void switchToManagingProfile(ActionEvent event) throws IOException { + adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("managing-profile-view.fxml")); + adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + adminScene =new Scene(adminViewNodes); + adminStage.setScene(adminScene); + adminStage.show(); } @FXML - public void switchToManagingDiscounts(ActionEvent event)throws IOException { - try { - adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("ManagingDiscounts.fxml")); - adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); - adminScene =new Scene(adminViewNodes); - adminStage.setScene(adminScene); - adminStage.show(); - - }catch (Exception e){ - System.out.println(e.getMessage()); - } - + public void switchToManagingDiscounts(ActionEvent event) throws IOException { + adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("discounts-view.fxml")); + adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + adminScene =new Scene(adminViewNodes); + adminStage.setScene(adminScene); + adminStage.show(); } @FXML - public void switchToManagingOrderHistory(ActionEvent event)throws IOException { - try { - adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("OrderHistory.fxml")); - adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); - adminScene =new Scene(adminViewNodes); - adminStage.setScene(adminScene); - adminStage.show(); - - }catch (Exception e){ - System.out.println(e.getMessage()); - } + public void switchToManagingOrderHistory(ActionEvent event) throws IOException { + adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("orders-for-admin-view.fxml")); + adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + adminScene =new Scene(adminViewNodes); + adminStage.setScene(adminScene); + adminStage.show(); } + @FXML + void logout(ActionEvent event) throws IOException { + Library.logOut(); + adminViewNodes= FXMLLoader.load(MainApplication.class.getResource("Login.fxml")); + adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + adminScene =new Scene(adminViewNodes); + adminStage.setScene(adminScene); + adminStage.show(); + } } diff --git a/src/main/java/com/asu/librarysystem/AllBooksController.java b/src/main/java/com/asu/librarysystem/AllBooksController.java index d86705b..f2613c1 100644 --- a/src/main/java/com/asu/librarysystem/AllBooksController.java +++ b/src/main/java/com/asu/librarysystem/AllBooksController.java @@ -47,7 +47,7 @@ public void backButton(ActionEvent event){ Account account = Library.getActiveAccount(); if (account instanceof Customer) { Customer customer =(Customer) account; - FXMLLoader loader = new FXMLLoader(getClass().getResource("name of.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("CustomerMain.fxml")); Parent root = loader.load(); // clsssName objName = loader.getController(); // objName.method; @@ -58,7 +58,7 @@ public void backButton(ActionEvent event){ } else if(account instanceof Borrower){ Borrower borrower =(Borrower) account; - FXMLLoader loader = new FXMLLoader(getClass().getResource("name.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("borrower-main-view.fxml")); Parent root = loader.load(); // clsssName objName = loader.getController(); // objName.method; diff --git a/src/main/java/com/asu/librarysystem/Book.java b/src/main/java/com/asu/librarysystem/Book.java index 0dda043..f9a3215 100644 --- a/src/main/java/com/asu/librarysystem/Book.java +++ b/src/main/java/com/asu/librarysystem/Book.java @@ -14,14 +14,15 @@ public class Book { private boolean status; private int price; private int quantity; - private String descreption; + private String description; private File cover; private ArrayList categories; + public Book(String title, String author, int publicationYear, boolean status, int price, int quantity - , String descreption, String coverPath, Category[] categories) { + , String description, String coverPath, Category[] categories) { this.id = ++idCounter; this.title = title; this.author = author; @@ -29,7 +30,7 @@ public Book(String title, String author, int publicationYear, boolean status, in this.status = status; this.price = price; this.quantity = quantity; - this.descreption = descreption; + this.description = description; setCover(coverPath); @@ -86,7 +87,11 @@ public void setPrice(int price) { public boolean isAvailable() { return quantity > 0; } - public String getDescreption() { return descreption; } + public String getDescription() { return description; } + public void setDescription(String description) { + this.description = description; + } + public void setCover(String path) { File newCover = new File(path); @@ -108,9 +113,12 @@ public String getCoverPath() { return cover.getAbsolutePath(); } - public ArrayList getCategories(){ + public ArrayList getCategories() { return this.categories; } + public void setCategories(ArrayList categories) { + this.categories = categories; + } } diff --git a/src/main/java/com/asu/librarysystem/BookController.java b/src/main/java/com/asu/librarysystem/BookController.java index 0be0383..b046139 100644 --- a/src/main/java/com/asu/librarysystem/BookController.java +++ b/src/main/java/com/asu/librarysystem/BookController.java @@ -14,6 +14,7 @@ import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.*; +import javafx.scene.control.Alert.AlertType; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.KeyEvent; @@ -69,6 +70,9 @@ public void initialize(URL url, ResourceBundle resourceBundle) { notifyMe.setOnMouseClicked(mouseEvent -> { Notifications notifications = new Notifications(); notifications.reservationConfirmation(currentBook); + Alert alert = new Alert(AlertType.INFORMATION); + alert.setContentText("You will be notified when book is available."); + alert.show(); }); } @@ -78,7 +82,7 @@ public void setScene(Book book) throws IOException { setCover(book.getCoverPath()); setProperties(book.getTitle(), book.getAuthor(), Integer.toString(book.getPublicationYear()) - , book.getDescreption(), book.getPrice(), book.getQuantity()); + , book.getDescription(), book.getPrice(), book.getQuantity()); Library.getReviewHandler().addReview(1, book.getId(), 3, "I don't love this book"); ArrayList ratings = Library.getReviewHandler().getBookRatings(book.getId()); @@ -163,7 +167,13 @@ private void setProperties(String name, String author, String releaseDate,String if (quantity > 0){ try { - InputStream imageLocation = new FileInputStream("data/bookSceneAssets/Status_icons/addToCartButton.png"); + InputStream imageLocation; + if (Library.getActiveAccount() instanceof Customer) { + imageLocation = new FileInputStream("data/bookSceneAssets/Status_icons/addToCartButton.png"); + } else { + imageLocation = new FileInputStream("data/bookSceneAssets/Status_icons/borrowButton.png"); + } + Image available = new Image(imageLocation); statusImage.setImage(available); @@ -182,10 +192,11 @@ private void setProperties(String name, String author, String releaseDate,String statusImage.setImage(outOfStock); statusImage.setCursor(Cursor.DEFAULT); statusImage.setOnMouseClicked(null); - - InputStream notifyMeImage = new FileInputStream("data/bookSceneAssets/Status_icons/notifyMeButton.png"); - Image notifyMe = new Image(notifyMeImage); - this.notifyMe.setImage(notifyMe); + if (Library.getActiveAccount() instanceof Borrower) { + InputStream notifyMeImage = new FileInputStream("data/bookSceneAssets/Status_icons/notifyMeButton.png"); + Image notifyMe = new Image(notifyMeImage); + this.notifyMe.setImage(notifyMe); + } } catch (FileNotFoundException e) { @@ -195,7 +206,18 @@ private void setProperties(String name, String author, String releaseDate,String } public void addToCart(MouseEvent e) { - System.out.println("Hello"); + if (Library.getActiveAccount() instanceof Customer) { + Library.getShoppingCart().addBook(currentBook.getId()); + Alert alert = new Alert(AlertType.INFORMATION); + alert.setContentText("Added to Shopping Cart."); + alert.show(); + } else { + Borrower account = (Borrower)Library.getActiveAccount(); + account.addTransaction(currentBook); + Alert alert = new Alert(AlertType.INFORMATION); + alert.setContentText("You have borrowed this book successfully!\nEnjoy Reading."); + alert.show(); + } } private String formatPrice(int price){ diff --git a/src/main/java/com/asu/librarysystem/SideBarController.java b/src/main/java/com/asu/librarysystem/BorrowerMainController.java similarity index 81% rename from src/main/java/com/asu/librarysystem/SideBarController.java rename to src/main/java/com/asu/librarysystem/BorrowerMainController.java index f88cc67..ea0db4b 100644 --- a/src/main/java/com/asu/librarysystem/SideBarController.java +++ b/src/main/java/com/asu/librarysystem/BorrowerMainController.java @@ -30,7 +30,7 @@ import java.util.Objects; import java.util.ResourceBundle; -public class SideBarController implements Initializable { +public class BorrowerMainController implements Initializable { private Stage primaryStage; private Scene scene; @@ -71,9 +71,9 @@ public class SideBarController implements Initializable { private Label Transactions; public void reservationConfirmationNotification() { - for (int i = 0; i < BorrowerController.getCurrentBorrower().getReservedBooks().size(); i++) + for (int i = 0; i < TransactionsForBorrowersController.getCurrentBorrower().getReservedBooks().size(); i++) { - Label label = new Label("You Have Successfully reserved \"" + BorrowerController.getCurrentBorrower().getReservedBooks().get(i).getTitle() + "\""); + Label label = new Label("You Have Successfully reserved \"" + TransactionsForBorrowersController.getCurrentBorrower().getReservedBooks().get(i).getTitle() + "\""); label.setFont(Font.font(30)); label.setTextFill(Color.WHITE); label.setPrefWidth(1280); @@ -89,8 +89,8 @@ public void availableForPickupNotification() { Notifications notifications = new Notifications(); if (notifications.availableForPickup()) { - for (int i = 0; i < BorrowerController.getCurrentBorrower().getReservedBooks().size(); i++) { - Label label = new Label("\"" + BorrowerController.getCurrentBorrower().getReservedBooks().get(i).getTitle() + "\"" + " is Available for Pickup"); + for (int i = 0; i < TransactionsForBorrowersController.getCurrentBorrower().getReservedBooks().size(); i++) { + Label label = new Label("\"" + TransactionsForBorrowersController.getCurrentBorrower().getReservedBooks().get(i).getTitle() + "\"" + " is Available for Pickup"); label.setFont(Font.font(30)); label.setTextFill(Color.WHITE); label.setPrefWidth(1280); @@ -121,7 +121,7 @@ public void CheckNotifications() } for (int i = 0; i < Notifications.booksDueDateIn3Days().size(); i++) { - Label label = new Label("Your Borrowed Book \"" + BorrowerController.getCurrentBorrower().getBorrowerTransactions().get(Notifications.booksDueDateIn3Days().get(i)).getBookName() +"\" is due in " + ChronoUnit.DAYS.between(LocalDate.now(),BorrowerController.getCurrentBorrower().getBorrowerTransactions().get(Notifications.booksDueDateIn3Days().get(i)).getReturnDate())+" days"); + Label label = new Label("Your Borrowed Book \"" + TransactionsForBorrowersController.getCurrentBorrower().getBorrowerTransactions().get(Notifications.booksDueDateIn3Days().get(i)).getBookName() +"\" is due in " + ChronoUnit.DAYS.between(LocalDate.now(),TransactionsForBorrowersController.getCurrentBorrower().getBorrowerTransactions().get(Notifications.booksDueDateIn3Days().get(i)).getReturnDate())+" days"); label.setFont(Font.font(30)); label.setTextFill(Color.WHITE); label.setPrefWidth(1280); @@ -134,7 +134,7 @@ public void CheckNotifications() } @Override public void initialize(URL url, ResourceBundle resourceBundle) { - Welcome.setText("Welcome, "+BorrowerController.getCurrentBorrower().getUserName()); + Welcome.setText("Welcome, "+TransactionsForBorrowersController.getCurrentBorrower().getUserName()); Slider.setTranslateX(-278); MiddlePane.setTranslateX(-278); CheckNotifications(); @@ -188,7 +188,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { }); Transactions.setOnMouseClicked(mouseEvent -> { try { - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("BorrowerTransactions.fxml"))); + Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("borrower-transactions-view.fxml"))); primaryStage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow(); scene = new Scene(root); primaryStage.setScene(scene); @@ -200,7 +200,11 @@ public void initialize(URL url, ResourceBundle resourceBundle) { }); MyBooks.setOnMouseClicked(mouseEvent -> { try { - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("BorrowerTransactions.fxml"))); + Parent root; + FXMLLoader loader = new FXMLLoader(getClass().getResource("My-Books.fxml")); + root = loader.load(); + MyBooksController sceneController = loader.getController(); + sceneController.startMyBooksController(); primaryStage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow(); scene = new Scene(root); primaryStage.setScene(scene); @@ -212,7 +216,11 @@ public void initialize(URL url, ResourceBundle resourceBundle) { }); Shopping.setOnMouseClicked(mouseEvent -> { try { - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("BorrowerTransactions.fxml"))); + Parent root; + FXMLLoader loader = new FXMLLoader(getClass().getResource("All-Books.fxml")); + root = loader.load(); + AllBooksController sceneController = loader.getController(); + sceneController.startAllBooksController(); primaryStage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow(); scene = new Scene(root); primaryStage.setScene(scene); @@ -224,7 +232,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { }); ManageProfile.setOnMouseClicked(mouseEvent -> { try { - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("BorrowerTransactions.fxml"))); + Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("managing-profile-view.fxml"))); primaryStage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow(); scene = new Scene(root); primaryStage.setScene(scene); @@ -236,7 +244,8 @@ public void initialize(URL url, ResourceBundle resourceBundle) { }); Logout.setOnMouseClicked(mouseEvent -> { try { - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("BorrowerTransactions.fxml"))); + Library.logOut(); + Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("Login.fxml"))); primaryStage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow(); scene = new Scene(root); primaryStage.setScene(scene); diff --git a/src/main/java/com/asu/librarysystem/CRUDBooks.java b/src/main/java/com/asu/librarysystem/CRUDBooks.java index 78ec31f..9896f5a 100644 --- a/src/main/java/com/asu/librarysystem/CRUDBooks.java +++ b/src/main/java/com/asu/librarysystem/CRUDBooks.java @@ -13,8 +13,14 @@ import javafx.scene.image.ImageView; import javafx.scene.control.cell.PropertyValueFactory; import javafx.stage.Stage; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.ResourceBundle; import java.io.File; @@ -50,13 +56,29 @@ public class CRUDBooks implements Initializable { @FXML private TextField quantityField; @FXML - private CheckBox statusCheckBox; - @FXML private ImageView coverImageView; @FXML private Image coverImage ; @FXML private ObservableList bookList = FXCollections.observableArrayList(); + @FXML + private TextField categoriesField; + @FXML + private TextArea descriptionBox;; + + @FXML + private CheckBox dramaBox; + + @FXML + private CheckBox horrorBox; + + @FXML + private CheckBox novelBox; + @FXML + private CheckBox selfDevBox; + @FXML + private CheckBox adventureBox; + @Override public void initialize(URL url, ResourceBundle resourceBundle) { @@ -66,6 +88,12 @@ public void initialize(URL url, ResourceBundle resourceBundle) { priceColumn.setCellValueFactory(new PropertyValueFactory<>("price")); quantityColumn.setCellValueFactory(new PropertyValueFactory<>("quantity")); + ArrayList books = Library.getBooks(); + + for (var book : books) { + bookList.add(book); + } + booksTable.setItems(bookList); } @@ -75,9 +103,38 @@ private void clearFields() { publicationYearField.clear(); priceField.clear(); quantityField.clear(); - statusCheckBox.setSelected(false); coverPathField.clear(); + descriptionBox.clear(); + adventureBox.setSelected(false); + dramaBox.setSelected(false); + horrorBox.setSelected(false); + novelBox.setSelected(false); + selfDevBox.setSelected(false); + } + + private Category[] checkedCategories() { + ArrayList checkedCategories = new ArrayList<>(); + + if (dramaBox.isSelected()) { + checkedCategories.add(Category.DRAMA); + } + if (adventureBox.isSelected()) { + checkedCategories.add(Category.ADVENTURE); + } + if (selfDevBox.isSelected()) { + checkedCategories.add(Category.SELFDEVELOPMENT); + } + if (horrorBox.isSelected()) { + checkedCategories.add(Category.HORROR); + } + if (novelBox.isSelected()) { + checkedCategories.add(Category.NOVEL); + } + Category[] cat = new Category[checkedCategories.size()]; + cat = checkedCategories.toArray(cat); + return cat; } + @FXML private void AddBook() { try { @@ -87,17 +144,25 @@ private void AddBook() { int price = Integer.parseInt(priceField.getText()); int quantity = Integer.parseInt(quantityField.getText()); String coverPath = coverPathField.getText(); - - coverImage = new Image(coverPath); - coverImageView.setImage(coverImage); - - Book newBook = new Book(title, author, year, true, price, quantity, - "",coverPath, new Category[]{Category.HORROR}); + String description = descriptionBox.getText(); + + Book newBook = new Book(title, author, year, true, price, quantity, + description,coverPath, checkedCategories()); + InputStream fileLocation; + try { + fileLocation = new FileInputStream(coverPathField.getText()); + coverImage = new Image(fileLocation); + coverImageView.setImage(coverImage); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + bookList.add(newBook); + Library.addBook(newBook); clearFields(); - + booksTable.refresh(); }catch (Exception addingBookException){ System.out.println(addingBookException.getCause()); } @@ -117,11 +182,38 @@ private void showBookDetails() { publicationYearField.setText(String.valueOf(selectedBook.getPublicationYear())); priceField.setText(String.valueOf(selectedBook.getPrice())); quantityField.setText(String.valueOf(selectedBook.getQuantity())); - statusCheckBox.setSelected(selectedBook.isAvailable()); coverPathField.setText(selectedBook.getCoverPath()); + descriptionBox.setText(selectedBook.getDescription()); + + + adventureBox.setSelected(false); + dramaBox.setSelected(false); + horrorBox.setSelected(false); + novelBox.setSelected(false); + selfDevBox.setSelected(false); + + for (Category cat : selectedBook.getCategories()) { + if (cat == Category.ADVENTURE) { + adventureBox.setSelected(true); + } else if (cat == Category.DRAMA) { + dramaBox.setSelected(true); + } else if (cat == Category.HORROR) { + horrorBox.setSelected(true); + } else if (cat == Category.NOVEL) { + novelBox.setSelected(true); + } else if (cat == Category.SELFDEVELOPMENT) { + selfDevBox.setSelected(true); + } + } - coverImage = new Image(coverPathField.getText()); - coverImageView.setImage(coverImage); + InputStream fileLocation; + try { + fileLocation = new FileInputStream(coverPathField.getText()); + coverImage = new Image(fileLocation); + coverImageView.setImage(coverImage); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } } } @FXML @@ -136,8 +228,18 @@ private void UpdateBook() { selectedBook.setPrice(Integer.parseInt(priceField.getText())); selectedBook.setQuantity(Integer.parseInt(quantityField.getText())); selectedBook.setCover(coverPathField.getText()); - coverImage = new Image(coverPathField.getText()); - coverImageView.setImage(coverImage); + selectedBook.setDescription(descriptionBox.getText()); + ArrayList al = new ArrayList(Arrays.asList(checkedCategories())); + selectedBook.setCategories(al); + + InputStream fileLocation; + try { + fileLocation = new FileInputStream(coverPathField.getText()); + coverImage = new Image(fileLocation); + coverImageView.setImage(coverImage); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } // Refresh TableView // I made a similar CRUD as a practice and Update wasn't working and I asked chatGPT it recommended this statement @@ -156,6 +258,7 @@ private void DeleteBook() { if (selectedBook != null) { bookList.remove(selectedBook); + Library.removeBook(selectedBook); clearFields(); } diff --git a/src/main/java/com/asu/librarysystem/CRUD_Borrower_Controller.java b/src/main/java/com/asu/librarysystem/CRUD_Borrower_Controller.java index d6b9a11..215b259 100644 --- a/src/main/java/com/asu/librarysystem/CRUD_Borrower_Controller.java +++ b/src/main/java/com/asu/librarysystem/CRUD_Borrower_Controller.java @@ -72,7 +72,7 @@ public void switch_To_Signup(ActionEvent event) throws IOException { public void switch_To_Main(ActionEvent event) throws IOException { - scene(event, "Update.fxml");//Admin Main fxml file + scene(event, "AdminMain.fxml");//Admin Main fxml file } public void switch_To_Delete_view(ActionEvent event) throws IOException { @@ -84,7 +84,7 @@ public void switch_To_Update_view(ActionEvent event) throws IOException { // return } - ObservableList List = FXCollections.observableArrayList(Library.borrowers); + ObservableList List = FXCollections.observableArrayList(Library.getBorrowers()); @Override public void initialize(URL url, ResourceBundle resourceBundle) { @@ -92,7 +92,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { borrowerName.setCellValueFactory(new PropertyValueFactory("userName")); borrowerNumberofBooks.setCellValueFactory(new PropertyValueFactory("noOfBooks")); borrowerPhoneNumber.setCellValueFactory(new PropertyValueFactory("phoneNumber")); - System.out.println(Library.borrowers); + //System.out.println(Library.borrowers); // List.addAll(Arrays.asList(Library.borrowers)); borrowersTable.setItems(List); } diff --git a/src/main/java/com/asu/librarysystem/CustomerController.java b/src/main/java/com/asu/librarysystem/CustomerController.java index 534b221..472bfdf 100644 --- a/src/main/java/com/asu/librarysystem/CustomerController.java +++ b/src/main/java/com/asu/librarysystem/CustomerController.java @@ -1,6 +1,7 @@ package com.asu.librarysystem; import javafx.event.ActionEvent; +import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; import javafx.scene.Parent; @@ -14,9 +15,12 @@ public class CustomerController { private Scene customerScene; private Parent customerViewNodes; - public void switchToShopping(ActionEvent event)throws IOException { + public void switchToShopping(ActionEvent event) throws IOException { try { - customerViewNodes= FXMLLoader.load(MainApplication.class.getResource("Shopping.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("All-Books.fxml")); + customerViewNodes = loader.load(); + AllBooksController sceneController = loader.getController(); + sceneController.startAllBooksController(); customerStage = (Stage)((Node)event.getSource()).getScene().getWindow(); customerScene =new Scene(customerViewNodes); customerStage.setScene(customerScene); @@ -28,7 +32,10 @@ public void switchToShopping(ActionEvent event)throws IOException { } public void switchToMyBooks(ActionEvent event)throws IOException { try { - customerViewNodes = FXMLLoader.load(MainApplication.class.getResource("MyBooks.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("My-Books.fxml")); + customerViewNodes = loader.load(); + MyBooksController sceneController = loader.getController(); + sceneController.startMyBooksController(); customerStage = (Stage) ((Node) event.getSource()).getScene().getWindow(); customerScene = new Scene(customerViewNodes); customerStage.setScene(customerScene); @@ -40,7 +47,7 @@ public void switchToMyBooks(ActionEvent event)throws IOException { } public void switchToManagingCustomerProfile(ActionEvent event)throws IOException { try { - customerViewNodes= FXMLLoader.load(MainApplication.class.getResource("ManagingCustomerProfile.fxml")); + customerViewNodes= FXMLLoader.load(MainApplication.class.getResource("managing-profile-view.fxml")); customerStage= (Stage)((Node)event.getSource()).getScene().getWindow(); customerScene =new Scene(customerViewNodes); customerStage.setScene(customerScene); @@ -50,5 +57,30 @@ public void switchToManagingCustomerProfile(ActionEvent event)throws IOException } } + @FXML + void switchToCart(ActionEvent event) { + try { + customerViewNodes= FXMLLoader.load(MainApplication.class.getResource("shopping-cart-view.fxml")); + customerStage= (Stage)((Node)event.getSource()).getScene().getWindow(); + customerScene =new Scene(customerViewNodes); + customerStage.setScene(customerScene); + customerStage.show(); + }catch (Exception switchingScenesException){ + System.out.println(switchingScenesException.getMessage()); + } + } + @FXML + void logout(ActionEvent event) { + try { + Library.logOut(); + Parent adminViewNodes = FXMLLoader.load(MainApplication.class.getResource("Login.fxml")); + Stage adminStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + Scene adminScene =new Scene(adminViewNodes); + adminStage.setScene(adminScene); + adminStage.show(); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/src/main/java/com/asu/librarysystem/DiscountsViewController.java b/src/main/java/com/asu/librarysystem/DiscountsViewController.java index 41c978a..8bf7b47 100644 --- a/src/main/java/com/asu/librarysystem/DiscountsViewController.java +++ b/src/main/java/com/asu/librarysystem/DiscountsViewController.java @@ -1,5 +1,6 @@ package com.asu.librarysystem; +import java.io.IOException; import java.net.URL; import java.util.ResourceBundle; import java.util.ArrayList; @@ -10,6 +11,9 @@ import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; +import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; @@ -68,8 +72,15 @@ public void add(ActionEvent event) { } } public void back(ActionEvent event) { - stage = (Stage)root.getScene().getWindow(); - stage.close(); + try { + Parent root = FXMLLoader.load(getClass().getResource("AdminMain.fxml")); + Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + Scene scene = new Scene(root); + primaryStage.setScene(scene); + primaryStage.show(); + } catch (IOException e) { + e.printStackTrace(); + } } @Override diff --git a/src/main/java/com/asu/librarysystem/Library.java b/src/main/java/com/asu/librarysystem/Library.java index 0a0e68b..c7b9174 100644 --- a/src/main/java/com/asu/librarysystem/Library.java +++ b/src/main/java/com/asu/librarysystem/Library.java @@ -1,539 +1,549 @@ -package com.asu.librarysystem; - -import java.io.*; -import java.util.ArrayList; -import java.util.Scanner; -import java.util.Stack; - -public class Library { - protected static ArrayList books = new ArrayList(); - protected static ArrayList customers = new ArrayList(); - protected static ArrayList borrowers = new ArrayList(); - private static Account activeAccount; - private static Admin admin = new Admin("Ahmad" , "1234" ,"01030243591") ; - private static ReviewHandler reviewHandler = new ReviewHandler(); - private static DiscountHandler discountHandler = new DiscountHandler(); - private static Stack previousBooks = new Stack(); - private static ShoppingCart shoppingCart = new ShoppingCart(); - - private static String lastViewer; - - public static String getLastViewer() { - return lastViewer; - } - - - public static void setLastViewer(String lastViewer) { - Library.lastViewer = new String(lastViewer); - } - - - public static Stack getPreviousBooks() { - return previousBooks; - } - - //########################## Start for book #########################// - public static void addBook(Book book) { - books.add(book); - } - - public static int getIndexBook(int id) { - for (int i = 0; i < books.size(); i++) { - if (id == books.get(i).getId()) { - return i; - } - } - return -1; - } - - public static boolean updateTitle(int id, String newTitle) { - int index = getIndexBook(id); - if (index != -1) { - books.get(index).setTitle(newTitle); - return true; - } - return false; - - } - - public static boolean updateAuthor(int id, String newAuthor) { - int index = getIndexBook(id); - if (index != -1) { - books.get(index).setAuthor(newAuthor); - return true; - } - return false; - } - - public static boolean updatePublicationYear(int id, int newPublicationYear) { - int index = getIndexBook(id); - if (index != -1) { - books.get(index).setPublicationYear(newPublicationYear); - return true; - } - return false; - } - - public static boolean updateStatus(int id, boolean newStatus) { - int index = getIndexBook(id); - if (index != -1) { - books.get(index).setStatus(newStatus); - return true; - } - return false; - } - - public static boolean updatePrice(int id, int newPrice) { - int index = getIndexBook(id); - if (index != -1) { - books.get(index).setPrice(newPrice); - return true; - } - return false; - } - - public static boolean removeBook(Book book) { - int index = getIndexBook(book.getId()); - if (index != -1) { - books.remove(index); - return true; - } - return false; - } - - // NOTE : We Want to Add something to Recommend Some Books if we can not ffind the book which user want // - public static Book searchBookByTitle(String title) { - for (int i = 0; i < books.size(); i++) { - String titleInArray = books.get(i).getTitle().toLowerCase(); - if (titleInArray.equals(title.toLowerCase())) { - return books.get(i); - } - } - return null; - } - - // NOTE : We Want to Add something to Recommend Some Books if we can not find the book which user want // - public static Book searchBookByAuthor(String author) { - for (int i = 0; i < books.size(); i++) { - String authorInArray = books.get(i).getAuthor().toLowerCase(); - if (authorInArray.equals(author.toLowerCase())) { - return books.get(i); - } - } - return null; - } - - public static Book searchBookById(int bookId) { - for (int i = 0; i < books.size(); i++) { - int IdInArray = books.get(i).getId(); - if (bookId == IdInArray) { - return books.get(i); - } - } - return null; - } - - //################ End of Books ###################// - //############### Start of Borrower ###############// - public static void addBorrower(Borrower borrower) { - borrowers.add(borrower); - } - - public static int getBorrowerIndex(int userId) { - for (int i = 0; i < borrowers.size(); i++) { - if (borrowers.get(i).getId() == userId) { - return i; - } - } - return -1; - } - public static boolean updateBorrowerName(int id, String newName) { - int index = getBorrowerIndex(id); - if (index != -1) { - borrowers.get(index).setUserName(newName); - return true; - } - return false; - } - - public static boolean updateBorrwerPhone(int id, String newPhone) { - int index = getBorrowerIndex(id); - if (index != -1) { - borrowers.get(index).setPhoneNumber(newPhone); - return true; - } - return false; - } - - public static Borrower searchBorrwerByPhoneNumber(String phoneNumber) { - for (Borrower b : borrowers) { - if (b.getPhoneNumber().equals(phoneNumber)) { - return b; - } - } - return null; - } - - public static Borrower searchBorrwerByID(int id) { - for (Borrower b : borrowers) { - if (b.getId()==id) { - return b; - } - } - return null; - } - - public static Borrower searchBorrwerByUserName(String userName) { - for (Borrower b : borrowers) { - if (b.getUserName().equals(userName)) { - return b; - } - } - return null; - } - - public static boolean removeBorrower(Borrower borrower) { - int index = getBorrowerIndex(borrower.getId()); - if (index != -1) { - borrowers.remove(index); - return true; - } - return false; - } - - // ############################ end of borrow ####################### - // ############################ Start of Customer ####################### - public static void addCustomer(Customer customer) { - customers.add(customer); - } - - public static int getCustomerIndex(int userId) { - for (int i = 0; i < customers.size(); i++) { - if (customers.get(i).getId() == userId) { - return i; - } - } - return -1; - } - - public static boolean removeCustomer(Customer customer) { - int index = getCustomerIndex(customer.getId()); - if (index != -1) { - customers.remove(index); - return true; - } - return false; - } - - public static Customer searchCustomerByID(int id) { - for (Customer b : customers) { - if (b.getId()==id) { - return b; - } - } - return null; - } - - public static Customer searchCustomerByUserName(String userName) { - for (Customer b : customers) { - if (b.getUserName().equals(userName)) { - return b; - } - } - return null; - } - - public static Customer searchCustomerByPhoneNumber(String phoneNumber) { - for (Customer b : customers) { - if (b.getPhoneNumber().equals(phoneNumber)) { - return b; - } - } - return null; - } - //##########################End customer ############### -//Note that we want to add a function to check if the string (phone number) contains digits only :) - - public static void signUp(Account account) { - if (account instanceof Borrower) { - addBorrower((Borrower) account); - } else if (account instanceof Customer) { - addCustomer((Customer) account); - } - activeAccount = account; - } - - public static void logOut() { - // Really I can't think of method to log out , please check it and you can edit it - activeAccount = null; - } - - public static Boolean logInByUserName(String userName, String password) { - if (searchBorrwerByUserName(userName) != null) { - if (searchBorrwerByUserName(userName).getPassword().equals(password)) { - activeAccount = searchBorrwerByUserName(userName); - return true; - } - } else if (searchCustomerByUserName(userName) != null) { - if (searchCustomerByUserName(userName).getPassword().equals(password)) { - activeAccount = searchCustomerByUserName(userName); - return true; - } - } else if (admin.getUserName().equals(userName)) { - if (admin.getPassword().equals(password)) { - activeAccount = admin; - return true; - } - } else { - return false; - } - return false; - } - - public static boolean logInByphoneNumber(String phoneNumber, String password) { - if (searchBorrwerByPhoneNumber(phoneNumber) != null) { - if (searchBorrwerByPhoneNumber(phoneNumber).getPassword().equals(password)) { - activeAccount = searchBorrwerByPhoneNumber(phoneNumber); - return true; - } - } else if (searchCustomerByPhoneNumber(phoneNumber) != null) { - if (searchCustomerByPhoneNumber(phoneNumber).getPassword().equals(password)) { - activeAccount = searchCustomerByPhoneNumber(phoneNumber); - return true; - } - } else if (admin.getPhoneNumber().equals(phoneNumber)) { - if (admin.getPassword().equals(password)) { - activeAccount = admin; - return true; - } - } else { - return false; - } - return false; - } - - public static ReviewHandler getReviewHandler() { - return reviewHandler; - } - - public static DiscountHandler getDiscountHandler() { - return discountHandler; - } - - public static Account getActiveAccount() { - return activeAccount; - } - - public static ShoppingCart getShoppingCart() { - return shoppingCart; - } - - public static ArrayList copyElementOfArrayList() { - return books; - } - - public static ArrayList searchInArrayListBookByTitle(String word , ArrayList arr) { - ArrayList foundBooks = new ArrayList(); - for (int i = 0; i < arr.size(); i++) { - String fullTitle = arr.get(i).getTitle().toLowerCase(); - for (int j = 0; j < fullTitle.length() - word.length(); j++) { - int counter = 0; - for (int k = 0; k < word.length(); k++) { - if (word.toLowerCase().charAt(k) == fullTitle.charAt(k + j)) - counter++; - else - break; - } - - if (counter == word.length()) { - foundBooks.add(arr.get(i)); - break; - } - } - } - return foundBooks; - } - - public static ArrayList searchInArrayListBookByAuthor(String word , ArrayList arr) { - ArrayList foundBooks = new ArrayList(); - for (int i = 0; i < arr.size(); i++) { - String authorName = arr.get(i).getAuthor().toLowerCase(); - for (int j = 0; j < authorName.length() - word.length(); j++) { - int counter = 0; - for (int k = 0; k < word.length(); k++) { - if (word.toLowerCase().charAt(k) == authorName.charAt(k + j)) - counter++; - else - break; - } - - if (counter == word.length()) { - foundBooks.add(arr.get(i)); - break; - } - } - } - return foundBooks; - } - - public static ArrayList searchBookByTitleInArray(String word) { - return searchInArrayListBookByTitle(word, books); - } - - public static ArrayList searchBookByAuthorInArray(String word) { - return searchInArrayListBookByAuthor(word, books); - } - -// public static void writeLibrary() { -// try { -// FileOutputStream write1=new FileOutputStream("books_data.txt"); -// for (Book obj : books) { -// write1.write((obj.getId()+","+obj.getTitle()+","+obj.getAuthor()+","+obj.getPublicationYear()+","+obj.isStatus()+","+obj.getPrice()+","+obj.getCoverPath()+"\n").getBytes()); -// } -// write1.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// try { -// FileOutputStream write2=new FileOutputStream("customers_data.txt"); -// for (Customer obj : customers) { -// write2.write((obj.getId()+","+obj.getUserName()+","+obj.getPassword()+","+obj.getPhoneNumber()+"\n").getBytes()); -// } -// write2.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// try { -// FileOutputStream write3=new FileOutputStream("borrowers_data.txt"); -// for (Borrower obj : borrowers) { -// write3.write((obj.getId()+","+obj.getUserName()+","+obj.getPassword()+","+obj.getPhoneNumber()+"\n").getBytes()); -// } -// write3.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// for(Borrower borrower : borrowers){ -// ArrayList transactions =borrower.copyElementOfArrayList(); -// try { -// FileOutputStream write=new FileOutputStream("transaction_data_"+borrower.getUserName()+".txt"); -// for (Transaction obj : transactions ) { -// String bookName=searchBookById(obj.getBookId()).getTitle(); -// write.write((obj.getTransactionId()+","+bookName+","+obj.getBorrowerId()+","+obj.getBorrowDate()+","+obj.getReturnDate()+"\n").getBytes()); -// } -// write.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// } -// -// for(Customer customer : customers){ -// ArrayList orders =customer.copyElementOfArrayList(); -// try { -// FileOutputStream write=new FileOutputStream("order_data_"+customer.getUserName()+".txt"); -// for (Order obj : orders ) { -// String bookName=searchBookById(obj.getBookId()).getTitle(); -// write.write((obj.getId()+","+bookName+","+obj.getQuantity()+"\n").getBytes()); -// } -// write.close(); -// } catch (FileNotFoundException e) { -// System.out.println("can't write"); -// } catch (IOException e) { -// System.out.println("can't write"); -// } -// -// } -// } - -// public static void readLibrary() { -// Scanner scanner1 = null; -// try { -// scanner1 = new Scanner(new FileInputStream("books_data.txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner1.hasNextLine()) { -// String line1 = scanner1.nextLine(); -// String[] parts1 = line1.split(","); -//// Book book=new Book(parts1[1],parts1[2],Integer.valueOf(parts1[3]),Boolean.valueOf(parts1[4]),Integer.valueOf(parts1[5]),Integer.valueOf(parts1[6]),parts1[7]); -// addBook(book); -// } -// scanner1.close(); -// -// Scanner scanner2 = null; -// try { -// scanner2 = new Scanner(new FileInputStream("customers_data.txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner2.hasNextLine()) { -// String line2 = scanner2.nextLine(); -// String[] parts2 = line2.split(","); -// Customer customer=new Customer(parts2[1],parts2[2],parts2[3]); -// addCustomer(customer); -// } -// scanner2.close(); -// -// Scanner scanner3 = null; -// try { -// scanner3 = new Scanner(new FileInputStream("borrowers_data.txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner3.hasNextLine()) { -// String line3 = scanner3.nextLine(); -// String[] parts3 = line3.split(","); -// Borrower borrower = new Borrower(parts3[1],parts3[2],parts3[3]); -// addBorrower(borrower); -// } -// scanner3.close(); -// -// for(Borrower borrower : borrowers) { -// Scanner scanner = null; -// try { -// scanner = new Scanner(new FileInputStream("transaction_data_"+borrower.getUserName()+".txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner.hasNextLine()) { -// String line = scanner.nextLine(); -// String[] parts = line.split(","); -// Transaction transaction = new Transaction(searchBookByTitle(parts[1]).getId(), borrower.getId(), Integer.valueOf(parts[3]), Integer.valueOf(parts[4])); -// borrower.addTransaction(searchBookById(transaction.getBookId()), transaction.getBorrowDate(),transaction.getReturnDate()); -// } -// scanner.close(); -// } -// -// for(Customer customer : customers) { -// Scanner scanner = null; -// try { -// scanner = new Scanner(new FileInputStream("order_data_"+customer.getUserName()+".txt")); -// } catch (FileNotFoundException e) { -// System.out.println("can't read"); -// } -// -// while (scanner.hasNextLine()) { -// String line = scanner.nextLine(); -// String[] parts = line.split(","); -// Order order = new Order(searchBookByTitle(parts[1]).getId(),Integer.valueOf(parts[2])); -// customer.addOrder(order.getBookId(),order.getQuantity()); -// } -// scanner.close(); -// } -// } - -} \ No newline at end of file +package com.asu.librarysystem; + +import java.io.*; +import java.util.ArrayList; +import java.util.Scanner; +import java.util.Stack; + +public class Library { + private static ArrayList books = new ArrayList(); + private static ArrayList customers = new ArrayList(); + private static ArrayList borrowers = new ArrayList(); + private static Account activeAccount; + private static Admin admin = new Admin("Ahmad" , "1234" ,"01030243591") ; + private static ReviewHandler reviewHandler = new ReviewHandler(); + private static DiscountHandler discountHandler = new DiscountHandler(); + private static Stack previousBooks = new Stack(); + private static ShoppingCart shoppingCart = new ShoppingCart(); + + private static String lastViewer; + + public static String getLastViewer() { + return lastViewer; + } + + + public static void setLastViewer(String lastViewer) { + Library.lastViewer = new String(lastViewer); + } + + + public static Stack getPreviousBooks() { + return previousBooks; + } + + //########################## Start for book #########################// + public static void addBook(Book book) { + books.add(book); + } + + public static int getIndexBook(int id) { + for (int i = 0; i < books.size(); i++) { + if (id == books.get(i).getId()) { + return i; + } + } + return -1; + } + + public static boolean updateTitle(int id, String newTitle) { + int index = getIndexBook(id); + if (index != -1) { + books.get(index).setTitle(newTitle); + return true; + } + return false; + + } + + public static boolean updateAuthor(int id, String newAuthor) { + int index = getIndexBook(id); + if (index != -1) { + books.get(index).setAuthor(newAuthor); + return true; + } + return false; + } + + public static boolean updatePublicationYear(int id, int newPublicationYear) { + int index = getIndexBook(id); + if (index != -1) { + books.get(index).setPublicationYear(newPublicationYear); + return true; + } + return false; + } + + public static boolean updateStatus(int id, boolean newStatus) { + int index = getIndexBook(id); + if (index != -1) { + books.get(index).setStatus(newStatus); + return true; + } + return false; + } + + public static boolean updatePrice(int id, int newPrice) { + int index = getIndexBook(id); + if (index != -1) { + books.get(index).setPrice(newPrice); + return true; + } + return false; + } + + public static boolean removeBook(Book book) { + int index = getIndexBook(book.getId()); + if (index != -1) { + books.remove(index); + return true; + } + return false; + } + + // NOTE : We Want to Add something to Recommend Some Books if we can not ffind the book which user want // + public static Book searchBookByTitle(String title) { + for (int i = 0; i < books.size(); i++) { + String titleInArray = books.get(i).getTitle().toLowerCase(); + if (titleInArray.equals(title.toLowerCase())) { + return books.get(i); + } + } + return null; + } + + // NOTE : We Want to Add something to Recommend Some Books if we can not find the book which user want // + public static Book searchBookByAuthor(String author) { + for (int i = 0; i < books.size(); i++) { + String authorInArray = books.get(i).getAuthor().toLowerCase(); + if (authorInArray.equals(author.toLowerCase())) { + return books.get(i); + } + } + return null; + } + + public static Book searchBookById(int bookId) { + for (int i = 0; i < books.size(); i++) { + int IdInArray = books.get(i).getId(); + if (bookId == IdInArray) { + return books.get(i); + } + } + return null; + } + + //################ End of Books ###################// + //############### Start of Borrower ###############// + public static void addBorrower(Borrower borrower) { + borrowers.add(borrower); + } + + public static int getBorrowerIndex(int userId) { + for (int i = 0; i < borrowers.size(); i++) { + if (borrowers.get(i).getId() == userId) { + return i; + } + } + return -1; + } + public static boolean updateBorrowerName(int id, String newName) { + int index = getBorrowerIndex(id); + if (index != -1) { + borrowers.get(index).setUserName(newName); + return true; + } + return false; + } + + public static boolean updateBorrwerPhone(int id, String newPhone) { + int index = getBorrowerIndex(id); + if (index != -1) { + borrowers.get(index).setPhoneNumber(newPhone); + return true; + } + return false; + } + + public static Borrower searchBorrwerByPhoneNumber(String phoneNumber) { + for (Borrower b : borrowers) { + if (b.getPhoneNumber().equals(phoneNumber)) { + return b; + } + } + return null; + } + + public static Borrower searchBorrwerByID(int id) { + for (Borrower b : borrowers) { + if (b.getId()==id) { + return b; + } + } + return null; + } + + public static Borrower searchBorrwerByUserName(String userName) { + for (Borrower b : borrowers) { + if (b.getUserName().equals(userName)) { + return b; + } + } + return null; + } + + public static boolean removeBorrower(Borrower borrower) { + int index = getBorrowerIndex(borrower.getId()); + if (index != -1) { + borrowers.remove(index); + return true; + } + return false; + } + + // ############################ end of borrow ####################### + // ############################ Start of Customer ####################### + public static void addCustomer(Customer customer) { + customers.add(customer); + } + + public static int getCustomerIndex(int userId) { + for (int i = 0; i < customers.size(); i++) { + if (customers.get(i).getId() == userId) { + return i; + } + } + return -1; + } + + public static boolean removeCustomer(Customer customer) { + int index = getCustomerIndex(customer.getId()); + if (index != -1) { + customers.remove(index); + return true; + } + return false; + } + + public static Customer searchCustomerByID(int id) { + for (Customer b : customers) { + if (b.getId()==id) { + return b; + } + } + return null; + } + + public static Customer searchCustomerByUserName(String userName) { + for (Customer b : customers) { + if (b.getUserName().equals(userName)) { + return b; + } + } + return null; + } + + public static Customer searchCustomerByPhoneNumber(String phoneNumber) { + for (Customer b : customers) { + if (b.getPhoneNumber().equals(phoneNumber)) { + return b; + } + } + return null; + } + //##########################End customer ############### +//Note that we want to add a function to check if the string (phone number) contains digits only :) + + public static void signUp(Account account) { + if (account instanceof Borrower) { + addBorrower((Borrower) account); + } else if (account instanceof Customer) { + addCustomer((Customer) account); + } + activeAccount = account; + } + + public static void logOut() { + // Really I can't think of method to log out , please check it and you can edit it + activeAccount = null; + } + + public static Boolean logInByUserName(String userName, String password) { + if (searchBorrwerByUserName(userName) != null) { + if (searchBorrwerByUserName(userName).getPassword().equals(password)) { + activeAccount = searchBorrwerByUserName(userName); + return true; + } + } else if (searchCustomerByUserName(userName) != null) { + if (searchCustomerByUserName(userName).getPassword().equals(password)) { + activeAccount = searchCustomerByUserName(userName); + return true; + } + } else if (admin.getUserName().equals(userName)) { + if (admin.getPassword().equals(password)) { + activeAccount = admin; + return true; + } + } else { + return false; + } + return false; + } + + public static boolean logInByphoneNumber(String phoneNumber, String password) { + if (searchBorrwerByPhoneNumber(phoneNumber) != null) { + if (searchBorrwerByPhoneNumber(phoneNumber).getPassword().equals(password)) { + activeAccount = searchBorrwerByPhoneNumber(phoneNumber); + return true; + } + } else if (searchCustomerByPhoneNumber(phoneNumber) != null) { + if (searchCustomerByPhoneNumber(phoneNumber).getPassword().equals(password)) { + activeAccount = searchCustomerByPhoneNumber(phoneNumber); + return true; + } + } else if (admin.getPhoneNumber().equals(phoneNumber)) { + if (admin.getPassword().equals(password)) { + activeAccount = admin; + return true; + } + } else { + return false; + } + return false; + } + + public static ReviewHandler getReviewHandler() { + return reviewHandler; + } + + public static DiscountHandler getDiscountHandler() { + return discountHandler; + } + + public static Account getActiveAccount() { + return activeAccount; + } + + public static ShoppingCart getShoppingCart() { + return shoppingCart; + } + + public static ArrayList copyElementOfArrayList() { + return books; + } + public static ArrayList getCustomers() { + return customers; + } + + + public static ArrayList searchInArrayListBookByTitle(String word , ArrayList arr) { + ArrayList foundBooks = new ArrayList(); + for (int i = 0; i < arr.size(); i++) { + String fullTitle = arr.get(i).getTitle().toLowerCase(); + for (int j = 0; j < fullTitle.length() - word.length(); j++) { + int counter = 0; + for (int k = 0; k < word.length(); k++) { + if (word.toLowerCase().charAt(k) == fullTitle.charAt(k + j)) + counter++; + else + break; + } + + if (counter == word.length()) { + foundBooks.add(arr.get(i)); + break; + } + } + } + return foundBooks; + } + + public static ArrayList searchInArrayListBookByAuthor(String word , ArrayList arr) { + ArrayList foundBooks = new ArrayList(); + for (int i = 0; i < arr.size(); i++) { + String authorName = arr.get(i).getAuthor().toLowerCase(); + for (int j = 0; j < authorName.length() - word.length(); j++) { + int counter = 0; + for (int k = 0; k < word.length(); k++) { + if (word.toLowerCase().charAt(k) == authorName.charAt(k + j)) + counter++; + else + break; + } + + if (counter == word.length()) { + foundBooks.add(arr.get(i)); + break; + } + } + } + return foundBooks; + } + + public static ArrayList searchBookByTitleInArray(String word) { + return searchInArrayListBookByTitle(word, books); + } + + public static ArrayList searchBookByAuthorInArray(String word) { + return searchInArrayListBookByAuthor(word, books); + } + public static ArrayList getBooks() { + return books; + } + public static ArrayList getBorrowers() { + return borrowers; + } + + +// public static void writeLibrary() { +// try { +// FileOutputStream write1=new FileOutputStream("books_data.txt"); +// for (Book obj : books) { +// write1.write((obj.getId()+","+obj.getTitle()+","+obj.getAuthor()+","+obj.getPublicationYear()+","+obj.isStatus()+","+obj.getPrice()+","+obj.getCoverPath()+"\n").getBytes()); +// } +// write1.close(); +// } catch (FileNotFoundException e) { +// System.out.println("can't write"); +// } catch (IOException e) { +// System.out.println("can't write"); +// } +// +// try { +// FileOutputStream write2=new FileOutputStream("customers_data.txt"); +// for (Customer obj : customers) { +// write2.write((obj.getId()+","+obj.getUserName()+","+obj.getPassword()+","+obj.getPhoneNumber()+"\n").getBytes()); +// } +// write2.close(); +// } catch (FileNotFoundException e) { +// System.out.println("can't write"); +// } catch (IOException e) { +// System.out.println("can't write"); +// } +// try { +// FileOutputStream write3=new FileOutputStream("borrowers_data.txt"); +// for (Borrower obj : borrowers) { +// write3.write((obj.getId()+","+obj.getUserName()+","+obj.getPassword()+","+obj.getPhoneNumber()+"\n").getBytes()); +// } +// write3.close(); +// } catch (FileNotFoundException e) { +// System.out.println("can't write"); +// } catch (IOException e) { +// System.out.println("can't write"); +// } +// +// for(Borrower borrower : borrowers){ +// ArrayList transactions =borrower.copyElementOfArrayList(); +// try { +// FileOutputStream write=new FileOutputStream("transaction_data_"+borrower.getUserName()+".txt"); +// for (Transaction obj : transactions ) { +// String bookName=searchBookById(obj.getBookId()).getTitle(); +// write.write((obj.getTransactionId()+","+bookName+","+obj.getBorrowerId()+","+obj.getBorrowDate()+","+obj.getReturnDate()+"\n").getBytes()); +// } +// write.close(); +// } catch (FileNotFoundException e) { +// System.out.println("can't write"); +// } catch (IOException e) { +// System.out.println("can't write"); +// } +// +// } +// +// for(Customer customer : customers){ +// ArrayList orders =customer.copyElementOfArrayList(); +// try { +// FileOutputStream write=new FileOutputStream("order_data_"+customer.getUserName()+".txt"); +// for (Order obj : orders ) { +// String bookName=searchBookById(obj.getBookId()).getTitle(); +// write.write((obj.getId()+","+bookName+","+obj.getQuantity()+"\n").getBytes()); +// } +// write.close(); +// } catch (FileNotFoundException e) { +// System.out.println("can't write"); +// } catch (IOException e) { +// System.out.println("can't write"); +// } +// +// } +// } + +// public static void readLibrary() { +// Scanner scanner1 = null; +// try { +// scanner1 = new Scanner(new FileInputStream("books_data.txt")); +// } catch (FileNotFoundException e) { +// System.out.println("can't read"); +// } +// +// while (scanner1.hasNextLine()) { +// String line1 = scanner1.nextLine(); +// String[] parts1 = line1.split(","); +//// Book book=new Book(parts1[1],parts1[2],Integer.valueOf(parts1[3]),Boolean.valueOf(parts1[4]),Integer.valueOf(parts1[5]),Integer.valueOf(parts1[6]),parts1[7]); +// addBook(book); +// } +// scanner1.close(); +// +// Scanner scanner2 = null; +// try { +// scanner2 = new Scanner(new FileInputStream("customers_data.txt")); +// } catch (FileNotFoundException e) { +// System.out.println("can't read"); +// } +// +// while (scanner2.hasNextLine()) { +// String line2 = scanner2.nextLine(); +// String[] parts2 = line2.split(","); +// Customer customer=new Customer(parts2[1],parts2[2],parts2[3]); +// addCustomer(customer); +// } +// scanner2.close(); +// +// Scanner scanner3 = null; +// try { +// scanner3 = new Scanner(new FileInputStream("borrowers_data.txt")); +// } catch (FileNotFoundException e) { +// System.out.println("can't read"); +// } +// +// while (scanner3.hasNextLine()) { +// String line3 = scanner3.nextLine(); +// String[] parts3 = line3.split(","); +// Borrower borrower = new Borrower(parts3[1],parts3[2],parts3[3]); +// addBorrower(borrower); +// } +// scanner3.close(); +// +// for(Borrower borrower : borrowers) { +// Scanner scanner = null; +// try { +// scanner = new Scanner(new FileInputStream("transaction_data_"+borrower.getUserName()+".txt")); +// } catch (FileNotFoundException e) { +// System.out.println("can't read"); +// } +// +// while (scanner.hasNextLine()) { +// String line = scanner.nextLine(); +// String[] parts = line.split(","); +// Transaction transaction = new Transaction(searchBookByTitle(parts[1]).getId(), borrower.getId(), Integer.valueOf(parts[3]), Integer.valueOf(parts[4])); +// borrower.addTransaction(searchBookById(transaction.getBookId()), transaction.getBorrowDate(),transaction.getReturnDate()); +// } +// scanner.close(); +// } +// +// for(Customer customer : customers) { +// Scanner scanner = null; +// try { +// scanner = new Scanner(new FileInputStream("order_data_"+customer.getUserName()+".txt")); +// } catch (FileNotFoundException e) { +// System.out.println("can't read"); +// } +// +// while (scanner.hasNextLine()) { +// String line = scanner.nextLine(); +// String[] parts = line.split(","); +// Order order = new Order(searchBookByTitle(parts[1]).getId(),Integer.valueOf(parts[2])); +// customer.addOrder(order.getBookId(),order.getQuantity()); +// } +// scanner.close(); +// } +// } +} diff --git a/src/main/java/com/asu/librarysystem/LoginController.java b/src/main/java/com/asu/librarysystem/LoginController.java index 95ed0d3..e99e277 100644 --- a/src/main/java/com/asu/librarysystem/LoginController.java +++ b/src/main/java/com/asu/librarysystem/LoginController.java @@ -64,12 +64,12 @@ else if (!Library.logInByUserName(username.getText(), password.getText())) { else if (Library.logInByUserName(username.getText(), password.getText())){ if(Library.getActiveAccount() instanceof Admin) - scene(event, "Delete-view.fxml");//Admin Main fxml file + scene(event, "AdminMain.fxml");//Admin Main fxml file else if (Library.getActiveAccount() instanceof Borrower) { - scene(event, "Update.fxml");//Borrower Main fxml file + scene(event, "borrower-main-view.fxml");//Borrower Main fxml file } else if (Library.getActiveAccount() instanceof Customer) { - scene(event, "CRUD_Borrower-view.fxml");//Customer Main fxml file + scene(event, "CustomerMain.fxml");//Customer Main fxml file } } diff --git a/src/main/java/com/asu/librarysystem/MainApplication.java b/src/main/java/com/asu/librarysystem/MainApplication.java index 3731b6b..103f464 100644 --- a/src/main/java/com/asu/librarysystem/MainApplication.java +++ b/src/main/java/com/asu/librarysystem/MainApplication.java @@ -41,7 +41,7 @@ public void start(Stage stage) throws IOException { // stage.setScene(scene); // stage.show(); - FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("SideBar.fxml")); + FXMLLoader fxmlLoader = new FXMLLoader(MainApplication.class.getResource("Login.fxml")); Scene scene = new Scene(fxmlLoader.load(),1280,720); // Image icon =new Image(""); // stage.getIcons().add(icon); @@ -88,11 +88,11 @@ public static void main(String[] args) { Library.addBook(book8); Library.addBook(book9); Library.addBook(book10); - Customer customer=new Customer("Ibrahem1","123","111"); + Customer customer=new Customer("ib","123","111"); Library.addCustomer(customer); Borrower borrower = new Borrower("Ibrahem","111","111"); Library.addBorrower(borrower); - Library.logInByUserName("Ibrahem1","123"); + //Library.logInByUserName("ib","123"); customer.addOrder(book1.getId(),2); customer.addOrder(book2.getId(),2); @@ -103,6 +103,8 @@ public static void main(String[] args) { borrower.addTransaction(book3); borrower.addTransaction(book5); borrower.addTransaction(book9); + + /* Login Borrower B = new Borrower("Hossam", "123456", "123456"); Book b = new Book("", "", 0, true, 1500, 4, "Any"); diff --git a/src/main/java/com/asu/librarysystem/MainController.java b/src/main/java/com/asu/librarysystem/MainController.java index 8ae5190..5e45f3d 100644 --- a/src/main/java/com/asu/librarysystem/MainController.java +++ b/src/main/java/com/asu/librarysystem/MainController.java @@ -38,11 +38,11 @@ public void pressed(ActionEvent event) { // } try { - FXMLLoader loader = new FXMLLoader(getClass().getResource("All-Books.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("Login.fxml")); root = loader.load(); - +/* AllBooksController sceneController = loader.getController(); - sceneController.startAllBooksController(); + sceneController.startAllBooksController();*/ stage = (Stage)((Node)event.getSource()).getScene().getWindow(); scene= new Scene(root); stage.setScene(scene); diff --git a/src/main/java/com/asu/librarysystem/ManagingCustomerProfile.java b/src/main/java/com/asu/librarysystem/ManagingCustomerProfile.java deleted file mode 100644 index 0ab0c28..0000000 --- a/src/main/java/com/asu/librarysystem/ManagingCustomerProfile.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.asu.librarysystem; - -import javafx.event.ActionEvent; -import javafx.fxml.FXML; -import javafx.fxml.FXMLLoader; -import javafx.fxml.Initializable; -import javafx.scene.Node; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.scene.control.TextField; -import javafx.scene.text.Text; -import javafx.stage.Stage; - -import java.io.IOException; -import java.net.URL; -import java.util.ResourceBundle; - -public class ManagingCustomerProfile implements Initializable { - private Stage customerStage; - private Scene customerScene; - private Parent customerViewNodes; - - @FXML - public void switchToManagingCustomerMain(ActionEvent event)throws IOException { - - try { - customerViewNodes= FXMLLoader.load(MainApplication.class.getResource("CustomerMain.fxml")); - customerStage= (Stage)((Node)event.getSource()).getScene().getWindow(); - customerScene =new Scene(customerViewNodes); - customerStage.setScene(customerScene); - customerStage.show(); - }catch (Exception switchingScenesException){ - System.out.println(switchingScenesException.getMessage()); - } - } - - Account customer = new Customer("ahmed khaled","12345678","01026428077"); - - @FXML - private TextField acountNameTextField; - @FXML - private TextField phoneNumberTextField; - @FXML - private TextField PasswordTextField; - @FXML - private TextField confiremingPasswordTextField; - - @FXML - private Text phoneNumberText; - @FXML - private Text acountNameText; - @FXML - private void editProfile(){ - - if(PasswordTextField.getText().equals(confiremingPasswordTextField.getText()) && !(PasswordTextField.getText().isEmpty())){ - customer.setPassword(PasswordTextField.getText()); - customer.setUserName(acountNameTextField.getText()); - customer.setPhoneNumber(phoneNumberTextField.getText()); - - acountNameText.setText(acountNameTextField.getText()); - phoneNumberText.setText(phoneNumberTextField.getText()); - - PasswordTextField.clear(); - confiremingPasswordTextField.clear(); - } - } - @Override - public void initialize(URL url, ResourceBundle resourceBundle) { - acountNameText.setText(customer.getUserName()); - phoneNumberText.setText(customer.getPhoneNumber()); - acountNameTextField.setText(customer.getUserName()); - phoneNumberTextField.setText(customer.getPhoneNumber()); - } -} \ No newline at end of file diff --git a/src/main/java/com/asu/librarysystem/ManagingAdminProfile.java b/src/main/java/com/asu/librarysystem/ManagingProfileController.java similarity index 51% rename from src/main/java/com/asu/librarysystem/ManagingAdminProfile.java rename to src/main/java/com/asu/librarysystem/ManagingProfileController.java index e417cb0..7141653 100644 --- a/src/main/java/com/asu/librarysystem/ManagingAdminProfile.java +++ b/src/main/java/com/asu/librarysystem/ManagingProfileController.java @@ -15,25 +15,28 @@ import java.net.URL; import java.util.ResourceBundle; -public class ManagingAdminProfile implements Initializable{ - private Stage customerStage; - private Scene customerScene; - private Parent customerViewNodes; - +public class ManagingProfileController implements Initializable{ @FXML - public void switchToManagingAdminMain(ActionEvent event)throws IOException { + public void switchToMain(ActionEvent event)throws IOException { try { - customerViewNodes= FXMLLoader.load(MainApplication.class.getResource("AdminMain.fxml")); - customerStage= (Stage)((Node)event.getSource()).getScene().getWindow(); - customerScene =new Scene(customerViewNodes); - customerStage.setScene(customerScene); - customerStage.show(); + Parent root; + if (Library.getActiveAccount() instanceof Admin) { + root = FXMLLoader.load(MainApplication.class.getResource("AdminMain.fxml")); + } else if (Library.getActiveAccount() instanceof Customer) { + root = FXMLLoader.load(MainApplication.class.getResource("CustomerMain.fxml")); + } else { + root = FXMLLoader.load(MainApplication.class.getResource("borrower-main-view.fxml")); + } + Stage stage= (Stage)((Node)event.getSource()).getScene().getWindow(); + Scene scene =new Scene(root); + stage.setScene(scene); + stage.show(); }catch (Exception switchingScenesException){ System.out.println(switchingScenesException.getMessage()); } } - Account admin = new Admin("ahmed khaled","12345678","01026428077"); + private Account account = Library.getActiveAccount(); @FXML private TextField acountNameTextField; @@ -52,9 +55,9 @@ public void switchToManagingAdminMain(ActionEvent event)throws IOException { private void editProfile(){ if(PasswordTextField.getText().equals(confiremingPasswordTextField.getText()) && !(PasswordTextField.getText().isEmpty())){ - admin.setPassword(PasswordTextField.getText()); - admin.setUserName(acountNameTextField.getText()); - admin.setPhoneNumber(phoneNumberTextField.getText()); + account.setPassword(PasswordTextField.getText()); + account.setUserName(acountNameTextField.getText()); + account.setPhoneNumber(phoneNumberTextField.getText()); acountNameText.setText(acountNameTextField.getText()); phoneNumberText.setText(phoneNumberTextField.getText()); @@ -65,9 +68,9 @@ private void editProfile(){ } @Override public void initialize(URL url, ResourceBundle resourceBundle) { - acountNameText.setText(admin.getUserName()); - phoneNumberText.setText(admin.getPhoneNumber()); - acountNameTextField.setText(admin.getUserName()); - phoneNumberTextField.setText(admin.getPhoneNumber()); + acountNameText.setText(account.getUserName()); + phoneNumberText.setText(account.getPhoneNumber()); + acountNameTextField.setText(account.getUserName()); + phoneNumberTextField.setText(account.getPhoneNumber()); } } diff --git a/src/main/java/com/asu/librarysystem/MyBooksController.java b/src/main/java/com/asu/librarysystem/MyBooksController.java index b908a7c..08c3ffc 100644 --- a/src/main/java/com/asu/librarysystem/MyBooksController.java +++ b/src/main/java/com/asu/librarysystem/MyBooksController.java @@ -48,7 +48,7 @@ public void backButton(ActionEvent event){ Account account = Library.getActiveAccount(); if (account instanceof Customer) { Customer customer =(Customer) account; - FXMLLoader loader = new FXMLLoader(getClass().getResource("name of.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("CustomerMain.fxml")); Parent root = loader.load(); // clsssName objName = loader.getController(); // objName.method; @@ -59,7 +59,7 @@ public void backButton(ActionEvent event){ } else if(account instanceof Borrower){ Borrower borrower =(Borrower) account; - FXMLLoader loader = new FXMLLoader(getClass().getResource("name.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("borrower-main-view.fxml")); Parent root = loader.load(); // clsssName objName = loader.getController(); // objName.method; diff --git a/src/main/java/com/asu/librarysystem/Notifications.java b/src/main/java/com/asu/librarysystem/Notifications.java index 4c6c2e3..32e6655 100644 --- a/src/main/java/com/asu/librarysystem/Notifications.java +++ b/src/main/java/com/asu/librarysystem/Notifications.java @@ -5,7 +5,7 @@ import java.util.ArrayList; public class Notifications { - private static final Borrower currentBorrower = BorrowerController.getCurrentBorrower(); + private static final Borrower currentBorrower = TransactionsForBorrowersController.getCurrentBorrower(); public static ArrayList booksDueDateIn3Days() { ArrayList transactionsDueIn3DaysIds = new ArrayList<>(); for(int i = 0; i < currentBorrower.getBorrowerTransactions().size(); i++) { @@ -20,8 +20,8 @@ public static ArrayList booksDueDateIn3Days() { public static ArrayList booksOverDueDate() { ArrayList booksOverDueDateIds= new ArrayList<>(); for(int i = 0; i < currentBorrower.getBorrowerTransactions().size(); i++) { - if(ChronoUnit.DAYS.between(LocalDate.now(), BorrowerController.getCurrentBorrower().getBorrowerTransactions().get(0).getReturnDate()) <= 0) { - booksOverDueDateIds.add(BorrowerController.getCurrentBorrower().getBorrowerTransactions().get(i).getBookName()); + if(ChronoUnit.DAYS.between(LocalDate.now(), TransactionsForBorrowersController.getCurrentBorrower().getBorrowerTransactions().get(0).getReturnDate()) <= 0) { + booksOverDueDateIds.add(TransactionsForBorrowersController.getCurrentBorrower().getBorrowerTransactions().get(i).getBookName()); } } return booksOverDueDateIds; diff --git a/src/main/java/com/asu/librarysystem/OrdersForAdminController.java b/src/main/java/com/asu/librarysystem/OrdersForAdminController.java index ffdddb5..238302b 100644 --- a/src/main/java/com/asu/librarysystem/OrdersForAdminController.java +++ b/src/main/java/com/asu/librarysystem/OrdersForAdminController.java @@ -1,5 +1,6 @@ package com.asu.librarysystem; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.ResourceBundle; @@ -8,8 +9,11 @@ import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; @@ -39,8 +43,15 @@ public class OrdersForAdminController implements Initializable { @FXML void back(ActionEvent event) { - Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow(); - stage.close(); + try { + Parent root = FXMLLoader.load(getClass().getResource("AdminMain.fxml")); + Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + Scene scene = new Scene(root); + primaryStage.setScene(scene); + primaryStage.show(); + } catch (IOException e) { + e.printStackTrace(); + } } @Override @@ -51,12 +62,14 @@ public void initialize(URL location, ResourceBundle resources) { priceColumn.setCellValueFactory(new PropertyValueFactory("price")); discountColumn.setCellValueFactory(new PropertyValueFactory("discountCode")); - Customer activeAccount = (Customer)Library.getActiveAccount(); - - ArrayList orders = activeAccount.getOrders(); - - for (var order : orders) { - tableData.add(new OrderRow(order, activeAccount.getUserName())); + ArrayList customers = Library.getCustomers(); + ArrayList orders; + + for (var customer : customers) { + orders = customer.getOrders(); + for (var order : orders) { + tableData.add(new OrderRow(order, customer.getUserName())); + } } mainTable.setItems(tableData); diff --git a/src/main/java/com/asu/librarysystem/OrdersForCustomerController.java b/src/main/java/com/asu/librarysystem/OrdersForCustomerController.java index e578cc8..f1000c4 100644 --- a/src/main/java/com/asu/librarysystem/OrdersForCustomerController.java +++ b/src/main/java/com/asu/librarysystem/OrdersForCustomerController.java @@ -1,5 +1,6 @@ package com.asu.librarysystem; +import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.ResourceBundle; @@ -8,8 +9,11 @@ import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; import javafx.scene.Node; +import javafx.scene.Parent; +import javafx.scene.Scene; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; import javafx.scene.control.cell.PropertyValueFactory; @@ -36,8 +40,15 @@ public class OrdersForCustomerController implements Initializable { @FXML void back(ActionEvent event) { - Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow(); - stage.close(); + try { + Parent root = FXMLLoader.load(getClass().getResource("CustomerMain.fxml")); + Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + Scene scene = new Scene(root); + primaryStage.setScene(scene); + primaryStage.show(); + } catch (IOException e) { + e.printStackTrace(); + } } @Override diff --git a/src/main/java/com/asu/librarysystem/ShoppingCartController.java b/src/main/java/com/asu/librarysystem/ShoppingCartController.java index addf9ff..813ae71 100644 --- a/src/main/java/com/asu/librarysystem/ShoppingCartController.java +++ b/src/main/java/com/asu/librarysystem/ShoppingCartController.java @@ -70,8 +70,15 @@ public void initialize(URL location, ResourceBundle resources) { } public void back(ActionEvent event) { - stage = (Stage)root.getScene().getWindow(); - stage.close(); + try { + Parent root = FXMLLoader.load(getClass().getResource("CustomerMain.fxml")); + Stage primaryStage = (Stage)((Node)event.getSource()).getScene().getWindow(); + Scene scene = new Scene(root); + primaryStage.setScene(scene); + primaryStage.show(); + } catch (IOException e) { + e.printStackTrace(); + } } public void delete(ActionEvent event) { diff --git a/src/main/java/com/asu/librarysystem/SignupController.java b/src/main/java/com/asu/librarysystem/SignupController.java index 9afe479..92c0f9a 100644 --- a/src/main/java/com/asu/librarysystem/SignupController.java +++ b/src/main/java/com/asu/librarysystem/SignupController.java @@ -58,11 +58,11 @@ public void AddUser(String userName, String phoneNumber, String Password) { if (customerRadio.isSelected()) { Customer C = new Customer(userName, Password, phoneNumber); - Library.customers.add(C); + Library.getCustomers().add(C); System.out.println("Customer"); } else if (borrowerRadio.isSelected()) { Borrower B = new Borrower(userName, Password, phoneNumber); - Library.borrowers.add(B); + Library.getBorrowers().add(B); System.out.println("Borrower"); } } diff --git a/src/main/java/com/asu/librarysystem/BorrowerController.java b/src/main/java/com/asu/librarysystem/TransactionsForBorrowersController.java similarity index 89% rename from src/main/java/com/asu/librarysystem/BorrowerController.java rename to src/main/java/com/asu/librarysystem/TransactionsForBorrowersController.java index 7fcd5ce..05d1f9e 100644 --- a/src/main/java/com/asu/librarysystem/BorrowerController.java +++ b/src/main/java/com/asu/librarysystem/TransactionsForBorrowersController.java @@ -24,10 +24,10 @@ import java.util.Objects; import java.util.ResourceBundle; -public class BorrowerController implements Initializable { +public class TransactionsForBorrowersController implements Initializable { private Stage primaryStage = new Stage(); private Scene scene; - private static Borrower currentBorrower = new Borrower("","",""); + private static Borrower currentBorrower = (Borrower)Library.getActiveAccount(); @FXML private Label Back; @FXML @@ -47,10 +47,10 @@ public class BorrowerController implements Initializable { @FXML private TableColumn TransactionIdColumn; - +/* public static void setCurrentBorrower(Borrower currentBorrower) { - BorrowerController.currentBorrower = currentBorrower; - } + TransactionsForBorrowersController.currentBorrower = currentBorrower; + }*/ public static Borrower getCurrentBorrower() { return currentBorrower; @@ -68,7 +68,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) { TransactionTableView.setItems(list); Back.setOnMouseClicked(mouseEvent -> { try { - Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("SideBar.fxml"))); + Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("borrower-main-view.fxml"))); primaryStage = (Stage)((Node)mouseEvent.getSource()).getScene().getWindow(); scene = new Scene(root); primaryStage.setScene(scene); diff --git a/src/main/resources/com/asu/librarysystem/AdminMain.fxml b/src/main/resources/com/asu/librarysystem/AdminMain.fxml index 778cbcd..0fc145e 100644 --- a/src/main/resources/com/asu/librarysystem/AdminMain.fxml +++ b/src/main/resources/com/asu/librarysystem/AdminMain.fxml @@ -39,7 +39,7 @@ - diff --git a/src/main/resources/com/asu/librarysystem/CRUDBooks.fxml b/src/main/resources/com/asu/librarysystem/CRUDBooks.fxml index e52b0fa..7453d5c 100644 --- a/src/main/resources/com/asu/librarysystem/CRUDBooks.fxml +++ b/src/main/resources/com/asu/librarysystem/CRUDBooks.fxml @@ -4,6 +4,7 @@ + @@ -22,46 +23,50 @@ - - - - - - - - - - - - - - - - - - + + + + - - + + + + +