예제 #1
0
        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");
        }
예제 #2
0
        public void TotalReport(Transactions[] myTransactions)
        {
            Console.Clear();
            BookReport.SortDate(myTransactions);
            Console.WriteLine("\nTotal rentals by month and year: \n");
            Transactions.PrintRent(myTransactions);
            Console.WriteLine("");
            Console.WriteLine("");

            string yearStr    = myTransactions[0].GetRentDate().Substring(6, 4);
            int    monthCount = 0;
            string monthStr   = myTransactions[0].GetRentDate().Substring(0, 2);

            Console.WriteLine("\nWould you like to see a report for a specific month? ('yes' or 'no')");
            string yes = Console.ReadLine();

            if (yes == "yes")
            {
                Console.Clear();
                Console.WriteLine("Enter a month and year to see the report from that month:\n");
                Console.WriteLine("ATTENTION: enter month as 'MM' and year as 'YYYY'");
                Console.WriteLine("\nEnter a month:\n");
                int    monthIntTemp = int.Parse(Console.ReadLine());
                string monthTemp    = monthIntTemp.ToString();
                Console.WriteLine("\nEnter a year:\n");
                string yearTemp = Console.ReadLine();

                for (int i = 0; i < Transactions.GetTranCount(); i++)
                {
                    if (yearTemp == myTransactions[i].GetRentDate().Substring(6, 4) && monthTemp == myTransactions[i].GetRentDate().Substring(0, 2))
                    {
                        monthCount++;
                    }
                }

                DateTime date      = new DateTime(2020, monthIntTemp, 1);
                string   wordMonth = date.ToString("MMMM");

                Console.Clear();
                Console.WriteLine("\nNumber of rentals in " + wordMonth + ": " + monthCount);
                Console.WriteLine("");
                for (int i = 0; i < Transactions.GetTranCount(); i++)
                {
                    if (yearTemp == myTransactions[i].GetRentDate().Substring(6, 4) && monthTemp == myTransactions[i].GetRentDate().Substring(0, 2))
                    {
                        Console.WriteLine(myTransactions[i]);
                    }
                }
                Console.WriteLine("\nPress enter to continue...");
                Console.ReadLine();

                Console.WriteLine("\nWould you like to write this to 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);
                    //Streamwrite the info written out above into a text file of the user's choice
                    for (int i = 0; i < Transactions.GetTranCount(); i++)
                    {
                        if (yearTemp == myTransactions[i].GetRentDate().Substring(6, 4) && monthTemp == myTransactions[i].GetRentDate().Substring(0, 2))
                        {
                            outFile.WriteLine(myTransactions[i]);
                        }
                    }
                    outFile.Close();
                    Console.WriteLine("\nSuccess! Text entered. (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);
                }
            }
        }