以文本方式查看主题

-  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=65712)

--  作者:qinlao666
--  发布时间:2015/3/20 23:26:00
--  按年自动编码
 例子     BF     15    01     22          W                 D   -          0001
           字符    年     月      日      拜访人员代码     拜访类型        序号(按年增加)

Select e.DataCol.Name
    Case "拜访_类型","拜访_人员"
        If e.DataRow.IsNull("拜访_类型") OrElse e.DataRow.IsNull("拜访_人员") Then
            e.DataRow("编号") = Nothing
        Else
            Dim bfry As String = e.DataRow("拜访_人员")
            If e.DataRow("拜访_人员") = "光" Then
                bfry = "W"
            ElseIf e.DataRow("拜访_人员") = "斌" Then
                bfry = "B"
            ElseIf e.DataRow("拜访_人员") = "桂" Then
                bfry = "G"
            ElseIf e.DataRow("拜访_人员") = "学" Then
                bfry = "X"
            ElseIf e.DataRow("拜访_人员") = "凯" Then
                bfry = "Z"
            ElseIf e.DataRow("拜访_人员") = "斌" Then
                bfry = "L"
            ElseIf e.DataRow("拜访_人员") = "龙" Then
                bfry = "I"
            ElseIf e.DataRow("拜访_人员") = "杰" Then
                bfry = "J"
            Else
                bfry = "P"
            End If
            
            Dim bflx As String = e.DataRow("拜访_类型")
            If e.DataRow("拜访_类型") = "电话" Then
                bflx = "D"
            Else
                bflx = "Z"
            End If
            
            
            Dim d As Date = e.DataRow("拜访_日期")
            Dim y As Integer = d.Year
            Dim m As Integer = d.Month
            Dim a As Integer = d.day
            
            
            Dim bf As String = "BF"
            Dim bh As String = bf & Format(d,"yy") \'生成编号的前4位,2位年
            
            If e.DataRow("编号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.Compute("Max(编号)","拜访_日期 >= #" & y & "#  And [序号] <> " & e.DataRow("序号")) \'取得该年的最大编号
                If max > "" Then \'如果存在最大编号
                    idx = CInt(max.Substring(11,4)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                
      
                
                Dim bh1 As String = bf & Format(d,"yyMMdd") \'生成编号的前8位,2位年
                
                e.DataRow("编号") = bh1 & bflx & bfry & "-" & Format(idx,"0000")
            End If
        End If
End Select

--  作者:Bin
--  发布时间:2015/3/21 8:58:00
--  
http://www.foxtable.com/help/topics/2403.htm