//used in program.cs to read info from text file into array public Transactions[] ReadTranData() { StreamReader inFile = new StreamReader(fileName); Transactions[] myTransactions = new Transactions[200]; string data = inFile.ReadLine(); Transactions.SetTranCount(0); while (data != null) { string[] temp = data.Split('#'); int tempRentID = int.Parse(temp[0]); int tempTranISBN = int.Parse(temp[1]); string custName = temp[2]; string custEmail = temp[3]; string rentDate = temp[4]; string returnDate = temp[5]; myTransactions[Transactions.GetTranCount()] = new Transactions(tempRentID, tempTranISBN, temp[2], temp[3], temp[4], temp[5]); myTransactions[Transactions.GetTranCount()].ToString(); Transactions.IncrTranCount(); data = inFile.ReadLine(); } inFile.Close(); return(myTransactions); }
public static Transactions[] GetTransactionData(Book[] myBooks) { Transactions[] myTransactions = new Transactions[200]; Console.WriteLine("Enter the ISBN of the book to be marked as rented (-1 to stop):\n "); int tranISBN = int.Parse(Console.ReadLine()); while (tranISBN != -1) { int indexFound = BookUtility.BinarySearch(myBooks, tranISBN); if (myBooks[indexFound].GetBookCount() > 0) { int copies1 = myBooks[indexFound].GetBookCount() - 1; myBooks[indexFound].SetBookCount(copies1); if (myBooks[indexFound].GetBookCount() == 0) { string status = "Rented"; myBooks[indexFound].SetStatus(status); } Console.WriteLine("Enter the customer's name:\n"); string customerName = Console.ReadLine(); Console.WriteLine("Enter the customer's email:\n"); string customerEmail = Console.ReadLine(); Random rnd = new Random(); int rentID = rnd.Next(); string rentDate = DateTime.Now.ToString("M/d/yyyy"); string returnDate = "N/A"; Transactions newTransactions = new Transactions(rentID, tranISBN, customerName, customerEmail, rentDate, returnDate); myTransactions[Transactions.GetTranCount()] = newTransactions; Transactions.IncrTranCount(); Console.WriteLine("Enter the ISBN of the book to be rented (-1 to stop):\n "); tranISBN = int.Parse(Console.ReadLine()); } else { Console.WriteLine("\nERROR... There are no available copies of this book\n"); GetTransactionData(myBooks); } } return(myTransactions); }
public static Transactions[] GetTransactionData(Book[] myBooks) { //creates transaction array to input books to be marked as rented Transactions[] myTransactions = new Transactions[200]; //show available books 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(); //get ISBN from user to identify boook being rented Console.WriteLine("Enter the ISBN of the book to be marked as rented (-1 to stop):\n "); int tranISBN = int.Parse(Console.ReadLine()); while (tranISBN != -1) { //search book array for ISBN int indexFound = BookUtility.BinarySearch(myBooks, tranISBN); //if the number of book copies is greater than 0 (there are still books available under this ISBN) if (myBooks[indexFound].GetBookCount() > 0) { //subract one from the number of book copies (one has been rented) int copies1 = myBooks[indexFound].GetBookCount() - 1; myBooks[indexFound].SetBookCount(copies1); //if the copy count now equals zero, mark the status under the book file as rented ie. there are none left if (myBooks[indexFound].GetBookCount() == 0) { string status = "Rented"; myBooks[indexFound].SetStatus(status); } //get rest of renter's info Console.Clear(); Console.WriteLine("\nEnter the customer's name:\n"); string customerName = Console.ReadLine(); Console.WriteLine("\nEnter the customer's email:\n"); string customerEmail = Console.ReadLine(); //rent ID randomized Random rnd = new Random(); int rentID = rnd.Next(); //rent date set to current date, return date set to N/A (per Dr. Saifee's instruction) string rentDate = DateTime.Now.ToString("MM/dd/yyyy"); string returnDate = "N/A"; Transactions newTransactions = new Transactions(rentID, tranISBN, customerName, customerEmail, rentDate, returnDate); myTransactions[Transactions.GetTranCount()] = newTransactions; Transactions.IncrTranCount(); Console.Clear(); Console.WriteLine("Enter the ISBN of the book to be rented (-1 to stop):\n "); tranISBN = int.Parse(Console.ReadLine()); } //if user tries to rent a book that there are no available copies of, error message is presented else { Console.WriteLine("\nERROR... There are no available copies of this book\n"); GetTransactionData(myBooks); } Console.WriteLine("\nBooks rented. Press enter to continue"); Console.ReadLine(); } return(myTransactions); }