DataTables("对阵表").DataRows.Clear'清空窗口上table控件绑定的表格数据
Dim bsrq As WinForm.DateTimePicker = e.Form.Controls("rq")'定义窗口上的日期控件
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 Integer = m.Value'定义窗口上的第几轮变量为整数型
Dim di3 As Date = bsrq.Value'定义窗口上的日期变量为日期型
'以上为定义窗口上的控件和变量,要不要这样定义,请指正。
Dim ds As DataRow = DataTables("对阵表").SQLfind("棋赛名称 = '" & di1 & "' And 第几轮比赛 = '" & di2 & "'")'定义ds为对阵表上的棋赛名称和第几轮比赛等于窗口控件上的棋赛名称和第几轮比赛上的行
Dim dr As DataRow = DataTables("比赛积分").SQLfind("棋赛名称 = '" & di1 & "'")'定义dr为当比赛积分表上的棋赛名称和第几轮比赛等于窗口控件上的棋赛名称和第几轮比赛上的行
Dim di4 As Integer = ds("桌号") = 0'定义di4为符合上面条件的行对应的桌号变量
'下面是根据基本信息表上的棋赛名称等于窗口控件上的棋赛名称,姓名不为空,身份列为参赛人,安桌号顺序生成以人数个数不安顺序随机生成编号,编号对应基本信息表上对应的姓名、编号,就是他应坐的桌号。
If dr Is Nothing Then
di1 = qsmc.Value
di2 = 1
Dim ls As Integer = DataTables("基本信息").SQLGetValues("棋赛名称|姓名|身份", "棋赛名称 = '" & di1 & "' And 姓名 is not null and 身份 = '参赛人'").Count
Dim ids1,ids2 As New List(of Integer) '用于存储洗牌前后的位置
For i As Integer = 0 To ls -1 '准备初始的牌
ids1.add(i)
Next
For i As Integer = 0 To ls - 1 '开始洗牌
Dim idx As Integer = ids1(rand.Next(0,ids1.count))
ids2.Add(idx)
ids1.Remove(idx)
Dim n = 2
If ls > = n Then
Dim ls1 As new List(Of String)
Do While ls1.count < n
Dim a = Rand.Next(0, ls)
If ls1.Contains(a) = False Then
ls1.add(ids2(a))
End If
Loop
di4 = di4 + 1
ds("红方_编号") = ls1(0)
ds("黑方_编号") = ls1(1)
End If
Next
Else
[此贴子已经被作者于2020/4/10 11:07:56编辑过]