Foxtable(狐表)用户栏目专家坐堂 → 再次求教关于时间分段的问题 我已经参考了文件,还是没有解决


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

主题:再次求教关于时间分段的问题 我已经参考了文件,还是没有解决

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


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

datacolchanged事件

 

Select Case e.DataCol.Name
    Case "日期起止"
        Dim str As String = e.DataRow("日期起止")
        Dim arr() As String = str.Split("-")
        Dim d As Date = CDate(arr(0).Replace(".","-"))
        e.DataRow("开始时间") = d
        d = CDate(arr(1).Replace(".","-"))
        e.DataRow("结束时间")=d
    Case "开始时间","结束时间"
        If e.DataRow.IsNull("开始时间") = False AndAlso e.DataRow.IsNull("结束时间") = False
            Dim dta As DataTable = e.DataTable
            Dim dr = e.DataRow
            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
        End If
End Select


 回到顶部