Exemple #1
0
        }//fill comboboxes

        //precondition: none
        //postcondition: book form loaded and editing done through form
        private void bookBtn_Click(object sender, EventArgs e)
        {                                        //precondition: none
            //postcondition: brings up book form
            if (bookComboBox.SelectedIndex >= 0) //make sure something is selected
            {
                BookForm bookForm = new BookForm();
                bookForm.ItemTitle         = _items[bookComboBox.SelectedIndex].Title;
                bookForm.ItemPublisher     = _items[bookComboBox.SelectedIndex].Publisher;
                bookForm.ItemLoanPeriod    = _items[bookComboBox.SelectedIndex].LoanPeriod.ToString();
                bookForm.ItemCopyrightYear = _items[bookComboBox.SelectedIndex].CopyrightYear.ToString();
                bookForm.ItemCallNumber    = _items[bookComboBox.SelectedIndex].CallNumber;
                //adds in text to boxes

                DialogResult result = bookForm.ShowDialog(); // show form
                if (result == DialogResult.OK)               // make sure ok is clicked
                {
                    _items[bookComboBox.SelectedIndex].Title         = bookForm.ItemTitle;
                    _items[bookComboBox.SelectedIndex].Publisher     = bookForm.ItemPublisher;
                    _items[bookComboBox.SelectedIndex].LoanPeriod    = int.Parse(bookForm.ItemLoanPeriod);
                    _items[bookComboBox.SelectedIndex].CopyrightYear = int.Parse(bookForm.ItemCopyrightYear);
                    _items[bookComboBox.SelectedIndex].CallNumber    = bookForm.ItemCallNumber;


                    //edits properties to match text boxes
                }
            }
        }
Exemple #2
0
        // Precondition: clicked on edit book item on menu
        // Postcondition: dialog box will appear to choose item that is going to be edited
        //                user will make selection, then book form will appear that is populated
        //                with book data that will be edited
        private void itemToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            EditBookSelectionForm editBookForm = new EditBookSelectionForm(_lib.GetItemsList()); // form to choose book that is going to be edited
            DialogResult          result       = editBookForm.ShowDialog();                      // result from edit book form
            int bookIndex;                                                                       // selected book index

            if (result == DialogResult.OK)
            {
                LibraryBook book;
                bookIndex = editBookForm.SelectedBookIndex; // selected index
                book      = (LibraryBook)_lib._items[bookIndex];
                BookForm bookForm = new BookForm();         // book form to edit book object

                // passing book object data to book form
                bookForm.BookAuthor        = book.Author;
                bookForm.ItemCallNumber    = book.CallNumber;
                bookForm.ItemCopyrightYear = book.CopyrightYear.ToString();
                bookForm.ItemLoanPeriod    = book.LoanPeriod.ToString();
                bookForm.ItemPublisher     = book.Publisher;
                bookForm.ItemTitle         = book.Title;


                DialogResult result2 = bookForm.ShowDialog(); // show book form
                if (result2 == DialogResult.OK)               // result ok? then the book now has edited values
                {
                    //get data back from form and update book object
                    book.Author        = bookForm.BookAuthor;
                    book.CallNumber    = bookForm.ItemCallNumber;
                    book.Title         = bookForm.ItemTitle;
                    book.Publisher     = bookForm.ItemPublisher;
                    book.CopyrightYear = int.Parse(bookForm.ItemCopyrightYear);
                    book.LoanPeriod    = int.Parse(bookForm.ItemLoanPeriod);
                }
            }
        }
Exemple #3
0
        // Precondition:  BookEdit, Edit menu item activated
        // Postcondition: The BookEdit dialog box is displayed. If data entered
        //                are OK, file is opened
        private void bookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items; //list of items

            items = _lib.GetItemsList();

            if (items.Count == 0) // Must have items in list
            {
                MessageBox.Show("Must have an item in the Library");
            }
            else
            {
                BookEdit     bEditForm = new BookEdit(items); //dialogbox form book
                DialogResult result    = bEditForm.ShowDialog();

                if (result == DialogResult.OK) //Only allows selection if ok
                {
                    BookForm     bookEditor = new BookForm();
                    LibraryBook  item       = (LibraryBook)items[bEditForm.BookIndex];
                    DialogResult edited     = bookEditor.ShowDialog(); //Opens the BookForm to edit
                    if (edited == DialogResult.OK)                     //Only edits if ok
                    {
                        item.Title         = bookEditor.ItemTitle;
                        item.Publisher     = bookEditor.ItemPublisher;
                        item.CopyrightYear = int.Parse(bookEditor.ItemCopyrightYear);
                        item.LoanPeriod    = int.Parse(bookEditor.ItemLoanPeriod);
                        item.CallNumber    = bookEditor.ItemCallNumber;
                    }
                    bookEditor.Dispose();
                }
            }
        }
Exemple #4
0
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //creates the book subform and opens it.
            BookForm     bookForm = new BookForm();
            DialogResult result;        //Holds the dialog result
            string       title;         //holds the title of the book
            string       publisher;     //holds the publisher of the book
            int          copyRightYear; //holds the copyRightYear of the book
            int          loanPeriod;    //holds the loanPeriod of the book
            string       callNum;       //holds the callNum of the book
            string       author;        //holds the author of the book

            result = bookForm.ShowDialog();

            if (result == DialogResult.OK) // Update when user clicks OK
            {
                title         = bookForm.Title;
                publisher     = bookForm.Publisher;
                copyRightYear = int.Parse(bookForm.CopyRightYear);
                loanPeriod    = int.Parse(bookForm.LoanPeriod);
                callNum       = bookForm.CallNumber;
                author        = bookForm.Author;

                newLibrary.AddLibraryBook(title, publisher, copyRightYear, loanPeriod, callNum, author);
            }
        }
        //Preconditions: Edit, Book menu item activated
        //Postconditions: Opens a dialog box to select a book to edit, and another form to edit the book
        private void bookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items; //list of items

            items = _lib.GetItemsList();

            if (items.Count == 0) // Must have items in list
            {
                MessageBox.Show("Must have an item in the Library");
            }
            else
            {
                LibraryItemEdit edit   = new LibraryItemEdit(items);
                DialogResult    result = edit.ShowDialog();

                if (result == DialogResult.OK) //Only allows selection if ok
                {
                    LibraryItem  item   = items[edit.ItemIndex];
                    BookForm     editor = new BookForm();      //seperate form but same format from bookform
                    DialogResult edited = editor.ShowDialog(); //Opens the BookForm to edit
                    if (edited == DialogResult.OK)             //Only edits if ok
                    {
                        item.Title         = editor.ItemTitle;
                        item.Publisher     = editor.ItemPublisher;
                        item.CopyrightYear = int.Parse(editor.ItemCopyrightYear);
                        item.LoanPeriod    = int.Parse(editor.ItemLoanPeriod);
                        item.CallNumber    = editor.ItemCallNumber;
                    }
                    editor.Dispose();
                }
            }
        }
Exemple #6
0
        private void bookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items;         // List of Items



            items = _lib.GetItemsList(); // gets list of items from library



            EditBookForm editBookForm     = new EditBookForm(items); // pass items to the form
            BookForm     editSelectedBook = new BookForm();          // create new book form

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

            // ensure user clicked OK
            if (result == DialogResult.OK)
            {
                try
                {
                    int bookCopyrightYear; // holds copyright year
                    int bookLoanPeriod;    // holds load period


                    LibraryBook selectedItem = (LibraryBook)items[editBookForm.ItemIndex];       // stores selected book

                    editSelectedBook.ItemTitle         = selectedItem.Title;
                    editSelectedBook.ItemPublisher     = selectedItem.Publisher;
                    editSelectedBook.ItemCopyrightYear = selectedItem.CopyrightYear.ToString();
                    editSelectedBook.ItemLoanPeriod    = selectedItem.LoanPeriod.ToString();
                    editSelectedBook.ItemCallNumber    = selectedItem.CallNumber;
                    editSelectedBook.BookAuthor        = selectedItem.Author;

                    int.TryParse(editSelectedBook.ItemCopyrightYear, out bookCopyrightYear);
                    int.TryParse(editSelectedBook.ItemLoanPeriod, out bookLoanPeriod);

                    result = editSelectedBook.ShowDialog();       // show form as dialog for selected book

                    _lib._items.RemoveAt(editBookForm.ItemIndex); // the book being edited is removed


                    LibraryBook editedBook = new LibraryBook(editSelectedBook.ItemTitle, editSelectedBook.ItemPublisher, bookCopyrightYear, bookLoanPeriod, editSelectedBook.ItemCallNumber, editSelectedBook.BookAuthor);

                    _lib._items.Insert(editBookForm.ItemIndex, editedBook); // the edited version of the book is added
                }
                catch (InvalidCastException)
                {
                    MessageBox.Show("Select a Book Item!"); // error if selected item is not a book
                }
                catch (ArgumentOutOfRangeException)
                {
                    MessageBox.Show("Select a Book!");  // error if no book selected
                }
            }


            editBookForm.Dispose(); // Good .NET practice - will get garbage collected anyway
        }
Exemple #7
0
        //Precondition: Insert -> book item is activated
        //Postcondition: New book is inserted
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm     bookForm = new BookForm();
            DialogResult result   = bookForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                library.AddLibraryBook(bookForm.BookTitle, bookForm.BookPublisher, int.Parse(bookForm.BookCopyright),
                                       int.Parse(bookForm.BookLoanPeriod), bookForm.BookCallNumber, bookForm.BookAuthor);
            }
        }
Exemple #8
0
        //Preconditions: user clicks edit then clicks book. user must select an item from the combo box
        //Postconditions: dialog box shows up with the books current information loaded into it. user can then change the info
        private void bookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items        = lib.GetItemsList();       //reference library items
            List <LibraryItem> bookList     = new List <LibraryItem>(); //create new list of only library books
            List <int>         bookIndecies = new List <int>();         //creates index of which book is stored in the index in the items list

            for (int i = 0; i < items.Count; ++i)
            {
                if (items[i] is LibraryBook)
                {
                    bookList.Add(items[i]);
                    bookIndecies.Add(i);
                }
            }

            if ((bookList.Count() == 0))
            {
                MessageBox.Show("Must have books in the book list");
            }
            else
            {
                EditBookForm editBookForm = new EditBookForm(bookList);
                DialogResult result1      = editBookForm.ShowDialog();

                if (result1 == DialogResult.OK)
                {
                    int itemIndex;                                //to hold index

                    itemIndex = bookIndecies[editBookForm.ItemIndex];
                    BookForm bookForm = new BookForm();

                    LibraryBook books = (LibraryBook)items[itemIndex];   //downcast

                    bookForm.ItemTitle         = items[itemIndex].Title;
                    bookForm.ItemPublisher     = items[itemIndex].Publisher;
                    bookForm.ItemCopyrightYear = items[itemIndex].CopyrightYear.ToString();
                    bookForm.ItemLoanPeriod    = items[itemIndex].LoanPeriod.ToString();
                    bookForm.ItemCallNumber    = items[itemIndex].CallNumber;
                    bookForm.BookAuthor        = books.Author; //from downcast

                    DialogResult result2 = bookForm.ShowDialog();

                    if (result2 == DialogResult.OK)
                    {
                        items[itemIndex].Title         = bookForm.ItemTitle;
                        items[itemIndex].Publisher     = bookForm.ItemPublisher;
                        items[itemIndex].CopyrightYear = int.Parse(bookForm.ItemCopyrightYear);
                        items[itemIndex].LoanPeriod    = int.Parse(bookForm.ItemLoanPeriod);
                        items[itemIndex].CallNumber    = bookForm.ItemCallNumber;
                        books.Author = bookForm.BookAuthor;  //from downcast
                    }
                }
            }
        }
        //Precondition: none
        //Postcondition: This will use the Book form to allow the user to input new books and return them onto a report.
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm     inputForm = new BookForm();
            DialogResult result    = inputForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                string title         = inputForm.BookTitle;
                string author        = inputForm.BookAuthor;
                string callNumber    = inputForm.BookCallNumber;
                string loanPeriod    = inputForm.BookLoanPeriod;
                string copyrightYear = inputForm.BookCopyrightYear;
            }
        }
Exemple #10
0
        // Precondition:  Edit, book menu item activated
        // Postcondition: The edit book dialog box is displayed.
        //                and a book can be selected from the combobox
        private void bookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items; //List of Library Items

            items = lib.GetItemsList();



            EditBook editBook = new EditBook(items);//opens edit book dialogbox

            DialogResult result = editBook.ShowDialog();

            int bookIndex;

            bookIndex = editBook.ItemIndex;//sets bookindex to book index from combobox

            //Precondition:User clicks ok on Book Form
            //Postcondition: Populates list with new book information
            if (result == DialogResult.OK)
            {
                LibraryBook book = (LibraryBook)lib._items[bookIndex];

                BookForm bookform = new BookForm();//book form dialog box is opened

                //Sets textboxs to have information from selected book
                bookform.ItemTitle         = book.Title;
                bookform.ItemPublisher     = book.Publisher;
                bookform.ItemCopyrightYear = book.CopyrightYear.ToString();
                bookform.ItemLoanPeriod    = book.LoanPeriod.ToString();
                bookform.ItemCallNumber    = book.CallNumber;
                bookform.BookAuthor        = book.Author;

                DialogResult result2 = bookform.ShowDialog();

                //Precondition:User selects a book
                //Postcondition: book information is set to book form textboxes
                if (result2 == DialogResult.OK)
                {
                    book.Title         = bookform.ItemTitle;
                    book.Publisher     = bookform.ItemPublisher;
                    book.CopyrightYear = int.Parse(bookform.ItemCopyrightYear);
                    book.LoanPeriod    = int.Parse(bookform.ItemLoanPeriod);
                    book.CallNumber    = bookform.ItemCallNumber;
                    book.Author        = bookform.BookAuthor;
                }
            }
        }
Exemple #11
0
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm     bookform = new BookForm(); // Bookform is created
            DialogResult result;                    // Dialog result is created

            result = bookform.ShowDialog();

            if (result == DialogResult.OK)
            {
                string title         = bookform.Title;                    // Title is set using the form property
                string publisher     = bookform.Publisher;                // Publisher is set using the form property
                int    copyrightyear = int.Parse(bookform.CopyrightYear); // Copyrightyear is set using the form property
                int    loanperiod    = int.Parse(bookform.LoanPeriod);    // Loanperiod is set using the form property
                string callnumber    = bookform.CallNumber;               // Callnumber is set using the form property
                string author        = bookform.Author;                   // Author is set using the form property

                // A new library book is added to the library
                newLibrary.AddLibraryBook(title, publisher, copyrightyear, loanperiod, callnumber, author);
            }
        }
Exemple #12
0
        private void BookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items;     // List of library items

            items = _lib.GetItemsList();

            if ((items.Count() == 0))
            {
                MessageBox.Show("Must have a book to edit!");
            }
            else
            {
                BookSelectionForm bookSelectForm = new BookSelectionForm(items); // The return dialog box form
                DialogResult      result         = bookSelectForm.ShowDialog();  // Show form as dialog and store result

                if (result == DialogResult.OK)
                {
                    LibraryBook b  = (LibraryBook)_lib._items[bookSelectForm.ItemIndex];
                    BookForm    bf = new BookForm();
                    bf.ItemTitle         = b.Title;
                    bf.ItemPublisher     = b.Publisher;
                    bf.ItemCopyrightYear = b.CopyrightYear.ToString();
                    bf.ItemLoanPeriod    = b.LoanPeriod.ToString();
                    bf.ItemCallNumber    = b.CallNumber;
                    bf.BookAuthor        = b.Author;

                    DialogResult result1 = bf.ShowDialog();

                    if (result1 == DialogResult.OK)
                    {
                        b.Title         = bf.ItemTitle;
                        b.Publisher     = bf.ItemPublisher;
                        b.CopyrightYear = int.Parse(bf.ItemCopyrightYear);
                        b.LoanPeriod    = int.Parse(bf.ItemLoanPeriod);
                        b.CallNumber    = bf.ItemCallNumber;
                        b.Author        = bf.BookAuthor;
                    }
                }
                bookSelectForm.Dispose();
            }
        }
Exemple #13
0
        // Precondition:  Insert, Book menu item activated
        // Postcondition: The Book dialog box is displayed. If data entered
        //                are OK, a LibraryBook is created and added to the library
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm     bookForm = new BookForm();        // The book dialog box form
            DialogResult result   = bookForm.ShowDialog(); // Show form as dialog and store result

            if (result == DialogResult.OK)                 // Only add if OK
            {
                try
                {
                    // Use form's properties to get book info to send to library
                    _lib.AddLibraryBook(bookForm.ItemTitle, bookForm.ItemPublisher, int.Parse(bookForm.ItemCopyrightYear),
                                        int.Parse(bookForm.ItemLoanPeriod), bookForm.ItemCallNumber, bookForm.BookAuthor);
                }

                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
        }
Exemple #14
0
        // Precondition:  Book menuItem activated
        // Postcondition: The book dialog box is displayed. If data entered
        //                are OK, a book is created and added to the list
        //                of books
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm Book = new BookForm(); //  The dialog box form, variable that interacts with book form

            result = Book.ShowDialog();
            string Title;                  // holds book's title
            string Publisher;              // holds book's author
            int    LoanPeriod;             // holds loan period
            int    Copyright;              // holds copyright year
            string CallNumber;             // holds call number
            string Author;                 // holds author of the book

            if (result == DialogResult.OK) // Only update if user chose OK from dialog box
            {
                Title      = Book.TitleValue;
                Publisher  = Book.PublisherValue;
                Copyright  = int.Parse(Book.CopyrightValue);  //Retrieve value from dialog box
                LoanPeriod = int.Parse(Book.LoanPeriodValue); //Retrieve value from dialog box
                CallNumber = Book.CallNumberValue;
                Author     = Book.AuthorValue;
                _lib.AddLibraryBook(Title, Publisher, Copyright, LoanPeriod, CallNumber, Author);
            }
        }
Exemple #15
0
        // Precondition: None
        // Postcondition: Opens a dialog box that will add a book to the library
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm Book = new BookForm(); // variable that interacts with book form

            result = Book.ShowDialog();
            string Title;      // the book's title
            string Publisher;  // the book's author
            int    LoanPeriod; // the loan period
            int    Copyright;  // the copyright year
            string CallNumber; // the call number in the library's system
            string Author;     // the writer of the book

            if (result == DialogResult.OK)
            {
                Title      = Book.titleTextbox.Text;
                Publisher  = Book.publisherTextbox.Text;
                Copyright  = int.Parse(Book.copyrightTextbox.Text);
                LoanPeriod = int.Parse(Book.loanPeriodTextbox.Text);
                CallNumber = Book.callNumberTextBox.Text;
                Author     = Book.authorTextbox.Text;
                _lib.AddLibraryBook(Title, Publisher, Copyright, LoanPeriod, CallNumber, Author);
            }
        }
Exemple #16
0
        //Precondition: none
        //Postcondition: Outputs the values of the selected book into the edit book form
        private void bookButton_Click(object sender, EventArgs e)
        {
            LibraryBook b = _lib._patrons[BookIndex];

            BookForm pf = new BookForm();

            pf.BookAuthor = b.Author;

            pf.ItemCopyrightYear = b.CopyrightYear;

            pf.ItemCallNumber = b.CallNumber;

            pf.ItemLoanPeriod = b.LoanPeriod;

            pf.ItemPublisher = b.Publisher;

            pf.ItemTitle = b.Title;

            DialogResult result = pf.ShowDialog();

            //Precondition: The result is valid
            //Postcondition: Outputs the values of the selected book into the edit book form
            if (result == DialogResult.OK)
            {
                b.Author = pf.BookAuthor;

                b.CopyrightYear = pf.ItemCopyrightYear;

                b.CallNumber = pf.ItemCallNumber;

                b.LoanPeriod = pf.ItemLoanPeriod;

                b.Publisher = pf.ItemPublisher;

                b.Title = pf.ItemTitle;
            }
        }
Exemple #17
0
        private void BookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List <LibraryItem> items; // List of items

            items = _lib.GetItemsList();


            if (items.Count() == 0) // Must have items
            {
                MessageBox.Show("Must have books to edit!", "Edit Patron Error");
            }
            else
            {
                SelectBookForm selectBookForm = new SelectBookForm(items); // The Select Book dialog box form load with items

                DialogResult result = selectBookForm.ShowDialog();         // Show form as dialog and stores result

                if (result == DialogResult.OK)                             // Only add if OK
                {
                    try
                    {
                        BookForm bookForm = new BookForm(); // The patron dialog box form


                        LibraryBook selected = (LibraryBook)items[selectBookForm.BookIndex]; //carryovers the selected book's properties into the new form
                        bookForm.ItemTitle         = selected.Title;                         // sets itemTitle property to one the user selected
                        bookForm.ItemPublisher     = selected.Publisher;                     // sets ItemPublisherTxt property to one the user selected
                        bookForm.ItemCopyrightYear = selected.CopyrightYear.ToString();      // sets ItemCopyrightYearsTxt property to one the user selected
                        bookForm.ItemLoanPeriod    = selected.LoanPeriod.ToString();         // sets LoanPeriodTxt property to one the user selected
                        bookForm.ItemCallNumber    = selected.CallNumber;                    // sets ItemCallNumberTxt  property to one user selected
                        bookForm.BookAuthor        = selected.Author;                        // sets bookAuthorTxt property to one user selected



                        bookForm.ShowDialog();                                              // Show form as dialog and store result
                        if (result == DialogResult.OK)                                      // Only add if OK
                        {
                            selected.Title         = bookForm.ItemTitle;                    // sets Title to input
                            selected.Publisher     = bookForm.ItemPublisher;                // sets Publisher to input
                            selected.CopyrightYear = int.Parse(bookForm.ItemCopyrightYear); // sets CopyrightYears to input
                            selected.LoanPeriod    = int.Parse(bookForm.ItemLoanPeriod);    // sets Loan Period to input
                            selected.CallNumber    = bookForm.ItemCallNumber;               // sets Call Number to input
                            selected.Author        = bookForm.BookAuthor;                   // sets Call Number to input
                        }

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

                    catch (ArgumentOutOfRangeException)
                    {
                        MessageBox.Show("Enter Input into the Proper Field", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    catch (InvalidOperationException)
                    {
                        MessageBox.Show("Invalid Operation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    catch (FormatException)
                    {
                        MessageBox.Show("Please Enter Correct Format", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                selectBookForm.Dispose(); // Good .NET practice - will get garbage collected anyway
            }
        }
        private void bookToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            List<LibraryItem> items = new List<LibraryItem>();  //list for all library items
            List<LibraryItem> books = new List<LibraryItem>();  //list for library books
            List<int> bookIndices;      // List of index values of items checked out

            items = lib.GetItemsList(); //get current list of library items
            bookIndices = new List<int>(); //list for book indicies

            for (int i = 0; i < items.Count(); i++) //loop to end of list
            {
                if (items[i] is LibraryBook) //if the item type is LibraryBook
                {
                    books.Add(items[i]); //add book to list
                    bookIndices.Add(i); //add item index
                }
            }

            BookEdit bookEditForm = new BookEdit(books); //form to choose the book to edit

            DialogResult result = bookEditForm.ShowDialog(); //show form with selected book data

            if (result == DialogResult.OK) //continue if OK
            {
                LibraryItem selectedItem = lib._items[bookIndices[bookEditForm.ItemIndex]]; //hold book selected to edit

                LibraryBook selectedBook = selectedItem as LibraryBook; //cast item as library book

                BookForm bform = new BookForm(); //new book form to load selected items to

                bform.ItemTitle = selectedBook.Title;   //add book title
                bform.ItemPublisher = selectedBook.Publisher;   //add publisher book
                bform.ItemCopyrightYear = selectedBook.CopyrightYear.ToString();    //add sting of copyright year
                bform.ItemLoanPeriod = selectedBook.LoanPeriod.ToString();  //add string of loan period
                bform.ItemCallNumber = selectedBook.CallNumber; //add call number
                bform.BookAuthor = selectedBook.Author; //add author

                result = bform.ShowDialog(); //show form with the selected book's data

                if (result == DialogResult.OK) //continue if OK
                {
                    selectedBook.Title = bform.ItemTitle;   //set new book title
                    selectedBook.Publisher = bform.ItemPublisher; //set new book publisher
                    selectedBook.CopyrightYear = int.Parse(bform.ItemCopyrightYear); //set new copyright year as int
                    selectedBook.LoanPeriod = int.Parse(bform.ItemLoanPeriod); //set new loan period as int
                    selectedBook.CallNumber = bform.ItemCallNumber; //set new call number
                    selectedBook.Author = bform.BookAuthor; //set new author
                }
            }
        }
        // Precondition:  Insert, Book menu item activated
        // Postcondition: The Book dialog box is displayed. If data entered
        //                are OK, a LibraryBook is created and added to the library
        private void bookToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BookForm bookForm = new BookForm(); // The book dialog box form

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

            if (result == DialogResult.OK) // Only add if OK
            {
                try
                {
                    // Use form's properties to get book info to send to library
                    lib.AddLibraryBook(bookForm.ItemTitle, bookForm.ItemPublisher, int.Parse(bookForm.ItemCopyrightYear),
                        int.Parse(bookForm.ItemLoanPeriod), bookForm.ItemCallNumber, bookForm.BookAuthor);
                }

                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
        }
Exemple #20
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
            }
        }