以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  怎么实现是从DataTables(Vars("btname11"))表中查找T2表接收字段中如果有来源列数对应的值的 且是否唯一等于是 时 就跳过 反之是否唯一不等于是就新建呢?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=173273)

--  作者:cnsjroom
--  发布时间:2021/11/22 12:11:00
--  怎么实现是从DataTables(Vars("btname11"))表中查找T2表接收字段中如果有来源列数对应的值的 且是否唯一等于是 时 就跳过 反之是否唯一不等于是就新建呢?
怎么实现是从DataTables(Vars("btname11"))表中查找T2表接收字段中如果有来源列数对应的值的  且是否唯一等于是 时 就跳过   反之是否唯一不等于是就新建呢?

当前代码如下:
Dim r As Row
Dim i,j As Integer
Dim t1,t2 As Table
Dim str1,str2 As String
Dim str As String
t1 = Tables(Vars("btname11"))
t2 = e.form.Controls("Table1").Table
str1 = e.form.Controls("TextBox1").value
str2 = e.form.Controls("ComboBox1").value
Dim prb As WinForm.ProgressBar = e.Form.Controls("ProgressBar1")
If str1 = "" OrElse str2 = "" Then
    Return
End If
Dim Book As New XLS.Book(str1)
Dim Sheet As XLS.Sheet = Book.Sheets(str2)
If e.Form.Controls("CheckBox1").checked = False Then
    For Each r In t2.Rows
        If r.IsNull("来源字段") OrElse r.IsNull("接收字段") Then
            MessageBox.Show("字段匹配未完成!")
            Return
        End If
    Next
    prb.Visible = True
    prb.Maximum = Sheet.Rows.Count - 1
    
    
    Dim s11 As String
    For Each c1 As Col In t1.Cols
        s11 = s11 & "," & c1.name
    Next
    s11 = s11.trim(",")
    Dim cs As String =  s11
    msgbox(cs)
    
    
    Dim s22 As String
    Dim zd1 As New Dictionary(Of Integer, String)
    For i = 0 To Sheet.Cols.count - 1
        If Sheet(0,i).text > ""
            zd1.Add(i,Sheet(0,i).Value)
            s22 = s22 & "," &  Sheet(0,i).Value
        End If
    Next
    s22 = s22.trim(",")
    Dim cs22 As String =  s22
    msgbox(cs22)
    
    Dim filter As String = "1=2"
    Dim ss11() As String = s11.split(",")
    Dim s111 As String = ss11(0)
    
    Dim ss22() As String = s22.split(",")
    Dim s222 As String = ss22(0)
    
    For i11 As Integer = 0 To ss11.length -1
        For i22 As Integer = 0 To ss22.length -1
            filter = filter & " or " & ss11(i11) & " <> " & ss22(i22)
        Next
    Next
    msgbox(filter)
           
    For i = 1 To Sheet.Rows.Count -1
        Dim dr As DataRow = DataTables(Vars("btname11")).Find(filter)   \'在这里怎么写find条件
        If dr Is Nothing Then \'如果不存在同编号的订单
            r = t1.AddNew()
            For j = 0 To t2.Rows.count - 1
                Dim ss As String  =Sheet(i,t2.Rows(j)("来源列数")).Value
                r(t2.Rows(j)("接收字段")) = ss.Replace(" ", "").Trim
            Next
        Else
            MessageBox.Show("存在相同内容,即将跳过")
        End If
        prb.Value = i
    Next
    
    
Else
    For j = 0 To Sheet.Cols.count - 1
        If t1.cols.Contains(Sheet(0,j).value) Then
            If str = "" Then
                str = Sheet(0,j).value
                str = str.Replace(" ", "").Trim
            Else
                str = str & "," & Sheet(0,j).value
                str = str.Replace(" ", "").Trim
            End If
        End If
    Next
    If str = "" Then
        MessageBox.Show("对不起,没有匹配字段!")
        Return
    End If
    If MessageBox.Show("是否只导入匹配字段?","询问",MessageBoxButtons.YesNo,MessageBoxIcon.Question) = DialogResult.Yes Then
        prb.Visible = True
        prb.Maximum = Sheet.Rows.Count - 1
        For i = 1 To Sheet.Rows.Count -1
            r = t1.AddNew()
            For j = 0 To str.split(",").Length - 1
                Dim sss As String =Sheet(i,j).Value
                r(str.split(",")(j)) = sss.Replace(" ", "").Trim
            Next
            prb.Value = i
        Next
    Else
        Return
    End If
End If
t1.DataTable.save
MessageBox.Show("数据导入完毕!")
\'e.Form.close

上述得到的内容:
不想显示所有的表列名  只想显示对应已经选择了接收字段的匹配列名  其他没有匹配的不显示

想实现的预期效果不是如图这样的那么多字段内容,只想实现就已经选择的来源字段和接收字段之间的不存在重复值就如下:
怎么实现是从DataTables(Vars("btname11"))表中查找T2表接收字段中如果有来源列数对应的值的  且是否唯一等于是 时 就跳过   反之是否唯一不等于是就新建呢?
For i = 1 To Sheet.Rows.Count -1               
        Dim dr As DataRow = DataTables(Vars("btname11")).Find(“”)   \'在这里怎么写find条件
        If dr Is Nothing Then \'如果不存在同编号的订单
            r = t1.AddNew()
            For j = 0 To t2.Rows.count - 1
                  Dim ss As String  =Sheet(i,t2.Rows(j)("来源列数")).Value
                  r(t2.Rows(j)("接收字段")) = ss.Replace(" ", "").Trim
             Next
        Else
            MessageBox.Show("存在相同内容,即将跳过")
        End If
        prb.Value = i
 Next

--  作者:有点蓝
--  发布时间:2021/11/22 13:49:00
--  
使用字典记录需要的列名
--  作者:cnsjroom
--  发布时间:2021/11/22 18:43:00
--  回复:(有点蓝)使用字典记录需要的列名
Dim zd1 As New Dictionary(Of Integer, String)
zd1.Add(“a”,“b”)

具体怎么操作呢?还要麻烦老师指导下,谢谢!项目文件目前也发不上来

--  作者:有点蓝
--  发布时间:2021/11/22 20:22:00
--  
参考这里的用法,看看是怎么生成和勾选的列有关的条件的:http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=173261&skin=0
--  作者:cnsjroom
--  发布时间:2021/11/23 11:16:00
--  回复:(有点蓝)参考这里的用法,看看是怎么生成和勾...
还得麻烦老师指导下   看了一下  没有得到头绪
学习了复合选择框的方法   对于表操作没有头绪
    Dim s As String
    Dim filter As String
    Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
    Dim idx As Integer = 0
    For Each Index As Integer In l.CheckedIndices
        Dim c As String = l.Items(Index)
        s = s & "|" & c
        If filter > "" Then filter = filter & " and "
        If DataTables(Vars("btname")).datacols(c).IsNumeric
            filter = filter & c & "={" & idx & "}"
        ElseIf DataTables(Vars("btname")).datacols(c).IsDate
            filter = filter & c & "=#{" & idx & "}#"
        Else
            filter = filter & c & "=\'{" & idx & "}\'"
        End If
        idx += 1
    Next
    s = s.trim("|")
    Dim dr As DataRow
    生成"比对表"的代码
    For Each sr() As String In DataTables(Vars("btname")).GetValues(s)
        dr = DataTables(Vars("btname")).find(CExp(filter,sr))
        If dr IsNot Nothing Then
            Dim r As Row = Tables("比对表").addnew
            For Each dc As Col In Tables(Vars("btname")).Cols
                r(dc.name) = dr(dc.name)
            Next
        End If
    Next

--  作者:有点蓝
--  发布时间:2021/11/23 11:30:00
--  
一样的东西,遍历列表框【For Each Index As Integer In l.CheckedIndices】改为遍历来源列所在的表;获取列表框选择项【Dim c As String = l.Items(Index)】改为获取表格的遍历的行的来源列。
--  作者:cnsjroom
--  发布时间:2021/11/23 12:27:00
--  回复:(有点蓝)一样的东西,遍历列表框【For Each I...

还是没有成功实现,还得麻烦老师辛苦一下  谢谢!
Dim i,j As Integer
Dim t1,t2 As Table
Dim str1,str2 As String
Dim str As String
t1 = Tables(Vars("btname11"))
t2 = e.form.Controls("Table1").Table
str1 = e.form.Controls("TextBox1").value
str2 = e.form.Controls("ComboBox1").value
Dim s As String
Dim filter As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
Dim idx As Integer = 0
Dim Vals As List(of String)
Vals = t2.DataTable.GetValues("来源字段")
For Index As Integer = 0 To Vals.Count - 1
    Dim c As String = Vals(Index)
    MessageBox.Show(c)
    s = s & "|" & c
    If filter > "" Then filter = filter & " and "
    If DataTables(Vars("btname")).datacols(c).IsNumeric
        filter = filter & c & "={" & idx & "}"
    ElseIf DataTables(Vars("btname")).datacols(c).IsDate
        filter = filter & c & "=#{" & idx & "}#"
    Else
        filter = filter & c & "=\'{" & idx & "}\'"
    End If
    MessageBox.Show(filter)
    idx += 1
Next
s = s.trim("|")
MessageBox.Show(s)
Dim dr As DataRow
生成"比对表"的代码
For Each sr() As String In DataTables(Vars("btname")).GetValues(s)
    dr = DataTables(Vars("btname")).find(CExp(filter,sr))
    If dr IsNot Nothing Then
        Dim r As Row = Tables("比对表").addnew
        For Each dc As Col In Tables(Vars("btname")).Cols
            r(dc.name) = dr(dc.name)
        Next
    End If
Next


--  作者:有点蓝
--  发布时间:2021/11/23 13:36:00
--  
什么地方有问题?
--  作者:小蜜蜂wowo
--  发布时间:2021/11/23 13:56:00
--  
ddddddd
--  作者:cnsjroom
--  发布时间:2021/11/23 14:54:00
--  回复:(有点蓝)什么地方有问题?
错误提示:
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2020.5.29.8
错误所在事件:窗口,导入Excel,Button6,Click
详细错误信息:
重载决策失败,因为没有最适合这些参数的 Public“Item”: 
    \'Public ReadOnly Property Item(Index As Integer) As Foxtable.DataTable\':
        不是最特定的。
    \'Public ReadOnly Property Item(TableName As String) As Foxtable.DataTable\':
        不是最特定的。

图片点击可在新窗口打开查看此主题相关图片如下:12.gif
图片点击可在新窗口打开查看

当前代码:【table1是窗体表,来源字段来源列数都从这里获取】
Dim i,j As Integer
Dim t1,t2 As Table
Dim str1,str2 As String
Dim str As String
t1 = Tables(Vars("btname11"))
t2 = e.form.Controls("Table1").Table
str1 = e.form.Controls("TextBox1").value
str2 = e.form.Controls("ComboBox1").value
Dim s As String
Dim filter As String
Dim idx As Integer = 0
Dim Vals As List(of String)
Vals = t2.DataTable.GetValues("来源字段")
MessageBox.Show(Vals.Count)
For Index As Integer = 0 To Vals.Count - 1
    Dim c As String = Vals(Index)
    MessageBox.Show(c)
    MessageBox.Show(1)
    s = s & "|" & c
    MessageBox.Show(2)
    MessageBox.Show(s)
    If filter > "" Then filter = filter & " and "
    If DataTables(Vars("btname")).datacols(c).IsNumeric
        filter = filter & c & "={" & idx & "}"
    ElseIf DataTables(Vars("btname")).datacols(c).IsDate
        filter = filter & c & "=#{" & idx & "}#"
    Else
        filter = filter & c & "=\'{" & idx & "}\'"
    End If
    MessageBox.Show(filter)
    idx += 1
Next
s = s.trim("|")
MessageBox.Show(3)
MessageBox.Show(s)
Dim dr As DataRow
\'生成"比对表"的代码
\'For Each sr() As String In DataTables(Vars("btname")).GetValues(s)
\'dr = DataTables(Vars("btname")).find(CExp(filter,sr))
\'If dr IsNot Nothing Then
\'Dim r As Row = Tables("比对表").addnew
\'For Each dc As Col In Tables(Vars("btname")).Cols
\'r(dc.name) = dr(dc.name)
\'Next
\'End If
\'Next