以文本方式查看主题

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

--  作者:webccc
--  发布时间:2017/10/1 17:29:00
--  [求助]自动编号
以下代码是在datacolchanged事件中的,重置“企业名称”和“合同签订日期”中的数据后,“企业编号”列里面并没有自动生成编号,请问是什么原因啊?
if e.DataCol.Name = "企业名称" orelse e.DataCol.Name = "合同签订日期" then
    if e.DataRow.IsNull("企业名称") Then
       e.DataRow("企业编号") = Nothing
    else 
         Dim dr As DataRow 
         dr = e.DataTable.find("企业名称 = \'" & e.datarow("企业名称") & "\'")
         if dr IsNot Nothing Then
            e.datarow("企业编号") = dr("企业编号")
         else
              If e.DataRow.IsNull("合同签订日期") then 
                 e.DataRow("企业编号") = Nothing
              Else
                  Dim bh As String = Format(e.DataRow("合同签订日期"),"yyyyMMdd")
                  If e.DataRow("企业编号").StartsWith(bh) = False
                     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(8,2)) + 1
                     Else
                        idx = 1
                     End If
                     e.DataRow("企业编号") = bh & Format(idx,"00")
                  End If
               End If
          End If
     end if
end if 
[此贴子已经被作者于2017/10/2 15:14:03编辑过]

--  作者:有点蓝
--  发布时间:2017/10/4 9:25:00
--  
max = e.DataTable.Compute("Max(企业编号)","企业编号 = \'" & e.datarow("企业编号")  & "\' and 合同签订日期 = #" & e.DataRow("合同签订日期") & "# And [_Identify] <> " & e.DataRow("_Identify"))
--  作者:webccc
--  发布时间:2017/10/27 11:22:00
--  
好的,非常感谢老师!