Example #1
0
        private static void ShowHistoryByCategory()
        {
            Console.WriteLine("\t\tStart date: ");
            Console.Write("Enter year --> ");
            var beginYear = int.Parse(Console.ReadLine());

            Console.Write("Enter month --> ");
            var beginMonth = int.Parse(Console.ReadLine());

            Console.Write("Enter day --> ");
            var beginDay = int.Parse(Console.ReadLine());

            var begin = new DateTime(beginYear, beginMonth, beginDay);

            Console.WriteLine("\t\t\n\nEnd date: \n");
            Console.Write("Enter year --> ");
            var endYear = int.Parse(Console.ReadLine());

            Console.Write("\nEnter month --> ");
            var endMonth = int.Parse(Console.ReadLine());

            Console.Write("\nEnter day --> ");
            var endDay = int.Parse(Console.ReadLine());

            var end = new DateTime(endYear, endMonth, endDay);

            var historyRange = new HistoryRange(actionWorker);

            var group = historyRange.Interval(begin, end);

            var linqResult = group.GroupBy(x => x.Category);

            foreach (var item in linqResult)
            {
                var sum = item.Sum(x => x.Currency.Amount);
                Console.WriteLine(item.Key);
                foreach (var i in item)
                {
                    Console.WriteLine(i);
                }
            }
        }
Example #2
0
        private static void ShowAccountStatistics()
        {
            Console.WriteLine("\t\tStart date: ");
            Console.Write("Enter year --> ");
            var beginYear = int.Parse(Console.ReadLine());

            Console.Write("Enter month --> ");
            var beginMonth = int.Parse(Console.ReadLine());

            Console.Write("Enter day --> ");
            var beginDay = int.Parse(Console.ReadLine());

            var begin = new DateTime(beginYear, beginMonth, beginDay);

            Console.WriteLine("\t\t\n\nEnd date: \n");
            Console.Write("Enter year --> ");
            var endYear = int.Parse(Console.ReadLine());

            Console.Write("\nEnter month --> ");
            var endMonth = int.Parse(Console.ReadLine());

            Console.Write("\nEnter day --> ");
            var endDay = int.Parse(Console.ReadLine());

            var end = new DateTime(endYear, endMonth, endDay);

            var historyRange = new HistoryRange(actionWorker);

            var group     = historyRange.Interval(begin, end);
            var filter    = group.Where(x => x.Type == ActionType.Expense);
            var sumResult = filter.Sum(x => x.Currency.Amount);


            var linqResult = filter.GroupBy(x => x.Category);

            foreach (var item in linqResult)
            {
                var sum = item.Sum(x => x.Currency.Amount);
                var res = (sum / sumResult) * 100;
                Console.WriteLine($"\n\t{item.Key} {decimal.Round(res,3)}%");
            }
        }