优化一下:
Dim dt3 As DataTable
Dim bd1 As GroupTableBuilder
Dim fxdts(8) As fxDataSource
Dim nms(),Ymds(),Bts() As String
Dim Filter,s2,s3 ,flt1,ep1,ep2,ep3 As String
Dim nms1 As String() = {"编码","名称","颜色","尺码","年份","季节","零售价"} '分組列1
Dim nms2 As String() = {"编码","名称","颜色","尺码","年份","季节"} '分組列2
Dim t3 As Table = e.Form.Controls("库存报表").Table
Ymds="D@F@T@R@R@@@@".split("@")
Bts= "库房_调拨出库@库房_收货入库@库房_返货出库@店铺_调拨出库@店铺_调拨入库@店铺_零售出库@店铺_零退入库@店铺_库调@店铺_退货入库".split("@") '統計標題
ep1 = "IsNull([库房_收货入库],0) +IsNull([库房_返货出库],0)+IsNull([库房_调拨出库],0)+IsNull([店铺_退货入库],0)-Isnull([店铺_库调],0)"
ep2 = "IsNull([店铺_库调],0) +IsNull([店铺_调拨入库],0)+IsNull([店铺_调拨出库],0)+IsNull([店铺_零退入库],0)"
ep2+="-Isnull([店铺_零售出库],0)-Isnull([店铺_退货入库],0)"
ep3 = "IsNull([合计_库房],0) +IsNull([合计_店铺],0)"
s3 ="品牌,门店,年份,季节,开始日期,截止日期"
For Each s2 In s3.split(",")
With e.Form.Controls(s2)
If .Value IsNot Nothing Then
If Filter > "" Then
Filter+ = " And "
End If
If s2 = "开始日期" Then
Filter+ = "单据日期 >= #" & .Value & "#"
ElseIf s2 = "截止日期" Then
Filter+ = "单据日期 <= #" & .Value & "#"
Else
Filter+ = s2 & " = '" & .Value & "'"
End If
End If
End With
Next
If Filter > "" Then
Tables("出入库明细").Filter = Filter
For n1 As Integer = 0 To 8
If n1 > 6 Then
dt3 = DataTables("库调明细表_主表")
Else
dt3 = DataTables("出入库明细")
End If
bd1 = New GroupTableBuilder("报表",dt3)
For Each s2 In nms1
If dt3.DataCols.Contains(s2) Then
bd1.Groups.AddDef(s2) '分组
End If
Next
bd1.Totals.AddDef("数量",Bts(n1)) '对数量进行统计
flt1= "收发类型= '" & Bts(n1).split("_")(1) & "'"
If Ymds(n1) > "" Then
flt1+= " And 业务单号首位 = '" & Ymds(n1) & "'"
End If
bd1.Filter = flt1 & " and " & Filter
fxdts(n1) = bd1.BuildDataSource()
nms = iif(n1 < 7,nms1,nms2)
If n1 > 0 Then fxdts(0).Combine(nms,fxdts(n1),nms)
Next
t3.StopRedraw
t3.DataSource = fxdts(0)
With t3.DataTable.DataCols
.Add("合计_库房", Gettype(Integer),ep1)
.Add("合计_店铺", Gettype(Integer),ep2)
.Add("合计_店库", Gettype(Integer),ep3)
End With
t3.AutoSizeCols
t3.ResumeRedraw
End If
[此贴子已经被作者于2014-5-6 22:29:34编辑过]