示例#1
0
        private void LoadItems()
        {
            try
            {
                _dispenser = CashDispenserFactory.GetDispenser();
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (_dispenser != null)
                {
                    dgvItems.Rows.Clear();

                    foreach (CashDispenserItem item in _dispenser.DispenserItems)
                    {
                        int             rowIndex = dgvItems.Rows.Add();
                        DataGridViewRow row      = dgvItems.Rows[rowIndex];
                        row.Cells[chdrSNo.Index].Value           = (rowIndex + 1);
                        row.Cells[chdrCassetteAlias.Index].Value = item.CassetteAlias;
                        row.Cells[chdrDenomination.Index].Value  = item.Denimination;
                        row.Cells[chdrTotalValue.Index].Value    = item.TotalValue;
                        row.Tag = item;
                    }

                    dgvItems.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                }
            }
        }
示例#2
0
        public static string ListOfBill(ICashDispenser cashDispenser, IDab dab)
        {
            if (!cashDispenser.IsSufficientBalance)
            {
                return("Solde insufisant");
            }
            else if (!cashDispenser.IsSufficientCash)
            {
                return("Billets dans Dab insufissant");
            }
            else if (!cashDispenser.IsValidAmount)
            {
                return("Quantite invalide");
            }
            else
            {
                StringBuilder reponse = new StringBuilder();

                for (int i = 0; i < cashDispenser.NumberOfBills.Length; i++)
                {
                    if (cashDispenser.NumberOfBills[i] > 0)
                    {
                        reponse.Append(" " + cashDispenser.NumberOfBills[i] + " x " + dab.GetBills()[i]);
                    }
                }

                return(reponse.ToString());
            }
        }
示例#3
0
        public BankModule(ICashDispenser dispenser, IAccountRepository accountRepo)
        {
            _dispenser = dispenser;
            _accountRepo = accountRepo;

            Get["/"] = _ =>
                           {
                               return @"<html>
                                          <body>
                                            <form action='/withdraw' method='post'>
                                              <label for='accountNo'>Account no</label>
                                              <input type='text' name='accountNo' id='accountNo'>
                                              <br />
                                              <label for='amount'>Amount</label>
                                              <input type='text' name='amount' id='amount'>
                                              <br />
                                              <input type='submit' name='withdraw' id='withdraw' value='Withdraw'>
                                            </form>
                                          </body>
                                        </html>";
                           };

            Post["/withdraw"] = p =>
                                    {
                                        var vm = this.Bind<WithdrawalVM>();
                                        var account = _accountRepo.GetAccount(vm.AccountNo);
                                        var teller = new Teller(_dispenser);
                                        teller.AuthenticateAs(account);
                                        teller.Withdraw(vm.Amount);
                                        return "It's done!";
                                    };
        }
示例#4
0
        private void LoadItems()
        {
            try
            {
                _dispenser = CashDispenserFactory.GetDispenser();
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (_dispenser != null)
                {
                    dgvItems.Rows.Clear();

                    foreach (CashDispenserItem item in _dispenser.DispenserItems)
                    {
                        int rowIndex = dgvItems.Rows.Add();
                        DataGridViewRow row = dgvItems.Rows[rowIndex];
                        row.Cells[chdrSNo.Index].Value = (rowIndex + 1);
                        row.Cells[chdrCassetteAlias.Index].Value = item.CassetteAlias;
                        row.Cells[chdrDenomination.Index].Value = item.Denimination;
                        row.Cells[chdrTotalValue.Index].Value = item.TotalValue;
                        row.Tag = item;
                    }

                    dgvItems.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
                }
            }
        }
示例#5
0
 public Withdrawal(int userAccount, IScreen atmScreen,
                   IBankDatabase atmBankDatabase, IKeypad atmKeypad, ICashDispenser atmCashDispenser)
     : base(userAccount, atmBankDatabase, atmScreen)
 {
     _keypad        = atmKeypad;
     _cashDispenser = atmCashDispenser;
 }
示例#6
0
        /// <summary>
        /// Loads the items.
        /// </summary>
        private void LoadItems()
        {
            LogManager.WriteLog("|=> (LoadItems) : Invoked.", LogManager.enumLogLevel.Info);
            string message = string.Empty;
            uint   iErrorCode;

            try
            {
                using (ICashDispenser dispenser = CashDispenserFactory.GetDispenser())
                {
                    bool isOK = false;
                    try
                    {
                        // GetStatus Calling
                        isOK = (CashDispenserItem.GetStatus(out message, out iErrorCode) == CashDispenserItem.DispenserStatus.Available);
                    }
                    catch (Exception ex)
                    {
                        _errorText = "Unable to connect cash dispenser.";
                        iErrorCode = 1;
                        ExceptionManager.Publish(ex);
                    }

                    // after calling GetStatus
                    _errorText = (isOK ? string.Empty : message);
                    for (int i = 0; i < dispenser.DispenserItems.Count; i++)
                    {
                        CashDispenserItem item = dispenser.DispenserItems[i];

                        if (item.DeckType == CashDispenserItem.TypeOfDeck.Upper)
                        {
                            _upperText.IsOK = Convert.ToInt32(_upperText.StatusText) == 0 ? false: !CashDispenserItem.IsUpperTrayError(iErrorCode);
                        }
                        else
                        {
                            _lowerText.IsOK = Convert.ToInt32(_lowerText.StatusText) == 0 ? false : !CashDispenserItem.IsLowerTrayError(iErrorCode);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _errorText = "Unable to connect cash dispenser.";
                ExceptionManager.Publish(ex);
            }
            finally
            {
                this.Dispatcher.Invoke(new Action(
                                           delegate()
                {
                    this.UpdateTexts();
                }
                                           ));
            }
        }
示例#7
0
        public ICashDispenser WithDraw(string name, decimal amount)
        {
            ICashDispenser cashDispenser = Factory.CreateCashDispenser();

            IAccount     account  = GetAccountByName(name);
            ITransaction withDraw = new WithDraw()
            {
                Account = account,
                Amount  = amount
            };

            if (account.Balance < amount)
            {
                cashDispenser.IsSufficientBalance = false;
                return(cashDispenser);
            }
            else
            {
                cashDispenser.IsSufficientBalance = true;
            }

            int[] bills = _dab.GetBills();

            for (int i = 0; i < bills.Length; i++)
            {
                if (!(amount < bills[i]))
                {
                    cashDispenser.NumberOfBills[i] = (int)amount / bills[i];
                    if (cashDispenser.NumberOfBills[i] > _dab.NumberOfBills[i])
                    {
                        cashDispenser.NumberOfBills[i] = _dab.NumberOfBills[i];
                    }
                    amount -= bills[i] * cashDispenser.NumberOfBills[i];
                }
            }

            if (amount > 10)
            {
                cashDispenser.IsSufficientCash = false;
                return(cashDispenser);
            }
            else if (amount > 0 && amount < 10)
            {
                cashDispenser.IsValidAmount = false;
                return(cashDispenser);
            }
            else
            {
                cashDispenser.IsSufficientCash = true;
                cashDispenser.IsValidAmount    = true;
                cashDispenser.Dispense(_dab);
                withDraw.Execute();
                return(cashDispenser);
            }
        }
示例#8
0
 /// <summary>
 /// no-argument ATM constructor initializes instance variables
 /// </summary>
 public ATM(ICashDispenser cashDispenser, IBankDatabase bankDatabase, IDepositSlot depositSlot, IKeypad keypad, IScreen screen, IMenu menu)
 {
     _userAuthenticated    = false;
     _currentAccountNumber = 0;
     _depositSlot          = depositSlot;
     _keypad        = keypad;
     _screen        = screen;
     _menu          = menu;
     _cashDispenser = cashDispenser;
     _bankDatabase  = bankDatabase;
 }
        /// <summary>
        /// Loads the items.
        /// </summary>
        private void LoadItems()
        {
            try
            {
                using (ICashDispenser dispenser = CashDispenserFactory.GetDispenser())
                {
                    string currencySymbol = ExtensionMethods.GetCurrencySymbol(string.Empty);

                    for (int i = 0; i < dispenser.DispenserItems.Count; i++)
                    {
                        CashDispenserItem item  = dispenser.DispenserItems[i];
                        string            sText = item.CassetteAlias + " : " + currencySymbol + " " + item.Denimination.ToString();

                        if (item.DeckType == CashDispenserItem.TypeOfDeck.Upper)
                        {
                            _upperDenomination = item.Denimination;
                            lblCD1.Text        = sText;
                            string balance = item.TotalValue.ToString();
                            if (string.IsNullOrEmpty(balance))
                            {
                                balance = "0";
                            }
                            lblBalance1.Text = balance;
                            txtCD1.Text      = "";
                            txtCD1.Tag       = item;
                            txtCD1_TextChanged(txtCD1, null);
                        }
                        else
                        {
                            _lowerDenomination = item.Denimination;
                            lblCD2.Text        = sText;
                            string balance = item.TotalValue.ToString();
                            if (string.IsNullOrEmpty(balance))
                            {
                                balance = "0";
                            }
                            lblBalance2.Text = balance;
                            txtCD2.Text      = "";
                            txtCD2.Tag       = item;
                            txtCD2_TextChanged(txtCD2, null);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }
        }
        /// <summary>
        /// Loads the items.
        /// </summary>
        private void LoadItems(bool isInit)
        {
            Brush redBrush   = Brushes.Red;
            Brush greenBrush = Brushes.Green;

            try
            {
                using (ICashDispenser dispenser = CashDispenserFactory.GetDispenser())
                {
                    string currencySymbol = ExtensionMethods.GetCurrencySymbol(string.Empty);

                    for (int i = 0; i < dispenser.DispenserItems.Count; i++)
                    {
                        CashDispenserItem item   = dispenser.DispenserItems[i];
                        string            sText  = item.CassetteAlias + " : ";
                        string            sText2 = currencySymbol + " " + item.Denimination.ToString();

                        string message = string.Empty;
                        bool   isOK    = isInit ? false : (item.TestStatus(out message) == CashDispenserItem.DispenserStatus.Available);
                        lblErrorDesc.Text = (isOK ? string.Empty : message);

                        Brush  brush      = isOK ? greenBrush : redBrush;
                        string statusText = string.Empty;

                        if (item.DeckType == CashDispenserItem.TypeOfDeck.Upper)
                        {
                            lblCD1.Text            = sText;
                            lblCD1Calc.Text        = sText2;
                            rcCD1Status.Content    = statusText;
                            rcCD1Status.Background = brush;
                        }
                        else
                        {
                            lblCD2.Text            = sText;
                            lblCD2Calc.Text        = sText2;
                            rcCD2Status.Content    = statusText;
                            rcCD2Status.Background = brush;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }
        }
 /// <summary>
 /// Loads the decks.
 /// </summary>
 public void LoadDecks()
 {
     using (ICashDispenser dispenser = CashDispenserFactory.GetDispenser())
     {
         IList <CashDispenserItem> items = dispenser.DispenserItems;
         foreach (CashDispenserItem item in items)
         {
             if (item.DeckType == CashDispenserItem.TypeOfDeck.Lower)
             {
                 this.LowerDeck = item;
             }
             else
             {
                 this.UpperDeck = item;
             }
         }
     }
 }
示例#12
0
        /// <summary>
        /// Loads the items.
        /// </summary>
        public void LoadDBItems()
        {
            if (!CashDispenserWorker.IsVisible)
            {
                return;
            }
            LogManager.WriteLog("|=> (LoadDBItems) : Invoked.", LogManager.enumLogLevel.Info);

            try
            {
                using (ICashDispenser dispenser = CashDispenserFactory.GetDispenser())
                {
                    string currencySymbol = ExtensionMethods.GetCurrencySymbol(string.Empty);

                    // before calling GetStatus
                    for (int i = 0; i < dispenser.DispenserItems.Count; i++)
                    {
                        CashDispenserItem item       = dispenser.DispenserItems[i];
                        string            sText      = item.CassetteAlias + " : ";
                        string            sText2     = currencySymbol + " " + item.Denimination.ToString();
                        string            statusText = item.RemainingValueCalculated.ToString();

                        if (item.DeckType == CashDispenserItem.TypeOfDeck.Upper)
                        {
                            _upperText.Text       = sText;
                            _upperText.Text2      = sText2;
                            _upperText.StatusText = statusText;
                        }
                        else
                        {
                            _lowerText.Text       = sText;
                            _lowerText.Text2      = sText2;
                            _lowerText.StatusText = statusText;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
            }
        }
 private void LoadItems()
 {
     try
     {
         _dispenser = CashDispenserFactory.GetDispenser();
     }
     catch (Exception ex)
     {
         ExceptionManager.Publish(ex);
     }
     finally
     {
         if (_dispenser != null)
         {
             //Gets the denom and total value for UPPER Cassette Alias
             IList <CashDispenserItem> dispenserUpperItems = _dispenser.DispenserItems;//.Where(Item => Item.DeckType.ToString().ToUpper() == "UPPER")
             //.ToList();
             foreach (CashDispenserItem item in dispenserUpperItems)
             {
                 if (item.DeckType == CashDispenserItem.TypeOfDeck.Upper)
                 {
                     txtCassetteAlias.Text = item.CassetteAlias;
                     txtDenom.Text         = item.Denimination.ToString().GetDecimal().ToString();
                     txtTotalValue.Text    = "0";
                     txtRemaining1.Text    = item.TotalValue.ToString().GetDecimal().ToString();
                     lblDeck1.Text         = item.DeckType.ToString();
                     txtCassetteAlias.Tag  = item;
                 }
                 else
                 {
                     txtCassetteAlias2.Text = item.CassetteAlias;
                     txtDenom2.Text         = item.Denimination.ToString().GetSingleFromString().ToString();
                     txtTotal2.Text         = "0";
                     txtRemaining2.Text     = item.TotalValue.ToString().GetDecimal().ToString();
                     lblDeck2.Text          = item.DeckType.ToString();
                     txtCassetteAlias2.Tag  = item;
                 }
             }
         }
     }
 }
 private void LoadItems()
 {
     try
     {
         _dispenser = CashDispenserFactory.GetDispenser();
     }
     catch (Exception ex)
     {
         ExceptionManager.Publish(ex);
     }
     finally
     {
         if (_dispenser != null)
         {
           //Gets the denom and total value for UPPER Cassette Alias
           IList<CashDispenserItem> dispenserUpperItems = _dispenser.DispenserItems;//.Where(Item => Item.DeckType.ToString().ToUpper() == "UPPER")
                 //.ToList();
           foreach (CashDispenserItem item in dispenserUpperItems)
           {
               if (item.DeckType == CashDispenserItem.TypeOfDeck.Upper)
               {
                   txtCassetteAlias.Text = item.CassetteAlias;
                   txtDenom.Text = item.Denimination.ToString().GetDecimal().ToString();
                   txtTotalValue.Text = "0";
                   txtRemaining1.Text = item.TotalValue.ToString().GetDecimal().ToString();
                   lblDeck1.Text = item.DeckType.ToString();
                   txtCassetteAlias.Tag = item;
               }
               else
               {
                   txtCassetteAlias2.Text = item.CassetteAlias;
                   txtDenom2.Text = item.Denimination.ToString().GetSingleFromString().ToString();
                   txtTotal2.Text = "0";
                   txtRemaining2.Text = item.TotalValue.ToString().GetDecimal().ToString();
                   lblDeck2.Text = item.DeckType.ToString();
                   txtCassetteAlias2.Tag = item;
               }
           }                    
         }
     }
 }
            /// <summary>
            /// Collect the change in the cash dispenser.
            /// </summary>
            /// <param name="request">The cash dispenser request value.</param>
            /// <returns>Returns success if the change is collected.</returns>
            public bool CollectChange(CashDispenserRequest request)
            {
                ThrowIf.Null(request, "request");

                ICashDispenser cashDispenser = CompositionManager.Instance.GetComponent <ICashDispenser>("WINDOWS");
                string         deviceName    = request.DeviceName;

                if (string.IsNullOrWhiteSpace(deviceName))
                {
                    deviceName = CashDispenserController.CashDispenserTestName;
                }

                if (cashDispenser != null)
                {
                    try
                    {
                        cashDispenser.Open(deviceName, null);
                        cashDispenser.CollectChange(request.Change, request.Currency);

                        return(true);
                    }
                    catch (Exception ex)
                    {
                        RetailLogger.Log.HardwareStationActionFailure("Hardware station an exception occurred when operating on cash dispenser.", ex);
                        throw new PeripheralException("Microsoft_Dynamics_Commerce_HardwareStation_CashDispenser_Error", ex.Message, ex);
                    }
                    finally
                    {
                        cashDispenser.Close();
                    }
                }
                else
                {
                    throw new PeripheralException("Microsoft_Dynamics_Commerce_HardwareStation_CashDispenser_Error");
                }
            }
示例#16
0
 public void WithDraw(ICashDispenser cashDispenser)
 {
 }
示例#17
0
文件: Atm.cs 项目: Josbleuet/ttd
 public Atm(ITransactionFactory transactionFactory, ICashDispenser cashDispenser)
 {
     this.transactionFactory = transactionFactory;
     this.cashDispenser      = cashDispenser;
 }
 public AutomatedTellerMachine(IAccountService accountService, ICashDispenser cashDispenser)
 {
     _accountService = accountService;
     _cashDispenser = cashDispenser;
 }
示例#19
0
 // TODO: Take dispenser and display as constructor parameters
 public MyAtmMachine(ICashDispenser cd, IDisplay dis, long withdrawAmount)
 {
     _cashDispenser  = cd;
     _display        = dis;
     _withdrawAmount = withdrawAmount;
 }
 public AtmAutomatorNancy(ICashDispenser cashDispenser)
 {
     _cashDispenser = cashDispenser;
 }
示例#21
0
 public void SetNextDispenser(ICashDispenser _nextDispenser)
 {
     nextDispenser = _nextDispenser;
 }
示例#22
0
 public TransactionService()
 {
     cashDispenser = new CashDispenser();
 }
示例#23
0
        public ITransaction CreateTransaction(int type, int currentAccountNumber, IBankDatabase atmBankDatabase, IScreen atmScreen, IKeypad atmKeypad, ICashDispenser atmCashDispenser, IDepositSlot atmDepositSlot)
        {
            ITransaction temp = null;

            switch (type)
            {
            case 1:
                temp = new BalanceInquiry(currentAccountNumber, atmScreen, atmBankDatabase);
                break;

            case 2:
                temp = new Withdrawal(currentAccountNumber, atmScreen, atmBankDatabase, atmKeypad, atmCashDispenser);
                break;

            case 3:
                temp = new Deposit(currentAccountNumber, atmScreen, atmBankDatabase, atmKeypad, atmDepositSlot);
                break;
            }

            return(temp);
        }
示例#24
0
 public Teller(ICashDispenser CashDispenser)
 {
     _cashDispsener = CashDispenser;
 }
示例#25
0
 public TransactionService(Entities context)
 {
     cashDispenser = new CashDispenser(context);
 }