以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 为什么改动一下就不行了? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=151044) |
||||
-- 作者:采菊东篱下 -- 发布时间:2020/6/13 16:08:00 -- 为什么改动一下就不行了? 原来的代码没问题的: 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 & "\'") Dim a As String = Cstr(Val(di2)-1) If DataTables("比赛积分").DataRows.count = 0 OrElse dr Is Nothing Then Dim dts As List(of DataRow) = DataTables("基本信息").SQLSelect("[棋赛名称] = \'" & di1 & "\'And [身份] = \'参赛人\'") Dim i2 As Integer = 1 Do While dts.Count > 0 Dim idx As Integer = rand.Next(0,dts.Count-1) dr = DataTables("比赛积分").AddNew() dr("桌号") = math.Ceiling((i2+1) \\ 2) dr("日期") = di3 dr("棋赛名称") = di1 dr("第几轮比赛") = di2 dr("编号") = dts(idx)("编号") dr("姓名") = dts(idx)("姓名") dts.RemoveAt(idx) i2 += 1 Loop DataTables("比赛积分").Save() DataTables("对阵表").DataRows.Clear Dim drs1 As List(of DataRow) = DataTables("比赛积分").SQLSelect("[棋赛名称] = \'" & di1 & "\'And [第几轮比赛] = \'" & di2 & "\'","","第几轮比赛,桌号") 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 因为还要利用dr继续写代码,就改为: 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 drs As List(of DataRow) = DataTables("比赛积分").SQLSelect("[棋赛名称] = \'" & di1 & "\'And [第几轮比赛] = \'" & di2 & "\'") For Each dr As DataRow In drs Dim a As String = Cstr(Val(di2)-1) Dim i2 As Integer = 1 Dim dts As List(of DataRow) = DataTables("基本信息").SQLSelect("[棋赛名称] = \'" & di1 & "\'And [身份] = \'参赛人\'") DataTables("比赛积分").DeleteFor("棋赛名称 is null and 第几轮比赛 is null") If di2 =1 And (DataTables("比赛积分").DataRows.count = 0 OrElse drs.count <= dts.Count) Then Do While dts.Count > 0 Dim idx As Integer = rand.Next(0,dts.Count-1) dr = DataTables("比赛积分").AddNew dr("桌号") = math.Ceiling((i2+1) \\ 2) dr("日期") = di3 dr("棋赛名称") = di1 dr("第几轮比赛") = di2 dr("编号") = dts(idx)("编号") dr("姓名") = dts(idx)("姓名") dts.RemoveAt(idx) i2 += 1 Loop DataTables("比赛积分").Save() DataTables("对阵表").DataRows.Clear Dim drs1 As List(of DataRow) = DataTables("比赛积分").SQLSelect("[棋赛名称] = \'" & di1 & "\'And [第几轮比赛] = \'" & di2 & "\'","","桌号") 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 End If Next 红色部分是我改动过的,删除添加的空行,不允按了多次按钮生成了多次数据。
|
||||
-- 作者:有点蓝 -- 发布时间:2020/6/13 16:32:00 -- 不行了指什么?什么地方不行了? 第一段红色代码,sqlselect如果有结果,能够进入for each循环,说明"比赛积分"表肯定是有数据的,第二段红色代码的判断【DataTables("比赛积分").DataRows.count = 0】完全就是多余的,因为count肯定不等于0。 至于【drs.count <= dts.Count】条件是否成立,自己调试一下 msgbox(drs.count) msgbox(dts.count)
|
||||
-- 作者:采菊东篱下 -- 发布时间:2020/6/13 17:17:00 -- 一开始是空表,或不存在棋赛名称和第几轮比赛,不要DataTables("比赛积分").DataRows.count = 0我也试过,都不能生成数据。代码在对阵表中的综合排座上。
密码:888888 |
||||
-- 作者:有点蓝 -- 发布时间:2020/6/13 17:31:00 -- 看不懂您的代码。请使用文字说明一下具体的实现逻辑,比如第一轮想做什么功能?把哪个表的数据按照什么规则填充到哪个表?最后生成的结果应该是怎么样的?最好是画个流程图,把您的思路表现出来 |
||||
-- 作者:采菊东篱下 -- 发布时间:2020/6/13 17:46:00 -- 加上messagebox.show(drs.count),完全没反应,因为比赛积分表中一开始完全没有记录,但必须加这判断,否则表上已生成数据,因为多次按按钮,再度生成。 |
||||
-- 作者:采菊东篱下 -- 发布时间:2020/6/13 19:25:00 -- 改为这样解决了: 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 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+1) \\ 2) dr("日期") = di3 dr("棋赛名称") = di1 dr("第几轮比赛") = di2 dr("编号") = dts(idx)("编号") dr("姓名") = dts(idx)("姓名") 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 End If
[此贴子已经被作者于2020/6/13 20:33:06编辑过]
|