以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]编号问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=69261)

--  作者:jygyyl
--  发布时间:2015/6/2 11:50:00
--  [求助]编号问题

以下是我模仿写的编号代码,不知问题出在哪,两三台机子同时工作时,依然会出现编号重复!求老师指点!谢谢!

 

Select e.DataCol.Name
    Case "投保日期","社区代码"
        If e.DataRow.IsNull("投保日期") OrElse e.DataRow.IsNull("社区代码") Then
            e.DataRow("保单编号") = Nothing
        Else
            Dim d As Date = e.DataRow("投保日期")
            Dim y As Integer = d.Year
            Dim m As Integer = d.Month
            Dim Days As Integer = Date.DaysInMonth(y,m)
            Dim fd As Date = New Date(y,1,1) \'获得该月的第一天
            Dim ld As Date = New Date(y,12,31) \'获得该月的最后一天
            Dim bh As String = e.DataRow("社区代码") & "-" & Format(d,"yyyy") & "-" \'生成编号的前缀
            If e.DataRow("保单编号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "社区代码 = \'"& e.DataRow("社区代码") & "\' And 投保日期 >= \'" & fd & "\' And 投保日期 <= \'" & ld & "\' And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.SQLCompute("Max(保单编号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(18,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("保单编号") = bh & Format(idx,"0000")
            End If
        End If
End Select


--  作者:Bin
--  发布时间:2015/6/2 11:52:00
--  
多人使用的话,要用这个方案http://www.foxtable.com/help/topics/1994.htm


--  作者:大红袍
--  发布时间:2015/6/2 12:07:00
--  

 你都没有Save这一行

 

e.DataRow("保单编号") = bh & Format(idx,"0000")

e.DataRow.Save


--  作者:jygyyl
--  发布时间:2015/6/3 11:51:00
--  谢谢!搞定了
谢谢!搞定了