/// <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(); } } } }
/// <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()); } } } } } }
/// <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++; } }