Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
为了动态汇总数据,使用Fill方法生成"设备折旧2"临时表,并想通过按钮代码进行运算。
生成临时表的按钮代码如下:
Dim dtb As New DataTableBuilder("设备折旧2")
dtb.AddDef("名称", Gettype(String), 16)
dtb.AddDef("产权单位", Gettype(String), 16)
dtb.Build()
DataTables("设备折旧2").Fill("Select * From {设备折旧}", "SCGL", False)
MainTable= Tables("设备折旧2")
下面这段代码,原来是放在"设备折旧"表的DataColChanged事件中的,现在想将其合并到上面的按钮代码中,应该如何修改,请各位老师指教,谢谢!!
'产权单位
Select Case e.DataCol.Name
Case "去向"
If e.DataRow.IsNull("去向") And e.DataRow.IsNull("产权单位") Then
e.DataRow("停用日期")=Nothing
Else
If e.DataRow.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)
e.DataRow("停用日期") = d
Dim dr As DataRow = DataTables("设备目录").Find("[设备编号] = '" & e.DataRow("设备编号") & "'")
If dr IsNot Nothing Then
dr("产权单位") = e.DataRow("产权单位")
End If
End If
End If
End Select
'折旧结束
Select Case e.DataCol.Name
Case "停用日期"
If e.DataRow.IsNull("停用日期") Then
e.DataRow("折旧结束") = Nothing
Else
Dim dt As Date = e.DataRow("停用日期")
e.DataRow("折旧结束") = new Date(dt.year,dt.month,Date.DaysInMonth(dt.year,dt.month))
End If
End Select
'折旧月数
Select Case e.DataCol.Name
Case "折旧开始","折旧结束"
If e.DataRow.IsNull("折旧开始") And e.DataRow.IsNull("折旧结束") Then
e.DataRow("折旧月数")=Nothing
Else
Dim d1 As Date = e.DataRow("折旧开始")
Dim d2 As Date = e.DataRow("折旧结束")
If d1>d2
e.DataRow("折旧月数") = 0
Else
e.DataRow("折旧月数") = (d2.year - d1.year) * 12 + (d2.month - d1.month) + 1
End If
End If
End Select
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
狐爸老师,请帮助:
这段代码修改后,黄色部分出错,应如何改?
'当月折旧
If nr.IsNull("折旧开始") And nr.IsNull("折旧结束") Then
nr("当月折旧")=Nothing
Else
Dim mydate As Date = Forms("设备管理").Controls("DateTimePicker1").Text
Dim y As Integer = mydate.Year
Dim m As Integer = mydate.Month
Dim a As Date = New Date(y,m,1) '月初
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim b As Date = New Date(y,m,Days) '月底
Dim c As Date = nr("折旧开始")
Dim d As Date = nr("折旧结束")
Dim f As Byte = DataTables("设备折旧").Compute("Sum(折旧月数)","[设备编号] = '" & e.NewValue & "'") '同设备编号的折旧月数合计
Dim g As Byte = nr("折旧年限")
If c > d OrElse b < c OrElse a > d OrElse f > g*12 Then
nr("当月折旧")= 0
Else
nr("当月折旧") = nr("月折旧费")
End If
End If
另外一段也请帮助看看,再次衷心感谢!!
'折旧累计
Dim tq,tq1,yf,js As Double
Dim ys,i As Integer
Select Case e.DataCol.Name
Case "设备编号"
Dim dr As DataRow = e.DataRow
If e.DataCol.Name = "设备编号" Then
tq = DataTables("设备折旧").Compute("Sum(折旧累计)","[设备编号] = '" & e.NewValue & "'and [启用日期] < #" & dr("启用日期") & "#") '此行同设备编号在启用日期以前发生的折旧累计
tq1 = tq
End If
ys = dr("折旧月数")
yf = dr("月折旧费")
js = dr("折旧基数")
For i = 0 To 100
If i = ys Then
Exit For
End If
If js - tq > yf Then
tq = tq + yf
Else
tq = tq + ( js - tq )
End If
Next
tq = tq - tq1
dr("折旧累计") = tq
' End If
End Select