以文本方式查看主题

-  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=159298)

--  作者:爱相随
--  发布时间:2020/12/21 17:07:00
--  多组合条件代码简化的问题
老师,下面代码是8个项目不同组合条件返回值(以下代码还没有循环完全,不同组合的循环),怎么简化相关代码呢??
Select e.DataCol.Name
    Case "客商名称","项目名称","收支项目","流量名称","部门名称","姓名","账户名称","自定义项目名称"
        If e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("流量名称") AndAlso e.DataRow.IsNull("部门名称") AndAlso e.DataRow.IsNull("姓名") AndAlso e.DataRow.IsNull("账户名称") AndAlso e.DataRow.IsNull("自定义项目名称")  Then
            e.DataRow("辅助项目") = Nothing
            
        Else
            Dim lb As String = e.DataRow("客商名称")
            If e.DataRow.IsNull("客商名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]" & "[收支:"  & e.DataRow("收支项目") & "]" & "[账户:" & e.DataRow("账户名称")& "]" & "[部门:" & e.DataRow("部门名称")& "]" & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称") & "]" & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"  
            ElseIf e.DataRow.IsNull("项目名称") Then
               e.DataRow("辅助项目") = "[客商:" & e.DataRow("客商名称") & "]" & "[收支:"  & e.DataRow("收支项目") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("收支项目") Then
               e.DataRow("辅助项目") = "[客商:" & e.DataRow("客商名称")  & "]" & "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("流量名称") Then
               e.DataRow("辅助项目") = "[客商:" & e.DataRow("客商名称")  & "]" & "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("部门名称") Then
               e.DataRow("辅助项目") = "[客商:" & e.DataRow("客商名称")  & "]" & "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("姓名") Then
               e.DataRow("辅助项目") = "[客商:" & e.DataRow("客商名称")  & "]" & "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("自定义项目名称") Then
               e.DataRow("辅助项目") = "[客商:" & e.DataRow("客商名称")  & "]" & "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[收支:" & e.DataRow("收支项目") & "]"
            ElseIf e.DataRow.IsNull("账户名称") Then
               e.DataRow("辅助项目") = "[客商:" & e.DataRow("客商名称")  & "]" & "[项目:" & e.DataRow("项目名称") & "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("项目名称") Then
               e.DataRow("辅助项目") = "[收支:"  & e.DataRow("收支项目") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("收支项目") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("部门名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("账户名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("流量名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("姓名") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[自定义项目:" & e.DataRow("自定义项目名称") 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[收支:" & e.DataRow("收支项目") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("项目名称") Then
               e.DataRow("辅助项目") = "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称")& "]"  & "[收支:" & e.DataRow("收支项目") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("部门名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称") & "]" 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("账户名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "现金流量:" & e.DataRow("流量名称") & "]" 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("姓名") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[收支:" & e.DataRow("收支项目")& "]"  & "[现金流量:" & e.DataRow("流量名称") & "]" 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("项目名称") Then
               e.DataRow("辅助项目") = "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("部门名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]" & "[职员:" & e.DataRow("姓名")& "]"  & "[现金流量:" & e.DataRow("流量名称") & "]" 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("账户名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[部门:" & e.DataRow("部门名称")& "]"  & "[职员:" & e.DataRow("姓名")& "]"  & "现金流量:" & e.DataRow("流量名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("姓名") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]" & "[现金流量:" & e.DataRow("流量名称") & "]" 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("姓名") AndAlso e.DataRow.IsNull("部门名称") Then
               e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称") & "]"  & "[账户:" & e.DataRow("账户名称")& "]" & "[现金流量:" & e.DataRow("流量名称") 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("姓名") AndAlso e.DataRow.IsNull("项目名称") Then
               e.DataRow("辅助项目") = "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]" & "[现金流量:" & e.DataRow("流量名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("姓名") AndAlso e.DataRow.IsNull("流量名称") Then
                e.DataRow("辅助项目") = "[账户:" & e.DataRow("账户名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]" & "[项目:" & e.DataRow("项目名称") & "]"
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("姓名") AndAlso e.DataRow.IsNull("流量名称") AndAlso e.DataRow.IsNull("账户名称") Then
                e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称")& "]"  & "[部门:" & e.DataRow("部门名称")& "]" 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("姓名") AndAlso e.DataRow.IsNull("流量名称") AndAlso e.DataRow.IsNull("部门名称") Then
                 e.DataRow("辅助项目") = "[项目:" & e.DataRow("项目名称")& "]"  & "[账户:" & e.DataRow("账户名称")& "]" 
            ElseIf e.DataRow.IsNull("客商名称") AndAlso e.DataRow.IsNull("自定义项目名称") AndAlso e.DataRow.IsNull("收支项目") AndAlso e.DataRow.IsNull("姓名") AndAlso e.DataRow.IsNull("流量名称") AndAlso e.DataRow.IsNull("部门名称") AndAlso e.DataRow.IsNull("项目名称") Then
                 e.DataRow("辅助项目") = "[账户:" & e.DataRow("账户名称")& "]" 
            End If
        End If
End Select

[此贴子已经被作者于2020/12/21 17:08:05编辑过]

--  作者:有点蓝
--  发布时间:2020/12/21 17:29:00
--  
dim s1() as string = {"客商名称","项目名称"}
dim s2() as string = {"客商","项目"}

dim str as string
for i as integer = 0 to s1.length - 1
if e.DataRow.IsNull(s1(i)) = false then
str = str  & "[" & d2(i) & ":" & e.DataRow(s1(i)) & "]"
end if
next
msgbox(str)
e.DataRow("辅助项目")  = str