// Precondition: Item, Check Out menu item activated // Postcondition: The Checkout dialog box is displayed. If data entered // are OK, an item is checked out from the library by a patron private void checkOutToolStripMenuItem_Click(object sender, EventArgs e) { List <LibraryItem> items; // List of library items List <LibraryPatron> patrons; // List of patrons items = _lib.GetItemsList(); patrons = _lib.GetPatronsList(); if (((items.Count - _lib.GetCheckedOutCount()) == 0) || (patrons.Count() == 0)) // Must have items and patrons { MessageBox.Show("Must have items and patrons to check out!", "Check Out Error"); } else { CheckoutForm checkoutForm = new CheckoutForm(items, patrons); // The check out dialog box form DialogResult result = checkoutForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { _lib.CheckOut(checkoutForm.ItemIndex, checkoutForm.PatronIndex); } checkoutForm.Dispose(); // Good .NET practice - will get garbage collected anyway } }
// Precondition: Item, Check Out menu item activated // Postcondition: The Checkout dialog box is displayed. If data entered // are OK, an item is checked out from the library by a patron private void checkOutToolStripMenuItem_Click(object sender, EventArgs e) { // Extra Credit - Only display items that aren't already checked out List <LibraryItem> notCheckedOutList; // List of items not checked out List <int> notCheckedOutIndices; // List of index values of items not checked out List <LibraryItem> items; // List of library items List <LibraryPatron> patrons; // List of patrons items = lib.GetItemsList(); patrons = lib.GetPatronsList(); items = lib.GetItemsList(); patrons = lib.GetPatronsList(); notCheckedOutList = new List <LibraryItem>(); notCheckedOutIndices = new List <int>(); for (int i = 0; i < items.Count(); ++i) { if (!items[i].IsCheckedOut()) // Not checked out { notCheckedOutList.Add(items[i]); notCheckedOutIndices.Add(i); } } if ((notCheckedOutList.Count() == 0) || (patrons.Count() == 0)) // Must have items and patrons { MessageBox.Show("Must have items and patrons to check out!", "Check Out Error"); } else { CheckoutForm checkoutForm = new CheckoutForm(notCheckedOutList, patrons); // The check out dialog box form DialogResult result = checkoutForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { try { int itemIndex; // Index of item from full list of items itemIndex = notCheckedOutIndices[checkoutForm.ItemIndex]; // Look up index from full list lib.CheckOut(itemIndex, checkoutForm.PatronIndex); } catch (ArgumentOutOfRangeException) // This should never happen { MessageBox.Show("Problem with Check Out Index!", "Check Out Error"); } } checkoutForm.Dispose(); // Good .NET practice - will get garbage collected anyway } }
// Precondition: Item, Check Out menu item activated // Postcondition: The Checkout dialog box is displayed. If data entered // are OK, an item is checked out from the library by a patron private void checkOutToolStripMenuItem_Click(object sender, EventArgs e) { // Extra Credit - Only display items that aren't already checked out List<LibraryItem> notCheckedOutList; // List of items not checked out List<int> notCheckedOutIndices; // List of index values of items not checked out List<LibraryItem> items; // List of library items List<LibraryPatron> patrons; // List of patrons items = lib.GetItemsList(); patrons = lib.GetPatronsList(); notCheckedOutList = new List<LibraryItem>(); notCheckedOutIndices = new List<int>(); for (int i = 0; i < items.Count(); ++i) if (!items[i].IsCheckedOut()) // Not checked out { notCheckedOutList.Add(items[i]); notCheckedOutIndices.Add(i); } if ((notCheckedOutList.Count() == 0) || (patrons.Count() == 0)) // Must have items and patrons MessageBox.Show("Must have items and patrons to check out!", "Check Out Error"); else { CheckoutForm checkoutForm = new CheckoutForm(notCheckedOutList, patrons); // The check out dialog box form DialogResult result = checkoutForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { try { int itemIndex; // Index of item from full list of items itemIndex = notCheckedOutIndices[checkoutForm.ItemIndex]; // Look up index from full list lib.CheckOut(itemIndex, checkoutForm.PatronIndex); } catch (ArgumentOutOfRangeException) // This should never happen { MessageBox.Show("Problem with Check Out Index!", "Check Out Error"); } } checkoutForm.Dispose(); // Good .NET practice - will get garbage collected anyway } }
// Precondition: Item, Check Out menu item activated // Postcondition: The Checkout dialog box is displayed. If data entered // are OK, an item is checked out from the library by a patron private void checkOutToolStripMenuItem_Click(object sender, EventArgs e) { List<LibraryItem> items; // List of library items List<LibraryPatron> patrons; // List of patrons items = lib.GetItemsList(); patrons = lib.GetPatronsList(); if ((items.Count() == 0) || (patrons.Count() == 0)) // Must have items and patrons MessageBox.Show("Must have items and patrons to check out!", "Check Out Error"); else { CheckoutForm checkoutForm = new CheckoutForm(items, patrons); // The check out dialog box form DialogResult result = checkoutForm.ShowDialog(); // Show form as dialog and store result if (result == DialogResult.OK) // Only add if OK { lib.CheckOut(checkoutForm.ItemIndex, checkoutForm.PatronIndex); } checkoutForm.Dispose(); // Good .NET practice - will get garbage collected anyway } }