Foxtable(狐表)用户栏目专家坐堂 → 关于分段时间


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

主题:关于分段时间

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/2 9:48:00 [显示全部帖子]

参考下面的代码改一下

 

Dim dta As DataTable = DataTables("表A")
For Each dr As DataRow In dta.Select("开始时间 is not null and 结束时间 is not null")
    For Each dc As DataCol In dta.DataCols
        If dc.Name.StartsWith("A") OrElse dc.Name.StartsWith("B") Then
            dr(dc.name) = Nothing
        End If
    Next
    Dim tempd1 As Date
    Dim tempd2 As Date
    Dim d_start As Date = dr("开始时间")
    Dim d_end As Date = dr("结束时间")
    Dim d_m1 As Date = new Date(d_start.Year, 6, 30)
    Dim d_e1 As Date = new Date(d_start.Year, 12, 31)
    Dim idx As Integer = 0
    If d_start <= d_m1 Then
        tempd1 = d_start
        If d_end <= d_m1 Then
            tempd2 = d_end
        Else
            tempd2 = d_m1
            idx = 1
        End If
    Else
        tempd1 = d_start
        If d_end <= d_e1
            tempd2 = d_end
        Else
            tempd2 = d_e1
            idx = 2
        End If
    End If
    Dim sp As TimeSpan = tempd2 - tempd1
    If tempd2 > new Date(tempd2.Year, 6, 30) Then
        dr("B" & tempd2.Year) = sp.TotalDays
    Else
        dr("A" & tempd2.Year) = sp.TotalDays
    End If
    If idx > 0 Then
        Dim d As Date = tempd2
        Do While d < d_end
            tempd1 = d.AddDays(1)
            Dim d2 As Date = iif(idx Mod 2 = 0, d.AddMonths(6), d.AddMonths(6).AddDays(1))
            If d2 >= d_end Then
                tempd2 = d_end
            Else
                tempd2 = d2
            End If
            sp = tempd2 - tempd1
            If tempd2 > new Date(tempd2.Year, 6, 30) Then
                dr("B" & tempd2.Year) = sp.TotalDays
            Else
                dr("A" & tempd2.Year) = sp.TotalDays
            End If
            idx += 1
            d = d2
        Loop
    End If
Next

[此贴子已经被作者于2016/12/2 11:39:04编辑过]

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


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2016/12/2 11:26:00 [显示全部帖子]

 单独做个按钮,执行5楼的代码,而不是放在DataColChanged事件里。

 回到顶部