以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  GetValues合并问题  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=158099)

--  作者:狐表(小白)
--  发布时间:2020/11/8 11:25:00
--  GetValues合并问题
老师,你好,以下代码当“备注”列都是空值时,为什么相同的两行数据不能合并,把备注列加上一样的内容时就可以?
如何实现当相同行的备注列是空值时也能合并?谢谢!

\'合并小于1200数量为1来源相同相同规格线条
Dim ss As List(Of String()) = DataTables(eform.name & "_Table2").GetValues("产品分类|产品型号|工艺|基材|木皮|来源|备注")
Dim dr1,dr2 As DataRow
For Each s As String() In ss
    Dim drs1 As List(Of DataRow) = DataTables(eform.name & "_Table2").Select("产品分类 = \'" & s(0) & "\' and 产品型号 = \'" & s(1) & "\' and 工艺 = \'" & s(2) & "\' and 基材 = \'" & s(3) & "\' and 木皮 = \'" & s(4) & "\' and 来源 = \'" & s(5) & "\' and 备注 = \'" & s(6) & "\' and 高 <=1200 and 数量= 1 and 不并线 = 0 and 导入类型=\'套线\'","高")
     Do While drs1.Count > 1
        dr1 = drs1(0)
        dr2 = drs1(drs1.Count - 1)
        dr1("序")=DataTables(eform.name & "_Table2").Compute("Max(序)") + 1
        dr1("行")=DataTables(eform.name & "_Table2").Compute("Max(行)") + 1
        Dim f as string
        f = dr1("来源") & "," & dr2("来源")
        dr1("来源") = String.join(",",f.split(",").Distinct.ToArray)
        dr1("高") = dr1("高") + dr2("高")
        If dr1("高") <=1200 then 
           dr1("高")=1200
        ElseIf dr1("高")>1200 And dr1("高")<=1500 then 
           dr1("高")=1500
        ElseIf dr1("高")>1500 And dr1("高")<=1800 then 
           dr1("高")=1800
        ElseIf dr1("高")>1800 And dr1("高")<=2200 then
           dr1("高")=2200 
        ElseIf dr1("高")>2200 And dr1("高")<=2400 then
           dr1("高")=2400
        End If
        dr1("备注")=dr1("备注")
        drs1.Remove(dr1)
        drs1.Remove(dr2)
        dr2.Delete
    Loop
Next
Tables("木门销售订单二级_table2").Save
[此贴子已经被作者于2020/11/8 11:26:09编辑过]

--  作者:有点蓝
--  发布时间:2020/11/8 20:28:00
--  
dim filter as string = "产品分类 = \'" & s(0) & "\' and 产品型号 = \'" & s(1) & "\' and 工艺 = \'" & s(2) & "\' and 基材 = \'" & s(3) & "\' and 木皮 = \'" & s(4) & "\' and 来源 = \'" & s(5) & "\' and 高 <=1200 and 数量= 1 and 不并线 = 0 and 导入类型=\'套线\'"
if s(6) > "" then
filter = filter & " and 备注 = \'" & s(6) & "\'"
eles
filter = filter & " and 备注 is null "
end if
Dim drs1 As List(Of DataRow) = DataTables(eform.name & "_Table2").Select(filter ,"高")

--  作者:狐表(小白)
--  发布时间:2020/11/9 8:23:00
--  
谢谢
[此贴子已经被作者于2020/11/9 8:24:26编辑过]

--  作者:狐表(小白)
--  发布时间:2020/11/11 10:49:00
--  
老师,按照你指导的方法我在代码里运行了两次判断,通过调试发现代码在运行到下面红色字体代码时是执行不成功报错?什么原因?谢谢!遍历的表数据在附近里面。
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:附件.xls


图片点击可在新窗口打开查看此主题相关图片如下:10a83724-f85e-4831-b632-3ac159cae049.png
图片点击可在新窗口打开查看

第一次判断
\'合并小于等于1200数量为1来源和备注都相同的相同规格线条
Dim ss As List(Of String()) = DataTables(eform.name & "_Table2").GetValues("产品分类|产品型号|工艺|基材|木皮|来源|备注")
Dim dr1,dr2 As DataRow
For Each s As String() In ss
Dim filter as string = "产品分类 = \'" & s(0) & "\' and 产品型号 = \'" & s(1) & "\' and 工艺 = \'" & s(2) & "\' and 基材 = \'" & s(3) & "\' and 木皮 = \'" & s(4) & "\' and 来源 = \'" & s(5) & "\' and 高 <=1200 and 数量= 1 and 不并线 = 0 and 竖线 = 0 and 导入类型=\'套线\'"
If s(6) > "" then
    filter = filter & " and 备注 = \'" & s(6) & "\'"
Else
    filter = filter & " and 备注 is null "
End If
\'MessageBox.Show(8)
Dim drs1 As List(Of DataRow) = DataTables(eform.name & "_Table2").Select(filter,"高")
     Do While drs1.Count > 1
     \'MessageBox.Show(7)
        dr1 = drs1(0)
        dr2 = drs1(drs1.Count - 1)
        dr1("序")=DataTables(eform.name & "_Table2").Compute("Max(序)") + 1
        dr1("行")=DataTables(eform.name & "_Table2").Compute("Max(行)") + 1
        \'Dim f as string
        dr1("来源") = dr1("来源") & "," & dr2("来源")
        \'dr1("来源") = String.join(",",f.split(",").Distinct.ToArray)
        dr1("高") = dr1("高") + dr2("高")
        If dr1("高") <=1200 then 
           dr1("高")=1200
        ElseIf dr1("高")>1200 And dr1("高")<=1500 then 
           dr1("高")=1500
        ElseIf dr1("高")>1500 And dr1("高")<=1800 then 
           dr1("高")=1800
        ElseIf dr1("高")>1800 And dr1("高")<=2200 then
           dr1("高")=2200 
        ElseIf dr1("高")>2200 And dr1("高")<=2400 then
           dr1("高")=2400
        End If
        dr1("备注")=dr1("备注")
        drs1.Remove(dr1)
        drs1.Remove(dr2)
        dr2.Delete
        \'MessageBox.Show(6)
    Loop
Next
Tables(eform.name & "_Table2").Save

第二次判断
\'合并小于等于1200数量为1的来源不同备注相同的相同规格线条
Dim ss1 As List(Of String()) = DataTables(eform.name & "_Table2").GetValues("产品分类|产品型号|工艺|基材|木皮|备注")
Dim dr11,dr22 As DataRow
For Each s1 As String() In ss1
Dim filter1 as string = "产品分类 = \'" & s1(0) & "\' and 产品型号 = \'" & s1(1) & "\' and 工艺 = \'" & s1(2) & "\' and 基材 = \'" & s1(3) & "\' and 木皮 = \'" & s1(4) & "\' and 高 <=1200 and 数量= 1 and 不并线 = 0 and 竖线 = 0 and 导入类型=\'套线\'"
If s1(5) > "" then
    filter1 = filter1 & " and 备注 = \'" & s1(5) & "\'"
Else
    filter1 = filter1 & " and 备注 is null "
End If
Dim drs11 As List(Of DataRow) = DataTables(eform.name & "_Table2").Select(filter1,"高")
     Do While drs11.Count > 1
      \'MessageBox.Show(4)
        dr11 = drs11(0)
        dr22 = drs11(drs11.Count - 1)
        dr11("序")=DataTables(eform.name & "_Table2").Compute("Max(序)") + 1
        dr11("行")=DataTables(eform.name & "_Table2").Compute("Max(行)") + 1
        \'Dim f as string
        \'f = dr11("来源") & "," & dr22("来源")
        \'dr11("来源")=String.Join(",",f.ToArray)
        dr11("来源")= dr11("来源") & "," & dr22("来源")
        dr11("高") = dr11("高") + dr22("高")
        If dr11("高") <=1200 then
           dr11("高")=1200
        ElseIf dr11("高")>1200 And dr11("高")<=1500 then 
           dr11("高")=1500
        ElseIf dr11("高")>1500 And dr11("高")<=1800 then 
           dr11("高")=1800
        ElseIf dr11("高")>1800 And dr11("高")<=2200 then
           dr11("高")=2200 
        ElseIf dr11("高")>2200 And dr11("高")<=2400 then
           dr11("高")=2400
        End If
        dr1("备注")=dr1("备注")
        drs11.Remove(dr11)
        drs11.Remove(dr22)
        dr22.Delete
    Loop
Next
Tables(eform.name & "_Table2").Save
[此贴子已经被作者于2020/11/11 10:50:59编辑过]

--  作者:有点蓝
--  发布时间:2020/11/11 10:58:00
--  
去掉dr1("备注")=dr1("备注"),自己给自己赋值,完全没有意义
--  作者:狐表(小白)
--  发布时间:2020/11/11 12:53:00
--  
谢谢