private void btnCheckCondition_Click(object sender, EventArgs e)
 {
     if (txtCopyNumber.Text != "")
     {
         if (CopyDAO.CheckCondition(int.Parse(txtCopyNumber.Text)) == 0)
         {
             MessageBox.Show("This book is available.");
             btnBorrow.Enabled = true;
         }
         else if (CopyDAO.CheckCondition(int.Parse(txtCopyNumber.Text)) == 2)
         {
             if (ReservationDAO.GetFirstReservation(CopyDAO.GetCopy(int.Parse(txtCopyNumber.Text)).BookNumber).MemberNumber
                 == int.Parse(txtMemberCode.Text))
             {
                 check = 1;
                 MessageBox.Show("This copy is available.");
                 btnBorrow.Enabled = true;
             }
             else
             {
                 MessageBox.Show("This copy is not available.");
             }
         }
         else
         {
             display(2);
             MessageBox.Show("Copy Number is invalid or This book is not available.");
         }
     }
     else
     {
         MessageBox.Show("Copy Code can not be blank.");
     }
 }
        private void btnReturn_Click(object sender, EventArgs e)
        {
            CirculatedCopy cc = new CirculatedCopy();

            cc.CirculatedCopyId = Convert.ToInt32(dgvBorrowedBooks.Rows[rowIndex].Cells["circulatedCopyId"].Value);
            cc.ReturnedDate     = dtpReturnedDate.Value;
            cc.FineAmount       = double.Parse(txtFineAmount.Text);
            CirculatedCopyDAO.Update(cc);

            Copy c = CopyDAO.GetCopy(Convert.ToInt32(dgvBorrowedBooks.Rows[rowIndex].Cells["copyNumber"].Value));

            if (ReservationDAO.GetFirstReservation(c.BookNumber) != null)
            {
                c.Type = 2;
            }
            else
            {
                c.Type = 0;
            }
            CopyDAO.UpdateType(c);

            view(int.Parse(txtMemberCode.Text));
            MessageBox.Show("Return Successful.");
            btnReturn.Enabled      = false;
            txtFineAmount.Text     = "";
            btnConfirmFine.Enabled = false;
        }
        private void btnBorrow_Click(object sender, EventArgs e)
        {
            if (dtpBorrowed.Value < dtpDue.Value)
            {
                CirculatedCopy cc = new CirculatedCopy();
                cc.CopyNumber   = int.Parse(txtCopyNumber.Text);
                cc.MemberNumber = int.Parse(txtMemberCode.Text);
                cc.BorrowedDate = dtpBorrowed.Value;
                cc.DueDate      = dtpDue.Value;

                if (CirculatedCopyDAO.Add(cc))
                {
                    Copy c = CopyDAO.GetCopy(int.Parse(txtCopyNumber.Text));
                    c.Type = 1;
                    CopyDAO.UpdateType(c);
                    display(2);
                    view(int.Parse(txtMemberCode.Text));
                    MessageBox.Show("Add Successful.");

                    if (check == 1)
                    {
                        Reservation r = ReservationDAO.GetFirstReservation(c.BookNumber);
                        r.Status = true;
                        ReservationDAO.UpdateStatus(r);
                    }

                    if (dgvBorrowedBooks.Rows.Count >= 5)
                    {
                        display(0);
                        MessageBox.Show("The number of borrowed books is 5. You can not borrow anymore book.");
                    }
                }
                else
                {
                    MessageBox.Show("Error.");
                }
            }
            else
            {
                MessageBox.Show("Borrowed date has to be smaller than Due date.");
            }
        }