private void button3_Click(object sender, EventArgs e) // search by author { listBox1.Items.Clear(); List <Book> ToPrint = LibraryApp.LookByAuthor(ref BookList, textBox2.Text); if (ToPrint.Count == 0) { MessageBox.Show("No books matched that search!"); } else { PrintTitles(ToPrint); } }
//public static Book ConfirmReturn(List<Book> CheckedOut, int BookIndex) //{ // while (true) // { // if (BookIndex > 0 && BookIndex <= CheckedOut.Count) // return CheckedOut[BookIndex]; // else // { // Console.WriteLine("I didn't understand. Try again!"); // int.TryParse(Console.ReadLine(), out BookIndex); // } // } //} public static void Search(ref List <Book> BookList) { Console.WriteLine("Do you want to search by Title or Author? (t/a)"); string TorA = Console.ReadLine().ToLower(); if (Regex.IsMatch(TorA, "^(t|title)$")) { Console.WriteLine("Please enter a title..."); string Input = Console.ReadLine(); Menu.PrintTitles(LibraryApp.LookByTitleKeyword(ref BookList, Input)); } if (Regex.IsMatch(TorA, "^(a|author)$")) { Console.WriteLine("Please enter an author..."); string Input = Console.ReadLine(); Menu.PrintTitles(LibraryApp.LookByAuthor(ref BookList, Input)); } }
private void button5_Click(object sender, EventArgs e) //return book { try { int index = listBox1.SelectedIndex; List <Book> ReturnList = Validation.CreateReturnList(ref BookList); ReturnList[index] = LibraryApp.ReturnBook(ReturnList[index]); foreach (Book x in BookList) { if (x.title == ReturnList[index].title) { x.duedate = ReturnList[index].duedate; x.status = ReturnList[index].status; } } MessageBox.Show("Thank you for not stealing our book!"); listBox1.Items.Clear(); } catch { MessageBox.Show("There were no books to return!"); } }
void button4_Click(object sender, EventArgs e) //checkout book { try { int index = listBox1.SelectedIndex; string y = listBox1.SelectedItem.ToString().Substring(0, 5); foreach (Book x in BookList) { if (x.title.Contains(y) && x.status == "Checked Out") { MessageBox.Show($"That book is already checked out and is due back {BookList[index].duedate}"); } else if (x.title.Contains(y) && x.status != "Checked Out") { LibraryApp.CheckOutBook(x); MessageBox.Show($"{x.title} is due back on {x.duedate}\n"); } } } catch { MessageBox.Show("No book was selected!"); } }