// 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 } }
private void checkOutToolStripMenuItem_Click(object sender, EventArgs e) { //sends the items, and patrons list to the checkout subform CheckoutForm checkoutForm = new CheckoutForm(newLibrary._items, newLibrary._patrons); DialogResult result; //holds the dialog result int item; //holds the item index int patron; //holds the patron index result = checkoutForm.ShowDialog(); if (result == DialogResult.OK)// Only update if user chose OK from dialog box { item = checkoutForm.ITEM; patron = checkoutForm.PATRON; newLibrary.CheckOut(item, patron); } }
// Precondition: None // Postcondition: Opens a dialog box that will check out an item in the library private void checkoutToolStripMenuItem_Click(object sender, EventArgs e) { CheckoutForm Checkout = new CheckoutForm(); // Variable that interacts with the checkout form foreach (var item in _lib.GetItemsList()) { Checkout.itemCombobox.Items.Add($"{item.Title},{item.CallNumber}"); } foreach (var patron in _lib.GetPatronsList()) { Checkout.patronCombobox.Items.Add($"{patron.PatronName},{patron.PatronID}"); } result = Checkout.ShowDialog(); int itemindex; int patronindex; if (result == DialogResult.OK) { itemindex = Checkout.itemCombobox.SelectedIndex; patronindex = Checkout.patronCombobox.SelectedIndex; _lib.CheckOut(itemindex, patronindex); } }
// 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 } }