0

我有一个 DataGrid,其中包含客户购买的多笔交易。我想要的是添加来自每个客户的交易购买,并将结果添加到相关图像上。我目前拥有的东西给了我逻辑错误,即在多个图像上添加相同的数量。

这是我的 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
4

1 回答 1

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"))
于 2013-05-21T22:12:37.923 回答