以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  自动编号跨年跟换代码后错误  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=46618)

--  作者:yuyu060712
--  发布时间:2014/2/26 13:18:00
--  自动编号跨年跟换代码后错误
NET Framework 版本:2.0.50727.3655
Foxtable 版本:2013.10.14.1
错误所在事件:表,质量反馈,DataColChanged
详细错误信息:
Exception has been thrown by the target of an invocation.
The expression contains undefined function call Year().
老师,换代码后提示错误
--  作者:lsy
--  发布时间:2014/2/26 13:26:00
--  
代码贴出来,或者把例子发上来,Year函数不会有问题吧。
--  作者:yuyu060712
--  发布时间:2014/2/26 13:42: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 bh As String = e.DataRow("类别") & "[" & Format(d,"yyyy") & "]" \'生成编号的前缀
            If e.DataRow("编号").StartsWith(bh) = False \'如果立案编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "类别 = \'"& e.DataRow("类别")  & " \'And [_Identify] <> " & e.DataRow("_Identify") & " and Year(登记日期)=" & y
                max = e.DataTable.Compute("Max(编号)",flt) \'取得区划机关行为简称的最大单据编号
                If max > "" Then \'如果存在最大立案编号
                    idx = CInt(max.Substring(8,3)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("编号") = bh & Format(idx,"000")
            End If
        End If
End Select

--  作者:don
--  发布时间:2014/2/26 13:43: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 bh As String = e.DataRow("类别") & "[" & Format(d,"yyyy") & "]" \'生成编号的前缀
            If e.DataRow("编号").StartsWith(bh) = False \'如果立案编号前缀不符
                Dim idx As Integer
                Dim max,flt,s1 As String
                Dim d1,d2 As Date
                d1 = New Date(y,1,1)
                d2 = New Date(y,12,31)

                Dim v1 as string() ={e.DataRow("类别"),e.DataRow("_Identify"),d1,d2}
                s1 ="类别 =\'{0}\' and [_Identify] ={1} and 登记日期 >= #{2}# and 登记日期 <= #{3}#"
                flt = String.format(s1,V1(0),V1(1),v1(2),v1(3))
                
                max = e.DataTable.Compute("Max(编号)",flt) \'取得区划机关行为简称的最大单据编号
                If max > "" Then \'如果存在最大立案编号
                    idx = CInt(max.Substring(8,3)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("编号") = bh & Format(idx,"000") 
            End If
        End If
End Select

--  作者:yuyu060712
--  发布时间:2014/2/26 14:32:00
--  
同类别的编号不会变全部是001
--  作者:Bin
--  发布时间:2014/2/26 14:35:00
--  
同一个问题不要分开提问两次,你直接上例子吧
--  作者:lsy
--  发布时间:2014/2/26 15:27: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 bh As String = e.DataRow("类别") & "[" & Format(d,"yyyy") & "]" \'生成编号的前缀
            If e.DataRow("编号").StartsWith(bh) = False \'如果立案编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String               

                flt = "类别 = \'"& e.DataRow("类别")  & " \'And [_Identify] <> " & e.DataRow("_Identify") & " and Convert(登记日期, \'System.String\') Like \'" & y & "%\'" 

                max = e.DataTable.Compute("Max(编号)",flt) \'取得区划机关行为简称的最大单据编号
                If max > "" Then \'如果存在最大立案编号
                    idx = CInt(max.Substring(8,3)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("编号") = bh & Format(idx,"000")
            End If
        End If
End Select