我想通过选择监测类别,自动完成项目编号,项目编号的规则是类别代码+年份+顺序号,以下代码自动生成的代码不会自动加1,请老师看看是哪里有错误?
Select e.DataCol.Name
Case "监测类别"
If e.DataRow.IsNull("监测类别") Then
e.DataRow("项目编号") = Nothing
Else
Dim lb As String
Select e.DataRow("监测类别")
Case "环境现状"
lb="H"
Case "竣工验收"
lb="Y"
Case "排污许可"
lb="P"
Case "其他委托"
lb="W"
Case "来样送检"
lb="S"
Case "验证比对"
lb="B"
End Select
If e.DataRow("项目编号").StartsWith(lb) = False '如果单据编号前缀不符
Dim max As String
Dim idx As Integer
Dim y As Date= Date.Today()
Dim bh As String = lb & y.year
max = e.DataTable.Compute("Max(项目编号)","监测类别 = '" & bh & "' And [_Identify] <> " & e.DataRow("_Identify")) '取得该类别的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(5,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("项目编号") = bh & Format(idx,"000")
End If
End If
End Select