Foxtable(狐表)用户栏目专家坐堂 → [求助]自动编号问题


  共有1590人关注过本帖树形打印复制链接

主题:[求助]自动编号问题

帅哥哟,离线,有人找我吗?
cqlwsam
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1014 积分:7535 威望:0 精华:0 注册:2010/4/12 12:23:00
[求助]自动编号问题  发帖心情 Post By:2018/8/27 17:39:00 [只看该作者]

代码如下:

'''
Dim dr As DataRow=e.DataRow
If e.DataCol.Name = "分组" Then
    If dr.IsNull("分组") Then
        dr("父键") = Nothing
        dr("主键")= Nothing
        dr("名称")=Nothing
    Else
        Dim txt As String = dr("分组")
        Dim dr1 As DataRow
        dr1= DataTables("主表").find("[分组]='" & txt & "'")
        If dr1 IsNot Nothing Then
            dr("父键")= dr1("父键")
       else
            Dim max As String = e.DataTable.Compute("Max(父键)")
            Dim idx As Integer
            If max > "" Then
                idx = CInt(max)+1
                MessageBox.Show(idx)
            Else
                idx=1
            End If
            dr("父键")=Format(idx,"00")
        End If
    End If
End If

表如截图

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

想实现:
1.在添加一行时,如果“分组”列的内容在原表中已经有了,父键中的值就等于相应的值。如新增行中的“分组”列为“科研管理”,父键值为“04”(已实现)。如果没有,则父键值在原来最大值上添加1,并填入“父键”中.

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2018/8/27 17:44:00 [只看该作者]

Dim dr As DataRow=e.DataRow
If e.DataCol.Name = "分组" Then
    If dr.IsNull("分组") Then
        dr("父键") = Nothing
        dr("主键")= Nothing
        dr("名称")=Nothing
    Else
        Dim txt As String = dr("分组")
        Dim dr1 As DataRow
        dr1= DataTables("主表").find("[分组]='" & txt & "' and _Identify <> " & dr("_Identify"))
        If dr1 IsNot Nothing Then
            dr("父键")= dr1("父键")
       Else
            Dim max As String = e.DataTable.Compute("Max(父键)")
            Dim idx As Integer
            If max > "" Then
                idx = CInt(max)+1
                MessageBox.Show(idx)
            Else
                idx=1
            End If
            dr("父键")=Format(idx,"00")
        End If
    End If
End If

 回到顶部