Beispiel #1
0
        /// <summary>
        /// Update Fines Table
        /// </summary>
        public void UpdateFines()
        {
            List <int>    currentLoanIds;
            tblBOOK_LOANS loans;
            tblFINE       fine;
            double        overDays = 0;
            double        totalFine;
            double        finePerDay = 0.25;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    #region Get Loans And Update Fines
                    // Get the all loans of which Fines are Due.
                    #region Fines - Associated with books not returned yet
                    currentLoanIds = new List <int>();
                    currentLoanIds = (from allLoans in entity.tblBOOK_LOANS
                                      where allLoans.Date_in == null && DateTime.Now > allLoans.Due_date
                                      select allLoans.Loan_id).ToList();

                    #endregion

                    //Get All loans which haven't payed Fines
                    #region Fines - Associated with books returned and Not Paid Yet
                    List <int> loanIds = new List <int>();
                    loanIds = (from allLoans in entity.tblBOOK_LOANS
                               join fines in entity.tblFINES on allLoans.Loan_id equals fines.Loan_id
                               where  allLoans.Date_in > allLoans.Due_date && fines.paid == false
                               select allLoans.Loan_id).ToList();
                    currentLoanIds.AddRange(loanIds);
                    #endregion

                    //update the Fines to above result
                    foreach (int loanid in currentLoanIds)
                    {
                        fine      = new tblFINE();
                        loans     = new tblBOOK_LOANS();
                        loans     = (from loan in entity.tblBOOK_LOANS where loan.Loan_id == loanid select loan).FirstOrDefault();
                        overDays  = (DateTime.Now - Convert.ToDateTime(loans.Due_date)).TotalDays;
                        overDays  = Math.Floor(overDays);
                        totalFine = overDays * finePerDay;
                        totalFine = Math.Round(totalFine, 2);
                        fine      = (from fines in entity.tblFINES
                                     where fines.Loan_id == loanid
                                     select fines).FirstOrDefault();
                        fine.paid        = false;
                        fine.Fine_amount = Convert.ToDecimal(totalFine);
                        entity.SaveChanges();
                    }
                    #endregion
                }
            }
            catch (Exception e)
            {
                // Excetpion in Entity
            }
        }
Beispiel #2
0
        /// <summary>
        /// Add New Book Loan Touple to Database And Fines.
        /// </summary>
        /// <param name="bookId">Book Id</param>
        /// <param name="branchId">Branch Id</param>
        /// <param name="cardNumber">Card Number</param>
        /// <param name="dateOut">Date Out</param>
        /// <param name="dueDate">Due Date</param>
        public bool AddNewBookLoanAndFines(string bookId, int branchId, int cardNumber, DateTime dateOut, DateTime dueDate)
        {
            tblBOOK_LOANS bookLoans;
            tblFINE       fines;
            bool          result;
            int           newLoanId;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    #region Add New Book Loans
                    bookLoans           = new tblBOOK_LOANS();
                    bookLoans.Book_id   = bookId.Trim();
                    bookLoans.Branch_id = branchId;
                    bookLoans.Card_no   = cardNumber;
                    bookLoans.Date_out  = dateOut;
                    bookLoans.Due_date  = dueDate;
                    entity.AddTotblBOOK_LOANS(bookLoans);
                    entity.SaveChanges();

                    newLoanId = (from latest in entity.tblBOOK_LOANS
                                 where latest.Book_id == bookId.Trim() && latest.Branch_id == branchId &&
                                 latest.Card_no == cardNumber
                                 select latest.Loan_id).FirstOrDefault();
                    #endregion

                    #region Add New Fines
                    fines             = new tblFINE();
                    fines.Book_id     = bookId.Trim();
                    fines.Loan_id     = newLoanId;
                    fines.paid        = true;
                    fines.Fine_amount = 0;
                    fines.Branch_id   = branchId;
                    entity.AddTotblFINES(fines);
                    entity.SaveChanges();
                    #endregion
                    result = true;
                }
                return(result);
            }
            catch (Exception e)
            {
                result = false;
                return(result);
                // Exception In Entity
            }
        }
Beispiel #3
0
        /// <summary>
        /// Update Book copies Issued Count and date In
        /// </summary>
        /// <param name="bookId">Book Id</param>
        /// <param name="branchId">Branch Id</param>
        public bool UpdateIssuedCopiesCountDateInDetails(string bookId, int branchId, int cardNumber, DateTime dateIn)
        {
            bool          result = true;
            tblBOOK_LOANS bookLoans;

            try
            {
                using (LibraryEntities entity = new LibraryEntities())
                {
                    string bookId_ = bookId.Trim();
                    #region Update Book Copies Issued Count
                    // Update Book Issued Count in Book Copies.
                    entity.uspUpdateIssuedCopiesCount(bookId_, branchId);
                    #endregion

                    #region Update Book Loans Table
                    // Update Book Loans Table.
                    bookLoans = new tblBOOK_LOANS();
                    bookLoans = (from item in entity.tblBOOK_LOANS
                                 where item.Book_id == bookId_ && item.Branch_id == branchId &&
                                 item.Card_no == cardNumber
                                 select item).FirstOrDefault();
                    bookLoans.Date_in = dateIn;
                    entity.SaveChanges();
                    #endregion

                    result = true;
                }
                return(result);
            }
            catch (Exception e)
            {
                result = false;
                return(result);
            }
        }