Select Case e.DataCol.Name
Case "开始时间","结束时间"
Dim dr As DataRow = e.DataRow
If dr.IsNull("结束时间") = False AndAlso dr.IsNull("开始时间") = False AndAlso dr("开始时间") <= dr("结束时间") Then
Dim d As Date = dr("开始时间")
Dim nr As Row
Dim qd As String = Format(dr("签署日期"),"yyyyMM")
Dim amount As Integer = dr("金额")
If Format(d,"yyyyMM") = Format(dr("结束时间"),"yyyyMM") Then
nr = Tables("项目.收益").AddNew()
nr("分期时间") = Format(d,"yyyyMM")
nr("分期金额") = dr("金额")
nr("确认时间") = qd
Else
Dim sum As Integer = 0
nr = Tables("项目.收益").AddNew()
nr("分期时间") = Format(d,"yyyyMM")
sum = (Date.DaysInMonth(d.Year,d.Month) - d.Day + 1)*100
nr("分期金额") = math.Min(sum,amount)
nr("确认时间") = qd
If sum >= amount Then Return
d = new Date(d.Year,d.Month,1).AddMonths(2).AddDays(-1)
Do While d < dr("结束时间")
nr = Tables("项目.收益").AddNew()
nr("分期时间") = Format(d,"yyyyMM")
nr("确认时间") = qd
Dim fqje As Integer = Date.DaysInMonth(d.Year,d.Month)*100
If fqje + sum > amount Then
nr("分期金额") = amount - sum
Return
End If
nr("分期金额") = fqje
sum += fqje
d = d.AddMonths(1)
Loop
If sum < amount Then
d = dr("结束时间")
nr = Tables("项目.收益").AddNew()
nr("分期时间") = Format(d,"yyyyMM")
nr("分期金额") = amount - sum
nr("确认时间") = qd
End If
End If
End If
End Select