Exemplo n.º 1
0
        public bool AddSpending(string category, decimal amount)
        {
            if (category == null || category.Length == 0 || amount <= 0)
            {
                return(false);
            }
            int categoryID = GetCategoryID(category);

            if (categoryID < 0)
            {
                return(false);
            }
            Spending spending = GetSpending(categoryID);

            if (spending != null)
            {
                spending.IncreaseAmount(amount);
                balance.Amount -= amount;
                return(true);
            }
            int id = spendings.Count;

            spendings.Add(new Spending(id, categoryID, amount));
            balance.Amount -= amount;
            return(true);
        }
Exemplo n.º 2
0
        private Spending GetSpending(int categoryID)
        {
            Spending spending = null;

            foreach (Spending s in spendings)
            {
                if (s.CategoryID == categoryID && s.Date.Equals(DateTime.Today))
                {
                    spending = s;
                    break;
                }
            }
            return(spending);
        }
Exemplo n.º 3
0
        public decimal ShowSpendingsInCategoryByInterval(string category, DateTime start, DateTime end)
        {
            if (category == null || category.Length == 0)
            {
                return(0);
            }
            Spending spending = null;
            int      catID    = GetCategoryID(category);

            foreach (Spending s in spendings)
            {
                if (s.CategoryID == catID && s.Date.CompareTo(start) >= 0 && s.Date.CompareTo(end) <= 0)
                {
                    spending = s;
                    break;
                }
            }
            return(spending == null ? 0 : spending.Amount);
        }