所以,我有这个函数,它接收一个数据表并按两列对用户进行排序。(排名和订单计数)
Function DetermineBestUser(ByVal usertable As DataTable)
Dim bestchoice As DataRow()
For u = 0 To usertable.Rows.Count - 1
If Not DoesProcessorNeedOrders(usertable.Rows(u).Item("UserName"), usertable.Rows(u).Item("Amount")) Then
usertable.Rows(u).Delete()
End If
Next
bestchoice = usertable.Select("", "Rank ASC, OrderCount DESC")
If IsDBNull(usertable) Then
Console.WriteLine("No user is qualified for this order at this moment")
End If
Return bestchoice(0)(0).ToString
End Function
问题是,有时此功能可以正常工作,并为我提供最高等级(1 或 2)和最低订单计数(0 - 30+)的用户。但是,有时它不会返回正确的人。我看到的唯一解决此问题的是将“Ordercount DESC”更改为“OrderCount ASC”;但是,此更改仅适用于该特定订单,然后返回错误的人。
我有一些测试运行会更详细地显示这一点:R1 & R2 = Rank 1 or 2 / "OrderCount"
Rank ASC, Ordercount ASC
#1
dane-R2 / 12
jerm-R1 / 15
tulsa-R1 / 5
---picks Jerm (should pick tulsa)
#2
Dane-R2 / 14
Jerm-R2 / 15
Kate- R2 / 15
---picks Dane
#3
Dane-R2 / 15
Jerm-R2 / 5
Kate-R2 / 5
---picks dane (should pick Jerm or Kate)
Rank ASC, Ordercount DESC
#1
dane-R2 / 12
jerm-R1 / 15
tulsa-R1 / 5
---picks Tulsa
#2
Dane-R2 / 14
Jerm-R2 / 15
Kate- R2 / 15
---picks Jerm (should pick Dane)
#3
Dane-R2 / 15
Jerm-R2 / 5
Kate-R2 / 5
---picks Jerm