コード例 #1
0
        private static void ShowHistory()
        {
            Console.Clear();
            Console.WriteLine("1.For Day");
            Console.WriteLine("2.For Week");
            Console.WriteLine("3.For Month");
            Console.WriteLine("4.For Year");
            HistoryRange range         = new HistoryRange(actionWorker);
            var          chooseHistory = Console.ReadKey(true).Key;

            switch (chooseHistory)
            {
            case ConsoleKey.D1: {
                foreach (var item in range.Day())
                {
                    Console.WriteLine(item);
                }
                break;
            }

            case ConsoleKey.D2: {
                foreach (var item in range.Week())
                {
                    Console.WriteLine(item);
                }
                break;
            }

            case ConsoleKey.D3: {
                foreach (var item in range.Month())
                {
                    Console.WriteLine(item);
                }
                break;
            }

            case ConsoleKey.D4: {
                foreach (var item in range.Year())
                {
                    Console.WriteLine(item);
                }
                break;
            }
            }
        }
コード例 #2
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);
                }
            }
        }
コード例 #3
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)}%");
            }
        }