以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=83343)

--  作者:yjd
--  发布时间:2016/4/6 20:17:00
--  [求助]
老师,我的代码如下,“已开通业务”是多值字段,包含若干选项,其中有一项是“网上银行”,我的数据源“wsyh.xls"内容如”
6611710000060716 网上银行
6611710007886848 网上银行
我希望达到,将“网上银行”选项勾选,不影响“已开通业务”多值字段其他选项的勾选。同时,Tables("对公客户明细")中没有相同“客户号”的记录不增加。谢谢老师!
If msgbox("网银数据导入可以更新已开通业务,是否进行导入?",65,"提示") = 1 Then
    Dim Book As New XLS.Book("D:\\khdaxt\\drgx\\wsyh.xls")
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Tables("对公客户明细").StopRedraw()
    Dim nms() As String = {"客户号","已开通业务"}
    For n As Integer = 0 To Sheet.Rows.Count -1
        Dim bh As String = sheet(n,0).Text
        Dim dr As DataRow = DataTables("对公客户明细").Find("客户号 = \'" & bh & "\'")
        For m As Integer = 0 To nms.Length - 1
            dr(nms(m)) = trim(Sheet(n,m).Value)
        Next
    Next
    Tables("对公客户明细").ResumeRedraw()
    msgbox("网银数据导入完毕!",64,"提示")
End If

--  作者:大红袍
--  发布时间:2016/4/6 20:50:00
--  
If msgbox("网银数据导入可以更新已开通业务,是否进行导入?",65,"提示") = 1 Then
    Dim Book As New XLS.Book("D:\\khdaxt\\drgx\\wsyh.xls")
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Tables("对公客户明细").StopRedraw()
    Dim nms() As String = {"客户号"}
    For n As Integer = 0 To Sheet.Rows.Count -1
        Dim bh As String = sheet(n,0).Text
        Dim dr As DataRow = DataTables("对公客户明细").Find("客户号 = \'" & bh & "\'")
        If dr Is Nothing Then
            dr = DataTables("对公客户明细").AddNew
           
        End If
        For m As Integer = 0 To nms.Length - 1
            dr(nms(m)) = trim(Sheet(n,m).Value)
        Next
        dr("已开通业务") = (dr("已开通业务") & "," & trim(Sheet(n,1).Value)).Trim(",")
    Next
    Tables("对公客户明细").ResumeRedraw()
    msgbox("网银数据导入完毕!",64,"提示")
End If

--  作者:yjd
--  发布时间:2016/4/6 21:29:00
--  
老师,没有实现xls表中有,Tables("对公客户明细")中没有相同“客户号”的记录不增加。另外,如果原多值字段已经勾选“网上银行”,执行代码后在“对公客户明细”表“已开通业务字段出现两个”网上银行“,怎样写代码实现原来已经勾选就不在重复添加。谢谢!
--  作者:大红袍
--  发布时间:2016/4/6 21:52:00
--  
If msgbox("网银数据导入可以更新已开通业务,是否进行导入?",65,"提示") = 1 Then
    Dim Book As New XLS.Book("D:\\khdaxt\\drgx\\wsyh.xls")
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Tables("对公客户明细").StopRedraw()
    Dim nms() As String = {"客户号"}
    For n As Integer = 0 To Sheet.Rows.Count -1
        Dim bh As String = sheet(n,0).Text
        Dim dr As DataRow = DataTables("对公客户明细").Find("客户号 = \'" & bh & "\'")
        \'        If dr Is Nothing Then
        \'            dr = DataTables("对公客户明细").AddNew
        \'        End If
        For m As Integer = 0 To nms.Length - 1
            dr(nms(m)) = trim(Sheet(n,m).Value)
        Next
        Dim s As String = trim(Sheet(n,1).Value)
        If dr("已开通业务").Contains(s) = False
            dr("已开通业务") = (dr("已开通业务") & "," & s).Trim(",")
        End If
    Next
    Tables("对公客户明细").ResumeRedraw()
    msgbox("网银数据导入完毕!",64,"提示")
End If

--  作者:yjd
--  发布时间:2016/4/6 22:17:00
--  
老师,没有实现xls表中有,而Tables("对公客户明细")中没有“客户号”的记录不增加。谢谢
--  作者:大红袍
--  发布时间:2016/4/6 22:28:00
--  
If msgbox("网银数据导入可以更新已开通业务,是否进行导入?",65,"提示") = 1 Then
    Dim Book As New XLS.Book("D:\\khdaxt\\drgx\\wsyh.xls")
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Tables("对公客户明细").StopRedraw()
    Dim nms() As String = {"客户号"}
    For n As Integer = 0 To Sheet.Rows.Count -1
        Dim bh As String = sheet(n,0).Text
        Dim dr As DataRow = DataTables("对公客户明细").Find("客户号 = \'" & bh & "\'")
        If dr IsNot Nothing Then
           
            For m As Integer = 0 To nms.Length - 1
                dr(nms(m)) = trim(Sheet(n,m).Value)
            Next
            Dim s As String = trim(Sheet(n,1).Value)
            If dr("已开通业务").Contains(s) = False
                dr("已开通业务") = (dr("已开通业务") & "," & s).Trim(",")
            End If
        End If
    Next
    Tables("对公客户明细").ResumeRedraw()
    msgbox("网银数据导入完毕!",64,"提示")
End If

--  作者:yjd
--  发布时间:2016/4/6 22:34:00
--  
谢谢老师!