コード例 #1
0
ファイル: BooksLibrary.cs プロジェクト: ranbe1/libraryProject
        private void LoanButton_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show("Do you wish to loan this book?", "Loan",
                                         MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            bool loanedAlready = loanedbll.checkIfLoanedAlready(Login.customer.Username, BooksLb.SelectedItem.ToString());
            Book book          = null;

            if (BooksLb.SelectedItem != null)
            {
                book = currSubject.SearchBookByName(BooksLb.SelectedItem.ToString());
            }
            if (book != null)
            {
                if (result == DialogResult.Yes && book.Copies > 0 &&
                    Login.customer.Loaned < maxBooks && loanedAlready == false)
                {
                    custbll.updateLoans(Login.customer.Username);
                    Login.customer.Loaned += 1;
                    bll.Loan_Book(currSubject.SearchBookByName(BooksLb.SelectedItem.ToString()), Login.customer.Username);
                    book.Copies -= 1;
                    printBook(book);

                    MessageBox.Show("Enjoy! you have 1 week to return the book.");
                }
                else if (result == DialogResult.Yes && book.Copies == 0)
                {
                    MessageBox.Show("Sorry there are no copies left from this book atm.");
                }
                else if (result == DialogResult.Yes && Login.customer.Loaned >= maxBooks)
                {
                    MessageBox.Show("Sorry but you already loaned " + maxBooks + " books , return at least 1 first!");
                }
                else if (loanedAlready)
                {
                    MessageBox.Show("Sorry but you already loaned this book!");
                }
            }
        }