static void Main(string[] args) { Book[] myBooks = BookFile.ReadBookFile(); Transaction[] myTransaction = TransactionFile.ReadTransactionFile(); Menu(myBooks, myTransaction); }
public static int EditBook(Book[] myBooks) { Console.WriteLine("What is the ISBN of the book you will be editing?:"); int editIsbn = int.Parse(Console.ReadLine()); bool found = false; int index = 0; for (int i = 0; i < Book.GetCount() && found == false; i++) { if (myBooks[i].GetIsbn() == editIsbn) { found = true; index = i; } } if (found != true) { Console.WriteLine("Book ISBN " + editIsbn + " not found"); } else { Console.WriteLine(myBooks[index].ToString()); EditMenu(index, myBooks); } BookFile.WriteToFile(myBooks); return(myBooks[index].GetIsbn()); }
public static Book[] GetBookData() { BookFile data = new BookFile("books.txt"); Book[] myBooks = data.ReadBookData(); Console.WriteLine("Enter book ISBN (-1 to stop): \n"); int ISBN = int.Parse(Console.ReadLine()); while (ISBN != -1) { int indexFound = BookUtility.BinarySearch(myBooks, ISBN); Console.WriteLine(indexFound); if (indexFound == -1) { int bookCount = 1; Console.Write("Enter the title: \n"); string title = Console.ReadLine(); Console.Write("Enter the author: \n"); string author = Console.ReadLine(); Console.Write("Enter the genre: \n"); string genre = Console.ReadLine(); Console.Write("Enter the listening time: \n"); double listeningTime = double.Parse(Console.ReadLine()); string status = "Available"; Book newBook = new Book(ISBN, title, author, genre, listeningTime, status, bookCount); myBooks[GetCount()] = newBook; IncrCount(); Console.Write("Enter book ISBN (- 1 to stop): \n"); ISBN = int.Parse(Console.ReadLine()); } else { int copies = myBooks[indexFound].GetBookCount() + 1; myBooks[indexFound].SetBookCount(copies); ISBN = -1; } } return(myBooks); }
public static void RentBook(Book[] myBooks, Transaction[] myTransaction) { Console.WriteLine("Enter your email:"); string email = Console.ReadLine(); Console.WriteLine("Enter the ISBN of the Book you want to rent:"); int rentIsbn = int.Parse(Console.ReadLine()); bool found = false; while (found == false) { for (int i = 0; i < Book.GetCount() && found == false; i++) { if (myBooks[i].GetInStock() == true && myBooks[i].GetIsbn() == rentIsbn) { myBooks[i].InStock(); found = true; } } if (found == false) { Console.WriteLine("Book not available for rent"); Console.WriteLine("Enter the ISBN of the Book you want to rent:"); rentIsbn = int.Parse(Console.ReadLine()); } } if (found == true) { int newId = myTransaction[Transaction.GetCount() - 1].GetId() + 1; DateTime date = DateTime.Today; string dateToday = date.ToString("d"); string returnDate = "N/A"; myTransaction[Transaction.GetCount()] = new Transaction(newId, email, rentIsbn, dateToday, returnDate); Transaction.SetCount(Transaction.GetCount() + 1); TransactionFile.WriteToFile(myTransaction); BookFile.WriteToFile(myBooks); } }
public static void ReturnBook(Book[] myBooks, Transaction[] myTransaction) { Console.WriteLine("Enter the email used to rent the book:"); string email = Console.ReadLine(); Console.WriteLine("Enter the ISBN of the book you would like to return:"); int returnId = int.Parse(Console.ReadLine()); DateTime date = DateTime.Today; string dateToday = date.ToString("d"); bool found = false; int index = 0; for (int i = 0; i < Book.GetCount() && found == false; i++) { for (int j = 0; j < Transaction.GetCount() && found == false; j++) { if (myTransaction[j].GetIsbn() == returnId && myTransaction[j].GetEmail() == email && myBooks[i].GetIsbn() == returnId) { found = true; myTransaction[j].SetReturnDate(dateToday); myBooks[i].InStock(); index = i; } } } if (found == true) { Console.WriteLine("You have returned " + myBooks[index].GetTitle()); TransactionFile.WriteToFile(myTransaction); BookFile.WriteToFile(myBooks); } else { Console.WriteLine("Transaction not found"); } }
public static void AddBook(Book[] myBooks) { Console.WriteLine("What is the ISBN of the new book?: "); int isbn = int.Parse(Console.ReadLine()); Console.WriteLine("What is the title of the book you would like to add?"); string title = Console.ReadLine(); Console.WriteLine("What is the genre of the book?: "); string genre = Console.ReadLine(); Console.WriteLine("Who is the author of the book?: "); string author = Console.ReadLine(); Console.WriteLine("How long is the recording (in minutes)?: "); int time = int.Parse(Console.ReadLine()); bool inStock = true; myBooks[Book.GetCount()] = new Book(isbn, title, genre, author, time, inStock); Book.SetCount(Book.GetCount() + 1); BookFile.WriteToFile(myBooks); }
//Method gets books from user to be added to book file public static Book[] GetBookData() { //read existing data from book file into array BookFile data = new BookFile("books.txt"); Book[] myBooks = data.ReadBookData(); Console.WriteLine("\nEnter book ISBN (-1 to stop): \n"); int ISBN = int.Parse(Console.ReadLine()); while (ISBN != -1) { //binary search checks to see if the book already exists, if not, it continues to get user info on the book int indexFound = BookUtility.BinarySearch(myBooks, ISBN); if (indexFound == -1) { int bookCount = 1; Console.Write("\nEnter the title: \n"); string title = Console.ReadLine(); Console.Write("\nEnter the author: \n"); string author = Console.ReadLine(); Console.Write("\nEnter the genre: \n"); string genre = Console.ReadLine(); Console.Write("\nEnter the listening time: \n"); double listeningTime = double.Parse(Console.ReadLine()); string status = "Available"; Book newBook = new Book(ISBN, title, author, genre, listeningTime, status, bookCount); myBooks[GetCount()] = newBook; IncrCount(); Console.Clear(); Console.Write("\nEnter book ISBN (- 1 to stop): \n"); ISBN = int.Parse(Console.ReadLine()); } //if the book ISBN already exists, program will increase the number of copies by one else { int copies = myBooks[indexFound].GetBookCount() + 1; myBooks[indexFound].SetBookCount(copies); //exits the GetBookData method ISBN = -1; string status = "Available"; myBooks[indexFound].SetStatus(status); Console.Clear(); Console.WriteLine("This ISBN already exists... a copy has been added"); Console.WriteLine("\nPress enter to continue..."); Console.ReadLine(); } } Console.Clear(); Console.WriteLine("\nBook(s) inputed"); Console.WriteLine("\nPress enter to continue..."); Console.ReadLine(); return(myBooks); }
static void Main(string[] args) { string selection = ""; while (selection != "exit") { selection = GetSelection(); BookFile data = new BookFile("books.txt"); Book[] myBooks = data.ReadBookData(); BookUtility bookUtility = new BookUtility(myBooks); BookFile bookFile = new BookFile("books.txt"); TranFile tranFile = new TranFile("transactions.txt"); Transactions[] myTransactions = new Transactions[200]; TranUtility tranUtility = new TranUtility(myTransactions); BookReport bookReport = new BookReport(myTransactions); //check the user selection and take them to the appropriate methods if (selection == "add") { Console.Clear(); myBooks = Book.GetBookData(); //everytime a book is added, the array gets sorted (to prepare for any binary searches), and then the book text file is cleared and the sorted info is inputed Book.SortAndSend(myBooks); } if (selection == "edit book") { Console.Clear(); Book.Edit(myBooks); } if (selection == "view") { Console.Clear(); Console.WriteLine("\nBooks available for rent:\n\n"); for (int i = 0; i < Book.GetCount(); i++) { if (myBooks[i].GetStatus() == "Available") { Console.WriteLine(myBooks[i]); } } Console.WriteLine("\nPress enter to continue..."); Console.ReadLine(); } if (selection == "rent") { //Lets the user input which book ISBN is to be rented Console.Clear(); myTransactions = Transactions.GetTransactionData(myBooks); Transactions.PrintRent(myTransactions); //Marks the book as rented in the book text file string rentPath = "books.txt"; File.WriteAllText(rentPath, String.Empty); TextWriter twP = new StreamWriter(rentPath, true); twP.Close(); Book.ToFile(myBooks); //write what is in the transactions array to the text file, read the text file and send back to array, sort the array Transactions.ToFile(myTransactions); myTransactions = tranFile.ReadTranData(); tranUtility.SelectionSort(myTransactions); Transactions.PrintRent(myTransactions); //clear and re-send sorted and edited array (update the text file) string tranPath = "transactions.txt"; File.WriteAllText(tranPath, String.Empty); TextWriter tWTran = new StreamWriter(tranPath, true); tWTran.Close(); Transactions.ToFile(myTransactions); } if (selection == "return") { Console.Clear(); //reading book file into array for use in book count returning myBooks = bookFile.ReadBookData(); //reading transaction file data into array for use myTransactions = tranFile.ReadTranData(); //show user books that can be returned Console.WriteLine("Book log:\n"); Transactions.PrintRent(myTransactions); Transactions.BookReturn(myTransactions, myBooks); //once the book is returned, send the updated array to the text file string path2 = "books.txt"; File.WriteAllText(path2, String.Empty); TextWriter tW2 = new StreamWriter(path2, true); tW2.Close(); Book.ToFile(myBooks); Console.WriteLine("\nBook returned."); Console.WriteLine("\nPress enter to continue... "); Console.ReadLine(); } if (selection == "total") { //reading transaction file data into array for use myTransactions = tranFile.ReadTranData(); bookReport.TotalReport(myTransactions); } if (selection == "individual") { Console.Clear(); //reading transaction file data into array for use myTransactions = tranFile.ReadTranData(); //sort by name before calling IndividualReport method tranUtility.SelectionSort(myTransactions); //calls method report BookReport.IndividualReport(myTransactions); Console.WriteLine("\nPress enter to continue... "); Console.ReadLine(); } if (selection == "historical") { myTransactions = tranFile.ReadTranData(); TranUtility.SelectionSortHist(myTransactions); Console.Clear(); Console.WriteLine("Here is the historical list: "); Console.WriteLine(""); bookReport.CustDateSort(myTransactions); Transactions.PrintRent(myTransactions); bookReport.Write(myTransactions); } if (selection == "delete") { Console.Clear(); Book.LineDelete(myBooks); Console.WriteLine("\nPress enter to continue..."); Console.ReadLine(); } if (selection == "genre") { Console.Clear(); myBooks = bookFile.ReadBookData(); BookUtility.SelectionSortGenre(myBooks); bookReport.GenreReport(myBooks); Console.WriteLine("\nPress enter to continue..."); Console.ReadLine(); } if (selection == "edit transaction") { Console.Clear(); myTransactions = tranFile.ReadTranData(); TranUtility.SelectionSortID(myTransactions); Transactions.Edit(myTransactions); } } Console.Clear(); Console.WriteLine("\n\n\n\n\n\n\nThanks for using my database!\n\n\n\n\n\n"); }
static void Main(string[] args) { string selection = ""; while (selection != "exit") { selection = GetSelection(); // Book[] myBooks = Book.GetBookData(); // Book.SortAndSend(myBooks); BookFile data = new BookFile("books.txt"); Book[] myBooks = data.ReadBookData(); BookUtility bookUtility = new BookUtility(myBooks); BookFile bookFile = new BookFile("books.txt"); TranFile tranFile = new TranFile("transactions.txt"); Transactions[] myTransactions = new Transactions[200]; TranUtility tranUtility = new TranUtility(myTransactions); BookReport bookReport = new BookReport(myTransactions); if (selection == "add") { myBooks = Book.GetBookData(); Book.SortAndSend(myBooks); } if (selection == "edit") { Book.Edit(myBooks); } if (selection == "view") { Console.WriteLine("\nBooks available for rent:\n\n"); for (int i = 0; i < Book.GetCount(); i++) { if (myBooks[i].GetStatus() == "Available") { Console.WriteLine(myBooks[i].GetTitle()); } } Console.WriteLine("\nPress enter to continue: "); Console.ReadLine(); } if (selection == "rent") { //Lets the user input which book ISBN is to be rented myTransactions = Transactions.GetTransactionData(myBooks); Transactions.PrintRent(myTransactions); //Marks the book as rented in the book text file string rentPath = "books.txt"; File.WriteAllText(rentPath, String.Empty); TextWriter twP = new StreamWriter(rentPath, true); twP.Close(); Book.ToFile(myBooks); //write what is in the transactions array to the text file, read the text file and send back to array, sort the array Transactions.ToFile(myTransactions); myTransactions = tranFile.ReadTranData(); tranUtility.SelectionSort(myTransactions); Transactions.PrintRent(myTransactions); //clear and re-send sorted and edited array (update the text file) string tranPath = "transactions.txt"; File.WriteAllText(tranPath, String.Empty); TextWriter tWTran = new StreamWriter(tranPath, true); tWTran.Close(); Transactions.ToFile(myTransactions); } if (selection == "return") { Console.Clear(); myTransactions = tranFile.ReadTranData(); Transactions.PrintRent(myTransactions); //return book Console.WriteLine("\nEnter the ISBN of the book to be returned: "); //search user return ISBN in transaction file int tempTranISBN = int.Parse(Console.ReadLine()); Console.WriteLine("\nEnter the customer's email: "); string tempEmail = Console.ReadLine(); for (int i = 1; i < Transactions.GetTranCount(); i++) { int tempFound = TranUtility.BinarySearch(myTransactions, tempTranISBN); if (tempEmail == myTransactions[i].GetCustomerEmail()) { if (i == tempFound) { //find the isbn instance in the transaction file and replace the N/A with the current date (date of return) string newReturnDate = DateTime.Now.ToString("M/d/yyyy"); myTransactions[tempFound].SetReturnDate(newReturnDate); } } } string tranPath = "transactions.txt"; File.WriteAllText(tranPath, String.Empty); TextWriter tWTran = new StreamWriter(tranPath, true); tWTran.Close(); Transactions.ToFile(myTransactions); Console.WriteLine("\nBook returned."); Console.WriteLine("\nPress enter to continue: "); Console.ReadLine(); } if (selection == "total") { myTransactions = tranFile.ReadTranData(); tranUtility.SelectionSort(myTransactions); //clear and re-send sorted and edited array (update the text file) string returnPath = "transactions.txt"; File.WriteAllText(returnPath, String.Empty); TextWriter tWReturn = new StreamWriter(returnPath, true); tWReturn.Close(); Transactions.ToFile(myTransactions); BookReport.SortDate(myTransactions); Console.WriteLine("\nTotal rentals by month and year: \n"); Transactions.PrintRent(myTransactions); Console.ReadLine(); Console.WriteLine("Would you like to save these to a text file? (yes or no) "); string answer = Console.ReadLine(); if (answer.ToLower() == "yes") { Console.WriteLine("\nEnter the name of the text file: "); string tempTxt = Console.ReadLine(); StreamWriter outFile = new StreamWriter(tempTxt); for (int i = 0; i < Transactions.GetTranCount(); i++) { outFile.WriteLine(myTransactions[i].GetRentID() + "#" + myTransactions[i].GetTranISBN() + "#" + myTransactions[i].GetCustomerName() + "#" + myTransactions[i].GetCustomerEmail() + "#" + myTransactions[i].GetRentDate() + "#" + myTransactions[i].GetReturnDate()); } outFile.Close(); } } if (selection == "individual") { myTransactions = tranFile.ReadTranData(); tranUtility.SelectionSort(myTransactions); //clear and re-send sorted and edited array (update the text file) string returnPath = "transactions.txt"; File.WriteAllText(returnPath, String.Empty); TextWriter tWReturn = new StreamWriter(returnPath, true); tWReturn.Close(); Transactions.ToFile(myTransactions); Console.WriteLine("\nEnter the customer's email: "); string tempIndvEmail = Console.ReadLine(); Console.WriteLine("\nCustomer rental history: \n"); for (int i = 1; i < Transactions.GetTranCount(); i++) { if (tempIndvEmail == myTransactions[i].GetCustomerEmail()) { Console.WriteLine(myTransactions[i]); } } Console.WriteLine("\nWould you like to enter this into a text file? (yes or no)"); string choice = Console.ReadLine(); if (choice.ToLower() == "yes") { Console.WriteLine("\nEnter the name of the text file: "); string tempTxt = Console.ReadLine(); StreamWriter outFile = new StreamWriter(tempTxt); for (int i = 1; i < Transactions.GetTranCount(); i++) { if (tempIndvEmail == myTransactions[i].GetCustomerEmail()) { outFile.WriteLine(myTransactions[i].GetRentID() + "#" + myTransactions[i].GetTranISBN() + "#" + myTransactions[i].GetCustomerName() + "#" + myTransactions[i].GetCustomerEmail() + "#" + myTransactions[i].GetRentDate() + "#" + myTransactions[i].GetReturnDate()); } } outFile.Close(); } Console.WriteLine("\nPress enter to continue: "); Console.ReadLine(); } if (selection == "historical") { myTransactions = tranFile.ReadTranData(); BookReport.CustDateSort(myTransactions); } } }