要达到"实话实说”的编号要求,我也实话实说,还真有点费劲,参考了狐狸他爹的流水账编码(狐狸他爹的高效率流水账那可真叫一个绝),勉强完成,经测试,符合“实话实说”的要求
Dim d As Date = e.DataRow("日期")
Dim StartDate As Date
Dim EndDate As Date
Dim Month As Integer = d.Month
Dim Year As Integer = d.Year
StartDate = New Date(Year,Month,1)
EndDate = New Date(Year,Month,Date.DaysInMonth(Year,Month))
If e.DataCol.Name = "日期" Then
If e.DataRow.IsNull("日期") Then
e.DataRow("编号") = Nothing
Else
If e.NewValue <> Nothing And e.DataRow("编号") = Nothing Then
'e.DataRow("编号") ="AA" & format(e.NewValue,"yyMMdd") '可替换
e.DataRow("编号") ="AA" & CStr(e.NewValue).Remove(0,2).Remove(2,1).Remove(4,1)
Dim dr As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [日期] = #" & d & "#", "[_SortKey] Desc")
If dr Is Nothing Then
mr("编号") = mr("编号") & format(1,"000")
dr = mr
End If
drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [日期] = '" & d & "'", "[_SortKey]")
For i As Integer = 1 To drs.Count - 1
drs(i)("编号") ="AA" & drs(i-1)("编号").SubString(drs(i-1)("编号").Length - 9) + 1
Next
End If
End If
End If
说明:如果要求编号确立后不允许修改的,将[_SortKey] 替换为[_Identify]
[此贴子已经被作者于2011-6-9 23:11:14编辑过]