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