Foxtable(狐表)用户栏目专家坐堂 → [求助]


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

主题:[求助]

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


加好友 发短信
等级:婴狐 帖子:47 积分:449 威望:0 精华:0 注册:2013/7/7 20:49:00
[求助]  发帖心情 Post By:2015/8/24 14:15:00 [只看该作者]

本人设计表如下:

图片点击可在新窗口打开查看此主题相关图片如下:qq拼音截图未命名.png
图片点击可在新窗口打开查看
在表的DataColChanged事件中加入如下代码:目的是自动生成委托编号。
If e.DataCol.Name = "委托日期" Then
    If e.DataRow.IsNull("委托日期") Then
        e.DataRow("委托编号") = Nothing
    Else
        Dim d As Date = e.DataRow("委托日期")
        Dim y As Integer = d.Year
        Dim fd As Date = New Date(y,1,1) '获得该年的第一天
        Dim ld As Date = New Date(y,12,31) '获得该年的最后一天
        Dim bh As String = Format(d,"yyyy") '生成编号的前4位,4位年.
        If e.DataRow("委托编号").StartsWith(bh) = False '如果编号的前4位不符
            Dim max As String
            Dim idx As Integer
            max = e.DataTable.Compute("Max(委托编号)","委托日期 >= #" & fd & "# And 委托日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该年的最大编号
            If max > "" Then '如果存在最大编号
                idx = CInt(max.Substring(8,3)) + 1 '获得最大编号的后三位顺序号,并加1
            Else
                idx = 1 '否则顺序号等于1
            End If
            e.DataRow("委托编号") = "WT-" & bh & "-" & Format(idx,"000")
        End If
    End If
我需要在选择不同的机构名称后,委托编号按照不同的机构进行重新编号,但目前存在的问题是机构名称改变后,委托编号还是按照顺序增加,上述代码该如何改进。



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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/8/24 14:41:00 [只看该作者]

参考代码

 

If e.DataCol.Name = "委托日期" OrElse e.DataCol.name = "机构名称" Then
    If e.DataRow.IsNull("委托日期") OrElse e.DataRow.isnull("机构名称") Then
        e.DataRow("委托编号") = Nothing
    Else
        Dim d As Date = e.DataRow("委托日期")
        Dim y As Integer = d.Year
        Dim fd As Date = New Date(y,1,1) '获得该年的第一天
        Dim ld As Date = New Date(y,12,31) '获得该年的最后一天
        Dim bh As String = Format(d,"yyyy") '生成编号的前4位,4位年.
        'If e.DataRow("委托编号").StartsWith(bh) = False '如果编号的前4位不符
        Dim max As String
        Dim idx As Integer
        max = e.DataTable.Compute("Max(委托编号)","机构名称 = '" & e.DataRow("机构名称") & "' and 委托日期 >= #" & fd & "# And 委托日期 <= #" & ld & "# And [_Identify] <> " & e.DataRow("_Identify")) '取得该年的最大编号
        If max > "" Then '如果存在最大编号
            idx = CInt(max.Substring(8,3)) + 1 '获得最大编号的后三位顺序号,并加1
        Else
            idx = 1 '否则顺序号等于1
        End If
        e.DataRow("委托编号") = "WT-" & bh & "-" & Format(idx,"000")
        'End If
    End If
End I
f

[此贴子已经被作者于2015/8/24 14:41:15编辑过]

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


加好友 发短信
等级:婴狐 帖子:47 积分:449 威望:0 精华:0 注册:2013/7/7 20:49:00
  发帖心情 Post By:2015/8/24 15:08:00 [只看该作者]

谢谢!

 回到顶部