以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]流水账相关  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=90325)

--  作者:陈嘉淳
--  发布时间:2016/9/9 20:33:00
--  [求助]流水账相关

代码如下

If e.DataCol.Name="第一列" Then
    If e.DataRow("_sortkey")=0 Then
        e.DataRow("第二列")=0-e.DataRow("第一列")
    Else
        Dim cunt As Integer = Tables("表A").Rows.Count
        For Each drs As DataRow In e.DataTable.Select("[_sortkey]>=" & e.DataRow("_sortkey"))
            Dim i As Integer= e.DataRow("_sortkey")
            Dim dr As DataRow= DataTables("表A").Find("[_sortkey]=" & i-1)
           e.DataRow("第二列")=dr("第二列")-e.DataRow("第一列")
           
        Next
    End If
End If

实现的是修改列一的数据得出列2的数据,列2=上一行列2-本行列1

想了很久实在是想不出来


--  作者:陈嘉淳
--  发布时间:2016/9/9 20:53:00
--  

If e.DataCol.Name="第一列" Then
    If e.DataRow("_sortkey")=0 Then
        e.DataRow("第二列")=0-e.DataRow("第一列")
    Else
        Dim cunt As Integer = Tables("表A").Rows.Count
        For i As Integer =e.DataRow("_sortkey") To cunt
            Dim dr As DataRow= DataTables("表A").Find("[_sortkey]=" & i-1)
            DataTables("表A").DataRows(i-1)("第二列")=dr("第二列")-DataTables("表A").DataRows(i-1)("第一列")
        Next
    End If
End If

 

最终还是想出来了,但是代码太繁琐了,希望大神指点一下


--  作者:有点蓝
--  发布时间:2016/9/10 8:56:00
--  
试试

If e.DataCol.Name="第一列" Then
    If e.DataRow("_sortkey")=0 Then
        e.DataRow("第二列")=0-e.DataRow("第一列")
    Else
        Dim drs As List(of DataRow)  = e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"),"_SortKey")
        Dim dr As DataRow= e.DataTable.Find("[_sortkey] < " & e.DataRow("_SortKey"),"_SortKey desc")
        drs(0)("第二列") = dr("第二列") - drs(0)("第一列")
        For i As Integer = 1 To drs.Count - 1
            drs(i)("第二列") = drs(i-1)("第二列") - drs(i)("第一列")
        Next
    End If
End If

--  作者:陈嘉淳
--  发布时间:2016/9/10 9:31:00
--  
谢谢,我昨天试了一下我自己的那段代码,不知道哪里还有问题,新插入的行不能正常运算,保存后就可以了
--  作者:有点蓝
--  发布时间:2016/9/10 9:49:00
--  
上例子测试