Dim bd1 As New CrossTableBuilder("统计表1",DataTables("进货单"))
Dim dt1 As fxDataSource
bd1.HGroups.AddDef("型号") '根据型号分组
bd1.VGroups.AddDef("日期",DateGroupEnum.Month,"a_{0}")
bd1.Totals.AddDef("数量","进货_数量") '对数量进行统计
dt1 = bd1.BuildDataSource()
Dim bd2 As New CrossTableBuilder("统计表2",DataTables("销售单"))
Dim dt2 As fxDataSource
bd2.HGroups.AddDef("型号") '根据型号分组
bd2.VGroups.AddDef("日期",DateGroupEnum.Month,"b_{0}")
bd2.Totals.AddDef("数量","销售_数量") '对数量进行统计
dt2 = bd2.BuildDataSource()
dt1.Combine("型号",dt2,"型号") '将销售统计数据组合到进货统计数据
dt1.show("test")
Dim t As Table = Tables("test")
Dim dic1 As new Dictionary(Of String, Col)
Dim dic2 As new Dictionary(Of String, Col)
For Each c As Col In t.Cols
If c.name.StartsWith("数量_") Then
If c.Caption.StartsWith("a_") Then
dic1.add(c.caption.split("_")(1), c)
Else
dic2.add(c.caption.split("_")(1), c)
End If
End If
Next
Dim idx As Integer = 1
For i As Integer = 1 To 12
If dic1.ContainsKey(i) Then
dic1(i).move(idx)
Else
t.DataTable.DataCols.Add("aa_" & i, Gettype(Double))
t.Cols("aa_" & i).move(idx)
dic1.add(i, t.Cols("aa_" & i))
End If
dic1(i).caption = i & "月_进货"
If dic2.ContainsKey(i) Then
dic2(i).move(idx+1)
Else
t.DataTable.DataCols.Add("bb_" & i, Gettype(Double))
t.Cols("bb_" & i).move(idx+1)
dic2.add(i, t.Cols("bb_" & i))
End If
dic2(i).caption = i & "月_销售"
t.DataTable.DataCols.Add("ab_相差" & i, Gettype(Double), "isnull(" & dic1(i).name & ",0)-isnull(" & dic2(i).name & ",0)", i & "月_相差")
t.Cols("ab_相差" & i).move(idx+2)
idx = idx + 3
Next