以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  不重复编号的生成问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=148007)

--  作者:lpp121
--  发布时间:2020/3/28 23:54:00
--  不重复编号的生成问题
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目2.table
老师帮忙看下为什么会有这种问题,编号有时连续有时不连续

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期") Then
        e.DataRow("合同编号") = Nothing
    Else
        Dim bh As String ="RL" & 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(12,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("合同编号") =bh & e.DataRow("个人代码") & "-" & Format(idx,"000")
        End If
    End If
End If



--  作者:有点蓝
--  发布时间:2020/3/29 20:49:00
--  
编码规则的问题,因为RL20200328V-011和RL20200328R-012加载比较,V比R大,所有最大值是RL20200328V-011而不是和RL20200328R-012

If e.DataCol.Name = "日期" OrElse e.DataCol.Name = "个人代码" Then
    If e.DataRow.IsNull("日期") OrElse e.DataRow.IsNull("个人代码") Then
        e.DataRow("合同编号") = Nothing
    Else
        Dim bh As String ="RL" & Format(e.DataRow("日期"),"yyyyMMdd") & e.DataRow("个人代码") \'取得编号的8位前缀
        If e.DataRow("合同编号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.SQLCompute("Max(Right(合同编号,3))", "日期 = #" & e.DataRow("日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("合同编号") =bh &  "-" & Format(idx,"000")
            e.DataRow.save
        End If
    End If
End If