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