Dim Days As Integer = Date.DaysInMonth(y,m)
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
Dim m As Integer = d.Month
Dim Days As Integer = Date.DaysInMonth(y,m,d)
Dim fd As Date = New Date(y,m,1)
Dim ld As Date = New Date(y,m,Days)
Dim bh As String = Format(d,"yyyyMMdd")
If e.DataRow("订单编号").StartsWith(bh) = False
Dim max As String
Dim idx As Integer
e.DataRow("订单编号") = Nothing
max = e.DataTable.Compute("Max(订单编号)","订货日期 >= #" & fd & "# And 订货日期 <= #" & ld & "#")
If max > "" Then
idx = CInt(max.Substring(7,3)) + 1
Else
idx = 1
End If
e.DataRow("订单编号") = bh & "-" & Format(idx,"000")
End If
End If
End If
[此贴子已经被作者于2013-4-6 10:45:14编辑过]