以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  求助:流水账代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=53771)

--  作者:爱相随
--  发布时间:2014/7/15 10:29:00
--  求助:流水账代码
老师,我要做一个流水账,有:项目名称、工程单位名称、费用类另、费用类别1、进度金额、累计进度等列,现在要做一个流水账,当“项目名称、工程单位名称、费用类别、费用类别1”相同时,才进行累计进度,因为同一个工程单位可能对同一个项目的不同工程进行施工,所以需要这么多条件。我根据帮助里的代码修改后的代码如下:
Select Case e.DataCol.Name
    Case "项目名称","工程单位名称","费用类别","费用类别1","进度金额"
        Dim dr As DataRow
        Dim mr As DataRow = e.DataRow
        Dim drs As List(of DataRow)
        dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & mr("项目名称") & " And [工程单位名称] = \'" & mr("工程单位名称") & " And [费用类别] = \'" & mr("费用类别") & " And [费用类别1] = \'" & mr("费用类别1") & "\'", "[_SortKey] Desc")
        If dr Is Nothing Then
            mr("累计进度") = mr("进度金额") 
            dr = mr
        End If
        drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & " And [工程单位名称] = \'" & dr("工程单位名称") & " And [费用类别] = \'" & dr("费用类别") &  " And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
        For i As Integer = 1 To drs.Count - 1
            drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额") 
        Next
        If e.DataCol.Name = "项目名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & e.OldValue & " And [工程单位名称] = \'" & e.OldValue & " And [费用类别] = \'" & e.OldValue & " And [费用类别1] = \'" & e.OldValue & "\'", "[_SortKey] Desc")
            If dr Is Nothing Then
                dr = e.DataTable.Find("[项目名称] = \'" & e.OldValue & "And [工程单位名称] = \'" & e.OldValue & "And [费用类别] = \'" & e.OldValue & "And [费用类别1] = \'" & e.OldValue & "\'", "[_SortKey]")
                If dr IsNot Nothing Then
                    dr("累计进度") = dr("进度金额") 
                End If
            End If
            If dr IsNot Nothing Then
                drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & " And [工程单位名称] = \'" & dr("工程单位名称") & " And [费用类别] = \'" & dr("费用类别") & " And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                For i As Integer = 1 To drs.Count - 1
                    drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额") 
                Next
            End If
        End If
End Select

Dim Key As Decimal
Dim Index As Integer
Dim Filter As String
Dim r As Row
Index = Math.Min(e.OldIndex, e.NewIndex)
Key = e.Table.Rows(Index)("_SortKey")
r = e.Table.Rows(e.NewIndex)
Filter = "[_SortKey] >= " & Key & " And [项目名称] = \'" & r("项目名称") &  " And [工程单位名称] = \'" & r("工程单位名称") &  " And [费用类别] = \'" & r("费用类别") &  " And [费用类别1] = \'" & r("费用类别1") & "\'"
e.Table.DataTable.DataCols("进度金额").RaiseDataColChanged(Filter)



e.DataRow("进度金额") = 0



当重置列时提示编译错误:
.NET Framework 版本:2.0.50727.3053
Foxtable 版本:2014.5.12.1
错误所在事件:表,进度信息表, DataColChanged
详细错误信息:
Exception has been thrown by the target of an invocation.
Syntax error: Missing operand after \'江苏太平洋建设有限公司\' operator.


就是“工程单位名称”这个地方有错,请老师和高手帮助指点,很感谢。
[此贴子已经被作者于2014-7-15 10:31:27编辑过]

--  作者:有点甜
--  发布时间:2014/7/15 10:37:00
--  

Select Case e.DataCol.Name
    Case "项目名称","工程单位名称","费用类别","费用类别1","进度金额"
        Dim dr As DataRow
        Dim mr As DataRow = e.DataRow
        Dim drs As List(of DataRow)
        dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & mr("项目名称") & "\' And [工程单位名称] = \'" & mr("工程单位名称") & "\' And [费用类别] = \'" & mr("费用类别") & "\' And [费用类别1] = \'" & mr("费用类别1") & "\'", "[_SortKey] Desc")
        If dr Is Nothing Then
            mr("累计进度") = mr("进度金额")
            dr = mr
        End If
        drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
        For i As Integer = 1 To drs.Count - 1
            drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
        Next
        If e.DataCol.Name = "项目名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & e.OldValue & "\' And [工程单位名称] = \'" & e.OldValue & "\' And [费用类别] = \'" & e.OldValue & "\' And [费用类别1] = \'" & e.OldValue & "\'", "[_SortKey] Desc")
            If dr Is Nothing Then
                dr = e.DataTable.Find("[项目名称] = \'" & e.OldValue & "And [工程单位名称] = \'" & e.OldValue & "\' And [费用类别] = \'" & e.OldValue & "\' And [费用类别1] = \'" & e.OldValue & "\'", "[_SortKey]")
                If dr IsNot Nothing Then
                    dr("累计进度") = dr("进度金额")
                End If
            End If
            If dr IsNot Nothing Then
                drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") & "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                For i As Integer = 1 To drs.Count - 1
                    drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
                Next
            End If
        End If
End Select


Dim Key As Decimal
Dim Index As Integer
Dim Filter As String
Dim r As Row
Index = Math.Min(e.OldIndex, e.NewIndex)
Key = e.Table.Rows(Index)("_SortKey")
r = e.Table.Rows(e.NewIndex)
Filter = "[_SortKey] >= " & Key & " And [项目名称] = \'" & r("项目名称") &  " And [工程单位名称] = \'" & r("工程单位名称") &  " And [费用类别] = \'" & r("费用类别") &  " And [费用类别1] = \'" & r("费用类别1") & "\'"
e.Table.DataTable.DataCols("进度金额").RaiseDataColChanged(Filter)

 

 


e.DataRow("进度金额") = 0


--  作者:爱相随
--  发布时间:2014/7/15 10:37:00
--  
明天就要向领导演示初步结果了,希望能够争取项目成功,请各位老师高手指点一下,再次感谢帮助我的老师前辈。
--  作者:有点甜
--  发布时间:2014/7/15 10:38:00
--  
 最基本的问题,左右都要加入单引号。
--  作者:爱相随
--  发布时间:2014/7/15 10:58:00
--  
非常谢谢有点甜老师,果然是那里的问题,但又有个问题,如果修改其中任何一个条件,修改后数据不会改变,比如原来是项目A,C单位,前期费、、设计费,将前期费和设计费修改后,累计数不会跟着变化,请问老师还有什么问题。
--  作者:有点甜
--  发布时间:2014/7/15 11:02:00
--  

 在这里加入对应的修改的列,即可

 

Case "项目名称","工程单位名称","费用类别","费用类别1","进度金额"


--  作者:爱相随
--  发布时间:2014/7/15 11:06:00
--  
请老师具体指点一下,在哪个位置加,是否还需要补充代码,补充什么代码,,一次到位吧,有机会贵单位如果开设培训班,一定来请老师当面指点。。。。希望贵单位早点开设培训班。。。。
--  作者:爱相随
--  发布时间:2014/7/15 11:19:00
--  
就是其中任意地方有修改,就自动累计到修改后相同条件的项目累计数上面去,比如开始录入有可能是项目名称录错了,其他没错,发现错误后修改项目名称,则数据会累计到修改后的项目上去
--  作者:有点甜
--  发布时间:2014/7/15 11:23:00
--  

 这样写,如果出错,就请上传例子。

 

Select Case e.DataCol.Name
    Case "项目名称","工程单位名称","费用类别","费用类别1","进度金额"
        Dim dr As DataRow
        Dim mr As DataRow = e.DataRow
        Dim drs As List(of DataRow)
        dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & mr("项目名称") & "\' And [工程单位名称] = \'" & mr("工程单位名称") & "\' And [费用类别] = \'" & mr("费用类别") & "\' And [费用类别1] = \'" & mr("费用类别1") & "\'", "[_SortKey] Desc")
        If dr Is Nothing Then
            mr("累计进度") = mr("进度金额")
            dr = mr
        End If
        drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
        For i As Integer = 1 To drs.Count - 1
            drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
        Next
        If e.DataCol.Name = "项目名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & e.OldValue & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey] Desc")
            If dr Is Nothing Then
                dr = e.DataTable.Find("[项目名称] = \'" & e.OldValue & "\'  And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                If dr IsNot Nothing Then
                    dr("累计进度") = dr("进度金额")
                End If
            End If
            If dr IsNot Nothing Then
                drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") & "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                For i As Integer = 1 To drs.Count - 1
                    drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
                Next
            End If
        End If
        If e.DataCol.Name = "费用类别1" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & e.Oldvalue & "\'", "[_SortKey] Desc")
            If dr Is Nothing Then
                dr = e.DataTable.Find("[项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & e.Oldvalue & "\'", "[_SortKey]")
                If dr IsNot Nothing Then
                    dr("累计进度") = dr("进度金额")
                End If
            End If
            If dr IsNot Nothing Then
                drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") & "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                For i As Integer = 1 To drs.Count - 1
                    drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
                Next
            End If
        End If
        If e.DataCol.Name = "费用类别" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & e.OldValue  &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey] Desc")
            If dr Is Nothing Then
                dr = e.DataTable.Find("[项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & e.OldValue  &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                If dr IsNot Nothing Then
                    dr("累计进度") = dr("进度金额")
                End If
            End If
            If dr IsNot Nothing Then
                drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") & "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                For i As Integer = 1 To drs.Count - 1
                    drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
                Next
            End If
        End If
        If e.DataCol.Name = "工程单位名称" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            dr = e.DataTable.Find("[_SortKey] < " & mr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & e.OldValue & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey] Desc")
            If dr Is Nothing Then
                dr = e.DataTable.Find("[项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & e.OldValue & "\' And [费用类别] = \'" & dr("费用类别") &  "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                If dr IsNot Nothing Then
                    dr("累计进度") = dr("进度金额")
                End If
            End If
            If dr IsNot Nothing Then
                drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [项目名称] = \'" & dr("项目名称") & "\' And [工程单位名称] = \'" & dr("工程单位名称") & "\' And [费用类别] = \'" & dr("费用类别") & "\' And [费用类别1] = \'" & dr("费用类别1") & "\'", "[_SortKey]")
                For i As Integer = 1 To drs.Count - 1
                    drs(i)("累计进度") = drs(i-1)("累计进度") + drs(i)("进度金额")
                Next
            End If
        End If
       
End Select


--  作者:爱相随
--  发布时间:2014/7/15 11:32:00
--  
谢谢老师的努力,不过提示错误。