实现了:
Dim qsmc As WinForm.ComboBox = e.Form.Controls("棋赛名称")
Dim di1 As String = qsmc.Value
Dim m As WinForm.TextBox = e.Form.Controls("第几轮")
Dim di2 As String = m.Value
Dim bsrq As WinForm.DateTimePicker = e.Form.Controls("rq")
Dim di3 As Date = bsrq.Value
Dim dr As DataRow = DataTables("比赛积分").SQLfind("[棋赛名称] = '" & di1 & "'And [第几轮比赛] = '" & di2 & "'")
Dim a As String = Cstr(Val(di2)-1)
Dim i2 As Integer = 1
Dim ii2 As Integer = 1
Dim dts As List(of DataRow) = DataTables("基本信息").SQLSelect("[棋赛名称] = '" & di1 & "'And [身份] = '参赛人'")
DataTables("比赛积分").DeleteFor("棋赛名称 is null and 第几轮比赛 is null")
Dim cnt As Integer
cnt = DataTables("比赛积分").Compute("Count([姓名])", "[棋赛名称] = '" & di1 & "'And [第几轮比赛] = '" & di2 & "'")
If di2 =1 And cnt = 0 Then
Do While dts.Count > 0
Dim idx As Integer = rand.Next(0,dts.Count-1)
dr = DataTables("比赛积分").AddNew
dr("桌号") = math.Ceiling((i2) / 2)
dr("日期") = di3
dr("棋赛名称") = di1
dr("第几轮比赛") = di2
dr("编号") = dts(idx)("编号")
dr("姓名") = dts(idx)("姓名")
dr("轮赛次数值转换") = Val(di2)
dts.RemoveAt(idx)
i2 + = 1
Loop
DataTables("比赛积分").Save()
DataTables("对阵表").DataRows.Clear
Dim drs1 As List(of DataRow) = DataTables("比赛积分").SQLSelect("[棋赛名称] = '" & di1 & "'And [第几轮比赛] = '" & di2 & "'","","桌号 Desc")
For i As Integer = 0 To drs1.Count - 1 Step 2
If i + 1 <= drs1.Count - 1
Dim nr As DataRow = DataTables("对阵表").AddNew
nr("桌号") = drs1(i)("桌号")
nr("红方_编号") = drs1(i)("编号")
nr("红方_姓名") = drs1(i)("姓名")
nr("黑方_编号") = drs1(i+1)("编号")
nr("黑方_姓名") = drs1(i+1)("姓名")
End If
Next
ElseIf di2 = 2 And cnt = 0 Then
Dim drs2 As List(of DataRow) = DataTables("比赛积分").SQLSelect("[棋赛名称] = '" & di1 & "'And [第几轮比赛] = '" & a & "'","","积分 Desc")
For ia As Integer = 0 To drs2.Count - 1
dr = DataTables("比赛积分").AddNew
Dim dts1 As DataRow = DataTables("基本信息").SQLFind("[棋赛名称] = '" & di1 & "'And [身份] = '参赛人' And [缺赛轮号] like '%" & di2 & "%' and [编号] = '" & drs2(ia)("编号") & "'")
If dts1 IsNot Nothing Then
dr("排序") = 0
Else
dr("排序") = math.Ceiling((ii2) / 2)
ii2 + = 1
End If
dr("棋赛名称") = di1
dr("第几轮比赛") = di2
dr("日期") = di3
dr("编号") = drs2(ia)("编号")
dr("姓名") = drs2(ia)("姓名")
dr("轮赛次数值转换") = Val(di2)
dr("上轮止累计积分") = drs2(ia)("积分")
dr("曾交战对手累计积分") = DataTables("比赛积分").SQLCompute("SUM(积分)","[桌号] = " & drs2(ia)("桌号") & "And ([编号] <> '" & drs2(ia)("编号") & "'or [姓名] <> '" & drs2(ia)("姓名") & "')")
i2 + = 1
Next
DataTables("比赛积分").Load
DataTables("比赛积分").Save()
DataTables("对阵表").DataRows.Clear
Dim drs3 As List(of DataRow) = DataTables("比赛积分").SQLSelect("[棋赛名称] = '" & di1 & "'And [第几轮比赛] = '" & di2 & "' and [排序] <> 0","","排序,上轮止累计积分 Desc,曾交战对手累计积分")
For ib As Integer = 0 To drs3.Count - 1 Step 2
Dim nr As DataRow = DataTables("对阵表").AddNew
If ib + 1 <= drs3.Count - 1
nr("桌号") = drs3(ib)("排序")
nr("红方_编号") = drs3(ib)("编号")
nr("红方_姓名") = drs3(ib)("姓名")
nr("黑方_姓名") = drs3(ib+1)("编号")
nr("黑方_姓名") = drs3(ib+1)("姓名")
nr("红方_上轮止累计积分") = drs3(ib)("上轮止累计积分")
nr("红方_曾交战对手累计积分") = drs3(ib)("曾交战对手累计积分")
nr("黑方_上轮止累计积分") = drs3(ib+1)("上轮止累计积分")
nr("黑方_曾交战对手累计积分") = drs3(ib+1)("曾交战对手累计积分")
Else
nr("桌号") = drs3(ib)("排序")
nr("红方_编号") = drs3(ib)("编号")
nr("红方_姓名") = drs3(ib)("姓名")
nr("红方_上轮止累计积分") = drs3(ib)("上轮止累计积分")
nr("红方_曾交战对手累计积分") = drs3(ib)("曾交战对手累计积分")
End If
Next
DataTables("比赛积分").SQLUpdate(drs3)
drs3 = DataTables("比赛积分").SQLSelect("[棋赛名称] = '" & di1 & "'And [第几轮比赛] = '" & di2 & "' and [排序] = 0","","排序,上轮止累计积分 Desc,曾交战对手累计积分")
For ib As Integer = 0 To drs3.Count - 1 Step 2
Dim nr As DataRow = DataTables("对阵表").AddNew
If ib + 1 <= drs3.Count - 1
nr("桌号") = 0
nr("红方_编号") = drs3(ib)("编号")
nr("红方_姓名") = drs3(ib)("姓名")
nr("红方_上轮止累计积分") = drs3(ib)("上轮止累计积分")
nr("红方_曾交战对手累计积分") = drs3(ib)("曾交战对手累计积分")
nr("黑方_编号") = drs3(ib+1)("编号")
nr("黑方_姓名") = drs3(ib+1)("姓名")
nr("黑方_上轮止累计积分") = drs3(ib+1)("上轮止累计积分")
nr("黑方_曾交战对手累计积分") = drs3(ib+1)("曾交战对手累计积分")
Else
nr("桌号") = 0
nr("红方_编号") = drs3(ib)("编号")
nr("红方_姓名") = drs3(ib)("姓名")
nr("红方_上轮止累计积分") = drs3(ib)("上轮止累计积分")
nr("红方_曾交战对手累计积分") = drs3(ib)("曾交战对手累计积分")
End If
Next
DataTables("比赛积分").SQLUpdate(drs3)