For Each Ary As String() In Arys
Dim filter As String = CExp("学校代码='{0}' and 年级代码='{1}' and 考试名称='{2}'",Ary(0),Ary(1),ary(2))
Dim bhstr As String = Ary(1) & Ary(0)
Dim bj As List(Of String) = dt.GetValues("班级",filter & " and 班级 in (1,2,3)","班级")
Dim bjlist As new List(Of List(of DataRow))(bj.Count)
Dim max As Integer = 0
For Each s As String In bj
Dim lst As List(of DataRow) = dt.Select(filter & " And 班级 ='" & s & "'","姓名")
If max < lst.Count Then max = lst.Count
bjlist.add(lst)
Next
Dim idx As Integer = 1
Dim dr As DataRow
For i As Integer = 0 To max - 1
For j As Integer = 0 To bjlist.Count - 1
Dim lst As List(of DataRow) = bjlist(j)
If i < lst.Count Then
dr = lst(i)
If dr("考号锁定") = False
dr("考号") = bhstr & Format(idx,"0000")
idx += 1
p.Value = i
End If
End If
Next
Next
bj = dt.GetValues("班级",filter & " and 班级 in (4,5,6,7)","班级")
bjlist.Clear
max = 0
For Each s As String In bj
Dim lst As List(of DataRow) = dt.Select(filter & " And 班级 ='" & s & "'","姓名")
If max < lst.Count Then max = lst.Count
bjlist.add(lst)
Next
idx = 1
dr = Nothing
For i As Integer = 0 To max - 1
For j As Integer = 0 To bjlist.Count - 1
Dim lst As List(of DataRow) = bjlist(j)
If i < lst.Count Then
dr = lst(i)
If dr("考号锁定") = False
dr("考号") = bhstr & Format(idx,"0000")
idx += 1
p.Value = i
End If
End If
Next
Next
Next