以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  导入自动编号的问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=86644)

--  作者:yuyoufei11
--  发布时间:2016/6/22 14:18:00
--  导入自动编号的问题

If e.DataCol.Name = "交期" Then
    If e.DataRow.IsNull("交期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("交期"),"yyyyMMdd") \'取得编号的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(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If
用上面这段代码在单个输入时自动编号很好,但批量导入时相同日期的都变为YYYYMMDD-01问大神代码该如何改动才能同日期的编号能递增

--  作者:大红袍
--  发布时间:2016/6/22 14:42:00
--  

试试,不行,就上传实例

 

If e.DataCol.Name = "交期" Then
    If e.DataRow.IsNull("交期") Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("交期"),"yyyyMMdd") \'取得编号的8位前缀
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前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(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End If
End If