现在可以统计了 但我把按各种分类统计好的表合并后 出现个错误提示 已经具有相同键的项
Dim bt As WinForm.TextBox = e.Form.Controls("TextBox1")
If bt.Text = Nothing Then
MessageBox.Show("请输入商品属性", "提示")
Return
Else If not IsNumeric(bt.Text) Then
MessageBox.Show("商品属性是数字", "提示")
Return
End If
Dim txt As String = bt.Text
Dim g As New GroupTableBuilder("进货表", DataTables("ic_t_inout_store_detail"))
Dim dt1 As fxDataSource
g.Groups.AddDef("商品属性")
g.Groups.AddDef("sheet_no")
g.Groups.AddDef("barcode","","条码")
g.Groups.AddDef("名称")
g.Groups.AddDef("商品尺码")
g.Totals.AddDef("in_qty","进货_数量","进货_数量")
g.Totals.AddDef("金额", "进货_金额")
g.Filter = "[sheet_no] Like 'PI%' and [商品属性] = '" & txt & "'"
dt1 = g.BuildDataSource()
Dim g2 As New GroupTableBuilder("销售流水表", DataTables("pos_t_saleflow"))
Dim dt2 As fxDataSource
g2.Groups.AddDef("商品条码")
g2.Groups.AddDef("商品尺码")
g2.Totals.AddDef("sale_qnty", "销售_数量")
g2.Totals.AddDef("实际金额", "销售_金额")
g2.Filter = "[商品属性] = " & txt & " And sell_way = 'A' And cm_no <> '00'"
dt2 = g2.BuildDataSource()
Dim g3 As New GroupTableBuilder("销售退货表", DataTables("pos_t_saleflow"))
Dim dt3 As fxDataSource
g3.Groups.AddDef("商品条码")
g3.Groups.AddDef("商品尺码")
g3.Totals.AddDef("sale_qnty", "退货_数量")
g3.Totals.AddDef("实际金额", "退货_金额")
g3.Filter = "[商品属性] = " & txt & " and sell_way = 'B'"
dt3 = g3.BuildDataSource()
Dim g4 As New GroupTableBuilder("销售赠送表", DataTables("pos_t_saleflow"))
Dim dt4 As fxDataSource
g4.Groups.AddDef("商品条码")
g4.Groups.AddDef("商品尺码")
g4.Totals.AddDef("sale_qnty", "赠送_数量")
g4.Totals.AddDef("实际金额", "赠送_金额")
g4.Filter = "[商品属性] = " & txt & " and sell_way = 'C'"
dt4 = g4.BuildDataSource()
dt1.Combine("barcode",dt2,"商品条码")
dt1.Combine("barcode",dt3,"商品条码")
dt1.Combine("barcode",dt4,"商品条码")
Tables("库销存_Table1").DataSource = dt1 '将统计结果绑定到Table
With DataTables("库销存_Table1").DataCols '用表达式列计算库存数据
.Add("库存_数量",Gettype(Integer), "IsNull([进货_数量],0) - ISNULL(销售_数量 ,0) + ISNULL(退货_数量,0) - ISNULL(赠送_数量,0)")
.Add("盈亏_金额",Gettype(Double), "IsNull([销售_金额],0) - ISNULL([退货_金额 ],0) - ISNULL([进货_金额],0)")
End With
With Tables("库销存_Table1")
.Cols("进货_金额").GrandTotal = True '指定要合计的列
.Cols("销售_金额").GrandTotal = True
.Cols("退货_金额").GrandTotal = True
.Cols("赠送_金额").GrandTotal = True
.Cols("盈亏_金额").GrandTotal = True
.GrandTotal = True '显示合计模式
End With
之前没有.Groups.AddDef("商品尺码")这个表达式列的时候(这个表达式就是我上面提问中需求的尺码名称), 可以统计出来。 我刚才单独Tables("库销存_Table1").DataSource = dt1 '将统计结果绑定到Table 把dt1 换2,3,4 挨个试了一遍 都可以统计好 就是合并的时候出问题了。 合并我也没有改动啊, 咋就不能了呢