Dim dr As DataRow = e.DataRow
Dim dt As DataTable = DataTables("号段管理")
Dim dr1 As DataRow = dt.Find("[启用] = True And [停止] = False")
If dr1 IsNot Nothing Then
Dim bh As String = dr1("开始号段")
bh = Format(e.DataTable.Compute("Max(编号)","编号 >= " & dr1("开始号段") & " and 编号 <= " & dr1("结束号段")) + 1,"0000000")
Do While bh > dr1("结束号段")
dr1("启用") = False
dr1("停止") = True
dr1 = dt.Find("[启用] = False And [停止] = False")
If dr1 IsNot Nothing Then
dr1("启用") = True
bh = dr1("开始号段")
bh = Format(e.DataTable.Compute("Max(编号)","编号 >= " & dr1("开始号段") & " and 编号 <= " & dr1("结束号段")) + 1,"0000000")
If bh <= dr1("结束号段") Then
Exit Do
End If
Else
MessageBox.Show("没有号段了")
Return
End If
Loop
dr("编号") = bh
End If