以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  限制了一样的不能导入,不起效果,请老师帮忙看看  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=121324)

--  作者:xxfoxtable
--  发布时间:2018/7/3 23:49:00
--  限制了一样的不能导入,不起效果,请老师帮忙看看
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目1.rar

原来是sql数据库,不方便传,变成了内部数据库

--  作者:有点甜
--  发布时间:2018/7/4 9:15:00
--  
不理解你的问题,你要实现什么功能?我测试可以导入数据。
--  作者:xxfoxtable
--  发布时间:2018/7/4 9:29:00
--  

约束了重复的不能导入,不能导入才对,导入了就不对了


--  作者:有点甜
--  发布时间:2018/7/4 11:00:00
--  

Dim dlg As new OpenFileDialog
    dlg.Filter = "Excel文件|*.xls"
    Dim fl As String
    If dlg.ShowDialog = DialogResult.OK Then
        fl = dlg.FileName
        Vars("rz")=True
        Dim dic As Dictionary(Of String ,String)
        \'Dim cmd As new SQLCommand
        \'cmd.CommandText = "select * From {khda}"
        \'Dim dt As DataTable = cmd.ExecuteReader(True)
        Dim book As new XLS.Book(fl)
        Dim sheet As XLS.Sheet = book.Sheets("sheet1")
        If sheet(0,1).Value<>"品名" Then
            msgbox("第一列品名不匹配")
            Return
        End If
        If sheet(0,2).Value<>"封装" Then
            msgbox("第二列封装不匹配")
            Return
        End If
        DataTables("销售").StopRedraw()
        Dim bz As Integer=0
        Dim d As Double
        Dim nms() As String = {"品名","封装","数量","单价","金额","仓库","区域","电话","备注"}
        For n As Integer = 1 To Sheet.Rows.Count -1
            If Sheet(n,1).Value=""
                Exit For
            End If
            Dim filter As String
            Dim filter1 As String
            If Sheet(n,2).Value Is Nothing Then
                filter = "品名 =\'" & Sheet(n,1).Value.Replace("*", "[*]").Replace("\'", "\'\'").Replace("%", "[%]")  & "\' and 封装 Is null and 单价=" & Sheet(n,4).Value & " And (仓库<>\'现货\' or 仓库 is null)"
                filter1 = "品名 =\'" & Sheet(n,1).Value.Replace("*", "[*]").Replace("\'", "\'\'").Replace("%", "[%]")   & "\' and 封装 Is null and (仓库<>\'现货\'  or 仓库 is null)"
               
            Else
                filter = "品名 =\'" & Sheet(n,1).Value.Replace("*", "[*]").Replace("\'", "\'\'").Replace("%", "[%]")   & "\' and 封装=\'" & Sheet(n,2).Value  &"\' And 单价=" & Sheet(n,4).Value & " And (仓库<>\'现货\'  or 仓库 is null)"
                filter1 = "品名 =\'" & Sheet(n,1).Value.Replace("*", "[*]").Replace("\'", "\'\'").Replace("%", "[%]") &"\'   And 封装=\'" & Sheet(n,2).Value  &"\' And (仓库<>\'现货\'  or 仓库 is null)"
            End If
            \'For Each pc As DataRow In DataTables("销售").Select("品名=\'" & Sheet(n,1).Value.Replace("*", "[*]").Replace("\'", "\'\'").Replace("%", "[%]") &"\' And 封装=\'" & Sheet(n,2).Value &"\' and (仓库<>\'现货\'  or 仓库 is null)")
            Dim pc As DataRow = DataTables("销售").find(filter)
            \'If (pc("单价")-Sheet(n,4).Value)>0  Or pc Is Nothing
            If pc Is Nothing
                Dim dr As DataRow =  DataTables("销售").AddNew()
                For m As Integer = 0 To nms.Length-1
                   
                    Select Case m
                        Case 0,1
                            dr(nms(m)) = Sheet(n,m+1).Value.trim().replace(chr(10), "").replace(chr(13), "")
                        Case 2,3,4
                            If Sheet(n,m+1).Value=""  Or Sheet(n,m+1).Value.trim="" Then
                            Else
                                If Double.TryParse(Sheet(n,m+1).Value, d)
                                    dr(nms(m)) = Sheet(n,m+1).Value
                                Else
                                    msgbox("行"& n & "列" & m+1 & "显示为" &Sheet(n,m+1).Value & "不是数值,记住后,请更改")
                                End If
                            End If
                        Case Else
                            dr(nms(m)) = Sheet(n,m+1).Value
                           
                    End Select
                Next
                dr.save
                Sheet(n,13).Value  ="导入成功"
               
               
                book.Save(fl)
                Dim zd As Integer
                Dim dj As Long=0
                Do While DataTables("销售").Select(filter1).Count>3
                    For Each cf As DataRow In DataTables("销售").Select(filter1)
                        If dj<cf("单价")
                            dj=cf("单价")
                            zd=cf("_identify")
                        End If
                    Next
                    DataTables("销售").DeleteFor("_identify=\'" & zd &"\'")
                Loop
            Else
                Sheet(n,13).Value  ="重复未导入!!"
            End If
        Next
        DataTables("销售").Save
        \'DataTables("销售").DeleteFor("品名 is null")
        \'DataTables("销售").Save
        Tables("销售").ResumeRedraw()
        msgbox("导入完成!!")
        Tables("销售").Sort="仓库"
        DataTables("销售").LoadFilter=""
        DataTables("销售").load

        Vars("rz")=False
    Else
        Return
    End If


--  作者:xxfoxtable
--  发布时间:2018/7/4 11:15:00
--  
Do While DataTables("销售").Select(filter1).Count>3
                    For Each cf As DataRow In DataTables("销售").Select(filter1)
                        If dj<cf("单价")
                            dj=cf("单价")
                            zd=cf("_identify")
                        End If
                    Next
                    DataTables("销售").DeleteFor("_identify=\'" & zd &"\'")
                Loop
这部分语句,我写的对吗?我看不是我想要的结果呢
--  作者:有点甜
--  发布时间:2018/7/4 11:36:00
--  

你这段代码,要实现什么功能?删除单价大于dj变量的行?

 

If DataTables("销售").Select(filter1).Count>3 Then

    DataTables("销售").DeleteFor("单价 > " & dj & " and " & filter1)

End If


--  作者:xxfoxtable
--  发布时间:2018/7/4 11:58:00
--  
不是,就是数据库中保留三条相同记录,多于三条记录时,删除单价最大的记录
--  作者:有点甜
--  发布时间:2018/7/4 12:22:00
--  

 

If DataTables("销售").Select(filter1).Count>3 Then

    Dim fdr As DataRow = DataTables("销售").find(filter1, "单价 desc")

    fdr.delete

End If