以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  自动生成编码失效  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=142272)

--  作者:cd_tdh
--  发布时间:2019/10/22 16:12:00
--  自动生成编码失效

老师,10月10号后的版本自动生成编码失效,原来一直正常,我已经升级到最新版本:

\'\'生成合同编码
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 bh As String = Format(d,"yyyyMM") \'生成编号的前6位,4位年,2位月.
        Dim  max As String
        Dim  idx As  Integer
        max = e.DataTable.sqlCompute("Max(合同编码)","合同送审日期 >= \'" & fd & "\' And 合同送审日期 <= \'" & d & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
        If  max > "" Then \'如果存在最大编号
            idx = CInt(max.Substring(bh.length+1,3)) + 1  \'获得最大编号的后三位顺序号,并加1
        Else
            idx = 1 \'否则顺序号等于1
        End  If
        For Each dr As DataRow In e.DataTable.sqlSelect("合同送审日期 > \'" & d & "\' And 合同送审日期 < \'" & fd.AddMonths(1) & "\'")
            idx += 1
            dr("合同编码") = bh & "-" & Format(idx,"000")
            dr.save
        Next
    End  If
    e.DataRow.Save
End  If

 

新建项目提示一下错误:

 


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20191022161631.png
图片点击可在新窗口打开查看

 

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目6.foxdb

[此贴子已经被作者于2019/10/22 16:17:51编辑过]

--  作者:有点蓝
--  发布时间:2019/10/22 16:20:00
--  
失效是什么现象?


--  作者:cd_tdh
--  发布时间:2019/10/22 16:25: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(7,3)) + 1  \'获得最大合同编码的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End  If
            e.DataRow("合同编码") = bh & "-" & Format(idx,"000")
        End If
    End  If
    e.DataRow.Save
End  If


--  作者:有点蓝
--  发布时间:2019/10/22 16:44:00
--  
内部表。access日期使用#号

\'\'生成合同编码
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 bh As String = Format(d,"yyyyMM") \'生成编号的前6位,4位年,2位月.
        Dim  max As String
        Dim  idx As  Integer
        max = e.DataTable.sqlCompute("Max(合同编码)","合同送审日期 >= #" & fd & "# And 合同送审日期 <= #" & d & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该月的最大编号
        If  max > "" Then \'如果存在最大编号
            idx = CInt(max.Substring(bh.length+1,3)) + 1  \'获得最大编号的后三位顺序号,并加1
        Else
            idx = 1 \'否则顺序号等于1
        End  If
        e.DataRow("合同编码") = bh & "-" & Format(idx,"000")
        For Each dr As DataRow In e.DataTable.sqlSelect("合同送审日期 > #" & d & "# And 合同送审日期 < #" & fd.AddMonths(1) & "#")
            idx += 1
            dr("合同编码") = bh & "-" & Format(idx,"000")
            dr.save
        Next
    End  If
    e.DataRow.Save
End  If

--  作者:cd_tdh
--  发布时间:2019/10/22 18:19:00
--  
这个我知道,第一个代码,在sql数据库编号不编号了,也不报错。
[此贴子已经被作者于2019/10/22 19:36:27编辑过]

--  作者:有点蓝
--  发布时间:2019/10/22 20:21:00
--  
4楼的代码仔细看看,改为单引号到SqlServer里测试