我有一个DataGrid,其中包含Customer的买入的多个交易。 我想要的是将每个客户的交易买入加起来并将结果添加到相关图像上。我现在所拥有的是逻辑错误,即在多个图像上添加相同的数量。
以下是我的DataGrid(列标题)的结构:[Name,Surname, Buyin, Type, StartTime, TransactionID, CustomerID]
这是我的代码:
Dim tbActivePlayers As DataTable = Me.ActivePlayersTableAdapter.GetData()
Dim tbTemp As New DataTable
' table = DataSet.Tables("Orders")
' Declare an object variable.
Dim objTotalBuyin As Object
Dim iCount, ilbl As Integer
ilbl = 1
Dim viewUniquePlayers As New DataView(tbActivePlayers)
Dim iActivePlayers As Integer = viewUniquePlayers.ToTable(True, "CustomerID").Rows.Count
Dim dtDataTable As DataTable = viewUniquePlayers.ToTable(True, "CustomerID")
Dim myLabel As Label
For iCount = 0 To dtDataTable.Rows.Count
objTotalBuyin = tbActivePlayers.Compute("Sum(Buyin)", "CustomerID = " & tbActivePlayers.Rows(iCount).Item("CustomerID"))
'MsgBox("Name: " & tbActivePlayers.Rows(iCount + 1).Item("Name") & ", Sumbuyin:" & sumObject.ToString & " ResultCount:" & ResultCount)
'
myLabel = CType(Me.Controls.Find("lblPlayer" & ilbl, True)(0), Label)
If Not myLabel Is Nothing Then
myLabel.Text = "Empty Seat"
End If
'
myLabel.Text = tbActivePlayers.Rows(iCount).Item("Name") & Environment.NewLine & _
"€" & objTotalBuyin.ToString
myLabel.Image = Global.PokerBusiness.My.Resources.Resources.seatocc
ilbl += 1
Next
答案 0 :(得分:0)
Compute
的过滤器功能似乎是基于tbActivePlayers
中的每一行,但是你在每一行上循环(因此计算行数)是一个独特玩家的视图。我的大脑编译器告诉我这可能是你的逻辑错误的根源,因为你可能会使用一个多次使用单个唯一客户ID的过滤器计算你的总和。考虑改变
objTotalBuyin = tbActivePlayers.Compute("Sum(Buyin)", "CustomerID = " & tbActivePlayers.Rows(iCount).Item("CustomerID"))
要
objTotalBuyin = tbActivePlayers.Compute("Sum(Buyin)", "CustomerID = " & dtDataTable.Rows(iCount).Item("CustomerID"))