1.原来 我是用窗口的SQLQuery表,用(窗口,的AfterLoad代码);然后,SQLQuery表里面也有;DataColChanged等代码;最后,再通过一个;保存,按钮;保存到:总分类账,表;
2.现在的想法是:想通过一个按钮:凭证过账,,来实现 1.里面的功能;(请教,老师,怎么实现 好些?)
3.目前是:把SQLQuery表改成:Tables("过渡表") ,但是,在msgbox(0) 时,弹说,没有:科目名称,列;
Tables("过渡表").DataTable.datarows.clear
'生成查询表
Dim dtb As New SQLJoinTableBuilder("应收工程款明细表1","凭证明细")
dtb.C
'dtb.AddTable("施工合同","合同编号","凭证明细","合同编号")
dtb.AddExp("年","Year(日期)",False)
dtb.AddExp("月","日期")
dtb.AddExp("科目代码","Case When len(科目代码) =4 Then 科目代码 Else SubString(科目代码,1,4) End")
dtb.AddExp("科目名称","会计科目_一级科目")
dtb.AddCols("借方金额","贷方金额")
'生成统计表
Dim b As New GroupTableBuilder("统计表1",dtb.BuildSql,"服务器" )
b.Groups.AddDef("科目代码") '根据产品分组
b.Groups.AddDef("科目名称") '根据产品分组
b.Groups.AddDef("年")
b.Groups.AddDef("月") '对数量进行统计
b.Totals.AddDef("借方金额") '对数量进行统计
b.Totals.AddDef("贷方金额") '对数量进行统计
b.Subtotal = True '生成汇总模式
b.SubtotalLevel = 0
Tables("过渡表").DataSource = b.BuildDataSource() '打开生成的统计表
If Tables("过渡表").DataTable.DataCols.Contains("凭证ID")=False Then
Tables("过渡表").DataTable.DataCols.Add("凭证ID", Gettype(String))
Tables("过渡表").DataTable.DataCols.Add("摘要", Gettype(String))
Tables("过渡表").DataTable.DataCols.Add("借或贷", Gettype(String))
Tables("过渡表").DataTable.DataCols.Add("余额", Gettype(Double))
Tables("过渡表").DataTable.DataCols.Add("日", Gettype(Integer))
Tables("过渡表").DataTable.DataCols.Add("会计期间", Gettype(Integer))
End If
msgbox(0)
Dim drs As New List(of DataRow)
For Each nm As String In Tables("过渡表").DataTable.GetValues("科目名称") '找出每个科目名称的第一行数据, 添加到集合drs中
drs.Add(Tables("过渡表").DataTable.Find("科目名称 = '" & nm & "'"))
Next
For Each r As DataRow In drs
Tables("过渡表").DataTable.DataCols("借方金额").RaiseDataColChanged(r)
Next
保存,按钮,代码如下:
Tables("总分类账").DataTable.DataRows.Clear
For i As Integer = 0 To Tables(e.form.Name & "_Table1").Rows.Count-1
Dim r As Row = Tables("总分类账").AddNew()
Dim strs As String() = {"科目代码","科目名称","年","月","日","凭证ID","摘要","借方金额","贷方金额","借或贷","余额","会计期间"}
For Each str As String In strs '以上是同一发包人的合计用的标记
r(str) = Tables(e.form.Name & "_Table1").Rows(i)(str)
Next
Next
'msgbox(0)
Tables("总分类账").save
Dim Cols1() As String = {"年","科目名称","科目代码","借或贷","余额"}
Dim Cols2() As String = {"年","科目名称","科目代码","借或贷","余额"}
'For Each dr1 As DataRow In DataTables("总分类账").Select("[金额] > 100")
For Each dr1 As DataRow In DataTables("总分类账").DataRows
If dr1.RowState <> DataRowState.Added Then
Dim dr2 As DataRow = DataTables("总分类账").AddNew()
For i As Integer = 0 To Cols1.Length -1
dr2(Cols2(i)) = dr1(Cols1(i))
dr2("月") = CInt(dr1("月"))+1
dr2("日") = 01
dr2("会计期间") = dr2("年") & Format(dr2("月"),"00")
dr2("摘要") = " 期 初 余 额"
Next
End If
Next
Dim Cols5() As String = {"年","月","日","科目名称","科目代码","借或贷","余额"}
Dim Cols6() As String = {"年","月","日","科目名称","科目代码","借或贷","余额"}
'For Each dr1 As DataRow In DataTables("总分类账").Select("[金额] > 100")
For Each dr1 As DataRow In DataTables("总分类账").DataRows
If dr1.RowState <> DataRowState.Added Then
Dim dr2 As DataRow = DataTables("总分类账").AddNew()
For i As Integer = 0 To Cols5.Length -1
dr2(Cols6(i)) = dr1(Cols5(i))
dr2("摘要") = " 本 年 累 计"
dr2("会计期间") = dr2("年") & Format(dr2("月"),"00")
dr2("借方金额") = DataTables("总分类账").Compute("Sum(借方金额)","[年] = '" & dr2("年") & "' and 月 <= '" & dr2("月") & "' and 科目代码 = '" & dr2("科目代码") & "' and 凭证ID is not null ")
dr2("贷方金额") = DataTables("总分类账").Compute("Sum(贷方金额)","[年] = '" & dr2("年") & "' and 月 <= '" & dr2("月") & "' and 科目代码 = '" & dr2("科目代码") & "' and 凭证ID is not null ")
'dr2("余额") = DataTables("总分类账").Compute("Sum(余额)","[年] = '" & dr2("年") & "' and 月 <= '" & dr2("月") & "' and 科目代码 = '" & dr2("科目代码") & "' and 凭证ID is not null ")
Next
End If
Next
Tables("总分类账").Sort = "科目代码,年,月,摘要 desc"
Tables("总分类账").save