以文本方式查看主题

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

--  作者:huangxueyao
--  发布时间:2017/1/18 11:59:00
--  求助:关于时间格式的一段代码
If e.DataCol.Name = "下单时间" Then
    If e.DataRow.IsNull("下单时间") Then
        e.DataRow("订单编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("下单时间"),"yyyyMMddHHmm") \'以下单日期加时间为准生成订单号前12位
        If e.DataRow("订单编号").StartsWith(bh) = False \'如果编号的前12位不符
            Dim max As String
            Dim idx As Integer
            MessageBox.show(e.DataRow("下单时间"))
            max = e.DataTable.Compute("Max(订单编号)","下单时间 = #" & e.DataRow("下单时间") & "# And [_Identify] <> " & e.DataRow("_Identify"))\'取得该天的最大编号
            MessageBox.show(max)
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(13,3))+1                \'获得最大编号的后四位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("订单编号") = bh  & Format(idx,"000")
        End If
    End If
End If


上面这段代码我是参考帮助手册的。现在的问题是红色部分不知道为什么判断不对,max一直为空,导致产生重复的订单编号


图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20170118115704.png
图片点击可在新窗口打开查看

[此贴子已经被作者于2017/1/18 11:59:35编辑过]

--  作者:有点色
--  发布时间:2017/1/18 12:06:00
--  

改一下

 

Dim d As Date = e.DataRow("下单时间")

max = e.DataTable.Compute("Max(订单编号)","下单时间 >= #" & d.Date & "# And 下单时间 < #" & d.Date.AddDays(1) & "# And [_Identify] <> " & e.DataRow("_Identify"))\'取得该天的最大编号


--  作者:huangxueyao
--  发布时间:2017/1/18 13:10:00
--  
If e.DataCol.Name = "下单时间" Then
    If e.DataRow.IsNull("下单时间") Then
        e.DataRow("订单编号") = Nothing
    Else
        Dim bh As String = Format(e.DataRow("下单时间"),"yyyyMMddHHmmss") \'以下单日期加时间为准生成订单号前14位
        If e.DataRow("订单编号").StartsWith(bh) = False \'如果编号的前14位不符
            Dim max As String
            Dim idx As Integer
            Dim d As Date = e.DataRow("下单时间")
            max = e.DataTable.Compute("Max(订单编号)","下单时间 >= #" & d.Date & "# And 下单时间 < #" & d.Date.AddDays(1) & "# And [_Identify] <> " & e.DataRow("_Identify"))\'取得该天的最大编号
            If max > "" Then \'如果存在最大编号
                idx = CInt(max.Substring(15,3))+1                \'获得最大编号的后四位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("订单编号") = bh  & Format(idx,"000")
        End If
    End If
End If

代码改成这样产生了问题


图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20170118115704.png
图片点击可在新窗口打开查看


--  作者:huangxueyao
--  发布时间:2017/1/18 13:13:00
--  
是这句出错了,已改好
idx = CInt(max.Substring(15,3))+1  
--  作者:有点色
--  发布时间:2017/1/18 14:18:00
--  

改成

 

idx = CInt(max.Substring(bh.length,3))+1