以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  关于自动编号  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=68518)

--  作者:新航程小何
--  发布时间:2015/5/19 17:25:00
--  关于自动编号
各位老师,我想实现功能如下:员工表(员工编号,部门名称),部门表(部门编号,部门名称)
1、员工编号,是根据“所属部门编号”生成
2、但是员工表中是没有部门编号,部门编号是在"部门"表中
我想实现编号功能,但是不知道怎么把员工编号改成:部门编号+2位顺序号
Select e.DataCol.Name
    Case "部门名称"
        If e.DataRow.IsNull("部门名称") Then
            e.DataRow("员工编号") = Nothing
        Else
            Dim lb As String = e.DataRow("部门名称")
            If e.DataRow("员工编号").StartsWith(lb) = False \'如果单据地块编号前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.SQLCompute("Max(员工编号)","所属园区 = \'" & lb & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该所属园区的最大地块编号
                If max > "" Then \'如果存在最大地块编号
                    idx = CInt(max.Substring(9,2)) + 1 \'获得最大地块编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("员工编号") = lb & Format(idx,"00")
            End If
        End If
End Select
[此贴子已经被作者于2015/5/19 17:25:43编辑过]

--  作者:Bin
--  发布时间:2015/5/19 17:31:00
--  
利用FIND 或者SQLFIND 根据部门名称 查找到对应的部门编号



dim dr as datarow = datatables("部门").find("部门名称=\'" & e.datarow("部门名称") & "\'")
if dr isnot nothing then
Dim lb As String = dr("部门编号")

end if

--  作者:新航程小何
--  发布时间:2015/5/19 17:43:00
--  
老师,我的下面代码也实现自动编号了,不过不能累加,每次顺序号都是“01”,编号的例子:ty2015010101-01
Select e.DataCol.Name
    Case "部门名称"
        If e.DataRow.IsNull("部门名称") Then
            e.DataRow("员工编号") = Nothing
        Else
            dim dr as datarow = datatables("部门").find("部门名称=\'" & e.datarow("部门名称") & "\'")
if dr isnot nothing then
Dim lb As String = dr("部门编号")
            If e.DataRow("员工编号").StartsWith(bh) = False \'如果单据地块编号前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.SQLCompute("Max(员工编号)","部门名称 = \'" & bh  & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该所属园区的最大地块编号
                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
[此贴子已经被作者于2015/5/19 19:05:33编辑过]

--  作者:大红袍
--  发布时间:2015/5/19 19:24:00
--  
 贴出完整代码,最后应该加一句 e.DataRow.Save
--  作者:新航程小何
--  发布时间:2015/5/19 19:28:00
--  
还是不行,是不是实现的代码哪错了?
--  作者:新航程小何
--  发布时间:2015/5/19 19:39:00
--  
Select e.DataCol.Name
    Case "部门名称"
        If e.DataRow.IsNull("部门名称") Then
            e.DataRow("员工编号") = Nothing
        Else
            Dim dr As DataRow = DataTables("部门单位").find("部门=\'" & e.DataRow("部门名称") & "\'")
            If dr IsNot Nothing Then
                Dim bh As String = dr("编号")
                If e.DataRow("员工编号").StartsWith(bh) = False \'如果单据地块编号前缀不符
                    Dim max As String
                    Dim idx As Integer
                    max = e.DataTable.SQLCompute("Max(员工编号)","部门名称 = \'" & bh  & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该所属园区的最大地块编号
                    If max > "" Then \'如果存在最大地块编号
                        idx = CInt(max.Substring(3,2)) + 1 \'获得最大地块编号的后三位顺序号,并加1
                    Else
                        idx = 1 \'否则顺序号等于1
                    End If
                    e.DataRow("员工编号") = bh & Format(idx,"00")
                End If
            End If
        End If
End Select
e.DataRow.Save
图片点击可在新窗口打开查看此主题相关图片如下:qq截图20150519193736.png
图片点击可在新窗口打开查看

--  作者:大红袍
--  发布时间:2015/5/19 19:39:00
--  
 贴出完整可以测试的代码,或者上传具体例子
--  作者:新航程小何
--  发布时间:2015/5/19 19:40:00
--  
六楼的就是完整的代码
--  作者:大红袍
--  发布时间:2015/5/19 19:41:00
--  
Select e.DataCol.Name
    Case "部门名称"
        If e.DataRow.IsNull("部门名称") Then
            e.DataRow("员工编号") = Nothing
        Else
            Dim dr As DataRow = DataTables("部门单位").find("部门=\'" & e.DataRow("部门名称") & "\'")
            If dr IsNot Nothing Then
                Dim bh As String = dr("编号")
                \'If e.DataRow("员工编号").StartsWith(bh) = False \'如果单据地块编号前缀不符
                Dim max As String
                Dim idx As Integer
                max = e.DataTable.SQLCompute("Max(员工编号)","部门名称 = \'" & bh  & "\' And [_Identify] <> " & e.DataRow("_Identify")) \'取得该所属园区的最大地块编号
                If max > "" Then \'如果存在最大地块编号
                    idx = CInt(max.Substring(bh.Length,2)) + 1 \'获得最大地块编号的后三位顺序号,并加1
                Else
                    idx = 1 \'否则顺序号等于1
                End If
                e.DataRow("员工编号") = bh & Format(idx,"00")
                e.DataRow.Save
                \'End If
            End If
        End If
End Select

--  作者:新航程小何
--  发布时间:2015/5/19 19:45:00
--  
还是原问题
[此贴子已经被作者于2015/5/19 19:45:46编辑过]