Foxtable(狐表)用户栏目专家坐堂 → 请问我有一个文件,如何导入


  共有4852人关注过本帖树形打印复制链接

主题:请问我有一个文件,如何导入

帅哥哟,离线,有人找我吗?
hongyefor
  21楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/7/26 13:36:00 [只看该作者]

如果多次导入的话会数据会重复,这个怎么办啊,因为里面自身就有重复的内容,用什么方法解决

[此贴子已经被作者于2016/7/26 13:36:41编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  22楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/7/26 13:53:00 [只看该作者]

Dim dlg As new FolderBrowserDialog
If dlg.ShowDialog = DialogResult.Ok Then
    Tables("表a").StopRedraw
    For Each dir As String In FileSys.GetDirectories(dlg.SelectedPath)
        For Each f As String In FileSys.GetFiles(dir)
            If f.EndsWith("_verifysign.log") Then
                Dim txt As String = FileSys.ReadAllText(f, Encoding.Default)
                Dim idx As Integer = txt.LastIndexOf("</business>")
               
                Dim s1 As String = txt.SubString(0, idx+11)
                Dim s2 As String = txt.SubString(idx+12)
                Dim xmlDoc As New System.XML.XmlDocument
                xmlDoc.Loadxml(s1)
               
                Dim ndList  = xmlDoc.GetElementsByTagName("input")
               
               
                Dim fphm As String
                Dim xhdwmc As String
                Dim fpzt As String
                For i As Integer = 0 To ndList.count - 1
                    If ndList(i).Item("fphm") IsNot Nothing Then fphm = ndList(i).Item("fphm").InnerText
                    If ndList(i).Item("xhdwmc") IsNot Nothing Then xhdwmc = ndList(i).Item("xhdwmc").InnerText
                    If ndList(i).Item("fpzt") IsNot Nothing Then fpzt = ndList(i).Item("fpzt").InnerText
                Next
                If fphm <> Nothing Then
                    ndList = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes
                    For i As Integer = 0 To ndList.count - 1
                        Dim spmc As String = ndList(i).Item("spmc").InnerText
                        Dim se As String = ndList(i).Item("se").InnerText
                        Dim dw As String = ndList(i).Item("dw").InnerText
                        Dim spsl As String = ndList(i).Item("spsl").InnerText
                        Dim dj As String = ndList(i).Item("dj").InnerText
                        Dim je As String = ndList(i).Item("je").InnerText
                        Dim r As Row = Tables("表A").AddNew
                        r("第一列") = fphm
                        r("第二列") = xhdwmc
                        r("第三列") =spmc
                        r("第四列") =spsl
                        r("第五列") = dw
                        r("第六列") = se
                        r("第七列") = dj
                        r("第八列") = je
                        r("第九列") = fpzt
                        r("第十列") = dlg.FileName
                    Next
                End If
            End If
        Next
    Next
    Tables("表a").ResumeRedraw
End If
For Each s As String In DataTables("表A").GetValues("第一列", "第九列 = '3'")
    DataTables("表A").DeleteFor("第一列 = '" & s & "' and 第九列 = '0'")
Next
If DataTables("表A").HasChanges Then
    DataTables("表A").Save
End If

 

 

这个这样错了吗?,错在哪里啊


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  23楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/26 14:31:00 [只看该作者]

 删除重复,参考

 

Dim idx As String = "-1,"
Dim idx_temp As String = ""
Dim pdr As DataRow = Nothing
Dim count As Integer = 0
Dim cs As String = "第一列,第二列"
For Each dr As DataRow In DataTables("表A").Select("", cs)
    Dim flag As Boolean = False
    If pdr IsNot Nothing Then
        For Each c As String In cs.split(",")
            If pdr(c).replace(" ","") <> dr(c).replace(" ", "") Then
                flag = True
                Exit For
            End If
        Next
        If flag Then
            If count > 1 Then
                idx &= idx_temp
            End If
            count = 1
            idx_temp = ""
        Else
            count += 1
            idx_temp &= dr("_Identify") & ","
        End If
    Else
        count += 1
    End If
    pdr = dr
Next

If count > 1 Then
    idx &= idx_temp
End If

 

DataTables("表A").DeleteFor("_Identify not In (" & idx.trim(",") & ")")


 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  24楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/7/27 11:38:00 [只看该作者]

按照上面的删除重复的代码可能,没有办法适用,我的想法是分两个表,一个是明细表(表A),还有一个是主表(表B)

将文件名导入到主表的“文件名”列

当导入数据时先查找“文件名”列,是否有该文件名存在,如果没有则导入,否则跳过

不会写代码,帮我改一下吧

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目119.foxdb


 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:signlog.part1.rar

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:signlog.part2.rar


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  25楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/27 12:18:00 [只看该作者]

请去看懂之前的代码。如果要判断,直接find即可,比如

 

If DataTables("某表").Find("某列 = '" & fphm & "'") Is Nothing Then

 

End If


 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  26楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/7/27 13:05:00 [只看该作者]

导入文件名称到“表B”的“文件名”列,这个代码不会写啊图片点击可在新窗口打开查看


 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  27楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/7/27 13:26:00 [只看该作者]

 

 

帮我看看,这个代码对吗?

 

Dim dlg As new FolderBrowserDialog
If dlg.ShowDialog = DialogResult.Ok Then
    Tables("表a").StopRedraw
    For Each dir As String In FileSys.GetDirectories(dlg.SelectedPath)
        For Each f As String In FileSys.GetFiles(dir)
            If DataTables("表B").Find("文件名 = '" & f & "'") Is Nothing Then
                If f.EndsWith("_verifysign.log") Then
                    Dim txt As String = FileSys.ReadAllText(f, Encoding.Default)
                    Dim idx As Integer = txt.LastIndexOf("</business>")                   
                    Dim s1 As String = txt.SubString(0, idx+11)
                    Dim s2 As String = txt.SubString(idx+12)
                    Dim xmlDoc As New System.XML.XmlDocument
                    xmlDoc.Loadxml(s1)                   
                    Dim ndList  = xmlDoc.GetElementsByTagName("input")                                       
                    Dim fphm As String
                    Dim ghdwmc As String
                    Dim fpzt As String
                    For i As Integer = 0 To ndList.count - 1
                        If ndList(i).Item("fphm") IsNot Nothing Then fphm = ndList(i).Item("fphm").InnerText
                        If ndList(i).Item("ghdwmc") IsNot Nothing Then ghdwmc = ndList(i).Item("ghdwmc").InnerText
                        If ndList(i).Item("fpzt") IsNot Nothing Then fpzt = ndList(i).Item("fpzt").InnerText                       
                    Next
                    If fphm <> Nothing Then
                        ndList = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes
                        For i As Integer = 0 To ndList.count - 1
                            Dim spmc As String = ndList(i).Item("spmc").InnerText
                            Dim se As String = ndList(i).Item("se").InnerText
                            Dim dw As String = ndList(i).Item("dw").InnerText
                            Dim spsl As String = ndList(i).Item("spsl").InnerText
                            Dim dj As String = ndList(i).Item("dj").InnerText
                            Dim je As String = ndList(i).Item("je").InnerText
                            Dim r As Row = Tables("表A").AddNew
                            r("第一列") = fphm
                            r("第二列") = ghdwmc
                            r("第三列") =spmc
                            r("第四列") =spsl
                            r("第五列") = dw
                            r("第六列") = se
                            r("第七列") = dj
                            r("第八列") = je
                            r("第九列") = fpzt
                        Next
                    End If
                End If
            End If
        Next
    Next
    Tables("表a").ResumeRedraw


 回到顶部
帅哥哟,离线,有人找我吗?
hongyefor
  28楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:二尾狐 帖子:524 积分:3676 威望:0 精华:0 注册:2012/7/27 10:28:00
  发帖心情 Post By:2016/7/27 13:27:00 [只看该作者]

    Tables("表b").StopRedraw
    For Each dir As String In FileSys.GetDirectories(dlg.SelectedPath)
        For Each f As String In FileSys.GetFiles(dir)
            If DataTables("表B").Find("文件名 = '" & f & "'") Is Nothing Then              
                If f.EndsWith("_verifysign.log") Then
                    Dim txt As String = FileSys.ReadAllText(f, Encoding.Default)
                    Dim idx As Integer = txt.LastIndexOf("</business>")                  
                    Dim s1 As String = txt.SubString(0, idx+11)
                    Dim s2 As String = txt.SubString(idx+12)
                    Dim xmlDoc As New System.XML.XmlDocument
                    xmlDoc.Loadxml(s1)                   
                    Dim ndList  = xmlDoc.GetElementsByTagName("input")                   
                    Dim kprq As String
                    Dim fphm As String
                    Dim ghdwmc As String
                    Dim ghdwdzdh As String
                    Dim ghdwsbh As String
                    Dim ghdwyhzh As String
                    Dim hjje As String
                    Dim hjse As String
                    Dim jshj As String
                    Dim fpzt As String
                    For i As Integer = 0 To ndList.count - 1
                        If ndList(i).Item("kprq") IsNot Nothing Then kprq = ndList(i).Item("kprq").InnerText
                        If ndList(i).Item("fphm") IsNot Nothing Then fphm = ndList(i).Item("fphm").InnerText
                        If ndList(i).Item("ghdwmc") IsNot Nothing Then ghdwmc = ndList(i).Item("ghdwmc").InnerText
                        If ndList(i).Item("ghdwdzdh") IsNot Nothing Then ghdwdzdh = ndList(i).Item("ghdwdzdh").InnerText
                        If ndList(i).Item("ghdwsbh") IsNot Nothing Then ghdwsbh = ndList(i).Item("ghdwsbh").InnerText
                        If ndList(i).Item("ghdwyhzh") IsNot Nothing Then ghdwyhzh = ndList(i).Item("ghdwyhzh").InnerText
                        If ndList(i).Item("hjje") IsNot Nothing Then hjje = ndList(i).Item("hjje").InnerText
                        If ndList(i).Item("hjse") IsNot Nothing Then hjse = ndList(i).Item("hjse").InnerText
                        If ndList(i).Item("jshj") IsNot Nothing Then jshj = ndList(i).Item("jshj").InnerText
                        If ndList(i).Item("fpzt") IsNot Nothing Then fpzt = ndList(i).Item("fpzt").InnerText
                        ndList = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes
                        Dim r As Row = Tables("表b").AddNew
                        r("第一列") = kprq
                        r("第二列") = fphm
                        r("第三列") =ghdwmc
                        r("第四列") =ghdwdzdh
                        r("第五列") = ghdwsbh
                        r("第六列") = ghdwyhzh
                        r("第七列") = hjje
                        r("第八列") = hjse
                        r("第九列") = jshj
                        r("第十列") = fpzt
                        r("文件名") = f
                    Next
                End If
            End If
        Next
    Next
    Tables("表b").ResumeRedraw
MessageBox.Show("fa piao导入完成")   
End If

For Each s As String In DataTables("表A").GetValues("第一列", "第九列 = '3'")
    DataTables("表A").DeleteFor("第一列 = '" & s & "' and 第九列 = '0'")
Next

DataTables("表b").DeleteFor(" 第十列 = '2'")
For Each s1 As String In DataTables("表B").GetValues("第二列", "第十列 = '3'")
    DataTables("表B").DeleteFor("第二列 = '" & s1 & "' and 第十列 = '0'")
Next

If DataTables("表A").HasChanges Then
    DataTables("表A").Save
End If
If DataTables("表B").HasChanges Then
    DataTables("表B").Save
End If


 回到顶部
帅哥哟,离线,有人找我吗?
大红袍
  29楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/7/27 14:51:00 [只看该作者]

参考代码

 

Dim dlg As new FolderBrowserDialog
If dlg.ShowDialog = DialogResult.Ok Then
    Tables("表a").StopRedraw
    For Each dir As String In FileSys.GetDirectories(dlg.SelectedPath)
        For Each f As String In FileSys.GetFiles(dir)
            If f.EndsWith("_verifysign.log") Then
                If DataTables("表B").Find("文件名 = '" & FileSys.GetName(f) & "'") Is Nothing Then
                    Dim txt As String = FileSys.ReadAllText(f, Encoding.Default)
                    Dim idx As Integer = txt.IndexOf("</business>")
                   
                    Dim s1 As String = txt.SubString(0, idx+11)
                    Dim s2 As String = txt.SubString(idx+12)
                    Dim xmlDoc As New System.XML.XmlDocument
                    xmlDoc.Loadxml(s1)
                   
                    Dim ndList  = xmlDoc.GetElementsByTagName("input")
                   
                   
                    Dim fphm As String
                    Dim xhdwmc As String
                    For i As Integer = 0 To ndList.count - 1
                        If ndList(i).Item("fphm") IsNot Nothing Then fphm = ndList(i).Item("fphm").InnerText
                        If ndList(i).Item("xhdwmc") IsNot Nothing Then xhdwmc = ndList(i).Item("xhdwmc").InnerText
                    Next
                    If fphm <> Nothing Then
                        Dim ndr As DataRow = DataTables("表B").addnew
                        ndr("第二列") = fphm
                        ndr("第三列") = xhdwmc
                        ndr("文件名") = FileSys.GetName(f)
                        ndList = xmlDoc.GetElementsByTagName("fyxm")(0).ChildNodes
                        For i As Integer = 0 To ndList.count - 1
                            Dim spmc As String = ndList(i).Item("spmc").InnerText
                            Dim se As String = ndList(i).Item("se").InnerText
                            Dim dw As String = ndList(i).Item("dw").InnerText
                            Dim spsl As String = ndList(i).Item("spsl").InnerText
                            Dim dj As String = ndList(i).Item("dj").InnerText
                            Dim je As String = ndList(i).Item("je").InnerText
                            Dim r As Row = Tables("表A").AddNew
                            r("第一列") = fphm
                            r("第二列") = xhdwmc
                            r("第三列") =spmc
                            r("第四列") =spsl
                            r("第五列") = dw
                            r("第六列") = se
                            r("第七列") = dj
                            r("第八列") = je
                           
                        Next
                    End If
                End If
            End If
        Next
    Next
    Tables("表a").ResumeRedraw
End If


 回到顶部
总数 29 上一页 1 2 3