以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]简化自动编号代码(已解决)  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=58147)

--  作者:yyzlxc
--  发布时间:2014/10/12 20:33:00
--  [求助]简化自动编号代码(已解决)
生产计划ID自动生成的代码:根据单据日期生成年度计划编号(表DataColChanged事件)。为了获取年度,增加了年度列,能否简化代码,取消年度列,请各位老师指教,谢谢。


Dim nd As String
Select Case e.DataCol.Name
    Case "单位","单据日期"
        If e.DataRow.IsNull("单据日期") Then
            e.DataRow("年度") = Nothing
        Else
            nd = Year(e.DataRow("单据日期")) \'提取年度
            e.DataRow("年度") = nd
        End If

        If e.DataRow.IsNull("单位") OrElse e.DataRow.IsNull("单据日期") Then
            e.DataRow("生产计划ID") = Nothing
        Else
            Dim max As String
            Dim idx As Integer
            Dim dw As String = e.DataRow("单位")
            max = e.DataTable.Compute("Max(生产计划ID)","单位 = \'"& dw &"\' And 年度 = \'"& nd &"\' And [_Identify] <> \'"& e.DataRow("_Identify") &"\'") \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(Right(max,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("生产计划ID") = dw & "-SC" & nd & Format(idx,"000")
        End If
End Select
[此贴子已经被作者于2014-10-12 21:08:17编辑过]

--  作者:有点甜
--  发布时间:2014/10/12 20:38:00
--  

 试试这样

 

Dim nd As String
Select Case e.DataCol.Name
    Case "单位","单据日期"


        If e.DataRow.IsNull("单位") OrElse e.DataRow.IsNull("单据日期") Then
            e.DataRow("生产计划ID") = Nothing
        Else
            Dim max As String
            Dim idx As Integer

            nd = Year(e.DataRow("单据日期")) \'提取年度
            Dim dw As String = e.DataRow("单位")
            max = e.DataTable.Compute("Max(生产计划ID)","生产计划ID like \'" & dw & "-SC" & nd & "%\' And [_Identify] <> \'"& e.DataRow("_Identify") &"\'") \'取得该月的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(Right(max,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("生产计划ID") = dw & "-SC" & nd & Format(idx,"000")
        End If
End Select

[此贴子已经被作者于2014-10-12 20:38:54编辑过]

--  作者:yyzlxc
--  发布时间:2014/10/12 21:08:00
--  
谢谢甜老师的指教,方案可行,又学了一招,再次衷心感谢!!