public BorrowController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                    IBookDAO bookDAO, ILoanDAO loanDAO, IMemberDAO memberDAO)
        {
            if(display == null) throw new ArgumentException("Display object was not provided to begin the application");
            if (reader == null) throw new ArgumentException("Reader object was not provided to begin the application");
            if (scanner == null) throw new ArgumentException("Scanner object was not provided to begin the application");
            if (printer == null) throw new ArgumentException("Printer object was not provided to begin the application");
            if (bookDAO == null) throw new ArgumentException("BookDAO object was not provided to begin the application");
            if (loanDAO == null) throw new ArgumentException("LoanDAO object was not provided to begin the application");
            if (memberDAO == null) throw new ArgumentException("MemberDAO object was not provided to begin the application");

            _display = display;
            _reader = reader;
            _scanner = scanner;
            _printer = printer;

            _bookDAO = bookDAO;
            _loanDAO = loanDAO;
            _memberDAO = memberDAO;

            _ui = new BorrowControl(this);

            _reader.Listener = this;
            _scanner.Listener = this;

            _bookList = new List<IBook>();
            _loanList = new List<ILoan>();

            _state = EBorrowState.CREATED;
        }
        public BorrowController(IDisplay display, ICardReader reader, IScanner scanner, IPrinter printer,
                                    IBookDAO bookDAO, ILoanDAO loanDAO, IMemberDAO memberDAO)
        {
            _display = display;
            _reader = reader;
            _scanner = scanner;
            _printer = printer;

            _ui = new BorrowControl(this);

            _state = EBorrowState.CREATED;
        }
 private void addControl(ABorrowControl control, EBorrowState state)
 {
     _controlDict.Add(state, control);
 }
        private void setState(EBorrowState state)
        {
            Console.WriteLine("Setting state: " + state);

            this._state = state;

            switch (state)
            {
                case EBorrowState.INITIALIZED:
                    _reader.Listener = this;
                    _scanner.Listener = this;
                    _currentControl = new SwipeCardControl(this);
                    _reader.Enabled = true;
                    _scanner.Enabled = false;
                    break;

                case EBorrowState.BORROWING_RESTRICTED:
                    _currentControl = new RestrictedControl(this);
                    _reader.Enabled = false;
                    _scanner.Enabled = false;
                    _currentControl.DisplayErrorMessage(String.Format("Member {0} cannot borrow at this time.", _borrower.ID));
                    break;

                case EBorrowState.SCANNING_BOOKS:
                    _currentControl = new ScanBookControl(this);
                    _reader.Enabled = false;
                    _scanner.Enabled = true;
                    _bookList = new List<IBook>();
                    _loanList = new List<ILoan>();
                    break;

                case EBorrowState.CONFIRMING_LOANS:
                    _currentControl = new ConfirmLoanControl(this);
                    _reader.Enabled = false;
                    _scanner.Enabled = false;
                    //display pending loans
                    foreach (ILoan loan in _loanList)
                    {
                        _currentControl.DisplayConfirmingLoan(loan.ToString());
                    }
                    break;

                case EBorrowState.COMPLETED:
                    _reader.Enabled = false;
                    _scanner.Enabled = false;
                    StringBuilder bld = new StringBuilder();
                    foreach (ILoan loan in _loanList)
                    {
                        _loanDAO.CommitLoan(loan);
                        bld.Append(loan.ToString() + "\n\n");
                    }
                    _printer.print(bld.ToString());
                    close();
                    return;

                case EBorrowState.CANCELLED:
                    _reader.Enabled = false;
                    _scanner.Enabled = false;
                    close();
                    return;

                default:
                    throw new ApplicationException("Unknown state");
            }
            _display.Display = _currentControl;
        }
Beispiel #5
0
 private void addControl(ABorrowControl control, EBorrowState state)
 {
     _controlDict.Add(state, control);
 }