原来运行正常,软件升级后出错,请各位老师指教,谢谢!
此主题相关图片如下:f.png
DataColChanged事件代码如下:
'跨表引用(表关联)
Select Case e.DataCol.Name
Case = "设备编号"
Dim nms() As String = {"设备名称","名称","折旧基数","折旧年限"}
If e.NewValue Is Nothing Then
For Each nm As String In nms
e.DataRow(nm) = Nothing
Next
Else
Dim dr As DataRow = DataTables("设备目录").Find("[设备编号] = '" & e.NewValue & "'")
If dr IsNot Nothing
For Each nm As String In nms
e.DataRow(nm) = dr(nm)
Next
End If
End If
End Select
'使用单位(跨表引用)
Select Case e.DataCol.Name
Case "去向"
If e.DataRow.IsNull("去向") And e.DataRow.IsNull("使用单位") Then
e.DataRow("归还日期")=Nothing
Else
Dim dr As DataRow = DataTables("设备目录").Find("[设备编号] = '" & e.DataRow("设备编号") & "'")
If e.DataRow.IsNull("去向") Then
Dim mydate As Date = Date.Today()
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)
e.DataRow("归还日期") = d
If dr IsNot Nothing Then
dr("使用单位") = e.DataRow("使用单位")
Else
dr("使用单位") = e.DataRow("产权单位")
End If
End If
End If
End Select
'日历天数(工作日废除)
Select Case e.DataCol.Name
Case "借用日期","归还日期"
If e.DataRow.IsNull("借用日期") And e.DataRow.IsNull("归还日期") Then
e.DataRow("日历天数")=Nothing
Else
Dim mydate As Date = Date.Today()
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)
Dim d1 As Date = e.DataRow("借用日期")
Dim d2 As Date = e.DataRow("归还日期")
If d1 > d2 OrElse d1 > d
e.DataRow("日历天数") = 0
Else
Dim cnt As Integer
If d2 > d
cnt = (d-d1).TotalDays
Else
cnt = (d2-d1).TotalDays
End If
e.DataRow("日历天数") = cnt
End If
End If
End Select
'日租金
Select Case e.DataCol.Name
Case "折旧基数","折旧年限"
Dim dr As DataRow = e.DataRow
If dr.IsNull("折旧基数") OrElse dr.IsNull("折旧年限") Then
dr("日租金") = Nothing
Else
dr("日租金") = dr("折旧基数") / (dr("折旧年限")*365)*1.5
End If
End Select
'租金累计
Select Case e.DataCol.Name
Case "日租金","日历天数"
Dim dr As DataRow = e.DataRow
If dr.IsNull("日租金") OrElse dr.IsNull("日历天数") Then
dr("租金累计") = Nothing
Else
dr("租金累计") =IIF(dr("使用单位")= "仓库",0,IIF(dr("产权单位") = dr("使用单位"),0,dr("日租金") * dr("日历天数")))
End If
End Select
'产权单位(跨表引用)
Select Case e.DataCol.Name
Case "设备编号","借用日期","归还日期"
Dim dr As DataRow = e.DataRow
Dim pr As DataRow
If dr.IsNull("设备编号") OrElse dr.IsNull("借用日期") OrElse dr.IsNull("归还日期") Then
dr("产权单位") = Nothing
Else
Dim filter As String
filter = "设备编号 = '" & dr("设备编号") & "' And 启用日期 <= '" & dr("借用日期") & "' And 停用日期 >= '" & dr("归还日期") & "'"
pr = DataTables("设备折旧").Find(filter)
If pr IsNot Nothing Then
dr("产权单位") = pr("产权单位")
End If
End If
End Select
'当月租金
Select Case e.DataCol.Name
Case "借用日期","归还日期"
If e.DataRow.IsNull("借用日期") And e.DataRow.IsNull("归还日期") Then
e.DataRow("当月租金")=Nothing
Else
Dim mydate As Date = Date.Today()
Dim y As Integer = mydate.Year
Dim m As Integer = mydate.Month
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim c As Date = (New Date(y,m,1)).adddays(-1)
Dim d As Date = New Date(y,m,Days)
Dim a As Date = e.DataRow("借用日期")
Dim b As Date = e.DataRow("归还日期")
Dim cnt As Integer '日历天数
If b<c OrElse a>d
cnt = 0
Else If a<c AndAlso b>=d
cnt = (d-c).TotalDays
Else If a>c AndAlso b>d
cnt = (d-a).TotalDays
Else If a<c AndAlso b<d
cnt = (b-c).TotalDays
Else cnt = (b-a).TotalDays
End If
Dim dr As DataRow = e.DataRow
e.DataRow("当月租金") = IIF(dr("使用单位")= "仓库",0,IIF(dr("产权单位") = dr("使用单位"),0,dr("日租金") * cnt))
End If
End Select
[此贴子已经被作者于2012-3-16 8:19:00编辑过]