gpt4 book ai didi

c# - 使用 LINQ to SQL 计算运行总计

转载 作者:太空宇宙 更新时间:2023-11-03 11:31:01 24 4
gpt4 key购买 nike

我有一个 WPF C# 应用程序,它通过 SQL-LINQ 连接访问数据并将其放在 Datagrid 上。我添加了一个 Running Pips 列,并一直在尝试弄清楚如何正确填充此列。我通过搜索网络找到了几种方法,但这些方法都不适合我的特定设置。大多数时候,我最终陷入了无限循环。我希望 Running Pips 列是累积的,并且计算顺序从最早的“收盘时间”开始。

Close Time   Profit    Running Profit
10.09.11 $10 $10
10.10.11 $20 $30
10.11.11 $15 $45

这里是代码的总结。我希望有人可以建议如何使用帮助我实现此代码所需的任何相关信息来修复此代码:

public void RefreshClose() {
if (CloseTradeCollection == null) return;
var i = 0;

if (StaticTool.SelectedAccount == null) {
ExistCloseTrade = false;
CloseTradeCollection.Clear();
return;
}

Account = StaticTool.SelectedAccount;

foreach (var trade in GetClosedTradesFromDb()) {
if (CloseTradeCollection.Count <= i) {
ExistCloseTrade = true;
var tradeDetails = new Trade {
Id = trade.id,
Ticket = trade.ticket,
OpenTime = trade.opentime,
CloseTime = trade.closetime,
Symbol = trade.symbol,
OpenPrice = trade.openprice,
ClosePrice = trade.closeprice,
Profit = trade.profit,
Comment = trade.comment.Trim(),
};

tradeDetails.History = tradeDetails.CloseTime - tradeDetails.OpenTime;
CloseTradeCollection.Add(tradeDetails);
}

else {
var tradeDetails = CloseTradeCollection[i];
tradeDetails.Id = trade.id;
tradeDetails.Ticket = trade.ticket;
tradeDetails.OpenTime = trade.opentime;
tradeDetails.CloseTime = trade.closetime;
tradeDetails.Symbol = trade.symbol;
tradeDetails.OpenPrice = trade.openprice;
tradeDetails.ClosePrice = trade.closeprice;
tradeDetails.Profit = trade.profit;
tradeDetails.Comment = trade.comment.Trim();
tradeDetails.History = DateTime.Now - tradeDetails.OpenTime;

//tradeDetails.RunningProfit = ????????

}

i++;
}
}

最佳答案

您可以创建一个局部变量来跟踪运行利润,利用赋值操作返回所赋值这一事实。

tradeDetails.RunningProfit = (runningProfit = runningProfit + trade.profit);

关于c# - 使用 LINQ to SQL 计算运行总计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7784377/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com