Foxtable(狐表)用户栏目专家坐堂 → 碰到一个离奇的问题,关于生日提醒(已解决)


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

主题:碰到一个离奇的问题,关于生日提醒(已解决)

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


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/1/5 15:47:00 [显示全部帖子]

 生日提醒通用代码。

Dim ids As String
Dim n As Integer = 9 '未来天数,含今天

Dim eDate As Date = Date.Today.AddDays(n)
For Each dr As DataRow In DataTables("员工").Select("姓名 is not null")
    Dim month As Integer = dr("生日").Month
    Dim day As Integer = dr("生日").Day
    Dim sDate As Date = new Date(Date.Today.Year, month, day)
    Dim days As TimeSpan = eDate - sDate
    If days.TotalDays >= 0 AndAlso days.TotalDays <= n OrElse days.TotalDays > 365 Then
        ids = ids & "," & dr("_Identify")   '记录生日的行号
    End If
Next

If ids > "" Then
    ids = ids.Trim(",")
    messagebox.show("未来"& n &"天内是" & ids & "的生日,给他们送去祝福吧.","生日提醒")
    Tables("窗口1_table1").filter = "[_Identify] In (" & ids &")"
End If

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


加好友 发短信
等级:狐神 帖子:6708 积分:34304 威望:0 精华:11 注册:2012/8/18 23:10:00
  发帖心情 Post By:2013/1/6 9:42:00 [显示全部帖子]

 代码这样写。忘记判断闰年2月29号的情况了。

Dim ids As String
Dim n As Integer = 9 '未来天数,含今天

Dim eDate As Date = Date.Today.AddDays(n)
For Each dr As DataRow In DataTables("基本信息").Select("出生日期 is not null")
    Dim month As Integer = dr("出生日期").Month
    Dim day As Integer = dr("出生日期").Day 
    If month = 2 AndAlso day = 29 Then
        If Date.IsLeapYear(Date.Today.Year) = False Then day = 28
    End If
    Dim sDate As Date = new Date(Date.Today.Year, month, day)
    Dim days As TimeSpan = eDate - sDate
    If days.TotalDays >= 0 AndAlso days.TotalDays <= n OrElse days.TotalDays > 365 Then
        ids = ids & "," & dr("_Identify")   '记录生日的行号
    End If
Next
If ids > "" Then
    ids = ids.Trim(",")
    messagebox.show("未来"& n &"天内是" & ids & "的生日,给他们送去祝福吧.","生日提醒")
    Tables("基本信息").filter = "[_Identify] In (" & ids &")"
End If

 回到顶部