For Each nr As DataRow In DataTables("设备折旧2").DataRows
If nr.IsNull("去向") And nr.IsNull("产权单位") Then
nr("停用日期")=Nothing
Else
If nr.IsNull("去向") Then
Dim mydate As Date = Forms("设备管理").Controls("DateTimePicker1").Text
Dim y As Integer = mydate.Year
Dim m As Integer = mydate.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim d As Date = New Date(y,m,Days)
nr("停用日期") = d
Dim dr As DataRow = DataTables("设备目录").Find("[设备编号] = '" & nr("设备编号") & "'")
If dr IsNot Nothing Then
dr("产权单位") = nr("产权单位")
End If
End If
End If
If nr.IsNull("停用日期") Then
nr("折旧结束") = Nothing
Else
Dim dt As Date = nr("停用日期")
nr("折旧结束") = new Date(dt.year,dt.month,Date.DaysInMonth(dt.year,dt.month))
End If
If nr.IsNull("折旧开始") And nr.IsNull("折旧结束") Then
nr("折旧月数")=Nothing
Else
Dim d1 As Date = nr("折旧开始")
Dim d2 As Date = nr("折旧结束")
If d1>d2
nr("折旧月数") = 0
Else
nr("折旧月数") = (d2.year - d1.year) * 12 + (d2.month - d1.month) + 1
End If
End If
Next