临时版本跟踪表有需求编号,临时版本编号,客户,博达机型,状态列。
需求编号的格式是YYYYMM3位流水号。如201412111.
现在想做的是临时版本编号为MM3位需求编号的流水号_YYYY。如:12111_2014.
1.当新增行的客户和博达机型在数据库已经存在,且状态为Bound or Confirming or Nopass 时,临时版本编号等于之前已分配的最大编号。(认为12111_2014比12110_2014大)
2.当新增行的客户和博达机型在数据库已经存在,且状态为除这些Bound and Confirming and Confirmed and Nopass 之外的状态时,临时版本编号等于MM3位需求编号的流水号_YYYY
3.当新增行的客户和博达机型在数据库是首次出现,临时版本编号等于YY3位需求编号的流水号_YYYY
下面这段代码改怎么修改才能实现需求。
Dim d As Date = Date.Today
Dim m As String = Format(d,"MM")
Dim y As String = Format(d,"yyyy")
Dim max As String
Dim idx As Integer
max = e.DataTable.SQLCompute("Max(临时版本编号)","SubString(临时版本编号,0,2) = '" & m & "' And SubString(临时版本编号,5,5) = '-" & y & "'")
max = e.DataTable.SQLCompute("Max(临时版本编号)","SubString(临时版本编号,0,2) = '" & m & "' And SubString(临时版本编号,5,5) = '-" & y & "'")
If max > "" Then
idx = CInt(max.Substring(e.DataRow("需求编号").Length,-3))
e.DataRow("临时版本编号") = m & Format(idx,"000") & "_" & y
Else
If DataCol.Name = "客户" AndAlso DataCol.Name = "博达机型" Then
If e.NewValue Is Nothing Then
e.DataRow("临时版本编号") = Nothing
Else
Dim dr As DataRow
dr = DataTables("临时版本跟踪表").SQLFind("[客户] = '" & e.NewValue & "' andalso [博达机型] = '" & e.NewValue & "' and [状态] = 'Bound' or [状态] = 'Confirming' or [状态] = 'Nopass'" )
If dr IsNot Nothing Then
e.DataRow("临时版本编号") = dr("临时版本编号")
End If
End If
End If
End If
e.DataRow.Save
Tables("临时版本跟踪表").Sort = "需求编号 DESC"
[此贴子已经被作者于2014-12-10 13:15:26编辑过]