以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 数据统计 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=146640) |
-- 作者:有点蓝 -- 发布时间:2020/2/28 14:09:00 -- 这个意思? Dim d As Date = Date.Today Dim m As String = Format(d,"yyyyMM") Dim m1 As String = Format(d.AddMonths(-1),"yyyyMM") Dim drs As List(Of DataRow) = DataTables("月结记录表").Select("月=\'" & m1 & "\'") If drs.Count = 0 Then msgbox("上个月未月结") Return End If Dim f2 As String = "1=2 " For Each dr As DataRow In drs f2 = f2 & "or ( 库位=\'" & dr("仓库名称") & "\' and 单据日期 > #" & dr("结束时间") & "#)" Next Dim bd1 As New GroupTableBuilder("统计表1",DataTables("出入库明细")) Dim dt1 As fxDataSource bd1.Groups.AddDef("编号") \'根据编号分组 bd1.Totals.AddDef("入库数","入库数量") \'对数量进行统计 bd1.Filter = f2 dt1 = bd1.BuildDataSource() Dim bd2 As New GroupTableBuilder("统计表2",DataTables("出入库明细")) Dim dt2 As fxDataSource bd2.Groups.AddDef("编号") \'根据编号分组 bd2.Totals.AddDef("出库数","出库数量") \'对数量进行统计 bd2.Filter = f2 dt2 = bd2.BuildDataSource() Dim bd3 As New GroupTableBuilder("统计表3",DataTables("库存")) Dim dt3 As fxDataSource bd3.Groups.AddDef("编号") \'根据编号分组 bd3.Totals.AddDef("库存数","上月结存") \'对数量进行统计 bd3.Filter = "月=\'" & m1 & "\'" dt3 = bd3.BuildDataSource() dt1.Combine("编号",dt2,"编号") \'将销售统计数据组合到进货统计数据 dt1.Combine("编号",dt3,"编号") \'将退货统计数据组合到进货统计数据 Tables("窗口1_Table1").DataSource = dt1 \'将统计结果绑定到Table With DataTables("窗口1_Table1").DataCols \'用表达式列计算库存数据 .Add("库存数量",Gettype(Integer), "IsNull([上月结存],0) + ISNULL([入库数量],0) - ISNULL([出库数量],0)") End With |
-- 作者:有点蓝 -- 发布时间:2020/2/28 15:20:00 -- 分组统计里自己加一个出库的分组即可 |
-- 作者:有点蓝 -- 发布时间:2020/2/28 16:00:00 -- dim nms() as string = {"编号","仓库名称"} dt3 = bd3.BuildDataSource() dt1.Combine(nms,dt2,nms) \'将销售统计数据组合到进货统计数据 dt1.Combine(nms,dt3,nms) \'将退货统计数据组合到进货统计数据 Tables("窗口1_Table1").DataSource = dt1
|
-- 作者:有点蓝 -- 发布时间:2020/2/28 16:59:00 -- 月结记录表数据有问题,自己仔细看看 |
-- 作者:有点蓝 -- 发布时间:2020/2/28 17:58:00 -- 拿个放大镜仔细看看前面2行的年月日 |
-- 作者:有点蓝 -- 发布时间:2020/2/28 20:39:00 -- 这样1月份比如成品库就有2条记录,怎么知道取哪一条? |
-- 作者:有点蓝 -- 发布时间:2020/2/28 21:37:00 -- 试试 Dim m1 As String = DataTables("库存").Compute("max(月)") Dim dict As new Dictionary(of String,Date) For Each y As String In DataTables("月结记录表").GetValues("仓库名称") Dim d As Date = DataTables("月结记录表").Compute("max(结束时间)","仓库名称=\'" & y & "\'") dict.Add(y,d) Next Dim f2 As String = "1=2 " For Each key As String In dict.Keys f2 = f2 & "or ( 仓库名称 =\'" & key & "\' and 单据日期 > #" & dict(key) & "#)" Next Dim bd1 As New GroupTableBuilder("统计表1",DataTables("出入库明细")) Dim dt1 As fxDataSource bd1.Groups.AddDef("编号") \'根据编号分组 bd1.Groups.AddDef("仓库名称") \'根据编号分组 bd1.Totals.AddDef("入库数","入库数量") \'对数量进行统计 bd1.Filter = f2 dt1 = bd1.BuildDataSource() Dim bd2 As New GroupTableBuilder("统计表2",DataTables("出入库明细")) Dim dt2 As fxDataSource bd2.Groups.AddDef("编号") \'根据编号分组 bd2.Groups.AddDef("仓库名称") \'根据编号分组 bd2.Totals.AddDef("出库数","出库数量") \'对数量进行统计 bd2.Filter = f2 dt2 = bd2.BuildDataSource() Dim bd3 As New GroupTableBuilder("统计表3",DataTables("库存")) Dim dt3 As fxDataSource bd3.Groups.AddDef("编号") \'根据编号分组 bd3.Groups.AddDef("仓库名称") \'根据编号分组 bd3.Totals.AddDef("库存数","上月结存") \'对数量进行统计 bd3.Filter = "月=\'" & m1 & "\'" dt3 = bd3.BuildDataSource() Dim nms() As String = {"编号","仓库名称"} dt3 = bd3.BuildDataSource() dt1.Combine(nms,dt2,nms) \'将销售统计数据组合到进货统计数据 dt1.Combine(nms,dt3,nms) \'将退货统计数据组合到进货统计数据 Tables("窗口1_Table1").DataSource = dt1 With DataTables("窗口1_Table1").DataCols \'用表达式列计算库存数据 .Add("库存数量",Gettype(Integer), "IsNull([上月结存],0) + ISNULL([入库数量],0) - ISNULL([出库数量],0)") End With |
-- 作者:有点蓝 -- 发布时间:2020/2/29 8:42:00 -- Dim Filter ,f3 As String With e.Form.Controls("仓库名称") If .Value IsNot Nothing Then If Filter >"" Then Filter = Filter & " And " End If Filter = Filter & "仓库名称 = \'" & .Value & "\'" f3 = "仓库名称 = \'" & .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 m1 As String = DataTables("库存").Compute("max(月)",Filter ) Dim dict As new Dictionary(of String,Date) For Each y As String In DataTables("月结记录表").GetValues("仓库名称",f3 ) Dim d As Date = DataTables("月结记录表").Compute("max(结束时间)","仓库名称=\'" & y & "\'") dict.Add(y,d) Next Dim f2 As String = "1=2 " For Each key As String In dict.Keys f2 = f2 & "or ( 仓库名称 =\'" & key & "\' and 单据日期 > #" & dict(key) & "#)" Next With e.Form.Controls("产品编码") If .Value IsNot Nothing Then If f2>"" Then f2= f2 & " And " End If f2= f2 & "编号 = \'" & .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.Filter = f2 dt1 = bd1.BuildDataSource() Dim bd2 As New GroupTableBuilder("统计表2",DataTables("出入库明细")) Dim dt2 As fxDataSource bd2.Groups.AddDef("编号") \'根据编号分组 bd2.Groups.AddDef("仓库名称") \'根据编号分组 bd2.Totals.AddDef("出库数","出库数量") \'对数量进行统计 bd2.Filter = f2 dt2 = bd2.BuildDataSource() Dim bd3 As New GroupTableBuilder("统计表3",DataTables("库存")) Dim dt3 As fxDataSource bd3.Groups.AddDef("编号") \'根据编号分组 bd3.Groups.AddDef("仓库名称") \'根据编号分组 bd3.Totals.AddDef("库存数","上月结存") \'对数量进行统计 bd3.Filter = "月=\'" & m1 & "\'" & iif(filter > ""," and ","") & filter dt3 = bd3.BuildDataSource() Dim nms() As String = {"编号","仓库名称"} dt3 = bd3.BuildDataSource() dt1.Combine(nms,dt2,nms) \'将销售统计数据组合到进货统计数据 dt1.Combine(nms,dt3,nms) \'将退货统计数据组合到进货统计数据 Tables("窗口1_Table1").DataSource = dt1 With DataTables("窗口1_Table1").DataCols \'用表达式列计算库存数据 .Add("库存数量",Gettype(Integer), "IsNull([上月结存],0) + ISNULL([入库数量],0) - ISNULL([出库数量],0)") End With
|
-- 作者:有点蓝 -- 发布时间:2020/3/3 16:27:00 -- 直接统计后台数据
但是这有一个问题,动态加载部分数据是没问题的,但是很多时候,我们的统计是针对所有数据的,而Foxtable的分组统计和交叉统计默认都是针对已经加载的数据,如果我要统计所有数据,难道需要将一百万甚至一千万记录全部加载到Foxtable?显然这是不可能的。 对于熟练掌握SQL语言的用户来说,这不是问题,直接自己编写SQL语句来统计即可;但实际上,SQL语言虽然入门容易,但是精通是很难的,对于一些复杂的统计,即使是一些非常资深的程序员,也不见得能够在短时间内写出合理高效的SQL语句来,何况是普通用户呢? 为此GroupTableBuilder和CrossTableBuilder都提供了一个名为FromServer的逻辑属性,只需将此属性设为True,即可直接统计后台数据。 例如: Dim g As New GroupTableBuilder("统计表1", DataTables("订单")) |
-- 作者:有点蓝 -- 发布时间:2020/3/3 20:43:00 -- 如果是表达式列,无法后台使用,改为数据列 |