Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

edit some method in my book, all book and Book controller(IB) #26

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/covers/1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/covers/9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 25 additions & 9 deletions src/main/java/com/asu/librarysystem/AllBooksController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ else if(account instanceof Borrower){

public void backButton(ActionEvent event){
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("name.fxml"));
Parent root = loader.load();
Account account = Library.getActiveAccount();
if (account instanceof Customer) {
Customer customer =(Customer) account;
FXMLLoader loader = new FXMLLoader(getClass().getResource("name of.fxml"));
Parent root = loader.load();
// clsssName objName = loader.getController();
// objName.method;
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene= new Scene(root);
stage.setScene(scene);
stage.show();
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene= new Scene(root);
stage.setScene(scene);
stage.show();
}
else if(account instanceof Borrower){
Borrower borrower =(Borrower) account;
FXMLLoader loader = new FXMLLoader(getClass().getResource("name.fxml"));
Parent root = loader.load();
// clsssName objName = loader.getController();
// objName.method;
Stage stage = (Stage)((Node)event.getSource()).getScene().getWindow();
Scene scene= new Scene(root);
stage.setScene(scene);
stage.show();
}

} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -102,7 +118,7 @@ private ArrayList<Book> arrayReadyToSearch(String word){
}
return foundBooks;
}
public void searshBook(){
public void searchBook(){
String word = searshText.getText();
ArrayList<Book>foundBooks=arrayReadyToSearch(word);
int colm=0;
Expand Down Expand Up @@ -139,10 +155,10 @@ public void searshBook(){
}
}
public void searshBookByKey(KeyEvent event){
searshBook();
searchBook();
}
public void searshBookByAction(ActionEvent event){
searshBook();
searchBook();
}

}
14 changes: 13 additions & 1 deletion src/main/java/com/asu/librarysystem/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class BookController implements Initializable {
@FXML
ImageView bookCover, statusImage, oneStarIcon, twoStarsIcon, threeStarsIcon, fourStarsIcon, fiveStarsIcon, notifyMe;
@FXML
Label name, author, releaseDate, price, description, countRatings, totalRating, textAreaCharCount, categories;
Label name, author, releaseDate, price, description, countRatings, totalRating, textAreaCharCount, categories, userName;
@FXML
Text warningMessage;
@FXML
Expand Down Expand Up @@ -68,6 +68,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
}

public void setScene(Book book) throws IOException {
displayUserName();
currentBook = book;
setCover(book.getCoverPath());

Expand Down Expand Up @@ -428,4 +429,15 @@ public void backButton(ActionEvent event){
e.printStackTrace();
}
}
private void displayUserName(){
Account account = Library.getActiveAccount();
if (account instanceof Customer) {
Customer customer =(Customer) account;
userName.setText(customer.getUserName());
}
else if(account instanceof Borrower){
Borrower borrower =(Borrower) account;
userName.setText(borrower.getUserName());
}
}
}
152 changes: 76 additions & 76 deletions src/main/java/com/asu/librarysystem/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public static ArrayList<Book> copyElementOfArrayList() {
}

public static ArrayList<Book> searchInArrayListBookByTitle(String word , ArrayList<Book> arr) {
ArrayList<Book> fondBooks = new ArrayList();
ArrayList<Book> 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++) {
Expand All @@ -321,16 +321,16 @@ public static ArrayList<Book> searchInArrayListBookByTitle(String word , ArrayLi
}

if (counter == word.length()) {
fondBooks.add(arr.get(i));
foundBooks.add(arr.get(i));
break;
}
}
}
return fondBooks;
return foundBooks;
}

public static ArrayList<Book> searchInArrayListBookByAuthor(String word , ArrayList<Book> arr) {
ArrayList<Book> fondBooks = new ArrayList();
ArrayList<Book> 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++) {
Expand All @@ -343,12 +343,12 @@ public static ArrayList<Book> searchInArrayListBookByAuthor(String word , ArrayL
}

if (counter == word.length()) {
fondBooks.add(arr.get(i));
foundBooks.add(arr.get(i));
break;
}
}
}
return fondBooks;
return foundBooks;
}

public static ArrayList<Book> searchBookByTitleInArray(String word) {
Expand All @@ -359,76 +359,76 @@ public static ArrayList<Book> 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<Transaction> 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<Order> 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 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<Transaction> 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<Order> 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;
Expand Down
Loading