//Removing a Book from the Book List public Book removeBook(Book removeBook) { BookStorage books = new BookStorage(); string[,] listBooks = books.allBooks(); removeBook.check = false; int index = 0; while (removeBook.check == false && index < 100) { if (removeBook.isbn == listBooks[index, 0]) { removeBook.check = true; } else { index += 1; } } for (int i = index; i < 99; i++) { for (int j = 0; j < 5; j++) { listBooks[i, j] = listBooks[i + 1, j]; } } books.writeAllBooks(listBooks); return(removeBook); }
//Searching for a book in the system public Book searchBook(Book searchBook) { BookStorage books = new BookStorage(); string[,] listBooks = books.allBooks(); searchBook.check = false; int counter = 0; while (searchBook.check == false && counter < 100) { if (searchBook.isbn == listBooks[counter, 0]) { searchBook.title = listBooks[counter, 1]; searchBook.author = listBooks[counter, 2]; searchBook.description = listBooks[counter, 3]; searchBook.stockNum = listBooks[counter, 4]; //Breaking the loop here after gathing above information searchBook.check = true; } counter += 1; } if (searchBook.check == false) { searchBook.isbn = "BOOK IS NOT IN SYSTEM"; } return(searchBook); }
public Book editBook(Book editBook) { BookStorage books = new BookStorage(); string[,] listBooks = books.allBooks(); editBook.check = false; int counter = 0; while (editBook.check == false && counter < 100) { if (editBook.isbn == listBooks[counter, 0]) { listBooks[counter, 1] = editBook.title; listBooks[counter, 2] = editBook.author; listBooks[counter, 3] = editBook.description; listBooks[counter, 4] = editBook.stockNum; editBook.check = true; } counter += 1; } if (editBook.check == true) { books.writeAllBooks(listBooks); } else if (editBook.check == false) { editBook.isbn = "BOOK IS NOT IN SYSTEM"; } return(editBook); }
private void getBooks_Click(object sender, RoutedEventArgs e) { BookStorage storage = new BookStorage(); string[,] showBooks = storage.allBooks(); string comBookString = ""; for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { comBookString = (comBookString + " " + showBooks[i, j]); } bookDisplay.Items.Add(comBookString); comBookString = ""; } }
//all book function private void getBooks_Click(object sender, RoutedEventArgs e) { BookStorage storage = new BookStorage(); string[,] showBooks = storage.allBooks(); string comBookString = ""; /* * MS for practice, you should try using a foreach loop * You will see foreach loops far more often in C# than you * see for loops */ bookDisplay.Items.Clear(); for (int i = 0; i < 100; i++) { for (int j = 0; j < 5; j++) { comBookString = (comBookString + " " + showBooks[i, j]); } bookDisplay.Items.Add(comBookString); comBookString = ""; } }