Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共3 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:当天序号会重复

1楼
edisontsui 发表于:2023/9/28 17:00:00
If e.DataCol.Name = "出入库日期" Then
    If e.DataRow("出入库记录数") = 0 AndAlso e.DataRow("出入库记录数2") = 0 Then
        If 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, m, 1) '获得该月的第一天
            Dim ld As Date = New Date(y, m, Days) '获得该月的最后一天
            Dim bh As String = Format(d, "yyyyMMdd") '生成代号前8位
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.SQLCompute("Max(当天序号)", "出入库日期 = '" & e.DataRow("出入库日期") & "' And [_Identify] <> " & e.DataRow("_Identify")) '取得当天的最大序号
                If max > "" Then '如果存在最大当天序号
                    idx = max + 1 '当天序号加1
                Else
                    idx = 1 '否则当天序号等于1
                End If
                e.DataRow("当天序号") = idx
                e.DataRow("出入库单号") = bh & "-" & Format(idx, "00")
                e.DataRow.save
        End If
    end if
End If

上面的代码用于取得全公司统一的、不重复的"当天序号",但是,在多用户的情况下,这个"当天序号"会出现重复的情况。请问是什么原因呢?谢谢。
2楼
有点蓝 发表于:2023/9/28 17:02:00
这种方式如果并发多,还是会有重复的。换种方式:http://www.foxtable.com/webhelp/topics/3008.htm
3楼
cd_tdh 发表于:2023/9/28 17:48:00
如果并发不是特别大,在保存行前在重新生成一次编号,重复几率极小,我实测没问题。
共3 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .03125 s, 2 queries.