看懂代码,改成自己需要的。如果自己不会改,实例发上来测试。
Dim dg As DataTable
Dim b As New SQLGroupTableBuilder("统计表1","劳务人员登记表")
If User.Name = "开发者" Or User.Name = "管理员" Then
b.Filter = ""
Else
b.Filter = "承包人机构 in ('" & User.Roles.replace(",","','") & "') or 监理机构 in ('" & User.Roles.replace(",","','") & "') or 业主机构 in ('" & User.Roles.replace(",","','") & "') or 劳务队负责人 in ('" & User.Roles.replace(",","','") & "')"
End If
b.Groups.AddDef("项目名称")
b.Groups.AddDef("施工合同段")
b.Groups.AddDef("劳务队名称")
b.Groups.AddDef("工种")
b.Totals.AddDef("姓名",AggregateEnum.Count,"人数") '根据客户列来统计记录数,也就是订单数
b.Totals.AddExp("退场人数", "case when 退场时间 is null then 0 else 1 end") '根据客户列来统计记录数,也就是订单数
dg = b.Build(True) '参数设置为True,生成一个临时表,不在主界面显示
'然后根据统计表生成目录树
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dg,"项目名称|施工合同段|劳务队名称|工种")
trv.StopRedraw
For Each nd As WinForm.TreeNode In trv.AllNodes
Dim Xmmc As String = nd.DataRow("项目名称")
Dim Xghtd As String = nd.DataRow("施工合同段")
Dim Lwdmc As String = nd.DataRow("劳务队名称")
Dim Gz As String = nd.DataRow("工种")
Select Case nd.Level
Case 0
Dim sy = dg.Compute("Sum(人数)", "项目名称 = '" & Xmmc & "'")
Dim ttc = dg.Compute("Sum(退场人数)", "项目名称 = '" & Xmmc & "'")
nd.Text = nd.text & "(在场" & sy-ttc & "人,退场" & ttc & "人)"
Case 1
Dim sy = dg.Compute("Sum(人数)", "项目名称 = '" & Xmmc & "' And 施工合同段 = '" & Xghtd & "'")
Dim ttc = dg.Compute("Sum(退场人数)", "项目名称 = '" & Xmmc & "' And 施工合同段 = '" & Xghtd & "'")
nd.Text = nd.text & "(在场" & sy-ttc & "人,退场" & ttc & "人)"
Case 2
Dim sy = dg.Compute("Sum(人数)", "项目名称 = '" & Xmmc & "' And 施工合同段 = '" & Xghtd & "'")
Dim ttc = dg.Compute("Sum(退场人数)", "项目名称 = '" & Xmmc & "' And 施工合同段 = '" & Xghtd & "' And 劳务队名称 = '" & Lwdmc & "'")
nd.Text = nd.text & "(在场" & sy-ttc & "人,退场" & ttc & "人)"
Case 3
nd.Text = nd.text & "(" & nd.DataRow("人数") & "人)"
End Select
Next
Dim suoyou = dg.Compute("Sum(人数)")
Dim tc = dg.Compute("Sum(退场人数)")
trv.Nodes.Insert("加载所有数据","加载所有数据(在场" & suoyou-tc & "人,退场" & tc & "人)",0)
trv.ResumeRedraw
e.Form.Controls("TextBox5").Value = 1 & "/" & DataTables("劳务人员登记表").TotalPages
vars("劳务人员登记表filter") = DataTables("劳务人员登记表").LoadFilter