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


C# ObservableCollection.Sum方法代码示例

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


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

示例1: HomePageViewModel

        public HomePageViewModel()
        {
            var worldRepository = new WorldDataRepository();

            Data = new ObservableCollection<DataItem>();
            ItemsSource = new ObservableCollection<CountryItem>();

            worldRepository.GetCountries().ContinueWith(list =>
            {
                Countries = list.Result;
                var dataItems = new ObservableCollection<DataItem>();
                foreach (var item in Countries)
                {
                    var countryItem = new CountryItem
                    {
                        Name = item.Name,
                        Change = item.Chg1Y,
                        IsChangePositive = item.IsChangePositive
                    };
                    double val = 0.0;
                    double.TryParse(item.LifeExpectancy, out val);
                    countryItem.LifeExpectancy = val;
                    ItemsSource.Add(countryItem);

                }
                foreach (var region in worldRepository.CountriesByRegion)
                {
                    var dataItem = new DataItem {Label = region.Key, Level = region.Value.Sum(x => x.Level.ToDouble())};
                    dataItems.Add(dataItem);
                }
                WorldPopulation = dataItems.Sum(l => l.Level * 1000).ToString("#,##0,,,.B", CultureInfo.InvariantCulture);
                LifeExpectancy = ItemsSource.Average(x => x.LifeExpectancy).ToString("00.00", CultureInfo.InvariantCulture);
                Data = dataItems;
            });
        }
开发者ID:nishanil,项目名称:WorldData-Dashboard,代码行数:35,代码来源:HomePageViewModel.cs

示例2: AttaquerMembre

 public int AttaquerMembre(ObservableCollection<Combattant> ennemis)
 {
     Combattant victime = SelectionMembre();
     int compteDegats= ennemis.Sum(adversaire => victime.SubirAttaque(adversaire));
     if (victime.EstMort())
     {
         OnIsDead(victime);
     }
     Debug.WriteLine("Le {4} {0} a perdu {1} pv :{2}/{3} pv", victime.Nom, compteDegats, victime.NbPv, victime.PvMax, victime.GetType().Name);
     
     return compteDegats;
 }
开发者ID:Carboxyde,项目名称:Kinect-Mercurochroume,代码行数:12,代码来源:GestionEquipe.cs

示例3: SetFromFile

        public void SetFromFile(string fileName)
        {
            Categories.Clear();

            ObservableCollection<CategoryViewModel> tempList = new ObservableCollection<CategoryViewModel>();

            using (ZipFile zip = ZipFile.Read(fileName))
            {
                foreach(var entry in zip.OrderByDescending(item=>item.CompressedSize))
                {
                    string category = GetCategoryForFile(entry.FileName);
                    var categoryVm = GetOrCreateCategoryFor(category, tempList);

                    FileViewModel fileVm = new FileViewModel();
                    fileVm.Name = entry.FileName;
                    fileVm.SizeInBytes = entry.CompressedSize;

                    categoryVm.Files.Add(fileVm);
                }
            }

            foreach (var category in tempList)
            {
                category.RecalculateEverything();
            }

            var totalSize = tempList.Sum(item => item.SizeInBytes);

            foreach (var category in tempList)
            {
                category.ContainingZipSize = totalSize;
            }

            foreach(var category in tempList.OrderByDescending(item=>item.SizeInBytes))
            {
                Categories.Add(category);
            }

        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:39,代码来源:BuiltFileSizeViewModel.cs

示例4: srv_UserList_GetLowerListDataCompleted

 void srv_UserList_GetLowerListDataCompleted(object sender, LotterySrv.GetLowerListDataCompletedEventArgs e)
 {
     if (e.Result.Count!=0)
     {
         obLowerData = e.Result as ObservableCollection<LowerListData>;
         PageSum.GameScores = obLowerData.Take(18).Sum(p => p.GameScores);
         PageSum.EnableScores = obLowerData.Take(18).Sum(p => p.EnableScores);
         PageSum.DisableScores = obLowerData.Take(18).Sum(p => p.DisableScores);
         TotalSum.GameScores = obLowerData.Sum(p => p.GameScores);
         TotalSum.EnableScores = obLowerData.Sum(p => p.EnableScores);
         TotalSum.DisableScores = obLowerData.Sum(p => p.DisableScores);
         obLowerData.Add(PageSum);
         obLowerData.Add(TotalSum);
         currentPos = 0;
         PagedCollectionView pageView = new PagedCollectionView(obLowerData);
         pageView.PageSize = 20;
         dpList.PageSize = 20;
         dpList.Source = pageView;
         dgList.ItemsSource = pageView;
     }
     gridLoading.Visibility = Visibility.Collapsed;
 }
开发者ID:dalinhuang,项目名称:my-un-code,代码行数:22,代码来源:LowerList.xaml.cs

示例5: srv_GameRecord_GetStatReportCompleted

 private void srv_GameRecord_GetStatReportCompleted(object sender, GetStatReportCompletedEventArgs e)
 {
     obStatReport = e.Result;
     gridLoading.Visibility = Visibility.Collapsed;
     currentPos = 0;
     if (e.Result.Count != 0)
     {
         RTotalSum = new StatReport();
         RTotalSum.UserID = "总合计";
         RTotalSum.BetMoney = obStatReport.Sum(p => p.BetMoney);
         RTotalSum.WinMoney = obStatReport.Sum(p => p.WinMoney);
         if (e.Result.Count < 18)
         {
             obStatReport = e.Result;
             RPageSum = new StatReport();
             RPageSum.UserID = "本页合计";
             RPageSum.BetMoney = obStatReport.Take(18).Sum(p => p.BetMoney);
             RPageSum.WinMoney = obStatReport.Take(18).Sum(p => p.WinMoney);
             obStatReport.Add(RPageSum);
             obStatReport.Add(RTotalSum);
             currentPos = 0;
             PagedCollectionView pageView = new PagedCollectionView(obStatReport);
             pageView.PageSize = 20;
             dpList.PageSize = 20;
             dpList.Source = pageView;
             dgList.ItemsSource = pageView;
         }
         else
         {
             int page = int.Parse(Math.Ceiling(double.Parse(e.Result.Count.ToString()) / 18).ToString());
             for (int i = 0; i < page; i++)
             {
                 int stayNum = e.Result.Count - (i * 20);
                 if (stayNum > 18)
                 {
                     RPageSum = new StatReport();
                     RPageSum.UserID = "本页合计";
                     RPageSum.BetMoney = obStatReport.Skip(i * 20).Take(18).Sum(p => p.BetMoney);
                     RPageSum.WinMoney = obStatReport.Skip(i * 20).Take(18).Sum(p => p.WinMoney);
                     obStatReport.Insert(i * 20 + 18, RPageSum);
                     obStatReport.Insert(i * 20 + 19, RTotalSum);
                 }
                 else
                 {
                     RPageSum = new StatReport();
                     RPageSum.UserID = "本页合计";
                     RPageSum.BetMoney = obStatReport.Skip(i * 20).Take(stayNum).Sum(p => p.BetMoney);
                     RPageSum.WinMoney = obStatReport.Skip(i * 20).Take(stayNum).Sum(p => p.WinMoney);
                     obStatReport.Insert(i * 20 + stayNum, RPageSum);
                     obStatReport.Insert(i * 20 + stayNum + 1, RTotalSum);
                 }
             }
             currentPos = 0;
             PagedCollectionView pageView = new PagedCollectionView(obStatReport);
             pageView.PageSize = 20;
             dpList.PageSize = 20;
             dpList.Source = pageView;
             dgList.ItemsSource = pageView;
         }
     }
 }
开发者ID:dalinhuang,项目名称:my-un-code,代码行数:61,代码来源:GameRecord.xaml.cs

示例6: RunBackup

        void RunBackup(ObservableCollection<DevicesGroup> driversToBackup, BackupType backupType)
        {
            CreatingBackup = true;

            string backupDir = Uri.UnescapeDataString(CfgFile.Get("BackupsFolder"));
            if (!String.IsNullOrEmpty(backupDir) && new DirectoryInfo(backupDir).Exists)
            {
                Progress = 0;
                int driversCount = 0;
                int totalDriversCount = driversToBackup.Sum(su => su.Devices.Count);
                foreach (DevicesGroup group in driversToBackup)
                {
                    group.GroupChecked = true;
                    foreach (DeviceInfo item in group.Devices)
                    {
                        if (driverUtils.BackupDriver(item.DeviceName, item.InfName, backupDir))
                        {
                            item.SelectedForRestore = true;
                            driversCount++;
                            Progress = driversCount * 100 / totalDriversCount;
                        }
                    }
                }
                if (CurrentDispatcher.Thread != null)
                {
                    CurrentDispatcher.BeginInvoke((Action)(() =>
                    {
                        BackupItems.Add(
                            new BackupItem(
                                backupDir,
                                DateTime.Now,
                                BackupTypes[backupType],
                                driversToBackup
                            )
                        );
                        SaveBackupItemsToXML();

                        BackupFinishTitle = String.Format(WPFLocalizeExtensionHelpers.GetUIString("DriversBackupedSuccesfully"), driversCount);
                        BackupStatus = BackupStatus.BackupFinished;
                        CreatingBackup = false;
                    }));
                }
            }
            else
            {
                if (CurrentDispatcher.Thread != null)
                {
                    CurrentDispatcher.BeginInvoke((Action)(() => WPFMessageBox.Show(Application.Current.MainWindow, LocalizeDictionary.Instance.Culture, WPFLocalizeExtensionHelpers.GetUIString("CheckBackupsFolder"), WPFLocalizeExtensionHelpers.GetUIString("CheckPreferences"), WPFMessageBoxButton.OK, MessageBoxImage.Error)));
                    CreatingBackup = false;
                }
            }
        }
开发者ID:nullkuhl,项目名称:driverGalaxy-release,代码行数:52,代码来源:MainWindowViewModel.cs

示例7: LoadCapexInfo

 private void LoadCapexInfo()
 {
     AccountCapexList = new ObservableCollection<AccountsCapexInfoSet>(_accountCapexService.GetCapexesById(CurrentAccount.Id));
     AvailableSum = CurrentAccount.AccountAmount.Value - AccountCapexList.Sum(c => c.AccountCapexAmount);
 }
开发者ID:Fredoq,项目名称:AccountsWork,代码行数:5,代码来源:AdditionalInfoViewModel.cs

示例8: SetPercentageFromWeight

 public static void SetPercentageFromWeight(ref ObservableCollection<Ingredient> items)
 {
     //__when ratios turned back on, loop through newly entered weights to set values
     double totalWeight = items.Sum(i => i.GetExactWeight());
     foreach (Ingredient ingredient in items)
     {
         ingredient.AdjustPercent((ingredient.GetExactWeight() / totalWeight) * 100);
         SetChildWeightsFromPercentage(ingredient);
     }
 }
开发者ID:CADTraveller,项目名称:RecipeMaster,代码行数:10,代码来源:ValueAdjusters.cs

示例9: LoadSalesForCurrentUser

        private void LoadSalesForCurrentUser()
        {
            ObservableCollection<SaleReportItem> result;

            System.Linq.Expressions.Expression<Func<SaleHeader, bool>> predicate;

            if (IsByDate)
                predicate = sh => sh.UserCode == User.Code && EntityFunctions.TruncateTime(sh.Date) == SelectedDate;
            else
                predicate = sh => sh.CustomerCode != null && sh.CustomerCode == SelectedCustomer.Code;

            IQueryable<SaleHeader> query = BusinessContext.Instance.Model.SaleHeaders.Where(predicate);

            result = new ObservableCollection<SaleReportItem>(query.Select(sh => new SaleReportItem { SaleHeader = sh }));

            var payment = from spi in BusinessContext.Instance.Model.SalePaymentItems
                          join sh in query on spi.SalePaymentHeader equals sh.SalePaymentHeader
                          group spi by spi.PaymentInstrument into g
                          select g;

            var paymentListSummary = new Dictionary<int, SalePaymentReportSummary>();
            SalePaymentReportSummary paymentItem;
            foreach (IGrouping<PaymentInstrument, SalePaymentItem> items in payment)
            {
                paymentListSummary.Add(items.Key.Code, new SalePaymentReportSummary(items.Key));
                paymentItem = paymentListSummary[items.Key.Code];
                foreach (SalePaymentItem salePaymentItem in items)
                {
                    paymentItem.TotalCount++;
                    paymentItem.TotalAmount += salePaymentItem.Quantity;
                }
            }

            int count = query.Count();

            Summary = new SaleReportSummary
            {
                TotalAmount = count > 0? result.Sum(sh => sh.SaleHeader.PriceSumValue): count,
                TotalCount = count,
                SalesPaymentSummary = new ObservableCollection<SalePaymentReportSummary>(paymentListSummary.Values)
            };

            Sales = result;
        }
开发者ID:sergiosorias,项目名称:terminalzero,代码行数:44,代码来源:SaleReportViewModel.cs


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