Tables("BBQ车间工资表").filter = ""
Tables("BBQ车间工资表").Sort = "姓名,生产形式"
Tables("BBQ车间工资表").Filter = "姓名 is Not null"
Dim d As Date
If Date.TryParse(e.sender.text, d) Then
Dim g As New CrossTableBuilder("统计表1", DataTables("BBQ车间工资表"))
g.HGroups.AddDef("姓名")
g.VGroups.AddDef("日期", DateGroupEnum.None)
g.Totals.AddDef("上班工时", "上班工时")
d = New Date(d.year, d.month, 1)
g.Filter = "日期 >= #" & d & "# and 日期 < #" & d.AddMonths(1) & "#"
Dim t As Table = e.Form.controls("table1").Table
g.Filter = Tables("BBQ车间工资表").Filter
t.StopRedraw
t.datasource = g.BuildDataSource
t.DataTable.DataCols.add("数据", Gettype(String))
t.DataTable.ReplaceFor("数据", "工时")
g = New CrossTableBuilder("统计表1", DataTables("BBQ车间工资表"))
g.HGroups.AddDef("姓名")
g.VGroups.AddDef("日期", DateGroupEnum.None)
g.Totals.AddDef("总金额", "总金额")
g.Filter = "日期 >= #" & d & "# and 日期 < #" & d.AddMonths(1) & "#"
g.Filter = Tables("BBQ车间工资表").Filter
g.Build
For Each r As Row In Tables("统计表1").Rows
Dim nr As Row = t.AddNew
For i As Integer = 0 To t.Cols.count - 2
nr(i) = r(i)
Next
nr("数据") = "金额"
Next
t.DataTable.DataCols.add("小计", Gettype(Double))
For Each r As Row In t.Rows
Dim sum As Double = 0
For i As Integer = 1 To t.Cols.count - 3
sum += r(i)
Next
r("小计") = sum
Next
t.Cols("数据").Move(1)
t.sort = "姓名,数据"
t.DataTable.DataCols.Add("_Sortkey", Gettype(Double))
For Each r As Row In t.Rows
r("_Sortkey") = r.Index
Next
t.sort = ""
Dim r1 As Row = t.AddNew
Dim r2 As Row = t.AddNew
r1("姓名") = "工时汇总"
r1("_Sortkey") = t.Rows.count
r2("姓名") = "金额汇总"
r2("_Sortkey") = t.Rows.count + 1
For i As Integer = 0 To t.Cols.count - 1
If t.Cols(i).IsNumeric Then
r1(i) = t.Compute("sum(" & t.Cols(i).name & ")", "数据 = '工时'")
r2(i) = t.Compute("sum(" & t.Cols(i).name & ")", "数据 = '金额'")
End If
Next
t.ResumeRedraw
End If