Foxtable(狐表)用户栏目专家坐堂 → [求助]日期时间比较


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

主题:[求助]日期时间比较

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/12/10 14:51:00 [显示全部帖子]

Dim d As Date = Date.Today
Dim dn As Integer = d.DayOfWeek
Dim sd As Date
If dn=6 Then
    sd=d
Else
    sd=d.AddDays(-dn-1)
End If
Dim sd2 As Date = sd.AddHours(6).AddMinutes(5)
dr("周六_早上_出勤") = Tables("欢迎").Compute("Count(VipLog_DateTime)","SN = '" & Vals(i)(0) & "'and VipLog_DateTime >= #" & sd & "# and VipLog_DateTime <= #" & sd2 & "#")    

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/12/10 17:10:00 [显示全部帖子]

1、你的列名定义规律一些,比如定义成 日1_1_1, 日1_1_2, 日1_2_1,表示:星期1_早上1_出勤1

 

     这样命名,可以减少编码量。

 

2、具体问题上传实例说明,说明具体逻辑。


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/12/10 23:02:00 [显示全部帖子]

 

Dim d As Date = Date.Today
Dim dn As Integer = d.DayOfWeek
Dim sd As Date
If dn=6 Then
    sd=d
Else
    sd=d.AddDays(-dn-1)
End If
Dim v1() As String = {"周六_早上_出勤","周六_早上_迟到","周六_早上_旷工","周六_早上_早退","周六_下午_出勤","周六_下午_迟到","周六_下午_旷工","周六_下午_早退","周六_晚上加班","周日_早上_出勤","周日_早上_迟到","周日_早上_旷工","周日_早上_早退","周日_下午_出勤","周日_下午_迟到","周日_下午_旷工","周日_下午_早退","周日_晚上加班","周一_早上_出勤","周一_早上_迟到","周一_早上_旷工","周一_早上_早退","周一_下午_出勤","周一_下午_迟到","周一_下午_旷工","周一_下午_早退","周一_晚上加班","周二_早上_出勤","周二_早上_迟到","周二_早上_旷工","周二_早上_早退","周二_下午_出勤","周二_下午_迟到","周二_下午_旷工","周二_下午_早退","周二_晚上加班","周三_早上_出勤","周三_早上_迟到","周三_早上_旷工","周三_早上_早退","周三_下午_出勤","周三_下午_迟到","周三_下午_旷工","周三_下午_早退","周三_晚上加班","周四_早上_出勤","周四_早上_迟到","周四_早上_旷工","周四_早上_早退","周四_下午_出勤","周四_下午_迟到","周四_下午_旷工","周四_下午_早退","周四_晚上加班","周五_早上_出勤","周五_早上_迟到","周五_早上_旷工","周五_早上_早退","周五_下午_出勤","周五_下午_迟到","周五_下午_旷工","周五_下午_早退","周五_晚上加班"}
Dim v2(v1.length-1) As Integer
For j As Integer = 0 To v2.length-1
    v2(j) = 0
Next
Dim dtb As New DataTableBuilder("统计测试")
dtb.adddef("卡号",Gettype(Integer),6)
dtb.AddDef("姓名", Gettype(String), 100)
dtb.AddDef("公司", Gettype(String), 64)
dtb.AddDef("岗位", Gettype(String), 64)
dtb.AddDef("应出勤", Gettype(Integer), 6)
For Each prd As String In v1
    dtb.AddDef(prd, Gettype(Double))
Next
dtb.Build()
Dim pr As DataRow = Nothing
DataTables("统计测试").StopRedraw
Dim drs = DataTables("欢迎").Select("", "SN,Chinese_Name,Company,VipLog_DateTime")
For i As Integer = 0 To drs.count
    Dim dr As DataRow = Nothing
    If i < drs.count Then
        dr = drs(i)
    End If
    If i = drs.count OrElse pr IsNot Nothing AndAlso (dr("sn") <> pr("sn") OrElse dr("Chinese_Name") <> pr("Chinese_Name") OrElse dr("Company") <> pr("Company")) Then
        Dim ndr As DataRow = DataTables("统计测试").AddNew()
        ndr("卡号") = pr("SN")
        ndr("姓名") = pr("Chinese_Name")
        ndr("公司") = pr("Company")
        ndr("岗位") = pr("Position")
        ndr("应出勤") = 1
        For n As Integer = 0 To dn+1
            ndr(v1(n*9)) = v2(n*9)
            ndr(v1(n*9+1)) = v2(n*9+1)
            ndr(v1(n*9+2)) = ndr("应出勤")-ndr(v1(n*9)) - ndr(v1(n*9+1))
            ndr(v1(n*9+3)) = v2(n*9+3)
            ndr(v1(n*9+4)) = v2(n*9+4)
            ndr(v1(n*9+5)) = v2(n*9+5)
            ndr(v1(n*9+6)) = ndr("应出勤")-ndr(v1(n*9+4)) - ndr(v1(n*9+5))
            ndr(v1(n*9+7)) = v2(n*9+7)
            ndr(v1(n*9+8)) = v2(n*9+8)
        Next
        For j As Integer = 0 To v2.length-1
            v2(j) = 0
        Next
        If i = drs.count Then
            Exit For
        End If
    End If
    Dim dtime As Date = dr("VipLog_DateTime")
    For n As Integer = 0 To dn+1
        Dim t1 As Date = sd.AddDays(n)
        Dim t2 As Date = sd.AddDays(n).AddHours(6).AddMinutes(5)
        Dim t3 As Date = sd.AddDays(n).AddHours(11)
        Dim t4 As Date = sd.AddDays(n).AddHours(11).AddMinutes(30)
        Dim t5 As Date = sd.AddDays(n).AddHours(12).AddMinutes(10)
        Dim t6 As Date = sd.AddDays(n).AddHours(13).AddMinutes(05)
        Dim t7 As Date = sd.AddDays(n).AddHours(17)
        Dim t8 As Date = sd.AddDays(n).AddHours(17).AddMinutes(30)
        Dim t9 As Date = sd.AddDays(n).AddHours(20)
        Dim t10 As Date = sd.AddDays(n).AddHours(23).AddMinutes(59)
        If dtime >= t1 AndAlso dtime <= t2 Then
            v2(n*9) += 1
            Exit For
        ElseIf dtime > t2 AndAlso dtime <= t3 Then
            v2(n*9+1) += 1
            Exit For
        ElseIf dtime > t3 AndAlso dtime <= t4 Then
            v2(n*9+3) += 1
            Exit For
        ElseIf dtime > t5 AndAlso dtime <= t6 Then
            v2(n*9+4) += 1
            Exit For
        ElseIf dtime > t6 AndAlso dtime <= t7 Then
            v2(n*9+5) += 1
            Exit For
        ElseIf dtime > t7 AndAlso dtime <= t8 Then
            v2(n*9+7) += 1
            Exit For
        ElseIf dtime > t9 AndAlso dtime <= t10 Then
            v2(n*9+8) += 1
            Exit For
        End If
    Next
    pr = dr
Next
MainTable= Tables("统计测试")
Dim t As Table = Tables("统计测试")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = True
t.TreeVisible = True
t.SpillNode = True

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "岗位"
g.TotalOn = "应出勤,周六_早上_出勤,周六_早上_迟到,周六_早上_旷工,周六_早上_早退,周六_下午_出勤,周六_下午_迟到,周六_下午_旷工,周六_下午_早退,周六_晚上加班,周日_早上_出勤,周日_早上_迟到,周日_早上_旷工,周日_早上_早退,周日_下午_出勤,周日_下午_迟到,周日_下午_旷工,周日_下午_早退,周日_晚上加班,周一_早上_出勤,周一_早上_迟到,周一_早上_旷工,周一_早上_早退,周一_下午_出勤,周一_下午_迟到,周一_下午_旷工,周一_下午_早退,周一_晚上加班,周二_早上_出勤,周二_早上_迟到,周二_早上_旷工,周二_早上_早退,周二_下午_出勤,周二_下午_迟到,周二_下午_旷工,周二_下午_早退,周二_晚上加班,周三_早上_出勤,周三_早上_迟到,周三_早上_旷工,周三_早上_早退,周三_下午_出勤,周三_下午_迟到,周三_下午_旷工,周三_下午_早退,周三_晚上加班,周四_早上_出勤,周四_早上_迟到,周四_早上_旷工,周四_早上_早退,周四_下午_出勤,周四_下午_迟到,周四_下午_旷工,周四_下午_早退,周四_晚上加班,周五_早上_出勤,周五_早上_迟到,周五_早上_旷工,周五_早上_早退,周五_下午_出勤,周五_下午_迟到,周五_下午_旷工,周五_下午_早退,周五_晚上加班"
g.Caption = "{0} 小计"
t.SubtotalGroups.Add(g)

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "公司"
g.TotalOn = "应出勤,周六_早上_出勤,周六_早上_迟到,周六_早上_旷工,周六_早上_早退,周六_下午_出勤,周六_下午_迟到,周六_下午_旷工,周六_下午_早退,周六_晚上加班,周日_早上_出勤,周日_早上_迟到,周日_早上_旷工,周日_早上_早退,周日_下午_出勤,周日_下午_迟到,周日_下午_旷工,周日_下午_早退,周日_晚上加班,周一_早上_出勤,周一_早上_迟到,周一_早上_旷工,周一_早上_早退,周一_下午_出勤,周一_下午_迟到,周一_下午_旷工,周一_下午_早退,周一_晚上加班,周二_早上_出勤,周二_早上_迟到,周二_早上_旷工,周二_早上_早退,周二_下午_出勤,周二_下午_迟到,周二_下午_旷工,周二_下午_早退,周二_晚上加班,周三_早上_出勤,周三_早上_迟到,周三_早上_旷工,周三_早上_早退,周三_下午_出勤,周三_下午_迟到,周三_下午_旷工,周三_下午_早退,周三_晚上加班,周四_早上_出勤,周四_早上_迟到,周四_早上_旷工,周四_早上_早退,周四_下午_出勤,周四_下午_迟到,周四_下午_旷工,周四_下午_早退,周四_晚上加班,周五_早上_出勤,周五_早上_迟到,周五_早上_旷工,周五_早上_早退,周五_下午_出勤,周五_下午_迟到,周五_下午_旷工,周五_下午_早退,周五_晚上加班"
g.Caption = "{0} 小计"
t.SubtotalGroups.Add(g)

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Sum
g.GroupOn = "*"
g.TotalOn = "应出勤,周六_早上_出勤,周六_早上_迟到,周六_早上_旷工,周六_早上_早退,周六_下午_出勤,周六_下午_迟到,周六_下午_旷工,周六_下午_早退,周六_晚上加班,周日_早上_出勤,周日_早上_迟到,周日_早上_旷工,周日_早上_早退,周日_下午_出勤,周日_下午_迟到,周日_下午_旷工,周日_下午_早退,周日_晚上加班,周一_早上_出勤,周一_早上_迟到,周一_早上_旷工,周一_早上_早退,周一_下午_出勤,周一_下午_迟到,周一_下午_旷工,周一_下午_早退,周一_晚上加班,周二_早上_出勤,周二_早上_迟到,周二_早上_旷工,周二_早上_早退,周二_下午_出勤,周二_下午_迟到,周二_下午_旷工,周二_下午_早退,周二_晚上加班,周三_早上_出勤,周三_早上_迟到,周三_早上_旷工,周三_早上_早退,周三_下午_出勤,周三_下午_迟到,周三_下午_旷工,周三_下午_早退,周三_晚上加班,周四_早上_出勤,周四_早上_迟到,周四_早上_旷工,周四_早上_早退,周四_下午_出勤,周四_下午_迟到,周四_下午_旷工,周四_下午_早退,周四_晚上加班,周五_早上_出勤,周五_早上_迟到,周五_早上_旷工,周五_早上_早退,周五_下午_出勤,周五_下午_迟到,周五_下午_旷工,周五_下午_早退,周五_晚上加班"
g.Caption = "总计"
t.SubtotalGroups.Add(g)

t.Subtotal()
DataTables("统计测试").ResumeRedraw


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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2017/12/11 14:38:00 [显示全部帖子]

代码不用改,设置一下下面

 


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

 回到顶部