Exemplo n.º 1
0
        private void Paint()
        {
            tvFinInstruments.Nodes.Clear();
            //достаем финансовые инструменты и сортируем по папкам
            List <FinType> finTypes = new List <FinType>()
            {
                FinType.Bond,
                FinType.Certificate,
                FinType.DepositaryReceipt,
                FinType.Equity,
                FinType.Fund
            };

            Dictionary <FinType, string> types = new Dictionary <FinType, string>()
            {
                { FinType.Bond, "Облигации" },
                { FinType.Certificate, "Сертификаты" },
                { FinType.DepositaryReceipt, "Депозитарные распискы" },
                { FinType.Equity, "Акции" },
                { FinType.Fund, "Фонды" },
            };

            Dictionary <FinTypeDetailedLevel, string> finTypeDetailedLevels =
                new Dictionary <FinTypeDetailedLevel, string>();

            foreach (var z in Enum.GetValues(typeof(FinTypeDetailedLevel)).OfType <FinTypeDetailedLevel>())
            {
                var type        = z.GetType();
                var memInfo     = type.GetMember(z.ToString());
                var attribute   = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                var description = ((DescriptionAttribute)attribute[0]).Description;
                finTypeDetailedLevels.Add(z, description);
            }

            foreach (var x in types)
            {
                int amount = positions.Count(p => p.FinType == x.Key);
                if (amount == 0)
                {
                    continue;
                }

                string key = string.Format("{1} ({0})", amount, x.Value);

                TreeNode root = tvFinInstruments.Nodes.Add(key, key);

                //у нас есть тип данных
                var secondLevelPositions = positions.Where(z => z.FinType == x.Key);

                Dictionary <FinTypeDetailedLevel, List <PortfolioPosition> > dictionary =
                    new Dictionary <FinTypeDetailedLevel, List <PortfolioPosition> >();

                foreach (var zz in secondLevelPositions)
                {
                    FinTypeDetailedLevel detailLevel = _provider.Get <FinTypeDetailedLevel>(zz,
                                                                                            ScalarAttribute.DetailedType,
                                                                                            DateTime.Today,
                                                                                            FinTypeDetailedLevel.Default);

                    if (dictionary.ContainsKey(detailLevel))
                    {
                        dictionary[detailLevel].Add(zz);
                    }
                    else
                    {
                        dictionary.Add(detailLevel, new List <PortfolioPosition>()
                        {
                            zz
                        });
                    }
                }

                foreach (var z in dictionary)
                {
                    int secondAmount = z.Value.Count();
                    if (secondAmount == 0)
                    {
                        continue;
                    }
                    string   secondKey  = string.Format("{1} ({0})", secondAmount, finTypeDetailedLevels[z.Key]);
                    TreeNode secondRoot = root.Nodes.Add(secondKey, secondKey);
                    foreach (var y in z.Value)
                    {
                        secondRoot.Nodes.Add(y.Ident, y.Ident);
                    }
                }
            }
        }