Dim dt As DataTable
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("派工人员", Gettype(String), 16)
dtb.AddDef("职务", Gettype(String), 16)
dtb.AddDef("项目编号", Gettype(String), 16)
dtb.AddDef("派工人数", Gettype(Double))
dtb.AddDef("派工时间", Gettype(Date))
dt = dtb.Build()
'开始逐行累加统计
'Dim lst As New Dictionary(of String ,DataRow) '定义一个字典,用于检索每个员工在统计表中对应的行
For Each dr1 As DataRow In DataTables("派工单").DataRows
If dr1.IsNull("派工人员") = False Then '如果工号列不为空
Dim nms() As String = dr1("派工人员").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("派工单号") '设置增行的产品
dr2("派工时间") = dr1("派工时间")
dr2("派工人数") = dr1("派工人数")
'lst.add(key,dr2) '将新增行添加到字典中,以便接下来检索
'End If
Next
End If
Next
DataTables("员工提成表").DataRows.Clear
For Each ary() As String In DataTables("统计").GetValues("项目编号|派工人员")
Dim r As Row = Tables("员工提成表").AddNew
r("项目编号") = ary(0)
r("派工人员") = ary(1)
Dim count As Integer = 0
Dim Dates As String = ""
For Each dr As DataRow In DataTables("统计").Select("项目编号 = '" & ary(0) & "' and 派工人员 = '" & ary(1) & "'")
count += 1
Dates &= dr("派工时间") & ","
Next
r("派工时间") = Dates.Trim(",")
r("提成比例") = count
Next