以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  统计下各岗位的人数,看看代码错在哪了  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=195785)

--  作者:deliangzhaoe
--  发布时间:2025/3/8 12:02:00
--  统计下各岗位的人数,看看代码错在哪了
想统计一下各岗位的员工人数,有的人不只一个岗位,所以在员工花名册中设计了岗位和其他岗位,其他岗位也在统计范围内。第一个岗位的人数能统计出来,但是其他岗位的数量就是统计不出来了,老师帮我看看代码错在哪了,怎么改?谢谢
在统计表的datacolchanged代码如下:
\'岗位人数计算
Select Case e.DataCol.name
    Case "岗位"
        Dim r1 As DataRow = DataTables("员工花名册").find("企业名称 = \'" & Tables("岗位人数统计").current ("企业名称") & "\' And 现所在单位 =  \'" & Tables("岗位人数统计").current ("部门") & "\' And 岗位 =  \'" & Tables("岗位人数统计").current ("岗位") & "\'")
        If r1 IsNot Nothing Then
            e.DataRow("人数") = DataTables("员工花名册").Compute("count(姓名)","员工状态 = \'在岗\' and 企业名称 = \'" & e.DataRow("企业名称") & "\' And 现所在单位 =  \'" & Tables("岗位人数统计").current ("部门") & "\' and 岗位 = \'" & e.DataRow("岗位") & "\'")
        Else
            e.DataRow("人数") = "0"
        End If
        Dim r3 As DataRow = DataTables("岗位人数统计").find("人数 = 0")
        If r3 IsNot Nothing Then
            r3("人数") = Nothing
        End If
        Dim r2 As DataRow = DataTables("员工花名册").find("企业名称 = \'" & r3("企业名称") & "\' And 其他岗位 =  \'" & r3("岗位") & "\'")
        If r2 IsNot Nothing Then
            r3("人数") = DataTables("员工花名册").Compute("count(姓名)","员工状态 = \'在岗\' and 企业名称 = \'" & r3("企业名称") & "\' and 其他岗位 = \'" & r3("岗位") & "\'")
        Else
            r3("人数") = "0"
        End If
End Select


图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20250308115358.png
图片点击可在新窗口打开查看
第一个表是员工花名册的部分列截图

图片点击可在新窗口打开查看此主题相关图片如下:微信截图_20250308115337.png
图片点击可在新窗口打开查看
第二表是统计出来的表。
请老师帮忙看一下怎么改。谢谢!


--  作者:有点蓝
--  发布时间:2025/3/8 14:05:00
--  
http://www.foxtable.com/webhelp/topics/2925.htmhttp://www.foxtable.com/webhelp/topics/0604.htm

不要搞那么复杂

Select Case e.DataCol.name
    Case "岗位"
        Dim count As Integer = DataTables("员工花名册").Compute("count(姓名)", "企业名称 = \'" & e.DataRow("企业名称") & "\' And 现所在单位 =  \'" & e.DataRow("部门") & "\' And (岗位 =  \'" & e.DataRow("岗位") & "\' or  其他岗位 =  \'" & e.DataRow("岗位") & ")")
        If count > 0 Then
            e.DataRow("人数") = count
        Else
            e.DataRow("人数") = Nothing
        End If
End Select


--  作者:deliangzhaoe
--  发布时间:2025/3/8 15:14:00
--  
我水平有限,只能做到这种程度啊。
--  作者:deliangzhaoe
--  发布时间:2025/3/8 16:19:00
--  
可以了。谢谢蓝老师指点。

Select Case e.DataCol.name
    Case "岗位"
        Dim count As Integer = DataTables("员工花名册").Compute("count(姓名)", "(企业名称 = \'" & e.DataRow("企业名称") & "\' And 现所在单位 =  \'" & e.DataRow("部门") & "\' And 岗位 =  \'" & e.DataRow("岗位") & "\' and 其他岗位 is null and 员工状态 = \'在岗\') or (企业名称 = \'" & e.DataRow("企业名称") & "\' and 其他岗位 is not null And 其他岗位 =  \'" & e.DataRow("岗位") & "\' and 员工状态 = \'在岗\')")
        If count > = 0 Then
            e.DataRow("人数") = count
        End If
End Select