以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求教]多字段统计-代码 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=136445) |
-- 作者:hcfbehero -- 发布时间:2019/6/13 14:14:00 -- [求教]多字段统计-代码 下图中作业人员_正式为作业人员 ,泵工方量分配_结算方量为前列人员共同完成,现需统计出人员列中每人的作业方量,并且以财务结算年月为条件进行统计,已做以下代码,可无法统计出(无结果),也未将财务结算年月条件加进去,请老师帮忙修改下代码为谢!ComboBox4所取为财务结算年月。 Dim bcty As WinForm.ComBoBox = e.Form.Controls("ComboBox4") Dim g As New GroupTableBuilder("统计表1", DataTables("泵送明细")) Dim dt1 As fxDataSource g.Groups.AddDef("财务结算年月") g.Groups.AddDef("泵车信息_编号") g.Groups.AddDef("泵车筛选", "车辆编号及车牌号") g.Totals.AddDef("砼方量_签单", "车辆作业方量_签单") g.Totals.AddDef("砼方量_补方", "车辆作业方量_补方") g.VerticalTotal = True g.Filter = "[财务结算年月] = \'" & bcty.text & "\' and [泵车信息_编号] < 100" dt1 = g.BuildDataSource() Dim g1 As New GroupTableBuilder("统计表1", DataTables("泵人档案")) Dim dt2 As fxDataSource g1.Groups.AddDef("泵工考勤统计_年月") g1.Groups.AddDef("泵工考勤统计_编号") g1.Groups.AddDef("泵工考勤统计_人员", "人员工资明细_姓名") g1.Totals.AddDef("泵工基础工资", "人员工资明细_基础工资") g1.Totals.AddDef("泵工考勤统计_出勤", "人员工资明细_出勤") g1.VerticalTotal = True g1.Filter = "[泵工考勤统计_年月] = \'" & bcty.text & "\'" dt2 = g1.BuildDataSource() Dim dt As DataTable Dim dtb As New DataTableBuilder("统计表1") dtb.AddDef("年月", Gettype(String), 16) dtb.AddDef("人员工资明细_姓名", Gettype(String), 16) dtb.AddDef("人员工资明细_作业方量", Gettype(Double)) dt = dtb.Build() \'开始逐行累加统计 Dim lst As New Dictionary(of String ,DataRow) \'定义一个字典,用于检索每个员工在统计表中对应的行 For Each dr1 As DataRow In DataTables("泵送明细").Select("财务结算年月=\'" & bcty.text & "\'") If dr1.IsNull("ZYRYZS") = False Then \'如果工号列不为空 Dim nms() As String = dr1("ZYRYZS").Split(",") \'将工号列内容拆分成数组 Dim v As Double = dr1("泵工方量分配_结算方量") / nms.Length \'获得平均之后每个工号的生产数量 For Each nm As String In nms \'遍历参与加工此产品的每个工号 Dim dr2 As DataRow Dim key As String = nm & "|" & dr1("财务结算年月") \'这里是关键,由工号和产品组成字典的关键词. If lst.ContainsKey(key) \'如果集合中包括此关键词对应的行 dr2= lst(key) \'将此行赋值给变量dr2 Else dr2 = dt.AddNew() \'否则增加一行. dr2("人员工资明细_姓名") = nm \'新增行的工号列设置为此工号 dr2("年月") = dr1("财务结算年月") \'设置增行的产品 lst.add(key,dr2) \'将新增行添加到字典中,以便接下来检索 End If dr2("人员工资明细_作业方量") = dr2("人员工资明细_作业方量") + v \'加上平均后的产量 Next End If Next Dim nms1 As String() = {"财务结算年月"} Dim nms2 As String() = {"泵工考勤统计_年月"} Dim nms3 As String() = {"年月"} dt1.Combine(nms1,dt2,nms2) dt1.Combine(nms1,dtb,nms3) Tables("明细根表_Table5").DataSource = dt1 [此贴子已经被作者于2019/6/16 13:48:39编辑过]
|
-- 作者:有点甜 -- 发布时间:2019/6/13 15:07:00 -- Dim bcty As WinForm.ComBoBox = e.Form.Controls("ComboBox4") Dim dt As DataTable
|
-- 作者:hcfbehero -- 发布时间:2019/6/16 13:12:00 -- 感谢甜版,但如何不让此表在我指定表格中显示后,不再生成临时表“统计表1”,另外我想把两个分组统计表与这个表合并,想得到的效果如下图一,请甜版帮我看下代码,我运行后,出现图二的错误。 图一 图二 代码 Dim bcty As WinForm.ComBoBox = e.Form.Controls("ComboBox4") Dim g As New GroupTableBuilder("统计表1", DataTables("泵送明细")) Dim dt1 As fxDataSource g.Groups.AddDef("财务结算年月") g.Groups.AddDef("泵车信息_编号") g.Groups.AddDef("泵车筛选", "车辆编号及车牌号") g.Totals.AddDef("砼方量_签单", "车辆作业方量_签单") g.Totals.AddDef("砼方量_补方", "车辆作业方量_补方") g.VerticalTotal = True g.Filter = "[财务结算年月] = \'" & bcty.text & "\' and [泵车信息_编号] < 100" dt1 = g.BuildDataSource() Dim g1 As New GroupTableBuilder("统计表1", DataTables("泵人档案")) Dim dt2 As fxDataSource g1.Groups.AddDef("泵工考勤统计_年月") g1.Groups.AddDef("泵工考勤统计_编号") g1.Groups.AddDef("泵工考勤统计_人员", "人员工资明细_姓名") g1.Totals.AddDef("泵工基础工资", "人员工资明细_基础工资") g1.Totals.AddDef("泵工考勤统计_出勤", "人员工资明细_出勤") g1.VerticalTotal = True g1.Filter = "[泵工考勤统计_年月] = \'" & bcty.text & "\'" dt2 = g1.BuildDataSource() Dim dt As DataTable Dim dtb As New DataTableBuilder("统计表1") dtb.AddDef("年月", Gettype(String), 16) dtb.AddDef("人员工资明细_姓名", Gettype(String), 16) dtb.AddDef("人员工资明细_作业方量", Gettype(Double)) dt = dtb.Build() \'开始逐行累加统计 Dim lst As New Dictionary(of String ,DataRow) \'定义一个字典,用于检索每个员工在统计表中对应的行 For Each dr1 As DataRow In DataTables("泵送明细").Select("财务结算年月=\'" & bcty.text & "\'") If dr1.IsNull("ZYRYZS") = False Then \'如果工号列不为空 Dim nms() As String = dr1("ZYRYZS").Split(",") \'将工号列内容拆分成数组 Dim v As Double = dr1("泵工方量分配_结算方量") / nms.Length \'获得平均之后每个工号的生产数量 For Each nm As String In nms \'遍历参与加工此产品的每个工号 Dim dr2 As DataRow Dim key As String = nm & "|" & dr1("财务结算年月") \'这里是关键,由工号和产品组成字典的关键词. If lst.ContainsKey(key) \'如果集合中包括此关键词对应的行 dr2= lst(key) \'将此行赋值给变量dr2 Else dr2 = dt.AddNew() \'否则增加一行. dr2("人员工资明细_姓名") = nm \'新增行的工号列设置为此工号 dr2("年月") = dr1("财务结算年月") \'设置增行的产品 lst.add(key,dr2) \'将新增行添加到字典中,以便接下来检索 End If dr2("人员工资明细_作业方量") = dr2("人员工资明细_作业方量") + v \'加上平均后的产量 Next End If Next Dim nms1 As String() = {"财务结算年月"} Dim nms2 As String() = {"泵工考勤统计_年月"} Dim nms3 As String() = {"年月"} dt1.Combine(nms1,dt2,nms2) dt1.Combine(nms1,dtb,nms3) Tables("明细根表_Table5").DataSource = dt1 [此贴子已经被作者于2019/6/16 13:44:42编辑过]
|
-- 作者:有点甜 -- 发布时间:2019/6/17 10:26:00 --
你也要对临时表【统计表1】进行分组统计,才能连接。
|