以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  按月生成编号,最后一天不能自动生成  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=153400)

--  作者:evolymft
--  发布时间:2020/8/10 10:43:00
--  按月生成编号,最后一天不能自动生成
请老师指点:按帮助做的代码,按月生成编号,最后一天不能自动生成。
--  作者:evolymft
--  发布时间:2020/8/10 10:43:00
--  
请老师指点:按帮助做的代码,按月生成编号,最后一天不能自动生成。


--  作者:evolymft
--  发布时间:2020/8/10 10:45:00
--  

If e.Dat\\aCol.Name = "日期" Then

    If\\ e.Data\\Row.IsNull("日期") Then

        e.Data\\Row("编号") = Nothing

    Else

        Dim d As Da\\te = e.D\\ataRow("日期")

        Dim y As Int\\eger = d.Year

        Dim m As In\\teger = d.Month

        Dim Days As Integer = Da\\te.DaysInMonth(y,m)

        Dim fd As Date = New Dat\\e(y,m,1) \'获得该月的第一天

        Dim ld As Date = New Dat\\e(y,m,Days) \'获得该月的最后一天

        Dim bh As String = For\\mat(d,"yyyyMM") \'生成编号的前6位,4位年,2位月.

        If e.Data\\Row("编号").Star\\sWith(bh) = False \'如果编号的前6位不符

            Dim max As St\\ring

            Dim idx As Integ\\er

            max = e.DataT\\\\able.Comp\\ute("Max(编号)","日期 >= #" & fd & "# And 日期 <= #" & ld & "# And [_Iden\\tify] <> " & e.DataRo\\w("_Identify")) \'取得该月的最大编号

            If max > "" Then \'如果存在最大编号

                idx = CInt(max.Subst\\ring(7,3)) + 1 \'获得最大编号的后三位顺序号,并加1

            Else

                idx = 1 \'否则顺序号等于1

            End If

            e.Data\\Row("编号") = bh & "-" & For\\mat(idx,"000")

        End If

    End If

End If



--  作者:有点蓝
--  发布时间:2020/8/10 11:12:00
--  
如果日期有时分秒,这样

max = e.DataT\\\\able.Comp\\ute("Max(编号)","日期 >= #" & fd & "# And 日期 < #" & ld.adddays(1) & "# And [_Iden\\tify] <> " & e.DataRo\\w("_Identify")) \'取得该月的最大编号

--  作者:2900819580
--  发布时间:2020/8/10 11:17:00
--  

试过,没有问题,不过你的判断条件最好更改一下

If e.DataRow("编号").StartsWith(bh) = False OrElse e.DataRow.IsNull("编号") then\'如果编号的前6位不符

 


--  作者:evolymft
--  发布时间:2020/8/10 11:35:00
--  
谢谢老师指点。
--  作者:cd_tdh
--  发布时间:2020/8/10 14:25:00
--  
以下是引用2900819580在2020/8/10 11:17:00的发言:

试过,没有问题,不过你的判断条件最好更改一下

If e.DataRow("编号").StartsWith(bh) = False OrElse e.DataRow.IsNull("编号") then\'如果编号的前6位不符

 

有问题,如果日期列是长时间格式,最后一天是有问题。你那样判断只是当有编号列不在重新生成而已,需要像有点蓝老师的那个方法处理

[此贴子已经被作者于2020/8/10 14:26:05编辑过]