当前位置: 首页>>代码示例>>C#>>正文


C# ObservableCollection.GroupBy方法代码示例

本文整理汇总了C#中System.Collections.ObservableCollection.GroupBy方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.GroupBy方法的具体用法?C# ObservableCollection.GroupBy怎么用?C# ObservableCollection.GroupBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.ObservableCollection的用法示例。


在下文中一共展示了ObservableCollection.GroupBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetAccountSummaryCallback

        private void GetAccountSummaryCallback(Guid instrumentId, List<CommonOpenInterestSummary> openInterestSummarys)
        {
            this.Dispatcher.BeginInvoke((Action)delegate()
            {
                if (openInterestSummarys == null) return;

                ExchangeSettingManager settingManager = this._App.ExchangeDataManager.GetExchangeSetting(this._CurrentExchangeCode);
                ObservableCollection<OpenInterestSummary> accountGroupSummarys = new ObservableCollection<OpenInterestSummary>();

                foreach (CommonOpenInterestSummary openInterestSummary in openInterestSummarys)
                {
                    OpenInterestSummary entity = new OpenInterestSummary(openInterestSummary, OpenInterestSummaryType.Account);
                    entity.InstrumentId = instrumentId;
                    Guid accountId = entity.Id;

                    Account account = settingManager.GetAccount(accountId);
                    if (account != null)
                    {
                        entity.Code = account.Code;
                    }

                    accountGroupSummarys.Add(entity);
                }

                OpenInterestSummary  instrumentSummary = this._OpenInterestSummarys.SingleOrDefault(P => P.Id == instrumentId);
                instrumentSummary.ChildSummaryItems.Clear();

                IEnumerable<IGrouping<string, OpenInterestSummary>> query = accountGroupSummarys.GroupBy(P => P.GroupCode, P => P);
                foreach (IGrouping<string, OpenInterestSummary> group in query)
                {
                   OpenInterestSummary groupSummary = new OpenInterestSummary(OpenInterestSummaryType.Group);

                   Guid accountId = accountGroupSummarys[0].Id;
                   Guid accountGroupId = Guid.Empty;

                   Account account = settingManager.GetAccount(accountId);
                   if (account != null)
                   {
                       accountGroupId = account.GroupId;
                   }

                   AccountGroup accountGroup = settingManager.GetAccountGroup(accountGroupId);
                   if (accountGroup != null)
                   {
                       groupSummary.Code = accountGroup.Code;
                   }

                   groupSummary.Id = accountGroupId;

                   List<OpenInterestSummary> accountSummarys = group.ToList<OpenInterestSummary>();
                   foreach (OpenInterestSummary item in accountGroupSummarys)
                   {
                       groupSummary.SetItem(item,true);
                       groupSummary.ChildSummaryItems.Add(item);
                   }
                   groupSummary.SetAvgPrice();
                   instrumentSummary.ChildSummaryItems.Add(groupSummary);
               }
            });
        }
开发者ID:BlueSky007,项目名称:ExchangeManager,代码行数:60,代码来源:OpenInterestControl.xaml.cs

示例2: GetAccountSummaryCallback

        private void GetAccountSummaryCallback(Guid instrumentId, List<CommonOpenInterestSummary> openInterestSummarys)
        {
            this.Dispatcher.BeginInvoke((Action)delegate()
            {
                if (openInterestSummarys == null) return;
                OpenInterestSummary instrumentSummary = this._OpenInterestSummaryModel.GetInstrumentSummaryItem(instrumentId);
                this._OpenInterestSummaryModel.ResetChildItem(instrumentSummary);

                ExchangeSettingManager settingManager = this._App.ExchangeDataManager.GetExchangeSetting(this._CurrentExchangeCode);
                ObservableCollection<OpenInterestSummary> accountItemList = new ObservableCollection<OpenInterestSummary>();

                foreach (CommonOpenInterestSummary commonEntity in openInterestSummarys)
                {
                    OpenInterestSummary accountSummaryItem = new OpenInterestSummary(commonEntity,OpenInterestSummaryType.Account);
                    accountSummaryItem.InstrumentId = instrumentId;
                    Guid accountId = accountSummaryItem.Id;

                    Account account = settingManager.GetAccount(accountId);
                    if (account == null) continue;

                    accountSummaryItem.GroupId = account.GroupId;
                    accountSummaryItem.Code = account.Code;

                    AccountGroup accountGroup = settingManager.GetAccountGroup(account.GroupId);
                    accountSummaryItem.GroupCode = accountGroup.Code;
                    accountItemList.Add(accountSummaryItem);
                }

                IEnumerable<IGrouping<string, OpenInterestSummary>> query = accountItemList.GroupBy(P => P.GroupCode, P => P);
                foreach (IGrouping<string, OpenInterestSummary> group in query)
                {
                    OpenInterestSummary accountItem = group.First();
                    OpenInterestSummary groupSummary = new OpenInterestSummary(null,OpenInterestSummaryType.Group);
                    groupSummary.UpdateGroupFromAccountItem(accountItem);//更新分子分母

                    List<OpenInterestSummary> accountSummarys = group.ToList<OpenInterestSummary>();
                    foreach (OpenInterestSummary item in accountSummarys)
                    {
                        groupSummary.SetItem(item, true);
                        groupSummary.ChildSummaryItems.Add(item);
                    }
                    groupSummary.SetAvgPrice();
                    instrumentSummary.ChildSummaryItems.Add(groupSummary);
                }
            });
        }
开发者ID:BlueSky007,项目名称:ExchangeManager,代码行数:46,代码来源:OpenInterestControl.xaml.cs


注:本文中的System.Collections.ObservableCollection.GroupBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。