比如甲、乙两队各随机抽取一个编号,组成红、黑双方各一人为一桌,安顺序递增桌号,随机先、后手,先手执红方。我这样写,已经能生成配对排序,但要随机先后手时红色代码报错:
.NET Framework 版本:4.0.30319.18063
Foxtable 版本:2021.11.18.11
错误所在事件:菜单,团体赛排座,Click
详细错误信息:
This row has been removed from a table and does not have any data. BeginEdit() will allow creation of new data in this row.
此主题相关图片如下:qq图片20211121204444.png
If Forms("主窗口").opened Then
Dim qsmc As WinForm.ComboBox = Forms("主窗口").Controls("棋赛名称")
Dim di1 As String = qsmc.Value
If di1 = "" Then
messagebox.show("请选择棋赛名称")
Return
End If
Dim m As WinForm.TextBox = Forms("主窗口").Controls("第几轮")
Dim di2 As String = m.Value
If di2 = "" Then
messagebox.show("请输入第几轮")
Return
End If
Dim bsrq As WinForm.DateTimePicker = Forms("主窗口").Controls("rq")
Dim di3 As Date = bsrq.Value
If Forms("主窗口").Controls("rq").text = "" Then
messagebox.show("请选择日期")
Return
End If
Dim bslx As WinForm.TextBox = Forms("主窗口").Controls("bslx")
Dim lx As String = bslx.Value
Dim fz As WinForm.DropDownBox = Forms("主窗口").Controls("fenzhu")
Dim Str As String = fz.Value
If Forms("主窗口").Controls("fenzhu").text = "" Then
messagebox.show("请选择分组")
Return
End If
Dim i2 As Integer = 1
Dim i3 As Integer = 1
Dim ii2 As Integer = 1
Dim tbl As WinForm.Table
Dim tab As WinForm.TabControl = Forms("主窗口").Controls("TabControl1")
If tab.TabPages.Contains(Str) = False Then
tab.TabPages.Add(Str,Str)
tbl = Forms("主窗口").CreateSQLTable("Table'" & Str & "'","Select * Fro m {综合组}","")
tbl.SetBounds(0, 0, 983, 580)
Forms("主窗口").Controls("TabControl1").Tabpages(Str).AddControl(tbl)
Forms("主窗口").Controls("TabControl1").SelectedIndex = tab.TabPages.count + 1
Else
tbl = Forms("主窗口").Controls("Table'" & Str & "'")
End If
tbl.Table.SetColVisibleWidth("桌号|30|红方_名次|40|红方_编号|40|红方_姓名|60|红方_上轮止累计积分|80|红方_曾交战对手累计积分|80|红方_签名|60|当前局成绩_红方|80|当前局成绩_黑方|80|黑方_签名|60|黑方_名次|40|黑方_编号|40|黑方_姓名|60|黑方_上轮止累计积分|80|黑方_曾交战对手累计积分|80")
tbl.Table.SetHeaderRowHeight(40)
If lx = "团体赛" Then
Dim dr As DataRow = DataTables("比赛积分").SQLfind("[团体赛或个人赛] = '" & lx & "' And [棋赛名称] = '" & di1 & "' And [第几轮比赛] = '" & di2 & "' And [分组] = '" & Str & "'")
Dim dtsh1 As List(of DataRow) = DataTables("基本信息").SQLSelect("[团体赛或个人赛] = '" & lx & "' And [棋赛名称] = '" & di1 & "' And [分组] = '" & Str & "' And [身份] = '参赛人' And [所属团体] = '" & Forms("主窗口").Controls("团体名称").text & "'")
Dim dtsh2 As List(of DataRow) = DataTables("基本信息").SQLSelect("[团体赛或个人赛] = '" & lx & "' And [棋赛名称] = '" & di1 & "' And [分组] = '" & Str & "' And [身份] = '参赛人' And [所属团体] = '" & Forms("主窗口").Controls("对阵团体名称").text & "'")
DataTables("比赛积分").DeleteFor("[棋赛名称] Is null")
Dim cnt As Integer = DataTables("比赛积分").Compute("Count([姓名])", "[团体赛或个人赛] = '" & lx & "' And [棋赛名称] = '" & di1 & "' And [第几轮比赛] = '" & di2 & "' And [分组] = '" & Str & "'")
If di2 = 1 And cnt = 0 Then
Do While dtsh1.Count > 0
Dim idx1 As Integer = rand.Next(0,dtsh1.Count)
dr = DataTables("比赛积分").AddNew()
dr("排序") = i2
dr("日期") = di3
dr("棋赛名称") = di1
dr("棋赛副名") = Forms("主窗口").Controls("TextBox4").text
dr("第几轮比赛") = di2
dr("编号") = dtsh1(idx1)("编号")
dr("姓名") = dtsh1(idx1)("姓名")
dr("团体赛或个人赛") = lx
dr("分组") = Str
dtsh1.RemoveAt(idx1)
i2 = i2 + 1
Loop
Do While dtsh2.Count > 0
Dim idx2 As Integer = rand.Next(0,dtsh2.Count)
dr = DataTables("比赛积分").AddNew()
dr("排序") = i3
dr("日期") = di3
dr("棋赛名称") = di1
dr("棋赛副名") = Forms("主窗口").Controls("TextBox4").text
dr("第几轮比赛") = di2
dr("编号") = dtsh2(idx2)("编号")
dr("姓名") = dtsh2(idx2)("姓名")
dr("团体赛或个人赛") = lx
dr("分组") = Str
dtsh2.RemoveAt(idx2)
i3 = i3 + 1
Loop
DataTables("比赛积分").Load
DataTables("比赛积分").Save()
tbl.Table.DataTable.DataRows.Clear
Dim drs1 As List(of DataRow) = DataTables("比赛积分").SQLSelect("[团体赛或个人赛] = '" & lx & "' And [棋赛名称] = '" & di1 & "' And [第几轮比赛] = '" & di2 & "'","","排序")
Dim pz As List(of DataRow) = DataTables("比赛积分").SQLSelect("[团体赛或个人赛] = '" & lx & "' And [棋赛名称] = '" & di1 & "' And [第几轮比赛] = '" & di2 & "' And [排序] =" & dr("排序"))
Messagebox.show(drs1.Count)
For i As Integer = 0 To drs1.Count - 1
Dim nr As DataRow = tbl.Table.DataTable.AddNew()
If i <= drs1.Count And rand.Next(0,1) = 0 Then
nr("桌号") = pz(0)("排序")
nr("红方_编号") = pz(0)("编号")
nr("红方_姓名") = pz(0)("姓名")
nr("黑方_编号") = pz(1)("编号")
nr("黑方_姓名") = pz(1)("姓名")
ElseIf i <= drs1.Count And rand.Next(0,1) = 1 Then
nr("桌号") = drs1(1)("排序")
nr("红方_编号") = pz(1)("编号")
nr("红方_姓名") = pz(1)("姓名")
nr("黑方_编号") = pz(0)("编号")
nr("黑方_姓名") = pz(0)("姓名")
End If
Next
DataTables("比赛积分").SQLUpdate(drs1)
End If
End If
DataTables("比赛积分").load
tbl.Table.DataTable.GlobalHandler.DataColChanging = True
Else
Return
End If
[此贴子已经被作者于2021/11/21 23:28:26编辑过]