Foxtable(狐表)用户栏目专家坐堂 → [求助] 带字母的自动编号的问题


  共有2252人关注过本帖平板打印复制链接

主题:[求助] 带字母的自动编号的问题

帅哥哟,离线,有人找我吗?
mikee
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:89 积分:947 威望:0 精华:0 注册:2017/8/7 14:36:00
[求助] 带字母的自动编号的问题  发帖心情 Post By:2017/10/19 14:22:00 [只看该作者]

因为习惯了用字母表示年月,所以在DataRowAdding中写了个增加行则自动编号, 可是在取编号最大值得时候有点问题,请问如何修改?

If e.DataRow.IsNull("日期") Then
    e.DataRow("日期") = Date.Now()
End If

Dim str As String = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Dim d As Date = e.DataRow("日期")
Dim y As Integer = d.Year - 2001
Dim m As Integer = d.Month - 1
Dim bh As String = str.Substring(y,1) & str.Substring(m,1) 
If e.DataRow("编号").StartsWith(bh) = False 
    Dim max As String
    Dim idx As Integer
    max = e.DataTable.Compute("max(编号)","编号 like '" & bh & "*'") 
    If max > "" Then 
        idx = CInt(max.Substring(7,3)) + 1 
    Else
        idx = 1
    End If
    e.DataRow("编号") = bh & "-" & Format(idx,"000")
End If

 回到顶部