Beispiel #1
0
 private void btnCheckOut_Click(object sender, EventArgs e)
 {
     try
     {
         dataLayer = new DataLayer();
         if (txtCheckOutbookId.Text.Trim() != string.Empty && txtCheckOutBranchId.Text.Trim() != string.Empty && txtCheckOutCardNumber.Text.Trim() != string.Empty)
         {
             int card_no  = Convert.ToInt32(txtCheckOutCardNumber.Text.Trim());
             int branchId = Convert.ToInt32(txtCheckOutBranchId.Text.Trim());
             #region If Card Number Exists
             // If Card Number is available in DB
             if (dataLayer.IsCardNoExists(card_no))
             {
                 #region If Library Branch have Atleast a copy
                 //Verify given Book Id and Branch Id would have atleast a book copy.
                 if (dataLayer.GetAvailableBooks(txtCheckOutbookId.Text.Trim(), branchId) >= Constants.MinCopies)
                 {
                     #region If Card Number holds < 3 copies
                     // Verify number of issued copies by Card number (Should not be more than 3).
                     if (dataLayer.GetCardNoBookIssuedCount(card_no) < Constants.MaxCopies)
                     {
                         List <uspGetFinesById_Result> fines = new List <uspGetFinesById_Result>();
                         fines = dataLayer.GetFines(card_no, string.Empty, false);
                         if (fines.Count == 0)
                         {
                             #region Card Holder is not issuing same Book
                             if (!dataLayer.IsSameCopyCheckedOut(card_no, txtCheckOutbookId.Text.Trim()))
                             {
                                 #region Borrower not having any Fines Pending
                                 bool bookIssued = dataLayer.AddNewBookLoanAndFines(txtCheckOutbookId.Text.Trim(), branchId, card_no, DateTime.Now.Date, DateTime.Now.Date.AddDays(14));
                                 if (bookIssued)
                                 {
                                     txtCheckOutbookId.Text     = string.Empty;
                                     txtCheckOutBranchId.Text   = string.Empty;
                                     txtCheckOutCardNumber.Text = string.Empty;
                                     errorCheckOut.Text         = Constants.BookIssued + card_no;
                                     errorCheckOut.Show();
                                 }
                                 else
                                 {
                                     errorCheckOut.Text = Constants.ErrorInIssuing;
                                     errorCheckOut.Show();
                                 }
                                 #endregion
                             }
                             else // Borrower is checking out same copy
                             {
                                 errorCheckOut.Text = Constants.SameCopyCheckOut;
                                 errorCheckOut.Show();
                             }
                             #endregion
                         }
                         else
                         {
                             #region Pending Fines
                             errorCheckOut.Text = Constants.PendingFines;
                             errorCheckOut.Show();
                             #endregion
                         }
                     }
                     else // Card number already holds 3 copies
                     {
                         errorCheckOut.Text = Constants.CardNumber + card_no + Constants.ThreeCopies;
                         errorCheckOut.Show();
                     }
                     #endregion
                 }
                 else // No copies Available
                 {
                     errorCheckOut.Text = Constants.NoBook;
                     errorCheckOut.Show();
                 }
                 #endregion
             }
             else // Card Number is not present in DB
             {
                 errorCheckOut.Text = Constants.NoBorrower;
                 errorCheckOut.Show();
             }
             #endregion
         }
         else
         {
             errorCheckOut.Text = Constants.RequiredFields;
             errorCheckOut.Show();
         }
     }
     catch (Exception ex)
     {
         errorCheckOut.Text = Constants.Error + ex.Message;
     }
 }