コード例 #1
0
        /// <summary>
        /// Checks the database to make sure that the bookCopy and member exist there and returns true if they are found.
        /// </summary>
        /// <returns>Returns true if both of the parameter values are found in the database. Otherwise returns false.</returns>
        private bool ValidLoanInput()
        {
            string selectedBookCopyName = bookCopyLoanTB.Text;

            string[] selectedBookSplit = selectedBookCopyName.Split('-');
            int      selectedBookID;

            if (!int.TryParse(selectedBookSplit[selectedBookSplit.Count() - 1].Trim(), out selectedBookID)) //If the string doesnt end with a number
            {
                return(false);
            }
            loanInputBookCopy = bookCopyService.Find(selectedBookID);
            string selectedMemberName = memberLoanTB.Text;

            loanInputMember = memberService.GetMemberByName(selectedMemberName);
            if (!bookCopyService.All().Contains(loanInputBookCopy))
            {
                return(false);
            }
            if (!memberService.All().Contains(loanInputMember))
            {
                return(false);
            }

            //Date Validation
            //if (timeOfLoan.Value.Date <= DateTime.Now.Date) //Need to be able to set a passed date to create late loans for Demo.
            //    return false;
            if (dueDateDTP.Value.Date <= timeOfLoanDTP.Value.Date)
            {
                return(false);
            }

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Gets member and bookccopy from listboxes and creates a new loan.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLoan_Click(object sender, EventArgs e)
        {
            int      id           = loanService.GenerateId();
            DateTime timeOfloan   = DateTime.Now;
            DateTime dueDate      = timeOfloan.AddDays(15.0);
            DateTime?timeOfReturn = null;
            Member   mem          = lbMembers.SelectedItem as Member;
            BookCopy copy         = lbCopies.SelectedItem as BookCopy;

            if (lbMembers.SelectedIndex == -1 && lbCopies.SelectedIndex == -1)
            {
                MessageBox.Show("Please choose a member and a copy.");
            }
            else
            {
                Loan loan = new Loan
                {
                    Id           = id,
                    TimeOfLoan   = timeOfloan,
                    DueDate      = dueDate,
                    TimeOfReturn = timeOfReturn,
                    Member       = mem,
                    MemberId     = mem.MemberId,
                    BookCopy     = copy,
                    BookCopyId   = copy.Id
                };

                loanService.Add(loan);
                loanService.Edit(loan);
            }
        }
コード例 #3
0
 /// <summary>
 /// Custom draw mode to enable text coloring based on bookCopy availability.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void lbCopies_DrawItem(object sender, DrawItemEventArgs e)
 {
     if (e.Index > -1)                                        // If user clicked on an actual item from the listbox.
     {
         BookCopy item = lbCopies.Items[e.Index] as BookCopy; // Get the current item and cast it to MyListBoxItem
         e.DrawBackground();
         e.DrawFocusRectangle();
         if (item != null)
         {
             Color color = availableColor;
             if (item.OnActiveLoan())
             {
                 color = unavailableColor;
             }
             e.Graphics.DrawString(            // Draw the appropriate text in the ListBox
                 item.ToString(),              // The message linked to the item
                 lbCopies.Font,                // Take the font from the listbox
                 new SolidBrush(color),        // Set the color
                 0,                            // X pixel coordinate
                 e.Index * lbCopies.ItemHeight // Y pixel coordinate.  Multiply the index by the ItemHeight defined in the listbox.
                 );
         }
         else
         {
             e.Graphics.DrawString(                  // Draw the appropriate text in the ListBox
                 lbCopies.Items[e.Index].ToString(), // The message linked to the item
                 lbCopies.Font,                      // Take the font from the listbox
                 new SolidBrush(Color.Black),        // Set the color
                 0,                                  // X pixel coordinate
                 e.Index * lbCopies.ItemHeight       // Y pixel coordinate.  Multiply the index by the ItemHeight defined in the listbox.
                 );
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Checks if the input in condition is a number and if true, creates a new bookcopy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddCopy_Click(object sender, EventArgs e)
        {
            int id = copyService.GenerateId();

            int x;

            bool convertSuccess = int.TryParse(txtCondition.Text, out x);

            Book book = lbOfBooks.SelectedItem as Book;

            if (convertSuccess && lbOfBooks.SelectedIndex != -1)
            {
                if (1 <= x && x <= 10)
                {
                    BookCopy copy = new BookCopy
                    {
                        Id        = id,
                        Condition = x,
                        Book      = book,
                        BookId    = book.Id
                    };

                    copyService.Add(copy);
                    copyService.Edit(copy);
                }
                else
                {
                    MessageBox.Show("Invalid input, condition was not a number within the specified limit");
                }
            }
            else
            {
                MessageBox.Show("Invalid input");
            }
        }
コード例 #5
0
ファイル: BookForm.cs プロジェクト: Becc-s/super-barnacle
        //Add book
        private void btAddBook_Click(object sender, EventArgs e)
        {
            string   ISBN   = txtIsbn.Text;
            Book     bok1   = new Book();
            BookCopy kopia1 = new BookCopy();

            bok1.Description = txtDescription.Text;
            bok1.Title       = txtTitle.Text;
            int  isbn   = bok1.ISBN;
            bool isAInt = int.TryParse(ISBN, out isbn);

            bok1.Author = (Author)lbBooksByAuthor.SelectedItem;
            kopia1.Book = bok1;


            if (bok1.Author != null && txtDescription.Text != null && txtIsbn.Text != null && isAInt == true)
            {
                LibraryForm library = new LibraryForm();
                _bookService.Add(bok1);
                _bookCopyService.Add(kopia1);

                this.Close();
            }
            else
            {
                MessageBox.Show("You have to select an author and add description. ISBN have to be a number");
            }
        }
コード例 #6
0
        /// <summary>
        /// If a book has been selected, it adds a new copy of that book to the database, and makes the new bookcopy the selected bookCopy in the bookCopyListBox.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void addCopyBTN_Click(object sender, EventArgs e)
        {
            // Can only add new copy if a book has been selected
            if (lbBooks.SelectedItem != null)
            {
                string confirmBoxText  = "Do you want to add a new copy of the book: '" + currentBookDisplay[lbBooks.SelectedIndex].ToString() + "'?";
                string confirmBoxTitle = "Add new book copy";
                if (ConfirmedPopup(confirmBoxText, confirmBoxTitle))
                {
                    Book     selectedBook = currentBookDisplay[lbBooks.SelectedIndex];
                    BookCopy newBookCopy  = new BookCopy()
                    {
                        Book = selectedBook
                    };
                    // Adds the new copy to the database
                    bookCopyService.Add(newBookCopy);

                    // Makes the newly created copy the selected item in the listbox
                    lbCopies.SelectedIndex = currentBookCopyDisplay.IndexOf(newBookCopy);
                }
            }
            else
            {
                InfoPopup("You need to select a book to add a copy of.", "Can't create book Copy");
            }
        }
コード例 #7
0
        private void Loan(BookCopy bookCopy, Member member)
        {
            DateTime timeOfLoan = DateTime.Now;
            DateTime dueDate    = timeOfLoan.AddDays(15);
            Loan     newLoan    = new Loan(timeOfLoan, dueDate, bookCopy, member);

            loanService.Add(newLoan);
        }
コード例 #8
0
 public void Add(BookCopy copy)
 {
     if (!books.ContainsKey(copy.Book))
     {
         books.Add(copy.Book, new List <BookCopy>());
     }
     books[copy.Book].Add(copy);
 }
コード例 #9
0
        private void BTNAddCopy_Click(object sender, EventArgs e)
        {
            int      condition = Convert.ToInt32(dropDown_condition.SelectedItem);
            BookCopy newCopy   = new BookCopy(book, condition);

            bookCopyService.Add(newCopy);
            book.BookCopies.Add(newCopy);
            bookService.Edit(book);
            this.Close();
        }
コード例 #10
0
 /// <summary>
 /// Button that adds new book copies
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void addNewBookCopy_Click(object sender, EventArgs e)
 {
     try
     {
         Book     b        = lbBooks.SelectedItem as Book;
         BookCopy bookCopy = new BookCopy(b, Convert.ToInt32(cbBookCondition.SelectedItem.ToString()));
         bookCopyService.Add(bookCopy);
         Debug.WriteLine($"Added new book, {bookCopy.BookObject.Title} condition {bookCopy.Condition}");
     }
     catch (Exception exp)
     {
         MessageBox.Show("You need to specify a condition");
         Debug.WriteLine(exp);
     }
 }
コード例 #11
0
ファイル: LibraryForm.cs プロジェクト: Becc-s/super-barnacle
        private void btnCopy_Click(object sender, EventArgs e)
        {
            BookCopy kopia = new BookCopy();

            //Buy a copy of a selected book from the list
            if (lbBooks.SelectedItem != null)
            {
                kopia.Book = (Book)lbBooks.SelectedItem;
                _bookCopyService.Add(kopia);
                _bookCopyService.OnChanged(this, EventArgs.Empty);
            }
            else
            {
                MessageBox.Show("You have to select a book to make a copy!");
            }
        }
コード例 #12
0
        private void AddLoanButton_Click(object sender, EventArgs e)
        {
            var bookCopy = BookCopies_listBox.SelectedItem;
            var member   = Member_listBox.SelectedItem;

            if (bookCopy != null && member != null)
            {
                BookCopy _bookCopy = bookCopy as BookCopy;
                Member   _member   = member as Member;

                Loan loan = new Loan(_bookCopy, _member);

                _bookCopy.OnLoan = true;
                loanService.Add(loan);
            }
        }
コード例 #13
0
ファイル: LibraryForm.cs プロジェクト: Vildmusen/OOP2PROJECT
 private void add_copy_btn_Click(object sender, EventArgs e)
 {
     try
     {
         Book     original = lbResult.SelectedItem as Book;
         BookCopy copy     = new BookCopy {
             Book = original, Condition = 10
         };
         original.Copies.Add(copy);
         bookCopyService.Add(copy);
     }
     catch (Exception ex)
     {
         UserError(ex);
     }
 }
コード例 #14
0
        public void BookCopyReturned(int copyID, Reader reader)
        {
            BookCopy copy = FindCopy(copyID);

            if (copy == null)
            {
                throw new BookException("Copy with this id was not found");
            }
            if (!copy.ReaderID.Equals(reader.ID))
            {
                throw new BookException("Book taken not by this reader");
            }
            else
            {
                reader.BookReturned(copy);
            }
        }
コード例 #15
0
        private void BTNLoan_Click(object sender, EventArgs e)
        {
            BookCopy selectedBookCopy = lbAvailableCopies.SelectedItem as BookCopy;
            Member   selectedMember   = dropDown_members.SelectedItem as Member;

            if (selectedBookCopy == null)
            {
                MessageBox.Show("Please choose a Book copy to loan.");
            }
            else if (selectedMember == null)
            {
                MessageBox.Show("Please choose a Member to make a loan.");
            }
            else
            {
                Loan(selectedBookCopy, selectedMember);
            }
        }
コード例 #16
0
        private void lbx_firstbox_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selection       = cbx_second_select.Text;
            var secondSelection = lbx_secondbox.SelectedItem;

            if (-1 != lbx_firstbox.SelectedIndex)
            {
                SelectedAuthor   = lbx_firstbox.SelectedItem as Author;
                SelectedBookCopy = lbx_firstbox.SelectedItem as BookCopy;
                SelectedBook     = lbx_firstbox.SelectedItem as Book;
                SelectedLoan     = lbx_firstbox.SelectedItem as Loan;
                SelectedMember   = lbx_firstbox.SelectedItem as Member;
            }
            switch (FirstListBox)
            {
            case SelectedServiceList.SSL_AUTHOR:
            {
                cbx_second_select.DataSource = authorService.GetListBoxItems();
                break;
            }

            case SelectedServiceList.SSL_BOOK:
            {
                cbx_second_select.DataSource = bookService.GetListBoxItems();
                break;
            }

            case SelectedServiceList.SSL_MEMBER:
            {
                cbx_second_select.DataSource = memberService.GetListBoxItems();
                break;
            }
            }
            if (cbx_second_select.Items.Contains(selection))
            {
                cbx_second_select.SelectedItem = selection;
            }
            if (null != secondSelection && lbx_secondbox.Items.Contains(secondSelection))
            {
                lbx_secondbox.SelectedItem = secondSelection;
            }
        }
コード例 #17
0
        /// <summary>
        /// The button that adds the book copy.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_AddBookCopy_Click(object sender, EventArgs e)
        {
            if (cb_Condition.SelectedItem == null)
            {
                MessageBox.Show("Please choose a condition from the list.");
            }
            else
            {
                int bookCondition;

                if (int.TryParse(cb_Condition.SelectedItem.ToString(), out bookCondition))
                {
                    BookCopy bookCopy = new BookCopy()
                    {
                        Book      = selectedBook,
                        Condition = bookCondition
                    };
                    BCS.Add(bookCopy);
                }
            }
        }
コード例 #18
0
ファイル: LibraryForm.cs プロジェクト: lvlindv/OOP2-project-
 /// <summary>
 /// "Add new copy"-button
 /// </summary>
 private void button1_Click(object sender, EventArgs e)
 {
     if ((Book)comboBoxBook.SelectedItem != null)
     {
         try
         {
             BookCopy copy = new BookCopy((Book)comboBoxBook.SelectedItem, Convert.ToInt32(numericUpDownCopies.Value));
             bookCopyService.Add(copy);
             ShowAllBooks(bookService.All());
             LoanTabShowCopies(bookCopyService.GetAvailableBookCopies(loanService.All(), bookCopyService.All()));
             TEST(loanService.All(), bookCopyService.All());
         }
         catch (ArgumentNullException)
         {
             MessageBox.Show("Value can not be null.", "ArgumentNullException");
         }
     }
     else
     {
         MessageBox.Show("You need to choose a book.", "Error!");
     }
 }
コード例 #19
0
        public LibraryForm()
        {
            InitializeComponent();

            // Uncomment the line you wish to use
            // Use a derived strategy with a Seed-method
            Database.SetInitializer <LibraryContext>(new LibraryDbInit());

            ContextSingelton.GetContext().Database.Initialize(true);
            // Recreate the database only if the models change
            //Database.SetInitializer<LibraryContext>(new DropCreateDatabaseIfModelChanges<LibraryContext>());
            var test  = ContextSingelton.GetContext().Loans.ToList();
            var test2 = test.Where(loan => loan.Copy != null).ToList();

            // Always drop and recreate the database
            //Database.SetInitializer<LibraryContext>(new DropCreateDatabaseAlways<LibraryContext>());
            // MessageBox.Show(LibraryDbInit.GetRandomMember(new Random(DateTime.Now.Second)).PersonalID);

            authorService   = new AuthorService();
            bookService     = new BookService();
            bookCopyService = new BookCopyService();
            memberService   = new MemberService();
            loanService     = new LoanService();

            SelectedAuthor   = null;
            SelectedBookCopy = null;
            SelectedBook     = null;
            SelectedLoan     = null;
            SelectedMember   = null;

            FirstListBox = SelectedServiceList.SSL_NONE;

            authorService.Updated += new EventHandler(AuthorUpdated);
            bookService.Updated   += new EventHandler(BookUpdated);
            loanService.Updated   += new EventHandler(LoanUpdated);
            memberService.Updated += new EventHandler(MemberUpdated);

            lbl_firstbox.Text = string.Empty;
        }
コード例 #20
0
 private void lbx_secondbox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (-1 != lbx_secondbox.SelectedIndex)
     {
         /// Assigns the second selection to Selected member if not already selected
         /// in the first listbox (thus the null check).
         SelectedAuthor   = (null == SelectedAuthor || null != lbx_secondbox.SelectedItem as Author) ? lbx_secondbox.SelectedItem as Author : SelectedAuthor;
         SelectedBookCopy = (null == SelectedBookCopy || null != lbx_secondbox.SelectedItem as BookCopy) ? lbx_secondbox.SelectedItem as BookCopy : SelectedBookCopy;
         SelectedBook     = (null == SelectedBook || null != lbx_secondbox.SelectedItem as Book) ? lbx_secondbox.SelectedItem as Book : SelectedBook;
         SelectedLoan     = (null == SelectedLoan || null != lbx_secondbox.SelectedItem as Loan) ? lbx_secondbox.SelectedItem as Loan : SelectedLoan;
         SelectedMember   = (null == SelectedMember || null != lbx_secondbox.SelectedItem as Member) ? lbx_secondbox.SelectedItem as Member : SelectedMember;
     }
     else // no selection in second list, repopulate the original.
     {
         SelectedAuthor   = lbx_firstbox.SelectedItem as Author;
         SelectedBookCopy = lbx_firstbox.SelectedItem as BookCopy;
         SelectedBook     = lbx_firstbox.SelectedItem as Book;
         SelectedLoan     = lbx_firstbox.SelectedItem as Loan;
         SelectedMember   = lbx_firstbox.SelectedItem as Member;
     }
     PopulateUserForm();
 }
コード例 #21
0
 /// <summary>
 /// Creates a new loan, based on the previously selected user from MemberList form
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnCreate_Click(object sender, EventArgs e)
 {
     try
     {
         BookCopy bookCopy = lbAvailCopies.SelectedItem as BookCopy;
         Member   member   = FindMemberBiId(memberId);
         Debug.WriteLine(member.Name);
         //Loan newbookLoan = new Loan(bookCopy, member);
         Random rnd         = new Random();
         int    daysDiff    = rnd.Next(-20, 30);
         Loan   newbookLoan = new Loan(bookCopy, member, DateTime.Today.AddDays(daysDiff))
         {
             ReturnLoanTimestamp = null
         };
         member.LoanList.Add(newbookLoan);
         memberService.Edit(member);
     }
     catch (Exception exp)
     {
         MessageBox.Show("Unable to loan the book.");
         Debug.WriteLine(exp);
     }
 }
コード例 #22
0
        private void AddBook_Button_Click(object sender, EventArgs e)
        {
            // Skapar lista för smidig validering
            var validationList = new List <string>
            {
                AddBookISBN_textbox.Text,
                AddBookTitle_TextBox.Text,
                AddBookDescription_TextBox.Text,
            };

            if (CheckInput(validationList) && AddBookAuthor_ComboBox.SelectedItem != null)
            {
                var book = new Book()
                {
                    Isbn        = AddBookISBN_textbox.Text,
                    Title       = AddBookTitle_TextBox.Text,
                    Description = AddBookDescription_TextBox.Text,
                    Author      = (Author)AddBookAuthor_ComboBox.SelectedItem,
                    BookCopies  = (int)AddBookNumberOfCopies_drop.Value
                };

                _bookService.AddBook(book);

                for (int i = 0; i < book.BookCopies; i++)
                {
                    var bookCopy = new BookCopy()
                    {
                        Book = book
                    };

                    _bookCopyService.AddBookCopy(bookCopy);
                }

                ClearBookAdministration();
            }
        }
コード例 #23
0
ファイル: MakeLoanDialog.cs プロジェクト: mrSten/Library
 /// <summary>
 /// Gets Member & bookCopy values from Comboboxes
 /// </summary>
 /// <param name="sender">
 /// Object reference
 /// </param>
 /// <param name="e">
 /// Event data
 /// </param>
 private void buttonCreateLoan_Click(object sender, EventArgs e)
 {
     _LoanMember   = (Member)MembersBox.SelectedItem;
     _LoanBookCopy = (BookCopy)BookCopiesBox.SelectedItem;
 }
コード例 #24
0
        /// <summary>
        /// Event method for the submitbutton in the add/remove section
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void submitButton_Click(object sender, EventArgs e)
        {
            switch ((addRemoveEnum)cbbxAction.SelectedIndex)
            {
            case addRemoveEnum.AddBook:    //add book
            {
                //txtbxInput1 = title
                //txtbxInput2 = authorname
                //txtbxInput3 = ISBN
                //txtbxInput4 = description
                Author theAuthor;
                Book   theBook;
                try
                {
                    if (txtbxInput1.Text.Length == 0 || txtbxInput2.Text.Length == 0 || txtbxInput3.Text.Length == 0 || txtbxInput4.Text.Length == 0)
                    {
                        throw new InvalidInputException();
                    }

                    if (authorService.All().Where(a => a.Name == txtbxInput2.Text).Count() == 0)
                    {
                        theAuthor = new Author {
                            Name = txtbxInput2.Text, Books = new List <Book>()
                        };
                        authorService.Add(theAuthor);
                    }
                    else
                    {
                        theAuthor = authorService.All().Where(A => A.Name == txtbxInput2.Text).First();
                    }

                    theBook = new Book {
                        Title = txtbxInput1.Text, Author = theAuthor, Copies = new List <BookCopy>(), Description = txtbxInput4.Text, Isbn = txtbxInput3.Text
                    };
                    bookService.Add(theBook);
                }

                catch (InvalidInputException) { MessageBox.Show("Some input was invalid, please controll that none of the input textboxes are empty"); }
                break;
            }

            case addRemoveEnum.AddAuthor:     //Add Author
            {
                Author theAuthor;

                //txtbxInput1 = authorname
                try
                {
                    if (txtbxInput1.Text.Length == 0)
                    {
                        throw new InvalidInputException();
                    }
                    theAuthor = new Author {
                        Name = txtbxInput1.Text, Books = new List <Book>()
                    };
                    authorService.Add(theAuthor);
                }
                catch (InvalidInputException)
                {
                    MessageBox.Show("An author needs to have a name, please input a name in the name textbok");
                    txtbxInput1.Select();
                }
                break;
            }

            case addRemoveEnum.AddBookCopy:     //Add book copy
            {
                //txtbxInput1 = bookname
                BookCopy theBookCopy;
                Book     theBook;

                try
                {
                    if (txtbxInput1.Text.Length == 0)
                    {
                        throw new InvalidInputException();
                    }

                    theBook     = bookService.All().Where(B => B.Title == txtbxInput1.Text).First();
                    theBookCopy = new BookCopy {
                        Book = theBook, IsLoaned = false, Condition = "New"
                    };

                    bookCopyService.Add(theBookCopy);
                    theBook.Copies.Add(theBookCopy);
                }
                catch (InvalidInputException)
                {
                    MessageBox.Show("Please specify wich book you would like to add a copy of in the booktitle textbox");
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("The book was not found, please make sure that the book exists before creating a copy of it");
                }
                break;
            }

            case addRemoveEnum.RemoveBook:     //RemoveBook
            {
                //txtbxInput1 = bookname
                Book theBook;
                try
                {
                    if (txtbxInput1.Text.Length == 0)
                    {
                        throw new InvalidInputException();
                    }

                    theBook = bookService.All().Where(B => B.Title == txtbxInput1.Text).First();

                    foreach (var copy in bookCopyService.All().Where(b => b.Book == theBook))
                    {
                        //remove every copy of the book from bookcopyrepo
                        bookCopyService.Remove(copy);
                    }

                    //Remove the book from bookrepo
                    bookService.Remove(theBook);
                }
                catch (InvalidInputException)
                {
                    MessageBox.Show("Please specify wich book yo would like to remove in the booktitle textbox");
                    txtbxInput1.Select();
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("The book was not found, please controll that the book exists and that you've entered the correct title");
                    txtbxInput1.Select();
                }
                break;
            }

            case addRemoveEnum.RemoveAuthor:     //Remove author
            {
                //txtbxInput1 = authorname
                Author theAuthor;
                try
                {
                    if (txtbxInput1.Text.Length == 0)
                    {
                        throw new InvalidInputException();
                    }
                    //feth author
                    theAuthor = authorService.All().Where(a => a.Name == txtbxInput1.Text).First();

                    //remove all bookcopies of books written by the author
                    foreach (BookCopy bc in bookCopyService.All().Where(b => b.Book.Author == theAuthor))
                    {
                        bookCopyService.Remove(bc);
                    }

                    //remove all books written by the author
                    foreach (Book b in bookService.All().Where(b => b.Author == theAuthor))
                    {
                        bookService.Remove(b);
                    }

                    //finally remove the author
                    authorService.Remove(theAuthor);
                }
                catch (NotImplementedException)
                {
                    MessageBox.Show("Not yet implemented, not a requirement for the project");
                }

                catch (InvalidInputException)
                {
                    MessageBox.Show("Please input a Author Name in the author name input box");
                    txtbxInput1.Select();
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("The Author was not found, please make sure that the author exists and you've entered the correct name");
                    txtbxInput1.Select();
                }
                break;
            }

            case addRemoveEnum.RemoveBookCopy:     //remove book copy
            {
                //txtbxInput1 = bookcopyid

                BookCopy theBookCopy;
                int      bookCopyId = Convert.ToInt16(txtbxInput1.Text);
                try
                {
                    if (txtbxInput1.Text.Length == 0)
                    {
                        throw new InvalidInputException();
                    }
                    theBookCopy = bookCopyService.All().Where(bc => bc.Id == bookCopyId).First();

                    bookCopyService.Remove(theBookCopy);
                }
                catch (FormatException)
                {
                    MessageBox.Show("Please make sure that the input in the ID textbox is only numbers");
                    txtbxInput1.Select();
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("The copy was not found, please make sure that you've entered the right ID and that the copy exists");
                }
                break;
            }

            case addRemoveEnum.AddMember:     //add member
            {
                //txtbxInput1 = name
                //mtxtbxSSNRadd = socialssnr
                Member newMember;

                try { iscorrectofrmat(mtxtbxSSNRadd); }
                catch (InvalidSSNRException) { MessageBox.Show(mtxtbxSSNRadd.Text + " is not a valid Social security number, please enter a social scurity number by the form YYMMDD-XXXX"); }
                try
                {
                    if (txtbxInput1.Text.Length == 0)
                    {
                        throw new InvalidInputException();
                    }

                    //create new member
                    newMember = new Member {
                        SocialSecurityNr = mtxtbxSSNRadd.Text, Name = txtbxInput1.Text
                    };
                    memberService.Add(newMember);
                }
                catch (InvalidInputException)
                {
                    MessageBox.Show("A member can't be created without a full name, please enter [name1 name2] in the name textbox");
                    txtbxInput1.Focus();
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }
コード例 #25
0
ファイル: Reader.cs プロジェクト: zygintasbergeris/Library
 public void BookTaken(BookCopy copy)
 {
     copy.BookTaken(this.ID);
     TakenBooks.Add(copy);
 }
コード例 #26
0
ファイル: Reader.cs プロジェクト: zygintasbergeris/Library
 public void BookReturned(BookCopy copy)
 {
     TakenBooks.Remove(copy);
     copy.BookReturned();
 }
コード例 #27
0
 public void RemoveCopy(BookCopy copy)
 {
     books[copy.Book].Remove(copy);
 }