以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  代码优化  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=142981)

--  作者:sjf1234
--  发布时间:2019/11/11 9:54:00
--  代码优化
我要统计员工出勤和工作内容,下表所提的周运维和月运维等是员工直接提交的表格,在表格统计行,如果提交工作内容为周运维,则周运维列自动等于;感觉这代码可以实现功能,但是太繁琐;有改进的可能吗?小白一枚,请谅解!
Select Case e.DataCol.Name
    Case "站点任务"
        Dim dr As DataRow = e.DataRow
        If e.DataRow ("站点任务") = "周运维" Then
            dr ("周运维") = 1
        Else
            dr ("周运维") = Nothing
        End If
        If e.DataRow("站点任务") = "月运维" Then
            dr ("月运维") = 1
        Else
            dr ("月运维") = Nothing
        End If
        If e.DataRow ("站点任务") = "季度运维" Then
            dr ("季度运维") = 1
        Else
            dr ("季度运维") = Nothing
        End If
        If e.DataRow ("站点任务") = "设备故障维修" Then
            dr ("设备故障维修") = 1
        Else
            dr ("设备故障维修") = Nothing
        End If
        If e.DataRow ("站点任务") = "质控考核" Then
            dr ("质控考核") = 1
        Else
            dr ("质控考核") = Nothing
        End If
        If e.DataRow ("站点任务") = "站点安装" Then
            dr ("站点安装") = 1
        Else
            dr ("站点安装") = Nothing
        End If
        If e.DataRow ("站点任务") = "站点调试" Then
            dr ("站点调试") = 1
        Else
            dr ("站点调试") = Nothing
        End If
        If e.DataRow ("站点任务") =  "年度巡检" Then
            dr ("年度巡检") = 1
        Else
            dr ("年度巡检") = Nothing
        End If
        If e.DataRow ("站点任务") =  "配合环保例行检查" Then
            dr ("配合环保例行检查") = 1
        Else
            dr ("配合环保例行检查") = Nothing
        End If
        If e.DataRow ("站点任务") = "其他" Then
            dr ("其他") = 1
        Else
            dr ("其他") = Nothing
        End If
End Select


--  作者:有点蓝
--  发布时间:2019/11/11 10:10:00
--  
dim str as string = {"周运维","月运维","季度运维"}
Dim dr As DataRow = e.DataRow
for each s as string in str
     dr (s) = IIF(e.DataRow ("站点任务") = s,1,Nothing)
next

--  作者:sjf1234
--  发布时间:2019/11/26 10:16:00
--  
老师,提示错误!
错误信息:编译错误,变量“dr”在封闭块中隐藏变量。

--  作者:有点蓝
--  发布时间:2019/11/26 10:17:00
--  
说明“dr”这个变量重复定义了,换个名称,比如:dr2,dr3......
--  作者:sjf1234
--  发布时间:2019/11/26 10:22:00
--  
又有新的报错,错误信息:类型”string的1维数组“的值无法转换为”string”
--  作者:sjf1234
--  发布时间:2019/11/26 10:29:00
--  
Dim str() As String = {"周运维","月运维","季度运维"}
Dim dr1 As DataRow = e.DataRow
For Each s As String In str
     dr1 (s) = IIF(e.DataRow ("站点任务") = s,1,Nothing)
Next
老师谢谢,重新修改了,现在可以用了,实在太感谢!

--  作者:sjf1234
--  发布时间:2019/11/26 12:43:00
--  
老师,还有一个小问题,如同同一天完成两个工作任务,
例如:站点任务列内容为“周运维;月运维,怎么写代码分别让”周运维列”自动=1,”月运维列"=1,这个是在同一表面的!

--  作者:有点蓝
--  发布时间:2019/11/26 13:40:00
--  
Dim str() As String = {"周运维","月运维","季度运维"}
Dim dr1 As DataRow = e.DataRow
For Each s As String In str
     dr1 (s) = IIF(e.DataRow ("站点任务") like "*" & s & "*",1,Nothing)
Next