以文本方式查看主题

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

--  作者:edisontsui
--  发布时间:2021/1/13 8:13:00
--  计算同一数据列有多少个相同的数据
If CurrentTable.name = "接头BOM"
    dim cnt as integer = 0
    Dim dr As DataRow
    Dim mr As DataRow = e.DataRow
    Dim drs As List(of DataRow)
    dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & ")
    drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & ")
    For i As Integer = 1 To drs.Count - 1
        If drs(i)("物料号") <> drs(i-1)("物料号")    
            cnt = cnt + 1
        End If
    Next
    if cnt >= 1
        messagebox.show("本页面存在两个以上不同的物料号!")
    end if
end if 

上述代码是放在菜单上一个按钮里面的,用于统计某个数据列“物料号”里面有多少个不同的物料号。但是无法保存此代码,说“错误代码:Dim mr As DataRow = e.DataRow”。请你帮我修改一下。谢谢。

--  作者:y2287958
--  发布时间:2021/1/13 8:27:00
--  
为何不用GetValues
--  作者:有点蓝
--  发布时间:2021/1/13 8:45:00
--  
先看看:http://www.foxtable.com/webhelp/topics/0604.htm,不同事件有不同的e参数,菜单按钮不存在e.DataTable、e.DataRow这种东西,使用GetValues一句代码就可以了

dim cnt as integer = DataTables("接头BOM").GetValues("物料号").count
    if cnt > 1
        messagebox.show("本页面存在" & cnt & "个以上不同的物料号!")
    end i

--  作者:edisontsui
--  发布时间:2021/1/14 7:55:00
--  
如果只要统计筛选后能看到的数据(而不是加载的全部数据),如何改写代码?
--  作者:y2287958
--  发布时间:2021/1/14 8:09:00
--  
加个条件,例如tables("表").filter
--  作者:有点蓝
--  发布时间:2021/1/14 9:04:00
--  
.GetValues("物料号",tables("接头BOM").filter)
--  作者:edisontsui
--  发布时间:2021/1/14 15:33:00
--  
        For Each r1 As Row In Tables("接头BOM").Rows
            Dim st1 As String = "45107-800-01"
            Dim dr1 As DataRow = DataTables("接头BOM").Find("原材料 = \'" & st1 & "\'")
            If dr1 IsNot Nothing AndAlso dr1.IsNull("杆数") = False
                dr1("数量") = dr1("杆数") * 2
                dr1("生产核对记录") = "已核对 " & User.Name & " " & Date.Now
            End If
        Next

上述代码我是希望在筛选后的数据行里面查找,但是红色那行代码要怎样修改才行呢?

--  作者:有点蓝
--  发布时间:2021/1/14 15:38:00
--  
Dim st1 As String = "45107-800-01"
Dim filter As String = Tables("接头BOM").filter
If filter > "" Then
    filter = filter & " and "
End If
filter = filter & " 原材料 = \'" & st1 & "\'"
Dim dr1 As DataRow = DataTables("接头BOM").Find(filter )
If dr1 IsNot Nothing AndAlso dr1.IsNull("杆数") = False
    dr1("数量") = dr1("杆数") * 2
    dr1("生产核对记录") = "已核对 " & User.Name & " " & Date.Now
End If

--  作者:edisontsui
--  发布时间:2021/1/15 19:44:00
--  
        Dim st3 As String = "45216-104"
        Dim filter3 As String = Tables("接头BOM").filter
        If filter3 > "" Then
            filter3 = filter3 & " and "
        End If
        filter3 = filter3 & " 原材料.substring(0,9) = \'" & st3 & "\'"
        Dim dr3 As DataRow = DataTables("接头BOM").Find(filter3)
        If dr3 IsNot Nothing 
            If dr3.IsNull("杆数") = False
                dr3("数量") = dr3("杆数")
                dr3("生产核对记录") = "自动核对 " & User.Name & " " & Date.Now
            End If
        End If

上述代码我是想找出 “45216-104” 字头的物料号, 请问 原材料.substring(0,9) 这里应该怎么写呢?谢谢。

--  作者:edisontsui
--  发布时间:2021/1/16 8:01:00
--  
我改成这样就可以了: 
filter3 = filter3 & " substring(原材料,1,9) = \'" & st3 & "\'"