有两三个sql外部数据表,一个是库存表,一个是采购明细,一个是销售明细。(1)库存表需要在后台统计每个产品的当年平均采购单价作为采购的成本单价,应该如何写代码?(2)计算每个产品的所有入库数量- 所有出库数量 + 期初数量= 库存数量;
在datacolchanged事件里面写以下代码:然后用主表转换来强行触发,可以满足需求,但是特别耗时,有700多个产品,几条采购和销售记录,需要计算几十秒。麻烦老师指导一下思路噢。初学者,谢谢哈
Dim d As DataTable = DataTables("采购明细")
Dim dt As DataTable = DataTables("销售明细")
Dim yrk As Double = d.sqlCompute("sum(入库1)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
d.sqlCompute("sum(入库2)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
d.sqlCompute("sum(入库3)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
d.sqlCompute("sum(入库4)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
d.sqlCompute("sum(入库5)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
d.sqlCompute("sum(入库6)","[产品编号] = '" & e.DataRow("商品编号") & "'")
Dim yck As Double = dt.sqlCompute("sum(出库1)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库2)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库3)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库4)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库5)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库6)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库7)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库8)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库9)","[产品编号] = '" & e.DataRow("商品编号") & "'") + _
dt.sqlCompute("sum(出库10)","[产品编号] = '" & e.DataRow("商品编号") & "'")
If e.DataCol.Name = "商品编号" Then
e.DataRow("采购单价") = DataTables("采购明细").sqlCompute("avg(含税单价)","[产品编号] = '" & e.DataRow("商品编号") & "'")
e.DataRow("在途数量") = d.sqlCompute("sum(数量)","[产品编号] = '" & e.DataRow("商品编号") & "'") - yrk
e.DataRow("当前计划出库数量") = dt.sqlCompute("sum(数量)","[产品编号] = '" & e.DataRow("商品编号") & "'") - yck
e.DataRow("库存数量") = e.DataRow("期初数量") + yrk -yck
End If
以前我是通过把后台数据表都加载进入foxtable,然后通过表达式列来计算没有问题。但是数据如果多的话,就不行了;所以想学习分页加载,可是分页加载涉及到处理后台数据,这个没有思路。希望老师指点方法噢,谢谢!!