以文本方式查看主题

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

--  作者:jjjeyes
--  发布时间:2017/10/16 13:36:00
--  [求助]求老师帮忙看看为什么这个自动编号的代码不能自己累加
要求:根据"课程学期","课程名称","课程时间"三列的内容自动编号,如果存在同一"课程学期","课程名称","课程时间"则自动累加。
以下代码可以自动生成代码为“17181-134-TJ-01”,但是同一"课程学期","课程名称","课程时间"的班级增加了,却不能累加为“17181-134-TJ-02”,求教以下代码哪里有问题!

Select e.DataCol.Name
    Case "课程学期","课程名称","课程时间"
        If e.DataRow.IsNull("课程学期") OrElse e.DataRow.IsNull("课程名称") OrElse e.DataRow.IsNull("课程时间") Then
            e.DataRow("课程编号") = Nothing
        Else
            Dim sj As DataRow = DataTables("基本设置").find("课程时间 = \'" & e.DataRow("课程时间") & "\'")
            Dim mc As DataRow = DataTables("基本设置").find("课程名称 = \'" & e.DataRow("课程名称") & "\'")
            Dim xq As DataRow = DataTables("基本设置").find("课程学期 = \'" & e.DataRow("课程学期") & "\'")
            Dim bh As String = xq("学期编号") & "-" & sj("时间编号") & "-" & mc("课程名称编号") & "-" \'生成编号的前缀
            If e.DataRow("课程编号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "课程学期 = \'"& xq("学期编号") & "\'And 课程时间 = \'" & sj("时间编号") & "\'And 课程名称 = \'" & mc("课程名称编号") & "\'And [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(课程编号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(13,2)) + 1 \'获得最大单据编号的后二位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("课程编号") = bh & Format(idx,"00")
            End If
        End If
End Select

--  作者:有点甜
--  发布时间:2017/10/16 16:01:00
--  

改成这样

 

Select e.DataCol.Name
    Case "课程学期","课程名称","课程时间"
        If e.DataRow.IsNull("课程学期") OrElse e.DataRow.IsNull("课程名称") OrElse e.DataRow.IsNull("课程时间") Then
            e.DataRow("课程编号") = Nothing
        Else
            Dim sj As DataRow = DataTables("基本设置").find("课程时间 = \'" & e.DataRow("课程时间") & "\'")
            Dim mc As DataRow = DataTables("基本设置").find("课程名称 = \'" & e.DataRow("课程名称") & "\'")
            Dim xq As DataRow = DataTables("基本设置").find("课程学期 = \'" & e.DataRow("课程学期") & "\'")
            Dim bh As String = xq("学期编号") & "-" & sj("时间编号") & "-" & mc("课程名称编号") & "-" \'生成编号的前缀
            If e.DataRow("课程编号").StartsWith(bh) = False \'如果单据编号前缀不符
                Dim max As String
                Dim idx As Integer
                Dim flt As String
                flt = "课程编号 like \'" & bh & "%\' and [_Identify] <> " & e.DataRow("_Identify")
                max = e.DataTable.Compute("Max(课程编号)",flt) \'取得该月的相同工程代码的最大单据编号
                If max > "" Then \'如果存在最大单据编号
                    idx = CInt(max.Substring(bh.length,2)) + 1 \'获得最大单据编号的后二位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("课程编号") = bh & Format(idx,"00")
            End If
        End If
End Select


--  作者:有点甜
--  发布时间:2017/10/16 16:01:00
--  
如果还有问题,做个例子测试。