以文本方式查看主题

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

--  作者:扶风
--  发布时间:2015/10/15 16:04:00
--  关于自动编号

Select e.DataCol.Name
     Case  "cpmc"
          If e.DataRow.IsNull("cpmc") Then
             e.DataRow("xuhao") = Nothing
         Else
             Dim lb As  String = e.DataRow("cpmc")
             If e.DataRow("xuhao").StartsWith(lb) = False  \'如果单据编号前缀不符
                Dim max  As  String
                 Dim idx  As  Integer
                max = e.DataTable.Compute("Max(xuhao)","cpmc = \'" & lb  & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该类别的最大编号
                If max > ""  Then  \'如果存在最大编号
                    idx = CInt(max.Substring(2)) + 1  \'获得最大编号的后三位顺序号,并加1
                 Else
                     idx = 1  \'否则顺序号等于1
                 End  If
                 e.DataRow("xuhao") = lb.Substring(5,2) & Format(idx,"000000")
         End  If
      End  If
 End  Select

 

老师,如上代码写在表的dotacolchanged里实现了自动分类编码,但是存在这样的问题:

表的beforeload事件写了如下一段代码

e.DataTable.LoadFilter = "jiean = False "

 

用来控制仅加载未结案的行,如果所有行均已结案它会又从头开始编号。这并不是我们希望看到的,因为我们要用这个编号作为更新数据库里数据的依据,请问老师要如何修改?


--  作者:大红袍
--  发布时间:2015/10/15 16:46:00
--  

max = e.DataTable.Compute

 

改成

 

max = e.DataTable.SqlCompute

 

------------

 

e.DataRow("xuhao") = lb.Substring(5,2) & Format(idx,"000000")

 

改成

 

e.DataRow("xuhao") = lb.Substring(5,2) & Format(idx,"000000")

e.DataRow.Save


--  作者:扶风
--  发布时间:2015/10/15 16:58:00
--  

好的谢谢老师