错误的位置为:
Days = Date.DaysInMonth(e.DataRow("年") ,e.DataRow("月"))
e.DataRow("日") = Days
如果,把第一个(这个FOR NEXT是新增的行)
for i as ......
next
代码,删除,也不会弹错 ;
msgbox(e.DataRow("月")) ,错的原因是:月 = 0 ;
想请教一下,问题是怎么出现的? 想不明白
S elect Case e.DataCol.Name
Case "科目名称","借方金额","贷方金额"
Dim dr As DataRow
'Dim dr1 As DataRow
Dim mr As DataRow = e.DataRow
Dim drs As List(of DataRow)
Dim drs1 As List(of String)
Dim jk As Integer
Dim ck As Integer
'dr1 = e.DataTable.Find("[月] > " & mr("月") & " And [科目名称] = '" & mr("科目名称") & "'", "[月] Desc")
'If dr1 Is Nothing Then
dr = e.DataTable.Find("[月] < " & mr("月") & " And [科目名称] = '" & mr("科目名称") & "'", "[月] Desc")
'msgbox(11)
If dr Is Nothing Then '如果是第一行,计算结存
'msgbox(12)
drs1 = e.DataTable.GetValues("月","[年] = " & mr("年") & " and 月 > " & mr("月") & " ")
'msgbox(drs1.Count )
For i1 As Integer = 1 To drs1.Count
If mr("月")+i1 <=12 Then
Dim dr1 As DataRow= Tables(e.form.Name & "_Table1").DataTable.Find("[年] = " & mr("年") & " and [月] = " & mr("月")+i1 & " And [科目名称] = '" & mr("科目名称") & "'")
'msgbox(1)
If dr1 Is Nothing Then
Dim r1 As Row = Tables(e.form.Name & "_Table1").AddNew()
'msgbox(2)
r1("科目代码") = mr("科目代码")
r1("科目名称") = mr("科目名称")
r1("年") = mr("年")
r1("月") = mr("月")+i1
'Else
''msgbox(mr("月")+i1)
'Return
End If
End If
Next
jk = Tables(e.form.Name & "_Table1").DataTable.Compute("Sum(借方金额)","[月] < " & mr("月") & " And 科目名称 = '" & mr("科目名称") & "'")
ck = Tables(e.form.Name & "_Table1").DataTable.Compute("Sum(贷方金额)","[月] < " & mr("月") & " And 科目名称 = '" & mr("科目名称") & "'")
mr("余额") = e.DataRow("借方金额") - e.DataRow("贷方金额") + jk - ck
dr = mr
End If
drs = e.DataTable.Select("[月] >= " & dr("月") & " And [科目名称] = '" & dr("科目名称") & "'", "[月]")
For i As Integer = 1 To drs.Count - 1
drs(i)("余额") = drs(i-1)("余额") + drs(i)("借方金额") - drs(i)("贷方金额")
Next
If e.DataCol.Name = "科目名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then '如果修改的是科目名称列
dr = e.DataTable.Find("[月] < " & mr("月") & " And [科目名称] = '" & e.OldValue & "'", "[月] Desc") '找出旧科目名称的上一行
If dr Is Nothing Then '如果不存在上一行,那么本行就是旧科目名称的第一行,由于已经被修改为新科目名称,需要找出旧科目名称现在的第一行
dr = e.DataTable.Find("[科目名称] = '" & e.OldValue & "'", "[月]") '找出旧科目名称现在的第一行
If dr IsNot Nothing Then '如果找到,计算余额
jk = Tables(e.form.Name & "_Table1").DataTable.Compute("Sum(借方金额)","[月] < " & mr("月") & " And 科目名称 = '" & e.OldValue & "'")
ck = Tables(e.form.Name & "_Table1").DataTable.Compute("Sum(贷方金额)","[月] < " & mr("月") & " And 科目名称 = '" & e.OldValue & "'")
dr("余额") = dr("借方金额") - dr("贷方金额") + jk - ck
End If
End If
If dr IsNot Nothing Then
drs = e.DataTable.Select("[月] >= " & dr("月") & " And [科目名称] = '" & dr("科目名称") & "'", "[月]")
For i As Integer = 1 To drs.Count - 1
drs(i)("余额") = drs(i-1)("余额") + drs(i)("借方金额") - drs(i)("贷方金额")
Next
End If
End If
Case "余额"
If e.DataRow("余额") >= 0 Then
e.DataRow("借或贷") = "借"
Else
e.DataRow("借或贷") = "贷"
End If
'
'Case "借方金额"
e.DataRow("凭证ID") = "汇 -" & " " & e.DataRow("月") & " "
If e.DataRow("摘要") <> "本年合计" Then
' e.DataRow("摘要") = "据" & " " & e.DataRow("月") & " " & "月记账凭证汇总"
e.DataRow("摘要") = " 本 期 合 计"
End If
'msgbox(7)
Dim Days As Integer
msgbox(e.DataRow("月"))
Days = Date.DaysInMonth(e.DataRow("年") ,e.DataRow("月"))
e.DataRow("日") = Days
e.DataRow("会计期间") = e.DataRow("年") & Format(e.DataRow("月"),"00")
End Select
[此贴子已经被作者于2017/10/12 14:51:59编辑过]