以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  未全部加载时 自动编号 重复问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=82328)

--  作者:yifan3429
--  发布时间:2016/3/16 0:49: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,m,1) \'获得该月的第一天
            Dim ld As Date = New Date(y,m,Days) \'获得该月的最后一天
            Dim bh As String = e.DataRow("客户代码") & "-" & Format(d,"yyyyMM") & "-" \'生成编号的前缀
            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.Compute("Max(订单号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(12,3)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("订单号") = bh & Format(idx,"000")
            End If
        End If
End Select



上述代码,如果我没有全部加载就会出现  和历史编号重复的事件   怎么避免  会从后台读取最大数  而不是当前显示最大数


请教老师们!

--  作者:狐狸爸爸
--  发布时间:2016/3/16 6:34:00
--  

参考:

 

http://www.foxtable.com/help/topics/1994.htm

 


--  作者:大红袍
--  发布时间:2016/3/16 9:22: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,m,1) \'获得该月的第一天
            Dim ld As Date = New Date(y,m,Days) \'获得该月的最后一天
            Dim bh As String = e.DataRow("客户代码") & "-" & Format(d,"yyyyMM") & "-" \'生成编号的前缀
            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(12,3)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("订单号") = bh & Format(idx,"000")
                e.DataRow.Save
            End If
        End If
End Select

--  作者:大红袍
--  发布时间:2016/3/16 9:23:00
--  

复杂的方法

 

http://www.foxtable.com/help/topics/3008.htm

 

 

http://www.foxtable.com/help/topics/1994.htm

 

[此贴子已经被作者于2016/3/16 9:23:25编辑过]

--  作者:liuyixin662
--  发布时间:2016/10/21 18:03:00
--  
老师你好,下面的代码出错麻烦指导一下(表未全部加载后台数据):If e.DataCol.Name = "录入日期" 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,"yyyyMM") \'生成编号的前6位,4位年,2位月.
        If e.DataRow("部件流转单号").StartsWith(bh) = False \'如果编号的前6位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.sqlCompute("Max(部件流转单号)","录入日期 >= #" & fd & "# And 录入日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(9,5)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("部件流转单号") = "BJ" & bh & "-" & Format(idx,"00000")
            e.DataRow.Save
        End If
    End If
End If

--  作者:liuyixin662
--  发布时间:2016/10/21 18:05:00
--  
错误提示
图片点击可在新窗口打开查看此主题相关图片如下:增加行时出错.bmp
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2016/10/22 8:48:00
--  
sqlserver数据库?

把#号全部改为单引号 \'

max = e.DataTable.sqlCompute("Max(部件流转单号)","录入日期 >= \'" & fd & "\' And 录入日期 <= \'" & ld & "\' And [_Identify] <> " & e.DataRow("_Identify"))
[此贴子已经被作者于2016/10/22 8:48:12编辑过]