以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  不能自动按左右顺序编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=97735)

--  作者:zoyong
--  发布时间:2017/3/17 15:49:00
--  不能自动按左右顺序编号

If e.DataCol.Name = "中标日期" Then
    If e.DataRow.IsNull("中标日期") Then
        e.DataRow("档案编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("中标日期"),"yy") \'取得编号的8位前缀
        If e.DataRow("档案编号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(档案编号)","中标日期 = #" & e.DataRow("中标日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("档案编号") = "P" & bh & Format(idx,"000")
        End If
    End If
End If

上面的代码,输入2017年后的日期都能自动按顺序编号,输入2017年以前,编号就会乱编,求帮忙

自动编号格式:P2015001    P2015002   P2015003   P2015004
                  P2016001    P2016002   P2016003   P2016004
                  P2017001    P2017002   P2017003   P2017004
[此贴子已经被作者于2017/3/17 15:57:09编辑过]

--  作者:有点色
--  发布时间:2017/3/17 16:25:00
--  
If e.DataCol.Name = "中标日期" Then
    If e.DataRow.IsNull("中标日期") Then
        e.DataRow("档案编号") = Nothing
    Else
        Dim bh As String = "P" & Format(e.DataRow("中标日期"),"yyyy") \'取得编号的8位前缀
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(档案编号)","档案编号 like \'" & bh & "%\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(bh.length)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("档案编号") = bh & Format(idx,"000")
    End If
End If