以文本方式查看主题

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

--  作者:qinlao666
--  发布时间:2015/3/21 13:07:00
--  自动编号问题不能按顺序增加

老师请帮我看下代码,为什么不能自己增加顺序好,都是001

 

 

Select e.DataCol.Name
    Case "拜访_类型","拜访_人员"
        If e.DataRow.IsNull("拜访_类型") OrElse e.DataRow.IsNull("拜访_人员") Then
            e.DataRow("编号") = Nothing
        Else
            Dim bfry As String = e.DataRow("拜访_人员")
            If e.DataRow("拜访_人员") = "汪晓光" Then
                bfry = "W"
            ElseIf e.DataRow("拜访_人员") = "张志斌" Then
                bfry = "B"
            ElseIf e.DataRow("拜访_人员") = "巩中桂" Then
                bfry = "G"
            ElseIf e.DataRow("拜访_人员") = "汪振学" Then
                bfry = "X"
            ElseIf e.DataRow("拜访_人员") = "周荣凯" Then
                bfry = "Z"
            ElseIf e.DataRow("拜访_人员") = "张良斌" Then
                bfry = "L"
            ElseIf e.DataRow("拜访_人员") = "吴小龙" Then
                bfry = "I"
            ElseIf e.DataRow("拜访_人员") = "刘杰" Then
                bfry = "J"
            Else
                bfry = "P"
            End If
           
            Dim bflx As String = e.DataRow("拜访_类型")
            If e.DataRow("拜访_类型") = "电话" Then
                bflx = "D"
            Else
                bflx = "Z"
            End If
           
            Dim bf As String = "BF"
            Dim d As Date = e.DataRow("拜访_日期")
            Dim y As Integer = d.Year
            Dim m As Integer = d.Month
            Dim Days As Integer = Date.DaysInMonth(y,m)
            Dim fd As Date = New Date(y,m,1) \'获得该月的第一天
            Dim ld As Date = New Date(y,m,Days) \'获得该月的最后一天
            Dim bh As String = bf & Format(d,"yyMM") \'生成编号的前6位,4位年,2位月.
            If e.DataRow("编号").StartsWith(bh) = False \'如果编号的前6位不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.Compute("Max(编号)","拜访_日期 >= #" & fd & "# And 拜访_日期 <= #" & ld & "# And [序号] <> " & e.DataRow("序号")) \'取得该月的最大编号
                If len(max) = 14 Then   \'如果存在最大编号
                    idx = CInt(max.Substring(11,3)) + 1 \'获得最大编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("编号") = bh & bflx & bfry & "-" & Format(idx,"000")
            End If
        End If
End Select


--  作者:Bin
--  发布时间:2015/3/21 13:34:00
--  
调试一下.看看得出的 Max是什么 

messagebox.show(max)

--  作者:qinlao666
--  发布时间:2015/3/21 13:47:00
--  

结果不一样啊


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20150321134906.jpg
图片点击可在新窗口打开查看

--  作者:qinlao666
--  发布时间:2015/3/21 13:55:00
--  

每次的调试结果都是一样的


--  作者:Bin
--  发布时间:2015/3/21 14:03:00
--  
If len(max) = 14 Then

你截图的是长度12  当然永远进入Else

--  作者:qinlao666
--  发布时间:2015/3/21 22:23:00
--  
老师帮我看下,我把长度改成12后,又遇到的新问题
--  作者:qinlao666
--  发布时间:2015/3/21 22:24:00
--  

到003后又不增加了


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20150321220748.jpg
图片点击可在新窗口打开查看

--  作者:qinlao666
--  发布时间:2015/3/21 23:30:00
--  
图片点击可在新窗口打开查看
--  作者:有点甜
--  发布时间:2015/3/22 9:33:00
--  
Select e.DataCol.Name
    Case "拜访_类型","拜访_人员"
        If e.DataRow.IsNull("拜访_类型") OrElse e.DataRow.IsNull("拜访_人员") Then
            e.DataRow("编号") = Nothing
        Else
            Dim bfry As String = e.DataRow("拜访_人员")
            If e.DataRow("拜访_人员") = "汪晓光" Then
                bfry = "W"
            ElseIf e.DataRow("拜访_人员") = "张志斌" Then
                bfry = "B"
            ElseIf e.DataRow("拜访_人员") = "巩中桂" Then
                bfry = "G"
            ElseIf e.DataRow("拜访_人员") = "汪振学" Then
                bfry = "X"
            ElseIf e.DataRow("拜访_人员") = "周荣凯" Then
                bfry = "Z"
            ElseIf e.DataRow("拜访_人员") = "张良斌" Then
                bfry = "L"
            ElseIf e.DataRow("拜访_人员") = "吴小龙" Then
                bfry = "I"
            ElseIf e.DataRow("拜访_人员") = "刘杰" Then
                bfry = "J"
            Else
                bfry = "P"
            End If
           
            Dim bflx As String = e.DataRow("拜访_类型")
            If e.DataRow("拜访_类型") = "电话" Then
                bflx = "D"
            Else
                bflx = "Z"
            End If
           
            Dim bf As String = "BF"
            Dim d As Date = e.DataRow("拜访_日期")
            Dim bh As String = bf & Format(d,"yyMM") & bflx & bfry & "-"
           
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(编号)","编号 like \'" & bh & "%\'")
            If len(max) = 14 Then   \'如果存在最大编号
                idx = CInt(max.Substring(bh.Length)) + 1 \'获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 \'否则顺序号等于1
            End If
            e.DataRow("编号") = bh & Format(idx,"000")
        End If
End Select

--  作者:qinlao666
--  发布时间:2015/3/22 12:57:00
--  
谢谢甜老师,问题解决了。我想请问下max = e.DataTable.Compute("Max(编号)","编号 like \'" & bh & "%\'")
这代码是什么意思?主要是这个%我不知道干什么用的