Ejemplo n.º 1
0
        // Precondition:  The checked out item list menu button is clicked.
        // Postcondition: Checked out item list is displayed in form
        //
        private void checkOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <LibraryItem> notcheckedoutitems = new List <LibraryItem>(); //creating an array of items not checked out
            DialogResult       result;                                        //the result of the dialog box

            // Each library item is added to the array of items not checked out
            foreach (LibraryItem i in newLibrary._items)
            {
                if (!i.IsCheckedOut())
                {
                    notcheckedoutitems.Add(i);
                }
            }

            //creating the checkout form (dialog)
            CheckOut checkout = new CheckOut(notcheckedoutitems, newLibrary.GetPatronsList());

            // Checkout form is shown
            result = checkout.ShowDialog();

            if (result == DialogResult.OK)
            {
                //This is the actual item selected by the user to return
                var selecteditem = notcheckedoutitems.ElementAt(checkout.ItemSelected);

                // Walking through the array looking for the item to return
                // When found, the item is returned.
                foreach (LibraryItem i in newLibrary.GetItemsList())
                {
                    if (i == selecteditem)
                    {
                        int positionOfItem = newLibrary.GetItemsList().IndexOf(i);    //position of the selected item

                        newLibrary.CheckOut(positionOfItem, checkout.PatronSelected); //returning the item
                    }
                }
            }
        }
        //Precondition: none
        //Postcondition: This will check out any books and output the information onto the Checked Out Report.
        private void checkOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CheckOut     inputForm = new CheckOut(_lib._items, _lib._patrons);
            DialogResult result    = inputForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                int    patronIndex = inputForm.PatronIndex;
                string callNo      = inputForm.CallNumber;
                int    itemindex   = -1;
                for (int x = 0; x < _lib._items.Count; ++x) // this for loop is used to make sure the user can't check out a book that is checked out by another patron.
                {
                    if (_lib._items[x].CallNumber == callNo)
                    {
                        itemindex = x;
                    }
                }
                if (itemindex > -1)
                {
                    _lib.CheckOut(itemindex, patronIndex);
                }
            }
        }