Exemplo n.º 1
0
        public PersonForm(LibraryPatron p)
        {
            InitializeComponent();
            patron = p;
            if (patron == null)
            {
                new NotificationForm("Failed to load person.").ShowDialog();
                //  log
                this.Close();
            }
            bool isStudent = patron is Student;

            if (isStudent)
            {
                Student tmp = patron as Student;
                outputRole.Text = tmp.Status.ToString();
            }
            else
            {
                Lecturer tmp = patron as Lecturer;
                outputRole.Text = "Lecturer";
                outputID.Text   = tmp.ID;
            }
            outputName.Text              = patron.Name;
            outputAddress.Text           = patron.Address;
            outputEmail.Text             = patron.Email;
            outputPhone.Text             = patron.Phone;
            outputPPSN.Text              = patron.PPSN;
            booksBorrowedList.DataSource = patron.ToList();
        }
Exemplo n.º 2
0
        private void personSearchBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            LibraryPatron p = personSearchBox.SelectedItem as LibraryPatron;

            if (p != null)
            {
                new PersonForm(p).ShowDialog();
            }
        }
Exemplo n.º 3
0
        //  Person selected with button, open PersonForm for the selected Person
        private void personDetailsButton_Click(object sender, EventArgs e)
        {
            LibraryPatron p = personSearchBox.SelectedItem as LibraryPatron;

            if (p != null)
            {
                new PersonForm(p).ShowDialog();
            }
        }
Exemplo n.º 4
0
        private void borrowersBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            LibraryPatron borrower = borrowedBox.SelectedItem as LibraryPatron;

            if (borrower != null)
            {
                var confirmResult = MessageBox.Show(
                    string.Format("Are you sure you want to return '{0}', by {1}, from {2}", book.Title, book.Author, borrower.Name),
                    "Confirmation", MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes && borrower.ReturnBook(book))
                {
                    listener.NotifyReturn();
                    this.Close();
                }
            }
        }
Exemplo n.º 5
0
        //  when user double clicks on a person this is called
        private void personSearchBox_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            //  Safety measure
            try
            {
                borrower = personSearchBox.SelectedItem as LibraryPatron;
                if (borrower == null)
                    throw new ArgumentNullException("LoanForm[39]: Selected person not of type 'LibraryPatron'");
            }catch(ArgumentNullException ane)
            {
                //  log exception
                new NotificationForm("Patron not found.").ShowDialog();
            }

            //  If borrower has reached their book limit, notify and do not allow loan
            if (borrower.ReachedBookLimit())
                new NotificationForm(borrower.Name + " has met their quota of " + (int)(borrower as Student).Status + " books, and therefore cannot borrow anymore books.").ShowDialog();
            else if (borrower.HasBook(book))    //  if they already have the book, not allowed another
                new NotificationForm(borrower.Name + " already has a copy of this book. 1 copy permitted only.").ShowDialog();
            else
            {
                //  Confirm loaning book to the right person
                var confirmResult = MessageBox.Show(
                string.Format("Are you sure you want to loan: '{0}', by {1}, to {2}", book.Title, book.Author, borrower.Name),
                                    "Confirmation",
                                    MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    //  User confirmed yes, therefore system attempt to loan selected patron the book
                    if (College.Instance.Library.LoanBook(book, borrower))
                        listener.NotifyLoan();  //  update listener

                    this.Close();
                }
            }
        }