Ejemplo n.º 1
0
        //Precondition: return menu item click
        //Postcondition: show return form and pass data to checkout form
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReturnForm   returnDialog = new ReturnForm(LibraryData.GetItemsList());
            DialogResult result;

            result = returnDialog.ShowDialog();
            if (result == DialogResult.OK)
            {
                LibraryData.ReturnToShelf(returnDialog.items);
            }
        }
Ejemplo n.º 2
0
        // Precondition:  Item, Return menu item activated
        // Postcondition: The Return dialog box is displayed. If data entered
        //                are OK, an item is returned to the library
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Extra Credit - Only display items that are already checked out

            List <LibraryItem> checkedOutList;    // List of items checked out
            List <int>         checkedOutIndices; // List of index values of items checked out
            List <LibraryItem> items;             // List of library items

            items             = _lib.GetItemsList();
            checkedOutList    = new List <LibraryItem>();
            checkedOutIndices = new List <int>();

            for (int i = 0; i < items.Count(); ++i)
            {
                if (items[i].IsCheckedOut()) // Checked out
                {
                    checkedOutList.Add(items[i]);
                    checkedOutIndices.Add(i);
                }
            }

            if ((checkedOutList.Count() == 0)) // Must have checked out items
            {
                MessageBox.Show("Must have items to return!", "Return Error");
            }
            else
            {
                ReturnForm returnForm = new ReturnForm(checkedOutList); // The return dialog box form

                DialogResult result = returnForm.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 = checkedOutIndices[returnForm.ItemIndex];                             // Look up index from full list
                        decimal lateFee = _lib.ReturnToShelf(_lib.GetItemsList()[itemIndex].CallNumber); //Changed to
                        //correspond with the new ReturnToShelf parameters; also assigns the return value to a decimal so
                        //that it can be displayed in a MessageBox
                        MessageBox.Show($"Late Fee: {lateFee:C}");
                    }
                    catch (ArgumentOutOfRangeException) // This should never happen
                    {
                        MessageBox.Show("Problem with Return Index!", "Return Error");
                    }
                }

                returnForm.Dispose(); // Good .NET practice - will get garbage collected anyway
            }
        }
Ejemplo n.º 3
0
        // Precondition:  None
        // Postcondition: Returns items using return form
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReturnForm   retrnForm = new ReturnForm(_lib.GetItemsList());
            DialogResult result;

            result = retrnForm.ShowDialog();

            if (result == DialogResult.OK) // Checks out item based on validated user selection
            {
                _lib.ReturnToShelf(retrnForm.ItemsValue);
                MessageBox.Show("You have returned this library item!");
            }
        }
Ejemplo n.º 4
0
        // Precondition:  None
        // Postcondition: Return's the items that the user selects to return from the subform Returnform.
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //sends the items list to the return subform
            ReturnForm   returnForm = new ReturnForm(newLibrary._items);
            DialogResult result; //holds the dialog result
            int          item;   //holds the item index

            result = returnForm.ShowDialog();

            if (result == DialogResult.OK)// Only update if user chose OK from dialog box
            {
                item = returnForm.Item;
                newLibrary.ReturnToShelf(item);
            }
        }
Ejemplo n.º 5
0
        //Precondition: Item -> return item is activated
        //Postcondition: Item is returned
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <LibraryItem>   items;   //List of library items
            List <LibraryPatron> patrons; //List of library patrons

            items   = library.GetItemsList();
            patrons = library.GetPatronsList();

            ReturnForm   returnForm = new ReturnForm(items);   //Check out dialog box form
            DialogResult result     = returnForm.ShowDialog(); //Show form as dialog & store the result

            if (result == DialogResult.OK)
            {
                library.ReturnToShelf(returnForm.ItemIndex);
            }
        }
Ejemplo n.º 6
0
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {                                                                    //precondition: none
            //postcondition:returns book
            ReturnForm returnBox = new ReturnForm(item._items, item._patrons //instance of return form
                                                  );
            //instance of checkout form

            DialogResult result;

            result = returnBox.ShowDialog();
            if (returnBox.bookcomboBox.SelectedIndex >= 0)
            {
                item._items[returnBox.bookcomboBox.SelectedIndex].
                ReturnToShelf();
                mainTxt.Clear();
            }
        }
Ejemplo n.º 7
0
        // Precondition: None
        // Postcondition: Opens a Dialog box that will return an item to the library
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ReturnForm Return = new ReturnForm(); // Variable that interacts with the return form

            foreach (var item in _lib.GetItemsList())
            {
                Return.returnComboBox.Items.Add($"{item.Title},{item.CallNumber}");
            }
            int itemindex; //value that was selected from the form

            result = Return.ShowDialog();

            if (result == DialogResult.OK)
            {
                itemindex = Return.returnComboBox.SelectedIndex;
                _lib.ReturnToShelf(itemindex);
            }
        }
Ejemplo n.º 8
0
        // Precondition:  Item, Return menu item activated
        // Postcondition: The Return dialog box is displayed. If data entered
        //                are OK, an item is returned to the library
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items;     // List of library items

            items = _lib.GetItemsList();

            if ((_lib.GetCheckedOutCount() == 0)) // Must have items to return
            {
                MessageBox.Show("Must have items to return!", "Return Error");
            }
            else
            {
                ReturnForm returnForm = new ReturnForm(items); // The return dialog box form

                DialogResult result = returnForm.ShowDialog(); // Show form as dialog and store result

                if (result == DialogResult.OK)                 // Only add if OK
                {
                    _lib.ReturnToShelf(returnForm.ItemIndex);
                }

                returnForm.Dispose(); // Good .NET practice - will get garbage collected anyway
            }
        }
Ejemplo n.º 9
0
        // Precondition:  Item, Return menu item activated
        // Postcondition: The Return dialog box is displayed. If data entered
        //                are OK, an item is returned to the library
        private void returnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Extra Credit - Only display items that are already checked out

            List<LibraryItem> checkedOutList; // List of items checked out
            List<int> checkedOutIndices;      // List of index values of items checked out
            List<LibraryItem> items;          // List of library items
            List<LibraryPatron> patrons;      // List of patrons

            items = lib.GetItemsList();
            patrons = lib.GetPatronsList();
            checkedOutList = new List<LibraryItem>();
            checkedOutIndices = new List<int>();

            for (int i = 0; i < items.Count(); ++i)
                if (items[i].IsCheckedOut()) // Checked out
                {
                    checkedOutList.Add(items[i]);
                    checkedOutIndices.Add(i);
                }

            if ((checkedOutList.Count() == 0)) // Must have checked out items
                MessageBox.Show("Must have checked out items to return!", "Return Error");
            else
            {
                ReturnForm returnForm = new ReturnForm(checkedOutList); // The return dialog box form

                DialogResult result = returnForm.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 = checkedOutIndices[returnForm.ItemIndex]; // Look up index from full list
                        lib.ReturnToShelf(itemIndex);
                    }
                    catch (ArgumentOutOfRangeException) // This should never happen
                    {
                        MessageBox.Show("Problem with Return Index!", "Return Error");
                    }
                }
                returnForm.Dispose(); // Good .NET practice - will get garbage collected anyway
            }
        }
Ejemplo n.º 10
0
        // Precondition:  Edit, Book menu item activated
        // Postcondition: The book selected from the library has been edited
        //                with the new information replacing the existing object's
        //                properties
        private void bookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> bookItems; // List of items that are books
            List <LibraryItem> items;     // List of library items

            items     = _lib.GetItemsList();
            bookItems = new List <LibraryItem>();

            for (int i = 0; i < items.Count(); ++i)
            {
                if (items[i] is LibraryBook) // Book?
                {
                    bookItems.Add(items[i]);
                }
            }

            if ((bookItems.Count() == 0)) // Must have books to edit
            {
                MessageBox.Show("Must have books to edit!", "Edit Error");
            }
            else
            {
                ReturnForm siForm = new ReturnForm(bookItems); // The select item dialog box form
                                                               // Just reused ReturnForm, they are identical
                siForm.Text = "Edit Book";                     // Change return form's title to match new purpose

                DialogResult result = siForm.ShowDialog();     // Show form as dialog and store result

                if (result == DialogResult.OK)                 // Only edit if OK
                {
                    int selectedIndex;                         // Index of selected item

                    selectedIndex = siForm.ItemIndex;

                    if (selectedIndex >= 0)                                             // -1 if didn't select item from combo box (should never happen!)
                    {
                        LibraryBook editBook = bookItems[selectedIndex] as LibraryBook; // Book being edited

                        //LibraryBook editBook = (LibraryBook)bookItems[selectedIndex]; // Book being edited
                        // Need downcast to get to Author
                        BookForm bookForm = new BookForm(); // The book dialog box form

                        // Populate form fields from selected book
                        bookForm.ItemTitle         = editBook.Title;
                        bookForm.ItemPublisher     = editBook.Publisher;
                        bookForm.ItemCallNumber    = editBook.CallNumber;
                        bookForm.ItemCopyrightYear = editBook.CopyrightYear.ToString("D4"); // ToString since property is String on form
                        bookForm.ItemLoanPeriod    = editBook.LoanPeriod.ToString();        // ToString since property is String on form
                        bookForm.BookAuthor        = editBook.Author;

                        DialogResult editResult = bookForm.ShowDialog(); // Show form as dialog and store result

                        if (editResult == DialogResult.OK)               // Only update book if OK
                        {
                            // Edit book properties using form fields
                            try
                            {
                                //Edits the item dictionary so that it isn't corrupted due to the keys changing
                                //_lib.ChangeItemKey(bookItems[selectedIndex].CallNumber, editBook.CallNumber, editBook);

                                editBook.Title     = bookForm.ItemTitle;
                                editBook.Publisher = bookForm.ItemPublisher;
                                //editBook.CallNumber = bookForm.ItemCallNumber; //(Edited out to prevent corruption of
                                //dictionary
                                editBook.Author        = bookForm.BookAuthor;
                                editBook.CopyrightYear = int.Parse(bookForm.ItemCopyrightYear);
                                editBook.LoanPeriod    = int.Parse(bookForm.ItemLoanPeriod);
                            }
                            catch (FormatException) // This should never happen if form validation works!
                            {
                                MessageBox.Show("Problem with Book Validation!", "Validation Error");
                            }
                        }
                        bookForm.Dispose(); // Good .NET practice - will get garbage collected anyway
                    }
                }
                siForm.Dispose(); // Good .NET practice - will get garbage collected anyway
            }
        }
Ejemplo n.º 11
0
        // Precondition:  Item, Return menu item activated
        // Postcondition: The Return dialog box is displayed. If data entered
        //                are OK, an item is returned to the library
        private void returnToolStripMenuItem_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 return!", "Return Error");
            else
            {
                ReturnForm returnForm = new ReturnForm(items); // The return dialog box form

                DialogResult result = returnForm.ShowDialog(); // Show form as dialog and store result

                if (result == DialogResult.OK) // Only add if OK
                {
                    lib.ReturnToShelf(returnForm.ItemIndex);
                }

                returnForm.Dispose(); // Good .NET practice - will get garbage collected anyway
            }
        }