Foxtable(狐表)用户栏目专家坐堂 → 员工生日查询出错,问题原来在这里!请教如何改进?


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

主题:员工生日查询出错,问题原来在这里!请教如何改进?

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


加好友 发短信
等级:童狐 帖子:217 积分:1646 威望:0 精华:0 注册:2018/1/21 10:25:00
员工生日查询出错,问题原来在这里!请教如何改进?  发帖心情 Post By:2019/6/26 6:21:00 [只看该作者]

列出一个月内过生日的员工,提示出错,熬夜排查,原来是员工之中有一个2月29日出生的。加入一段代码后,问题消除,但是,如何改进呢?
Dim ids As String
Dim n As Integer = 30 '未来天数,含今天,所以实际是未来30天
For Each dr As Row In Tables("员工基础表").Rows
    
    Dim dt As Date = dr("出生日期")
    If dt.Month = 2 AndAlso dt.Day = 29
        MessageBox.show("发现本单位有2月29日出生的员工,请单独记录,本查询未列出该员工!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
        Continue For
    End If
    Dim dt1 As New Date(Date.Today.Year,dt.Month,dt.Day)
    Dim dt2 As  New Date(Date.Today.AddDays(n).Year,dt.Month,dt.Day)
    If (dt1 >= Date.Today AndAlso dt1 < Date.Today.AddDays(n)) OrElse (dt2 >= Date.Today AndAlso dt2 < Date.Today.AddDays(n)) Then
        ids = ids & "," & dr("_Identify")
    End If
Next
If ids > "" Then
    ids = ids.Trim(",")
    Tables("员工基础表").filter = "[_Identify] In (" & ids &")"
    MessageBox.show("近30天内过生日的员工有 " & Tables("员工基础表").Rows.Count & " 名!,请及时慰问.","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
Else
    MessageBox.show("近30天内没有过生日的员工!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
End If

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


加好友 发短信
等级:一尾狐 帖子:459 积分:3471 威望:0 精华:0 注册:2011/6/6 11:22:00
  发帖心情 Post By:2019/6/26 9:40:00 [只看该作者]

Dim ids As String
Dim n As Integer = 30 '未来天数,含今天,所以实际是未来30天
For Each dr As Row In Tables("员工基础表").Rows
    
    Dim dt As Date = dr("出生日期")
    If dt.Month = 2 AndAlso dt.Day = 29
        dt = "#2/28/" & dr.Year &"#" ' 在这里处理一下日期,统一将闰年的29日都改为28日
    End If
    Dim dt1 As New Date(Date.Today.Year,dt.Month,dt.Day)
    Dim dt2 As  New Date(Date.Today.AddDays(n).Year,dt.Month,dt.Day)
    If (dt1 >= Date.Today AndAlso dt1 < Date.Today.AddDays(n)) OrElse (dt2 >= Date.Today AndAlso dt2 < Date.Today.AddDays(n)) Then
        ids = ids & "," & dr("_Identify")
    End If
Next
If ids > "" Then
    ids = ids.Trim(",")
    Tables("员工基础表").filter = "[_Identify] In (" & ids &")"
    MessageBox.show("近30天内过生日的员工有 " & Tables("员工基础表").Rows.Count & " 名!,请及时慰问.","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
Else
    MessageBox.show("近30天内没有过生日的员工!","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning)
End If
[此贴子已经被作者于2019/6/26 10:02:27编辑过]

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


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


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


加好友 发短信
等级:童狐 帖子:217 积分:1646 威望:0 精华:0 注册:2018/1/21 10:25:00
  发帖心情 Post By:2019/6/26 19:36:00 [只看该作者]

谢谢诸位!

 回到顶部