换了一个代码写法,已经实现次级编号的自动递增
代码如下:
Select e.DataCol.Name
Case "入住时间","租赁性质","承租人"
If e.DataRow.isnull("合同编号") Then
If e.DataRow.IsNull("入住时间") OrElse e.DataRow.IsNull("租赁性质") Then
e.DataRow("合同编号") = Nothing
Else
Dim d As Date = e.DataRow("入住时间")
Dim bh As String = "" & e.DataRow("项目") & "-" & e.DataRow("租赁性质") & "-" & Format(d,"yyyy") & "-"
Dim max As String
Dim idx As Integer
Dim flt As String
flt = "合同编号 like '" & bh & "%' And [_Identify] <> " & e.DataRow("_Identify")
max = e.DataTable.Compute("Max(合同编号)",flt)
If max > "" Then
idx = CInt(max.Substring(bh.Length,4)) + 1
Else
idx = 1
End If
e.DataRow("合同编号") = bh & Format(idx,"0000")
End If
End If
If e.DataRow.IsNull("承租人") Then '次级编号的判断语句,加入了这一句才实现次级编号
e.DataRow("批次") = Nothing
Else
Dim lb As String = e.DataRow("承租人")
If e.DataRow("批次").StartsWith(lb) = False
Dim maxx As String
Dim idxx As Integer
maxx = e.DataTable.Compute("Max(批次)","承租人 = '" & lb & "' And [_Identify] <> " & e.DataRow("_Identify"))
If maxx > "" Then
idxx = CInt(maxx.Substring(1,2)) + 1
Else
idxx = 1
End If
e.DataRow("批次") = "第" & Format(idxx,"00") & "批"
End If
End If
End Select
(已实现全部功能,代码也更新了,希望这个例子对大家有帮助)
[此贴子已经被作者于2015-2-2 14:34:39编辑过]