Ejemplo n.º 1
0
        /// <summary>
        /// Find a solution to give money back to user
        /// </summary>
        /// <param name="money"></param>
        /// <returns>
        /// List of denominations to return to user
        /// </returns>
        public static List<ATMMoneyItem> Solution(float money)
        {
            var list = new List<ATMMoneyItem>();

            _list = _list.OrderBy(x => x.Denomination).ToList();
            _list.Reverse();

            float withdrawalMoney = money;


            foreach (ATMMoneyItem t in _list)
                if (withdrawalMoney > 0)
                {
                    var temp = (int)(withdrawalMoney / t.Denomination);
                    var item = new ATMMoneyItem
                               {
                                   Currency = ConstParameters.CURRENCY, 
                                   Denomination = t.Denomination
                               };
                    if (temp < t.Quantity)
                    {
                        withdrawalMoney -= t.Denomination * temp;
                        item.Quantity = temp;
                    }

                    else
                    {
                        withdrawalMoney -= t.Denomination * t.Quantity;
                        item.Quantity = t.Quantity;
                    }
                    list.Add(item);
                }

            return list;
        }
Ejemplo n.º 2
0
 public  static List<ATMMoneyItem> GetMoneyStore()
 {
     var list = new List<ATMMoneyItem>(); 
     cnn = SqlConnectionData.getAtmConnection();
     string queryCommand = "Select * from ATMMoneyStore";
     var adapter = new SqlDataAdapter(queryCommand, cnn);
     var mn = new DataTable();
     adapter.Fill(mn);
     if (mn.Rows.Count > 0)
     {
         int count = 0;
         while (count < mn.Rows.Count)
         {
             ATMMoneyItem money = new ATMMoneyItem();
             money.Denomination = Convert.ToSingle(mn.Rows[count]["Denomination"].ToString());
             money.Currency = mn.Rows[count]["Currency"].ToString();
             money.Quantity = Convert.ToInt32(mn.Rows[count]["Quantity"].ToString());
             list.Add(money);
             count++;
         }
         
     }
     SqlConnectionData.CloseConnection();
     return list;
 }