Dim Filter As String = "商品编号 is not null"
With e.Form.Controls("StartDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "进货日期 >= #" & .Value & "#"
End If
End With
With e.Form.Controls("EndDate")
If .Value IsNot Nothing Then
If Filter >"" Then
Filter = Filter & " And "
End If
Filter = Filter & "进货日期 <= #" & .Value & "#"
End If
End With
With e.Form.Controls("商品名称")
If .Value IsNot Nothing Then
If Filter > "" Then
Filter = Filter & " And "
End If
Filter = Filter & "商品名称 = '" & .Value & "'"
End If
End With
Dim bd1 As New GroupTableBuilder("统计表1",DataTables("进货单"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("商品编号") '根据商品编号分组
bd1.Groups.AddDef("商品名称") '根据商品编号分组
bd1.Totals.AddDef("数量","进货_数量") '对数量进行统计
bd1.Totals.AddDef("金额","进货_金额") '对金额进行统计
bd1.Filter = Filter
dt1 = bd1.BuildDataSource()
Dim bd2 As New GroupTableBuilder("统计表2",DataTables("销售单"))
Dim dt2 As fxDataSource
bd2.Groups.AddDef("商品编号") '根据商品编号分组
bd2.Groups.AddDef("商品名称") '根据商品编号分组
bd2.Totals.AddDef("数量","销售_数量") '对数量进行统计
bd2.Totals.AddDef("金额","销售_金额") '对金额进行统计
bd2.Filter = Filter.replace("进货日期","销售日期")
dt2 = bd2.BuildDataSource()
Dim bd3 As New GroupTableBuilder("统计表3",DataTables("退货单"))
Dim dt3 As fxDataSource
bd3.Groups.AddDef("商品编号") '根据商品编号分组
bd3.Groups.AddDef("商品名称") '根据商品编号分组
bd3.Totals.AddDef("数量","退货_数量") '对数量进行统计
bd3.Totals.AddDef("金额","退货_金额") '对金额进行统计
bd3.Filter = Filter.replace("进货日期","退货日期")
dt3 = bd3.BuildDataSource()
Dim ns() As String = {"商品编号","商品名称"}
dt1.Combine(ns,dt2,ns) '将销售统计数据组合到进货统计数据
dt1.Combine(ns,dt3,ns) '将退货统计数据组合到进货统计数据
Tables("库存_Table1").DataSource = dt1 '将统计结果绑定到Table
With DataTables("库存_Table1").DataCols '用表达式列计算库存数据
.Add("库存_数量",Gettype(Integer), "IsNull([进货_数量],0) - ISNULL([销售_数量],0) + ISNULL([退货_数量],0)")
.Add("库存_金额",Gettype(Double), "[库存_数量] /[进货_数量] * [进货_金额]")
End With
我前面的销售单,退货单,进货单,也都设置了表属性DataColChanged事件代码,主要是希望,前面基础信息表的客户名称那些有添加新的名称或者修改,这里也可以实时更新,代码您帮我看看
If e.DataCol.Name = "客户编号" Then '如果内容发生变动的是品名列
If e.NewValue Is Nothing Then '如果新值是空白,也就是品名列的内容为空
e.DataRow("客户") = Nothing '那么清空此行单价列的内容
Else
Dim dr As DataRow
'否则在产品表查找同名的产品行,将找到的行赋值给变量dr
dr = DataTables("客户信息").Find("[客户编号] = '" & e.NewValue & "'")
If dr IsNot Nothing Then '如果找到了同名的产品行,也就是dr不是Nothing
e.DataRow("客户") = dr("客户")
End If
End If
End If
If e.DataCol.Name = "商品编号" Then
If e.NewValue Is Nothing Then
e.DataRow("商品名称") = Nothing
e.DataRow("规格") = Nothing
e.DataRow("单位") = Nothing
e.DataRow("型号") = Nothing
e.DataRow("单价") = Nothing
Else
Dim dr As DataRow
dr = DataTables("商品信息").Find("[商品编号] = '" & e.NewValue & "'")
If dr IsNot Nothing
e.DataRow("商品名称") = dr("商品名称")
e.DataRow("型号") = dr("型号")
e.DataRow("规格") = dr("规格")
e.DataRow("单位") = dr("单位")
e.DataRow("单价") = dr("单价")
End If
End If
End If
Select Case e.DataCol.Name
Case "商品名称","型号","规格","单位"
Dim Filter As String = "[商品编号] = '" & e.DataRow("商品编号") & "'"
DataTables("退货单").ReplaceFor(e.DataCol.Name, e.NewValue, Filter)
End Select
Select Case e.DataCol.Name
Case "客户"
Dim Filter As String = "[客户编号] = '" & e.DataRow("客户编号") & "'"
DataTables("退货单").ReplaceFor(e.DataCol.Name, e.NewValue, Filter)
End Select