以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]控件Click下的自动编号问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=108175)

--  作者:cyh2017
--  发布时间:2017/10/17 18:06:00
--  [求助]控件Click下的自动编号问题

以下代码是DataColchanged下的自动编号代码,,请问如果要移到 按钮控件的click下,增加一行后,直接按条件给个编号,要怎么修改。。。。。。



Select e.DataCol.Name
    Case "公司名称"
        If e.DataRow.IsNull("公司名称")  Then
            e.DataRow("公司编号") = Nothing
        Else
                If e.DataRow("公司编号").StartsWith("C") = False \'如果编号前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.Compute("Max(公司编号)"," [_Identify] <> " & e.DataRow("_Identify")) \'取得最大编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(1,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("公司编号") = "C" & Format(idx,"0000")
            End If
        End If
End Select

--  作者:有点甜
--  发布时间:2017/10/17 19:59:00
--  
Dim dt As DataTable = DataTables("表A")
Dim ndr As DataRow = dt.addnew
Dim max As String
Dim idx As Integer
max = dt.Compute("Max(公司编号)"," [_Identify] <> " & ndr("_Identify")) \'取得最大编号
If max > "" Then \'如果存在最大单据编号
    idx = CInt(max.Substring(1,4)) + 1 \'获得最大单据编号的后四位顺序号,并加1
Else
    idx = 1 \'否则顺序号等于1
End If
ndr("公司编号") = "C" & Format(idx,"0000")