示例#1
0
        // Precondition:  Report, Checked Out Items menu item activated
        // Postcondition: The list of checked out items is displayed in the
        //                reportTxt text box
        private void checkedOutItemsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StringBuilder result = new StringBuilder(); // Holds text as report being built
                                                        // StringBuilder more efficient than String
            List <LibraryItem>            items;        // List of library items
            Dictionary <string, DateTime> transactions; // Dictionary of CheckedOutTransactions
            string NL = Environment.NewLine;            // NewLine shortcut

            items        = _lib.GetItemsList();
            transactions = _lib.GetCheckedOutTransactions(); //Retrives the list of transactions

            // LINQ: selects checked out items
            var checkedOutItems =
                from item in items
                where item.IsCheckedOut()
                select item;

            result.Append($"Checked Out Items - {checkedOutItems.Count()} items{NL}{NL}");

            foreach (LibraryItem item in checkedOutItems) //String edited to display the items checkout date and due date
            {
                result.Append($"{item}{NL}Date Checked Out: {transactions[item.CallNumber].Date.ToShortDateString()}{NL}Date Due: {transactions[item.CallNumber].Date.AddDays(item.LoanPeriod).ToShortDateString()}{NL}");
            }

            reportTxt.Text = result.ToString();

            // Put cursor at start of report
            reportTxt.SelectionStart = 0;
        }
示例#2
0
        // Precondition:  Report, Checked Out Items menu item activated
        // Postcondition: The list of checked out items is displayed in the
        //                reportTxt text box
        private void checkedOutItemsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            StringBuilder result = new StringBuilder();              // Holds text as report being built
                                                                     // StringBuilder more efficient than String
            List <LibraryItem>             items;                    // List of library items
            string                         NL = Environment.NewLine; // NewLine shortcut
            IDictionary <string, DateTime> transDates;

            items = _lib.GetItemsList();

            // LINQ: selects checked out items
            var checkedOutItems =
                from item in items
                where item.IsCheckedOut()
                select item;

            transDates = _lib.GetCheckedOutTransactions();
            result.Append($"Checked Out Items - {checkedOutItems.Count()} items{NL}{NL}");


            // Walk thru list and print out all attributes and transaction dates of each checked out item
            for (int i = 0; i < checkedOutItems.Count(); i++)
            {
                result.Append($"{checkedOutItems.ElementAt(i)}{NL}Checked Out Date: {transDates.ElementAt(i).Value.ToShortDateString()}{NL}" +
                              $"Return By: {transDates.ElementAt(i).Value.AddDays(FindLoanPeriod(transDates.ElementAt(i).Key)).ToShortDateString()}{NL}{NL}");
            }

            // set final string to the actual text box
            reportTxt.Text = result.ToString();

            // Put cursor at start of report
            reportTxt.SelectionStart = 0;
        }