以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 水平汇总问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=194732) |
-- 作者:g1j2h3 -- 发布时间:2025/1/9 9:25:00 -- 水平汇总问题 请教老师,像下边的统计表水平汇总代码如何写 我的统计代码如下,我只想在最后增加两列是汇总全年的入库数量和出库数量及库存数量,每个月不显示库存数量 Dim sql As String = "selec t 入库日期 As 日期,类别,库存编码,产品名称,规格,单位,入库数量,0 as 出库数量 fro m {入库明细} union selec t 出库日期 As 日期,类别,库存编码,产品名称,规格,单位,0 as 入库数量,出库数量 fro m {出库明细}" Dim bd1 As New CrossTableBuilder("统计表1", sql) Dim dt1 As fxDataSource bd1.HGroups.AddDef("类别") bd1.HGroups.AddDef("库存编码") \'根据型号分组 bd1.HGroups.AddDef("产品名称") bd1.HGroups.AddDef("规格") bd1.HGroups.AddDef("单位") bd1.VGroups.AddDef("日期", DateGroupEnum.Year, "{0}年") bd1.VGroups.AddDef("日期", "{0}月") bd1.Totals.AddDef("入库数量") \'对数量进行统计 bd1.Totals.AddDef("出库数量") \'对数量进行统计 dt1 = bd1.BuildDataSource() Dim bd3 As New GroupTableBuilder("统计表2", DataTables("产品信息")) Dim dt3 As fxDataSource bd3.Groups.AddDef("类别") bd3.Groups.AddDef("库存编码") \'根据型号分组 bd3.Groups.AddDef("产品名称") bd3.Groups.AddDef("规格") bd3.Groups.AddDef("单位") bd3.Totals.AddDef("期初库存") \'对数量进行统计 dt3 = bd3.BuildDataSource() Dim nms As String() = {"类别", "库存编码", "产品名称", "规格", "单位"} dt3.Combine(nms, dt1, nms) Tables("窗口1_Table1").DataSource = dt3 \'将统计结果绑定到Table DataTables("入库明细").LoadFilter = "" DataTables("入库明细").Load DataTables("出库明细").loadFilter = "" DataTables("出库明细").load For i As Integer = DataTables("窗口1_Table1").DataCols.Count - 1 To 6 Dim ss() As String = DataTables("窗口1_Table1").DataCols(i).Caption.Split("_") Dim aa() As String = DataTables("窗口1_Table1").DataCols(i).Name.Split("_") DataTables("窗口1_Table1").DataCols.Add(ss(0) & "_" & ss(1) & "_库存数量", GetType(Integer), "IsNull([期初库存],0) + IsNull([入库数量_" & aa(1) & "],0) - ISNULL([出库数量_" & aa(1) & "],0)") Tables("窗口1_Table1").Cols(ss(0) & "_" & ss(1) & "_库存数量").Move(i + 1) Next [此贴子已经被作者于2025/1/9 10:52:14编辑过]
|
-- 作者:g1j2h3 -- 发布时间:2025/1/9 10:56:00 -- 已解决 |
-- 作者:有点蓝 -- 发布时间:2025/1/9 11:11:00 -- Dim lst As New List(Of String) For i As Integer = DataTables("窗口1_Table1").DataCols.Count - 1 To 6 Step - 2 Dim ss() As String = DataTables("窗口1_Table1").DataCols(i).Caption.Split("_") Dim aa() As String = DataTables("窗口1_Table1").DataCols(i).Name.Split("_") If i=6 Then DataTables("窗口1_Table1").DataCols.Add(ss(0) & "_" & ss(1) & "_库存数量", GetType(Integer), "IsNull([期初库存],0) + IsNull([入库数量_" & aa(1) & "],0) - ISNULL([出库数量_" & aa(1) & "],0)") Else lst.Add(ss(0) & "_" & ss(1) & "_库存数量") DataTables("窗口1_Table1").DataCols.Add(ss(0) & "_" & ss(1) & "_库存数量", GetType(Integer), "IsNull([期初库存],0) + IsNull([入库数量_" & aa(1) & "],0) - ISNULL([出库数量_" & aa(1) & "],0)") End If Tables("窗口1_Table1").Cols(ss(0) & "_" & ss(1) & "_库存数量").Move(i + 1) Next For i As Integer = 0 To lst.Count - 2 DataTables("窗口1_Table1").DataCols(lst(i)).Expression = DataTables("窗口1_Table1").DataCols(lst(i)).Expression.Replace("期初库存", lst(i + 1)) Next |
-- 作者:g1j2h3 -- 发布时间:2025/1/9 11:13:00 -- 老师,实际上我统计的目的是想把上一年的结存数量赋值到新的一年的“上年结存”列,麻烦老师指导 Dim y As Integer = Date.Today.Year Dim dt1 As New Date(y, 1, 1) Dim dt2 As New Date(y, 12, 31) Dim Filter As String Filter = "接单日期 >= #" & dt1 & "# And 接单日期 <= #" & dt2 & "#" Dim jd As String = "Selec t 接单日期,{接单登记}.接单单号,产品名称,规格型号,单位,销售数量,发货数量 as 已发货数量,(销售数量 - 发货数量) AS 未发货数量 Fro m {接单登记} Inner JOIN {接单明细} ON {接单明细}.[接单单号] = {接单登记}.[接单单号] " Dim bd1 As New CrossTableBuilder("统计表1", jd, "sale") bd1.HGroups.AddDef("产品名称") \'添加客户列用于水平分组 bd1.HGroups.AddDef("规格型号") \'添加客户列用于水平分组 bd1.HGroups.AddDef("单位") \'添加客户列用于水平分组 bd1.VGroups.AddDef("接单日期", DateGroupEnum.Year, "{0}年") bd1.VGroups.AddDef("接单日期", "{0}月") \'添加日期列用于垂直分组,按月分组 bd1.Totals.AddDef("销售数量", "接单") bd1.Totals.AddDef("已发货数量", "发货") bd1.Filter = Filter bd1.HorizontalTotal = True Tables("窗口1_Table1").DataSource = bd1.BuildDataSource() DataTables("窗口1_Table1").DataCols.Add( "上年结转", GetType(Integer)) Tables("窗口1_Table1").Cols("上年结转").Move(3) DataTables("窗口1_Table1").DataCols.Add( "合计_结存", GetType(Integer), "IsNull([上年结转],0)+IsNull([合计_接单],0) - ISNULL([合计_发货],0)") [此贴子已经被作者于2025/1/9 11:14:21编辑过]
|
-- 作者:有点蓝 -- 发布时间:2025/1/9 11:20:00 -- 上一年的结存数量在哪里? |
-- 作者:g1j2h3 -- 发布时间:2025/1/9 12:00:00 -- 麻烦老师给看下 Dim y As Integer = Date.Today.Year Dim dt1 As New Date(y, 1, 1) Dim dt2 As New Date(y, 12, 31) Dim Filter As String Filter = "接单日期 >= #" & dt1 & "# And 接单日期 <= #" & dt2 & "#" Dim jd As String = "Selec t 接单日期,{接单登记}.接单单号,产品名称,规格型号,单位,销售数量,发货数量 as 已发货数量,(销售数量 - 发货数量) AS 未发货数量 Fro m {接单登记} Inner JOIN {接单明细} ON {接单明细}.[接单单号] = {接单登记}.[接单单号] " Dim bd1 As New CrossTableBuilder("统计表1", jd, "sale") bd1.HGroups.AddDef("产品名称") \'添加客户列用于水平分组 bd1.HGroups.AddDef("规格型号") \'添加客户列用于水平分组 bd1.HGroups.AddDef("单位") \'添加客户列用于水平分组 bd1.VGroups.AddDef("接单日期", DateGroupEnum.Year, "{0}年") bd1.VGroups.AddDef("接单日期", "{0}月") \'添加日期列用于垂直分组,按月分组 bd1.Totals.AddDef("销售数量", "接单") bd1.Totals.AddDef("已发货数量", "发货") bd1.Filter = Filter bd1.HorizontalTotal = True Tables("窗口1_Table1").DataSource = bd1.BuildDataSource() DataTables("窗口1_Table1").DataCols.Add( "上年结转", GetType(Integer)) Tables("窗口1_Table1").Cols("上年结转").Move(3) DataTables("窗口1_Table1").DataCols.Add( "合计_结存", GetType(Integer), "IsNull([上年结转],0)+IsNull([合计_接单],0) - ISNULL([合计_发货],0)") Dim d = Date.Today d = d.addYears( - 1) Dim 年 As Integer = d.Year Dim dt3 As New Date(年, 1, 1) Dim dt4 As New Date(年, 12, 31) Dim Filterdate As String Filterdate = "接单日期 >= #" & dt3 & "# And 接单日期 <= #" & dt4 & "#" Dim bd2 As New CrossTableBuilder("统计表1", jd, "sale") bd2.HGroups.AddDef("产品名称") \'添加客户列用于水平分组 bd2.HGroups.AddDef("规格型号") \'添加客户列用于水平分组 bd2.HGroups.AddDef("单位") \'添加客户列用于水平分组 bd2.VGroups.AddDef("接单日期", DateGroupEnum.Year, "{0}年") bd2.VGroups.AddDef("接单日期", "{0}月") \'添加日期列用于垂直分组,按月分组 bd2.Totals.AddDef("销售数量", "接单") bd2.Totals.AddDef("已发货数量", "发货") bd2.Filter = Filterdate bd2.HorizontalTotal = True bd2.Build() \'Tables("窗口1_Table1").DataSource = bd2.BuildDataSource() Dim lst As New List(Of String) DataTables("统计表1").DataCols.Add( "上年结存", GetType(Integer)) Tables("统计表1").Cols("上年结存").Move(3) DataTables("统计表1").DataCols.Add( "合计_结存", GetType(Integer), "IsNull([上年结存],0)+IsNull([合计_接单],0) - ISNULL([合计_发货],0)") Tables("窗口1_Table1").Cols("上年结存") = Tables("统计表1").Cols("合计_结存")
[此贴子已经被作者于2025/1/9 12:16:05编辑过]
|
-- 作者:有点蓝 -- 发布时间:2025/1/9 13:32:00 -- 请上传实例说明 |