以文本方式查看主题

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

--  作者:jygyyl
--  发布时间:2021/9/28 16:16:00
--  [求助]不重复编码问题
在生成不重复编码是时,使用SQLCompute,有增加多行出现编码重复的问题;使用Compute,如后台数据没有被加载,出现新增编码与后台数据重复的问题。因项目有批量打印条码的需求。
求老师指点,能否先判断当前表(条码表)是否存在 “组别”=_UserAdmin and "组编码"=_UserPlace 的行,如果不存在,则执行

Select e.DataCol.Name
    Case "组别","组编码"
        If e.DataRow.IsNull("组别") OrElse e.DataRow.IsNull("组编码") Then
            e.DataRow("条码") = Nothing
        Else
            Dim bh As String = e.DataRow("组别") & e.DataRow("组编码")  \'生成编号的前缀
            If e.DataRow("条码").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "组别 = \'"& e.DataRow("组别") & "\' And 组编码 = \'"& e.DataRow("组编码") & "\' And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.SQLCompute("Max(条码)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(11,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("条码") = bh & Format(idx,"0000")
            End If
        End If
End Select

否则,执行
Select e.DataCol.Name
    Case "组别","组编码"
        If e.DataRow.IsNull("组别") OrElse e.DataRow.IsNull("组编码") Then
            e.DataRow("条码") = Nothing
        Else
            Dim bh As String = e.DataRow("组别") & e.DataRow("组编码")  \'生成编号的前缀
            If e.DataRow("条码").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "组别 = \'"& e.DataRow("组别") & "\' And 组编码 = \'"& e.DataRow("组编码") & "\' And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(条码)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(11,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("条码") = bh & Format(idx,"0000")
            End If
        End If
End Select


[此贴子已经被作者于2021/9/28 16:36:04编辑过]

--  作者:有点蓝
--  发布时间:2021/9/28 16:19:00
--  
生成条码后马上保存

                max = e.DataTable.SQLCompute("Max(条码)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(11,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("条码") = bh & Format(idx,"0000")
e.DataRow.save
            End If

--  作者:jygyyl
--  发布时间:2021/9/28 16:34:00
--  回复:(有点蓝)生成条码后马上保存    &n...
不成功啊!新增行没有保存,且增加多行编码依然重复。
--  作者:jygyyl
--  发布时间:2021/9/28 16:41:00
--  回复:(有点蓝)生成条码后马上保存    &n...
成功了!

在DataRowAdded中写入e.DataTable.Save()


--  作者:jygyyl
--  发布时间:2021/10/5 9:45:00
--  解决方法
在DataRowAdded中写入e.DataTable.Save()或 e.DataRow.save 都可以。用 e.DataRow.save 比较好。