以下是引用狐狸爸爸在2013-3-11 15:33:00的发言:
代码逻辑有问题,应该这样:
If e.DataCol.Name = "RQ" Then
If e.DataRow.IsNull("RQ") Then
e.DataRow("BH") = Nothing
Else
Dim bh As String = Format(e.DataRow("RQ"),"yyyyMMdd")
If e.DataRow("BH").StartsWith(bh) = False '如果编号的前8位不符
Dim idx As Integer
Dim max As String
If e.DataRow("RQ") = Vars("ksrq") Then '如果存在最大编号并且日期等于变量的日期
max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#") '取得该天的最大编号
idx = CInt(max.Substring(9,3)) + 1 '获得最大编号的后三位顺序号,并加1
If max > "" Then '如果不存在最大编号而日期等于变量的日期
idx = CInt(Vars("ksrq").Substring(9,3)) + 1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("BH") = bh & "-" & Format(idx,"000")
End If
End If
End If
End If
老总,代码不成功。开始我用“最大日期变量”来判断编号,现在直接用“最大编号变量”来判断取值。
代码如下:
If e.DataCol.Name = "RQ" Then
If e.DataRow.IsNull("RQ") Then
e.DataRow("BH") = Nothing
Else
Dim bh As String = Format(e.DataRow("RQ"),"yyyyMMdd")
If e.DataRow("BH").StartsWith(bh) = False
Dim idx As Integer
Dim max As String
max = e.DataTable.Compute("Max(BH)","RQ = #" & e.DataRow("RQ") & "#")
If max > "" Then如果存在最大编号
idx = CInt(max.Substring(9,3)) + 1
If max = "" And Vars("zdbh")>"" Then 如果不存在最大编号,但Vars("zdbh") 变量存在
idx = CInt(Vars("zdbh").Substring(9,3)) + 1
Else 如果两者都不存在
idx = 1
End If
e.DataRow("BH") = bh & "-" & Format(idx,"000")
End If
End If
End If
End If
问题是根本不生成编号。
[此贴子已经被作者于2013-3-11 20:37:05编辑过]