コード例 #1
0
ファイル: Transactions.cs プロジェクト: ptkatsaros1/Pa5-2-
        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 CustDateSort(Transactions[] myTransactions)
        {
            TranUtility.SelectionSortHist(myTransactions);

            string tempName = myTransactions[0].GetCustomerName();
            // string tempDate = myTransactions[0].GetRentDate();
            int count = 1;

            for (int i = 0; i < Transactions.GetTranCount(); i++)
            {
                if (tempName == myTransactions[i].GetCustomerName())
                {
                    Console.WriteLine(myTransactions[i]);
                }
                else
                {
                    ProcessBreak(myTransactions, ref tempName, ref count, i);
                }
            }
            ProcessBreak(myTransactions, ref tempName, ref count, 0);
        }
コード例 #3
0
ファイル: Transactions.cs プロジェクト: ptkatsaros1/finalPA
        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();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ptkatsaros1/finalPA
        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");
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: ptkatsaros1/Pa5-2-
        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);
                }
            }
        }