Пример #1
0
        public void TestRegisterExpenseType()
        {
            ExpenseTypeController retC = new ExpenseTypeController();
            retC.RegisterExpenseType("AAA", "aaa");
            retC.RegisterExpenseType("A1B1", "testes");

            List<ExpenseType> list = PersistenceFactory.GetFactory().GetRepository().GetExpenseTypeRepository().All();

            Assert.AreEqual(list[0].ToString(), "AAA - aaa");
            Assert.AreEqual(list[1].ToString(), "A1B1 - testes");
        }
Пример #2
0
        /// <summary>
        /// The specific method to the register expense type ui
        /// </summary>
        public void ShowRegisterExpenseType()
        {
            string key, description;

            Console.WriteLine("Insert the key for the expense type");
            key = Console.ReadLine();
            Console.WriteLine("Insert the description fot the expense type");
            description = Console.ReadLine();

            ExpenseTypeController retC = new ExpenseTypeController();
            retC.RegisterExpenseType(key, description);
        }
Пример #3
0
        /// <summary>
        /// Method that will list all of expense types in repository
        /// </summary>
        public void List()
        {
            ExpenseTypeController etC = new ExpenseTypeController();

            Console.WriteLine(" === Expense Type List ===");

            List<ExpenseType> list = etC.GetAllExpenseTypes();
            int i = 0;

            foreach (ExpenseType item in list)
            {
                Console.WriteLine(i);
                Console.WriteLine(item);
                Console.WriteLine("---\n");
                i++;
            }
        }
Пример #4
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());
                            }
                        }
                    }
                }

            }
        }
Пример #5
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();
                    }
                }
            }
        }