以文本方式查看主题

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

--  作者:l1q2lq
--  发布时间:2016/1/19 14:41:00
--  [流水编号
表属性新增行代码:e.DataRow("日期") = Date.Now

按照以下代码设置编号,为什么每行编号都是20160119-001,只有手动输入日期才会变成20160119-001,20160119-002.。。

If e.DataCol.Name = "日期" Then
    If e.DataRow.IsNull("日期"Then
        e.DataRow("编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("日期"),"yyyyMMdd"\'取得编号的8位前缀
        If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","日期 = #" & e.DataRow("日期") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & "-" & Format(idx,"000")
        End If
    End 
If

End
 If




--  作者:大红袍
--  发布时间:2016/1/19 14:47:00
--  
写到DataRowAdded事件,而非ing事件
--  作者:l1q2lq
--  发布时间:2016/1/19 14:52:00
--  
还是不行,一样的问题
--  作者:大红袍
--  发布时间:2016/1/19 14:54:00
--  

那尝试改成

 

e.DataRow("日期") = Date.Today


--  作者:l1q2lq
--  发布时间:2016/1/19 14:55:00
--  
可以了,但是日期列怎么直接获取当前time?
--  作者:大红袍
--  发布时间:2016/1/19 14:57:00
--  

代码改改

 

Dim d As Date = e.DataRow("日期").Date

max = e.DataTable.Compute("Max(编号)","日期 >= #" & d & "# and 日期 < #" & d.addDays(1) & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大编号

 


--  作者:l1q2lq
--  发布时间:2016/1/19 15:04:00
--  
类型integer的值无法转换为date
--  作者:大红袍
--  发布时间:2016/1/19 15:08:00
--  
Dim d As Date = Cdate(e.DataRow("日期")).Date
--  作者:l1q2lq
--  发布时间:2016/1/19 15:19:00
--  
e.DataRow("编号") = bh & "-" & Format(idx,"000")
麻烦再问下,上面这句变成
e.DataRow("编号") = bh & Format(idx,"000")
新增第二行的时候提示 调用的目标发生了异常。


--  作者:大红袍
--  发布时间:2016/1/19 15:42:00
--  

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

 

改成

 

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