Пример #1
0
        private void graphOfBalanceByTime_Click(object sender, EventArgs e)
        {
            Dictionary<DateTime, Decimal> balanceParts = new Dictionary<DateTime, Decimal>();
            decimal actual = 0;

            foreach (Item item in manager.GetAllItems().OrderBy(x => x.Date))
            {
                if (item.Type == TypeEnum.Income)
                {

                    if (!balanceParts.ContainsKey(item.Date))
                    {
                        balanceParts.Add(item.Date, 0);
                    }
                    actual += item.Value;
                    balanceParts[item.Date] = actual;
                }
                else
                {
                    if (!balanceParts.ContainsKey(item.Date))
                    {
                        balanceParts.Add(item.Date, 0);
                    }
                    actual -= item.Value;
                    balanceParts[item.Date] = actual;
                }
            }

            Dictionary<DateTime, Decimal>[] tmpParts = new Dictionary<DateTime, Decimal>[balanceParts.Count - 1];

            for (int i = 0; i < balanceParts.Count-1; i++)
            {
                tmpParts[i] = FillFreePlaces(
                     balanceParts.Keys.ElementAt(i),
                     balanceParts.Keys.ElementAt(i + 1),
                     balanceParts.Values.ElementAt(i),
                     balanceParts.Values.ElementAt(i + 1),
                     balanceParts);
            }

            for (int i = 0; i < tmpParts.Length; i++)
            {
                foreach (var item in tmpParts[i])
                {
                    balanceParts.Add(item.Key, item.Value);
                }
            }

            balanceParts = balanceParts.OrderBy
                (x => x.Key).ToDictionary(x => x.Key, x => x.Value);
            GraphWindow graphWindow = new GraphWindow(balanceParts);
            graphWindow.ShowDialog();
        }
Пример #2
0
        private void graphOfBalanceByCategoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Dictionary<String, Decimal> incomes = new Dictionary<String, Decimal>();
            Dictionary<String, Decimal> outgoes = new Dictionary<String, Decimal>();

            foreach (Item item in manager.GetAllItems())
            {
                if (item.Type == TypeEnum.Income)
                {
                    if (!incomes.ContainsKey(item.Category.Name)) incomes.Add(item.Category.Name, 0);
                    incomes[item.Category.Name] += item.Value;
                }
                else
                {
                    if (!outgoes.ContainsKey(item.Category.Name)) outgoes.Add(item.Category.Name, 0);
                    outgoes[item.Category.Name] += item.Value;
                }
            }
            incomes = incomes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
            outgoes = outgoes.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);

            GraphWindow graphWindow = new GraphWindow(incomes, outgoes);
            graphWindow.ShowDialog();
        }