以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  代码有什么问题么?为什么 编号都是001 不自动增加呢?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=85376)

--  作者:jinzhengbe
--  发布时间:2016/5/24 14:26:00
--  代码有什么问题么?为什么 编号都是001 不自动增加呢?
If e.DataCol.Name = "time" Then
    If e.DataRow.IsNull("time") Then
        e.DataRow("danhao") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("time"),"yyyyMMdd") \'取得danhao的8位前缀
        If e.DataRow("danhao").StartsWith(bh) = False \'如果danhao的前8位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(danhao)","time = #" & e.DataRow("time") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大danhao
            If max > "" Then \'如果存在最大danhao
                idx = CInt(max.Substring(9,3)) + 1 \'获得最大danhao的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("danhao") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

[此贴子已经被作者于2016/5/24 14:26:33编辑过]

--  作者:大红袍
--  发布时间:2016/5/24 14:46:00
--  

  max = e.DataTable.Compute("Max(danhao)","time = #" & e.DataRow("time") & "# And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大danhao

 

改成

 

  max = e.DataTable.Compute("Max(danhao)","danhao like \'" & bh & "%\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大danhao


--  作者:jinzhengbe
--  发布时间:2016/5/24 16:38:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:lvlv1.table



实验了一下,还是不行,麻烦大师给看看
--  作者:大红袍
--  发布时间:2016/5/24 17:24:00
--  
If e.DataCol.Name = "time" Then
    If e.DataRow.IsNull("time") Then
        e.DataRow("danhao") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("time"),"yyyyMMdd") \'取得danhao的8位前缀
        If e.DataRow("danhao").StartsWith(bh) = False \'如果danhao的前8位不符
            Dim max As String
            Dim idx As Integer
              max = e.DataTable.Compute("Max(danhao)","danhao like \'" & bh & "%\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大danhao
            If max > "" Then \'如果存在最大danhao
                idx = CInt(max.Substring(bh.length+1,3)) + 1 \'获得最大danhao的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("danhao") = bh & "-" & Format(idx,"000")
        End If
    End If
End If

--  作者:jinzhengbe
--  发布时间:2016/5/24 20:18:00
--  

max = e.DataTable.sqlCompute("Max(danhao)","danhao like \'" & bh & "%\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该天的最大danhao

红色部分是获取 数据库内的最大单号吧? 是这么用的么?或者有别的办法没有?


--  作者:大红袍
--  发布时间:2016/5/24 20:19:00
--  
就是5楼那样写,代码最后,要加上 e.DataRow.Save
--  作者:jinzhengbe
--  发布时间:2016/5/24 20:20:00
--  

因为每天会重复录入好几次。 每次打开之后单号都是从头开始的。这样的话,

编号也是从头开始,容易重复。 所以想查询远程数据库李最大的单号,而不是本地的最大单号


--  作者:大红袍
--  发布时间:2016/5/24 20:26:00
--  
看6楼。
--  作者:jinzhengbe
--  发布时间:2016/5/24 20:36:00
--  

实验了一下不行, 出来的单号都是一样的
图片点击可在新窗口打开查看此主题相关图片如下:无标题.png
图片点击可在新窗口打开查看


--  作者:大红袍
--  发布时间:2016/5/24 20:37:00
--  

DataRowAdding事件的代码,写到DataRowAdded去。

 

同时DataColChanged事件,要加上代码 e.DataRow.Save