If e.DataCol.Name = "住院年份" Then
If e.DataRow.IsNull("住院年份") Then
e.DataRow("编号") = Nothing
Else
Dim d As Date = e.DataRow("住院年份")
Dim y As Integer = d.Year
If e.DataRow.ISNULL("报告文号") = False '如果序号的前6位不符
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(编号)","住院年份=#" & e.DataRow("住院年份") & "# and 工号= '" & e.datarow("工号") & "'") '取得该月的最大编号
If max > "" Then '如果存在最大编号
idx = CInt(max.Substring(0,3)) + 1 '获得最大编号的后三位顺序号,并加1
Else
idx = 1 '否则顺序号等于1
End If
e.DataRow("编号") = Format(idx,"000")
End If
End If
End If