表DataColChanged事件如下代码,开发环境不报错,发布后偶发报如题错误,麻烦老师帮忙看一下,哪里错了,谢谢!
Select e.DataCol.Name
Case "签订日期","合同种类"
If e.DataRow.IsNull("签订日期") Or e.DataRow.IsNull("合同种类") Then
e.DataRow("合同编号") = Nothing
Else
Dim d As Date = e.DataRow("签订日期")
Dim y As Integer = d.Year
Dim Days As Integer = Date.DaysInMonth(y,12)
Dim fd As Date = New Date(y,1,1) '获得该年的第一天
Dim ld As Date = New Date(y,12,Days) '获得该年的最后一天
Dim bh As String = e.DataRow("合同种类") & "-" & Format(d,"yyyy") & "-" '生成合同编号的前缀
If e.DataRow("合同编号").StartsWith(bh) = False '如果单据合同编号前缀不符
Dim flt As String
flt = "合同种类 = '" & e.DataRow("合同种类") & "' And 签订日期 >= '" & fd & "' And 签订日期 <= '" & ld & "' And [_Identify] <> " & e.DataRow("_Identify")
Dim max1 As String
Dim max2 As String
max1 = e.DataTable.Compute("Max(合同编号)", flt) '取得该类别的最大编号
max2 = e.DataTable.SQLCompute("Max(合同编号)", flt) '取得该类别的最大编号
Dim idx1 As Integer
Dim idx2 As Integer
If max1 > "" Then '如果存在最大编号
idx1 = CInt(max1.Substring(bh.length, 4))
End If
If max2 > "" Then '如果存在最大编号
idx2 = CInt(max2.Substring(bh.length, 3))
End If
Dim idx As Integer = Math.Max(idx1, idx2)
idx = idx + 1 '获得最大编号加1
e.DataRow("合同编号") = bh & Format(idx, "0000")
End If
End If
End Select