Dim cs() As String = {"开始日期","结束日期","间隔周期", "合同号"}
If array.IndexOf(cs, e.DataCol.name) > -1 Then
Dim flag As Boolean = True
For Each c As String In cs
If e.DataRow.Isnull(c) Then
DataTables("明细表").DeleteFor("合同号 = '" & e.DataRow("合同号") & "'")
flag = False
Exit For
End If
Next
If flag Then
DataTables("明细表").DeleteFor("合同号 = '" & e.DataRow("合同号") & "'")
Dim n As Integer = e.DataRow("间隔周期")
Dim sd As Date = e.DataRow("开始日期")
Dim ed As Date = e.DataRow("结束日期")
Dim y,m,d As Integer
DateYMD(sd, ed,y,m,d)
Dim ms As Integer = (y*12+m)/n
Dim d2 As Date
Dim i As Integer
For i = 1 To ms
Dim ndr = DataTables("明细表").addnew
ndr("合同号") = e.DataRow("合同号")
ndr("期数") = i
ndr("开始日期") = sd.AddMonths((i-1)*n)
d2 = sd.AddMonths(i*n).AddDays(-1)
ndr("到期日期") = d2
Next
If d2 < ed And d > 0 Then
Dim ndr = DataTables("明细表").addnew
ndr("合同号") = e.DataRow("合同号")
ndr("期数") = i
ndr("开始日期") = d2.AddDays(1)
ndr("到期日期") = ed
End If
End If
End If
[此贴子已经被作者于2017/9/11 22:46:57编辑过]