示例#1
0
        public static void BookReturn(Transactions[] 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);
                    }
                }
            }
            //clear and resend
            string path5 = "transactions.txt";

            File.WriteAllText(path5, String.Empty);
            TextWriter tW5 = new StreamWriter(path5, true);

            tW5.Close();
            ToFile(myTransactions);
        }
示例#2
0
        public static void Edit(Transactions[] myTransactions)
        {
            // edit function
            Console.WriteLine("Enter the rental ID of the transaction you would like to edit: ");
            int tempID = int.Parse(Console.ReadLine());
            //searching ISBN to be able to edit a specific book
            int indexFound = TranUtility.BinarySearch(myTransactions, tempID);

            Console.Clear();
            Console.WriteLine("Please enter:\n'ID' to edit the Rental ID\n'ISBN' to edit the ISBN\n'Name' to edit the Customer Name\n'Email' to edit the Customer Email\n'Rent Date' to change the Rent Date\n'Return' to change the 'Return Date'");
            string answer = Console.ReadLine().ToLower();

            if (answer == "id")
            {
                Console.Clear();
                Console.WriteLine("\nEnter a new ID:");
                int newID = int.Parse(Console.ReadLine());
                //finds the instance of the ID entered and makes an edit to ID at that instance
                myTransactions[indexFound].SetRentID(newID);
            }
            else if (answer == "isbn")
            {
                Console.Clear();
                Console.WriteLine("\nEnter a new ISBN:");
                int newISBN = int.Parse(Console.ReadLine());
                //finds the instance of the ID entered and makes an edit to ID at that instance
                myTransactions[indexFound].SetTranISBN(newISBN);
            }
            else if (answer == "name")
            {
                Console.Clear();
                Console.WriteLine("\nEnter a new customer name:");
                string newName = Console.ReadLine();
                //finds the instance of the ISBN entered and makes an edit to genre at that instance
                myTransactions[indexFound].SetCustomerName(newName);
            }
            else if (answer == "email")
            {
                Console.Clear();
                Console.WriteLine("\nEnter a new customer email:");
                string newCE = Console.ReadLine();
                //finds the instance of the ISBN entered and makes an edit to listening time at that instance
                myTransactions[indexFound].SetCustomerEmail(newCE);
            }
            else if (answer == "rent date")
            {
                Console.Clear();
                Console.WriteLine("\nEnter a new rental date (MM/dd/yyyy:");
                string newRD = Console.ReadLine();
                //finds the instance of the ISBN entered and makes an edit to listening time at that instance
                myTransactions[indexFound].SetRentDate(newRD);
            }
            else if (answer == "return")
            {
                Console.Clear();
                Console.WriteLine("\nEnter a new return date (MM/dd/yyyy):");
                string newRetD = Console.ReadLine();
                //finds the instance of the ISBN entered and makes an edit to listening time at that instance
                myTransactions[indexFound].SetReturnDate(newRetD);
            }

            // clear and re-send sorted and edited array (update the text file)
            string path2 = "transactions.txt";

            File.WriteAllText(path2, String.Empty);
            TextWriter tW2 = new StreamWriter(path2, true);

            tW2.Close();
            ToFile(myTransactions);

            Console.WriteLine("\nTransaction edited. Press enter to continue.");
            Console.ReadLine();
        }
示例#3
0
        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);
                }
            }
        }