以文本方式查看主题

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

--  作者:lgj716330
--  发布时间:2019/7/23 9:41:00
--  [求助]多值字段与集合问题
Dim Vals As List(of String())
Vals = DataTables("凭证辅助信息").GetValues("凭证种类|借方科目编码|贷方科目编码|借方指定辅助核算编码","[凭证种类] = \'" & tj6 & "\' ")

上面其中“借方科目编码”和“贷方科目编码”列是多值字段,要怎么处理

--  作者:有点蓝
--  发布时间:2019/7/23 10:00:00
--  
想要做什么处理?
--  作者:lgj716330
--  发布时间:2019/7/23 10:05:00
--  
Dim Vals As List(of String())
Vals = DataTables("凭证辅助信息").GetValues("借方科目编码|贷方科目编码","[凭证种类] = \'" & tj6 & "\' ")
假设借方科目编码有两个值,希望集合是“科目1|科目2”这样的形式

--  作者:有点蓝
--  发布时间:2019/7/23 10:20:00
--  
取值后在修改集合,或者使用的时候把逗号替换为竖线(|)
for i as integer = 0 to vals.count - 1
    vals(i)(0) = vals(i)(0).replace(",","|")
next

--  作者:lgj716330
--  发布时间:2019/7/23 12:32:00
--  
没搞定,项目有点大,不好上传,补充说明下
For Each dr As DataRow In DataTables("会计凭证导入").DataRows
        If dr.IsNull("借方金额") = False Then
            dr("科目编码") = Vals(i)(0)
希望最终结果是,如果Vals(i)(0),则取多值字段中的“科目1”,如果Vals(i)(1),则取多值字段中的“科目2”

--  作者:有点蓝
--  发布时间:2019/7/23 14:07:00
--  
贴出完整代码
--  作者:lgj716330
--  发布时间:2019/7/23 14:47:00
--  
Dim b1 As New SQLGroupTableBuilder("统计表2","客户销售汇总表")
b1.C
b1.AddTable("客户销售汇总表","经销商编号","客户档案","业务系统编号") 
b1.Groups.AddDef("总公司") 
b1.Totals.AddDef("吊牌金额") 

b1.Build 

Dim f1 As New Filler
f1.SourceTable = DataTables("统计表2") 
f1.SourceCols = "吊牌金额" 
f1.DataTable = DataTables("会计凭证导入") 
f1.DataCols = "贷方金额" 
f1.Fill() 

Dim Vals1 As List(of String())
Vals1 = DataTables("凭证辅助信息").GetValues("借方科目编码|贷方科目编码")’其中“贷方科目编码”是多值字段
For i As Integer = 0 To Vals1.Count - 1
    For Each dr As DataRow In DataTables("会计凭证导入").DataRows
        If dr.IsNull("贷方金额") = False Then
            dr("科目编码") = Vals1(i)(1) \'要求是多值字段“贷方科目编码”的第一个科目即科目1
        End If
    Next
Next

Dim b2 As New SQLGroupTableBuilder("统计表3","客户销售汇总表")
b2.C
b2.AddTable("客户销售汇总表","经销商编号","客户档案","业务系统编号")
b2.Groups.AddDef("总公司") 
b2.Totals.AddDef("吊牌金额") 
b2.Totals.AddDef("结算金额") 
b2.Totals.AddExp("折扣金额","结算金额 - 吊牌金额") 

b2.Build 

Dim f2 As New Filler
f2.SourceTable = DataTables("统计表3") 
f2.SourceCols = "折扣金额" 
f2.DataTable = DataTables("会计凭证导入") 
f2.DataCols = "贷方金额" 
f2.Fill() \'填充数据

Dim Vals2 As List(of String())
Vals2 = DataTables("凭证辅助信息").GetValues("借方科目编码|贷方科目编码") ’其中“贷方科目编码”是多值字段
For i As Integer = 0 To Vals2.Count - 1
    For Each dr As DataRow In DataTables("会计凭证导入").DataRows
        If dr.IsNull("贷方金额") = False And dr.IsNull("科目编码") = True Then
            dr("科目编码") = Vals2(i)(2) ‘要求是多值字段“贷方科目编码”的第二个科目即科目2
        End If
    Next
Next

--  作者:有点蓝
--  发布时间:2019/7/23 14:56:00
--  
Dim Vals1 As List(of String())
Vals1 = DataTables("凭证辅助信息").GetValues("借方科目编码|贷方科目编码")\'其中"贷方科目编码"是多值字段
For i As Integer = 0 To Vals1.Count - 1
    For Each dr As DataRow In DataTables("会计凭证导入").DataRows
        If dr.IsNull("贷方金额") = False Then
            dr("科目编码") = Vals1(i)(1).split(",")(0) \'要求是多值字段"贷方科目编码"的第一个科目即科目1
        End If
    Next
Next

Dim Vals2 As List(of String())
Vals2 = DataTables("凭证辅助信息").GetValues("借方科目编码|贷方科目编码") \'其中"贷方科目编码"是多值字段
For i As Integer = 0 To Vals2.Count - 1
    For Each dr As DataRow In DataTables("会计凭证导入").DataRows
        If dr.IsNull("贷方金额") = False And dr.IsNull("科目编码") = True Then
dim arr() as string = Vals2(i)(2).split(",")
if arr.length > 1
            dr("科目编码") = arr(1) \'要求是多值字段"贷方科目编码"的第二个科目即科目2
end if
        End If
    Next
Next

--  作者:lgj716330
--  发布时间:2019/7/24 9:13:00
--  
dim arr() as string = Vals2(i)(1).split(",")
这样就对了