试试这个代码:
var afters = ctx.headers.SkipWhile(((x, index) => index <= currentItemIndex))
.TakeWhile((x, index) => index != ctx.headers.Count()-1).ToList();
for (int i = currentItemIndex+1, j=0; j < afters.Count; i++ ,j++)
{
var befores = ctx.headers.TakeWhile((x, index) => index <i);
afters[j].BeforeSSAmount = befores.SelectMany(x => x.StationStateItem).Sum(x => x.Amount);
}
编辑使用的ListCollectionView在WPF:
var afters = header.DataSource.Cast<StationStateHdr>().SkipWhile(((x, index) => index <= header.DataSource.CurrentPosition))
.TakeWhile((x, index) => index != header.DataSource.Cast<StationStateHdr>().Count()-1).ToList();
for (int i = header.DataSource.CurrentPosition+1, j=0; j < afters.Count; i++ ,j++)
{
var befores = header.DataSource.Cast<StationStateHdr>().TakeWhile((x, index) => index <i);
afters[j].BeforeSSAmount = befores.SelectMany(x => x.StationStateItem).Sum(x => x.Amount);
}
或此代码:
var listOfStationStateHdr = header.DataSource.Cast<StationStateHdr>();
listOfStationStateHdr.SkipWhile(((x, index) => index <= header.DataSource.CurrentPosition))
.TakeWhile((x, index) => index != header.DataSource.Cast<StationStateHdr>().Count() - 1).ToList().ForEach(x =>
{
x.BeforeSSAmount = listOfStationStateHdr.TakeWhile(y => y.Id < x.Id).SelectMany(b => b.StationStateItem).Sum(s => s.Amount);
});
或
var sumCurrent = CurrentStationStateHdr.StationStateItem.Sum(t => t.Amount);
var listOfStationStateHdr = header.DataSource.Cast<StationStateHdr>().ToList();
double? nextItembeforeSSAmount = listOfStationStateHdr[header.DataSource.CurrentPosition + 1].BeforeSSAmount;
listOfStationStateHdr.SkipWhile(((x, index) => index <= header.DataSource.CurrentPosition))
.TakeWhile((x, index) => index != header.DataSource.Cast<StationStateHdr>().Count() - 1).ToList().ForEach(x =>
{
x.BeforeSSAmount += sumCurrent - nextItembeforeSSAmount;
});
你应该先尝试......你总是问的问题和回答没有。 –
你想要更新两个表。手动做到这一点。或者atleast向我们显示您的对象类为这些..也显示更新的功能Table StationStateItem –
我想更新StationStateHdr表中的BeforeSSAmount,当我更改StationStateItem表中的Amout并单击保存按钮时。 –