以文本方式查看主题

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

--  作者:sanny
--  发布时间:2018/11/30 22:28:00
--  [求助]

 

版主,以下是选两条记录进行合并,反复测试黄色不对。Netweiht_Total 是通过表属性中表达式得出来的。它不让进行合并。

 

因为两条记录中的Netweight_PC 是不相同的,合并后想让Netweiht_Total 加总后再除以加总的数量,再得出一个Netweight_PC ,不知道如何修改,请帮忙一下,谢谢。

 

 

Dim t As Table = Tables("Shipment.customsinvoice")
Dim cr = t.Rows(t.BottomPosition )
For i As Integer = t.BottomPosition-1 To t.TopPosition Step -1
    If cr("ShippingNO") = t.Rows(i)("ShippingNO") AndAlso cr("NameinChinese") = t.Rows(i)("NameinChinese") AndAlso cr("Unit") = t.Rows(i)("unit") AndAlso cr("HS") = t.Rows(i)("HS")
        cr("Qty") += val(t.Rows(i)("Qty"))

        cr("TotalPrice") += val(t.Rows(i)("TotalPrice"))
        cr("PO_UnitPrice") += val(t.Rows(i)("TotalPrice"))/val(t.Rows(i)("Qty"))

        cr("GrossWeight_total") += val(t.Rows(i)("GrossWeight_Total"))
        cr("Netweight_Total") += val(t.Rows(i)("Netweight_Total"))
        cr("Netweight_PC") = cr("Netweight_total") /cr("Qty")


        t.Rows(i).delete
    Else
        cr = t.Rows(i)
    End If
Next


--  作者:有点蓝
--  发布时间:2018/11/30 22:50:00
--  
表达式列是不能使用代码进行赋值的。

Dim t As Table = Tables("Shipment.customsinvoice")
Dim cr = t.Rows(t.BottomPosition )
Dim Total As Double = cr("Netweight_Total")
For i As Integer = t.BottomPosition-1 To t.TopPosition Step -1
    If cr("ShippingNO") = t.Rows(i)("ShippingNO") AndAlso cr("NameinChinese") = t.Rows(i)("NameinChinese") AndAlso cr("Unit") = t.Rows(i)("unit") AndAlso cr("HS") = t.Rows(i)("HS")
        cr("Qty") += val(t.Rows(i)("Qty"))
        cr("TotalPrice") += val(t.Rows(i)("TotalPrice"))
        cr("PO_UnitPrice") += val(t.Rows(i)("TotalPrice"))/val(t.Rows(i)("Qty"))
        cr("GrossWeight_total") += val(t.Rows(i)("GrossWeight_Total"))
        Total += val(t.Rows(i)("Netweight_Total"))
        cr("Netweight_PC") = Total /cr("Qty")

        t.Rows(i).delete
    Else
        cr = t.Rows(i)
    End If
Next

--  作者:sanny
--  发布时间:2018/12/2 22:56:00
--  
版主,两条,三条或更多记录进行合并,其中一列每条记录的内容不同,比如 第一条是A,第二条是B,第三条是DDD,如果按现在的代码进行合并后,就会只取其中的一个内容,能帮忙把这些内容整到一起吗? 合并后该列中显示 A,B, DDD.. 如果几条记录的列内容相同就取一个,谢谢。
--  作者:有点甜
--  发布时间:2018/12/2 23:14:00
--  

1、你2楼的代码都是数值列累加,没有涉及字符列。

 

2、如果你需要字符列累加,改成比如 cr("Qty") &= t.Rows(i)("Qty") & ","


--  作者:sanny
--  发布时间:2018/12/3 11:41:00
--  
谢谢版主,便这个 逗号 , 位置不对,能帮忙调整一下吗
--  作者:sanny
--  发布时间:2018/12/3 11:42:00
--  

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

--  作者:sanny
--  发布时间:2018/12/3 11:43:00
--  
然后相同的,只取一次,可以吗?
--  作者:有点甜
--  发布时间:2018/12/3 13:07:00
--  
具体实例、代码分别贴出来测试。
--  作者:sanny
--  发布时间:2018/12/7 18:22:00
--  

再请问一下版主,如果要设定列字段 客户 为 AA 时才进行如下记录合并,能帮忙加一下吗?感谢。

 

 

Dim t As Table = Tables("Shipment.customsinvoice")
Dim cr = t.Rows(t.BottomPosition )
Dim Total As Double = cr("Netweight_Total")
For i As Integer = t.BottomPosition-1 To t.TopPosition Step -1
    If cr("ShippingNO") = t.Rows(i)("ShippingNO") AndAlso cr("NameinChinese") = t.Rows(i)("NameinChinese") AndAlso cr("Unit") = t.Rows(i)("unit") AndAlso cr("HS") = t.Rows(i)("HS")
        cr("Qty") += val(t.Rows(i)("Qty"))
        cr("TotalPrice") += val(t.Rows(i)("TotalPrice"))
        cr("PO_UnitPrice") += val(t.Rows(i)("TotalPrice"))/val(t.Rows(i)("Qty"))
        cr("GrossWeight_total") += val(t.Rows(i)("GrossWeight_Total"))
        Total += val(t.Rows(i)("Netweight_Total"))
        cr("Netweight_PC") = Total /cr("Qty")

        t.Rows(i).delete
    Else
        cr = t.Rows(i)
    End If
Next

--  作者:有点蓝
--  发布时间:2018/12/7 20:03:00
--  
If t.Rows(i)("客户") = "AA" andalso cr("ShippingNO") = t.Rows(i)("ShippingNO") AndAlso cr("NameinChinese") = t.Rows(i)("NameinChinese") AndAlso cr("Unit") = t.Rows(i)("unit") AndAlso cr("HS") = t.Rows(i)("HS")