Dim r1 As Row
Dim n1,n2 As Integer
Dim cp1,ht1,fl1,fl2 As String
Dim Cps,Hts As List(Of String)
Dim dt1 As DataTable =DataTables("欠货明细表")
fl1 ="欠货数量 <> 0"
Cps = dt1.GetUniqueValues(fl1,"产品型号")
For Each cp1 In Cps
fl2 ="产品型号='" & cp1 & "'And " & fl1
hts =dt1.GetUniqueValues(fl2,"合同编号")
If hts.Count > n2 Then
n2 =hts.Count
End If
Next
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("产品型号", Gettype(String), 32)
dtb.AddDef("欠货数量", Gettype(Integer))
For n1 = 1 To n2
dtb.AddDef("H" & n1 , Gettype(String), 32)
dtb.AddDef("Q" & n1 , Gettype(Integer))
Next
dtb.Build()
Tables("统计").StopRedraw
For Each cp1 In Cps
fl2 ="产品型号='" & cp1 & "'And " & fl1
hts =dt1.GetUniqueValues(fl2,"合同编号")
r1 =Tables("统计").AddNew
r1("产品型号") =cp1
r1("欠货数量") =dt1.Compute("sum(欠货数量)",fl2)
For n1 = 0 To hts.count-1
r1("H" & n1+1) =hts(n1)
r1("Q" & n1+1) =dt1.Compute("sum(欠货数量)",fl2 & " And 合同编号 ='" & hts(n1) & "'")
Next
Next
With DataTables("统计")
For n1 = 1 To n2
.DataCols("H" & n1).Caption = "欠货明细_合同编号"
.DataCols("Q" & n1).Caption = "欠货明细_欠货数量"
Next
.BuildHeader()
End With
Tables("统计").ResumeRedraw
MainTable= Tables("统计")
[此贴子已经被作者于2012-9-13 14:14:27编辑过]