Example #1
0
        public void BookScanned(int bookID)
        {
            if (bookID <= 0)
            {
                throw new ArgumentException(String.Format("BorrowCTL : bookScanned : bookID cannot be <= 0."));
            }
            if (state != BorrowCTLConstants.State.BORROWING)
            {
                throw new ApplicationException(
                        String.Format("BorrowCTL : cardScanned : illegal operation in state: {0}", state));
            }
            book = bookDAO.GetBookByID(bookID);
            if (book == null)
            {
                throw new ApplicationException(String.Format("BorrowCTL : bookScanned : bookID not found"));
            }

            if (book.State != BookConstants.BookState.AVAILABLE)
            {
                throw new ApplicationException(String.Format("BorrowCTL : bookScanned : illegal BookState: %s", book.State));
            }
            if (bookList.Contains(book))
            {
                throw new ApplicationException(String.Format("BorrowCTL : bookScanned : book %d already scanned: ", book.ID));
            }
            DateTime borrowDate = DateTime.Now;
            TimeSpan loanPeriod = new TimeSpan(LoanConstants.LOAN_PERIOD, 0, 0, 0);
            DateTime dueDate = borrowDate.Add(loanPeriod);

            loanDAO.CreatePendingLoan(member, book, borrowDate, dueDate);
            bookList.Add(book);
            pendingLoanCount++;

            atLoanLimit = ((existingLoanCount + pendingLoanCount) >= MemberConstants.LOAN_LIMIT);
            further_borrowing_allowed = !(overdue || atLoanLimit || overFineLimit);

            ui.DisplayBook(book);
            pendingList = loanDAO.GetPendingList(member);
            ui.DisplayPendingList(pendingList);

            if (atLoanLimit)
            {
                state = BorrowCTLConstants.State.COMPLETED;
                ui.SetState(state);
                pendingList = loanDAO.GetPendingList(member);
                ui.DisplayCompletedList(pendingList);

            }
        }
Example #2
0
 public void RejectPendingList()
 {
     if (state != BorrowCTLConstants.State.COMPLETED)
     {
         throw new ApplicationException(
                 String.Format("BorrowCTL : rejectPendingList : illegal operation in state: {0}", state));
     }
     pendingList = loanDAO.GetPendingList(member);
     pendingList.Clear();
     bookList.Clear();
     pendingLoanCount = 0;
     state = BorrowCTLConstants.State.BORROWING;
     ui.SetState(state);
     ui.ScanBook();
 }
Example #3
0
 public void ScansCompleted()
 {
     if (state != BorrowCTLConstants.State.BORROWING)
     {
         throw new ApplicationException(
                 String.Format("BorrowCTL : scanNext : illegal operation in state: {0}", state));
     }
     state = BorrowCTLConstants.State.COMPLETED;
     ui.SetState(state);
     pendingList = loanDAO.GetPendingList(member);
     ui.DisplayCompletedList(pendingList);
 }
Example #4
0
 public void Initialise()
 {
     state = BorrowCTLConstants.State.STARTED;
     ui.Initialise(this);
     ui.SetState(state);
 }
Example #5
0
 public void ConfirmPendingList()
 {
     if (state != BorrowCTLConstants.State.COMPLETED)
     {
         throw new ApplicationException(
                 String.Format("BorrowCTL : confirmPendingList : illegal operation in state: {0}", state));
     }
     loanDAO.CommitPendingLoans(member);
     bookList = null;
     state = BorrowCTLConstants.State.CONFIRMED;
     ui.SetState(state);
     ui.PrintLoanSlip();
 }
Example #6
0
        public void CardScanned(int memberID)
        {
            if (memberID <= 0)
            {
                throw new ArgumentException(String.Format("BorrowCTL : cardScanned : memberID cannot be <= 0."));
            }
            if (state != BorrowCTLConstants.State.STARTED)
            {
                throw new ApplicationException(
                        String.Format("BorrowCTL : cardScanned : illegal operation in state: {0}", state));
            }
            member = memberDAO.GetMemberByID(memberID);
            if (member == null)
            {
                throw new ApplicationException(String.Format("BorrowCTL : cardScanned : memberID not found"));
            }
            overdue = member.HasOverDueLoans;
            atLoanLimit = member.HasReachedLoanLimit;
            overFineLimit = member.HasReachedFineLimit;
            further_borrowing_allowed = !(overdue || atLoanLimit || overFineLimit);
            existingLoanCount = member.Loans.Count;

            ui.DisplayBorrowerDetails(member);
            if (further_borrowing_allowed)
            {
                state = BorrowCTLConstants.State.BORROWING;
                ui.SetState(state);
                loanDAO.CreateNewPendingList(member);
                bookList.Clear();
                ui.ScanBook();
            }
            else
            {
                state = BorrowCTLConstants.State.DISALLOWED;
                ui.SetState(state);
            }
        }
Example #7
0
 public void Cancel()
 {
     if (state != BorrowCTLConstants.State.STARTED && state != BorrowCTLConstants.State.DISALLOWED)
     {
         loanDAO.ClearPendingLoans(member);
     }
     state = BorrowCTLConstants.State.ENDED;
     ui.SetState(state);
 }
Example #8
0
 public void BorrowUcEnded()
 {
     if (state != BorrowCTLConstants.State.CONFIRMED)
     {
         throw new ApplicationException(
                 String.Format("BorrowCTL : borrowUCended : illegal operation in state: {0}", state));
     }
     state = BorrowCTLConstants.State.ENDED;
     ui.SetState(state);
 }