Example #1
0
        /// <summary>
        /// Show a graph of the expenses by type from a given month
        /// </summary>
        private void GraphByTypeAndMonth()
        {
            int month = 99, year = 99;
            do
            {
                Console.WriteLine("Choose a month.\nPress 0 to exit.");
                int.TryParse(Console.ReadLine(), out month);
            } while (month > 12 || month < 0);

            if (month > 0)
            {
                do
                {
                    Console.WriteLine("Choose a year.\nPress 0 to exit.");
                    int.TryParse(Console.ReadLine(), out year);
                } while (year > DateTime.Now.Year || year < 0);

                if (year > 0)
                {
                    List<string> typeStr = new List<string>();
                    List<double> sums = new List<double>();
                    double max = 0;

                    ExpenseTypeController etc = new ExpenseTypeController();
                    List<ExpenseType> expenseTypes = etc.GetAllExpenseTypes();

                    ExpenseController ec = new ExpenseController();
                    foreach (ExpenseType type in expenseTypes)
                    {
                        List<Expense> expenses = ec.GetExpensesByTypeAndMonth(type, month, year);
                        if (expenses.Count > 0)
                        {
                            typeStr.Add(type.key);
                            double tmpAmount = 0;
                            foreach (Expense exp in expenses)
                            {
                                tmpAmount += exp.payment.amount;   
                            }
                            if (tmpAmount > max)
                            {
                                max = tmpAmount;
                            }

                            sums.Add(tmpAmount);
                        }
                    }

                    for (int i = 0; i < typeStr.Count; i++)
                    {
                        Console.Write(typeStr[i] + "\t");
                        int nrStar = (int)sums[i] * 10 / (int)max;
                        for (int j = 0; j < nrStar; j++)
                        {
                            Console.Write("*");
                        }
                        Console.WriteLine();
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// List the expenses by category from given month
        /// </summary>
        private void ListByTypeAndMonth()
        {
            int month = 99, year = 99;
            do
            {
                Console.WriteLine("Choose a month.\nPress 0 to exit.");
                int.TryParse(Console.ReadLine(), out month);
            } while (month > 12 || month < 0);

            if (month > 0)
            {
                do
                {
                    Console.WriteLine("Choose a year.\nPress 0 to exit.");
                    int.TryParse(Console.ReadLine(), out year);
                } while (year > DateTime.Now.Year || year < 0);

                if (year > 0)
                {
                    ExpenseTypeController etc = new ExpenseTypeController();
                    List<ExpenseType> expenseTypes = etc.GetAllExpenseTypes();

                    ExpenseController ec = new ExpenseController();
                    foreach (ExpenseType type in expenseTypes)
                    {
                        List<Expense> expenses = ec.GetExpensesByTypeAndMonth(type, month, year);
                        if (expenses.Count > 0)
                        {
                            Console.WriteLine(type.ToString());
                            foreach (Expense exp in expenses)
                            {
                                Console.WriteLine(exp.ToString());
                            }
                        }
                    }
                }

            }
        }
        public void TestGetExpensesByMonthAndType()
        {
            ExpenseController ec = new ExpenseController();
            ExpenseType type = new ExpenseType("AAA", "aaa");
            Money money1 = new Money("EUR");
            Payment pay1 = new Payment(money1, 15);
            DateTime date = new DateTime(2012, 12, 21, 15, 30, 00);
            ec.RegisterExpense(type, pay1, date, "AAA");

            DateTime date1 = DateTime.Now;
            ec.RegisterExpense(type, pay1, date1, "BBB");

            List<Expense> list = ec.GetExpensesByTypeAndMonth(type, date1.Month, date1.Year);
            Assert.AreEqual(String.Format("Expense:\nDescription: BBB\nType: AAA - aaa\nPayment: Payment: Money\nCurrency: EUR\nAmount: 15\nDate: {0}", date1), list[0].ToString());
        }