Wpf DataTable选择借方和贷方匹配的行
其中,DataTable具有以下列 帐号(整数)(唯一) 借方(十进制) 信用(十进制) 选定(布尔值) 可能有多行具有相同的帐号,并且有借方分录或贷方分录。我试图做的是匹配借项和贷项,它们加起来等于相同的值,并通过遍历所有行将它们标记为选中。有什么办法可以达到这个目的吗 谢谢 e、 g SQLWpf DataTable选择借方和贷方匹配的行,wpf,datagrid,datatable,Wpf,Datagrid,Datatable,其中,DataTable具有以下列 帐号(整数)(唯一) 借方(十进制) 信用(十进制) 选定(布尔值) 可能有多行具有相同的帐号,并且有借方分录或贷方分录。我试图做的是匹配借项和贷项,它们加起来等于相同的值,并通过遍历所有行将它们标记为选中。有什么办法可以达到这个目的吗 谢谢 e、 g SQL 这可能不是最好的解决方案,但似乎确实有效 我正在通过数据表进行三次传递 通过一级-如果每个客户的借方总额等于贷方总额,则将其标记为选中 Pass two-为客户添加信用总额,并迭代借记,直到达到相同的
这可能不是最好的解决方案,但似乎确实有效 我正在通过数据表进行三次传递 通过一级-如果每个客户的借方总额等于贷方总额,则将其标记为选中 Pass two-为客户添加信用总额,并迭代借记,直到达到相同的值,并将其标记为选中 传递三个-清除与同一客户的借方分录匹配的任何剩余贷方分录
For Each Row As DataRow In BalanceDT.Rows
Dim vAcct As String = Row("Acct")
Dim vDebits As Decimal = BalanceDT.Compute("SUM(Debit)", "Acct = '" & vAcct & "'")
Dim vCredits As Decimal = BalanceDT.Compute("SUM(Credit)", "Acct = '" & vAcct & "'")
If vDebits = vCredits Then
Row("Selected") = True
End If
Next
Dim CurrentCust As String = ""
Dim TransactionDT As New DataTable
Dim ExitFor As Boolean = False
With TransactionDT.Columns
.Add("ID", GetType(Integer))
End With
For Each Row As DataRow In BalanceDT.Rows
Dim vAcct As String = Row("Acct")
ExitFor = False
TransactionDT.Rows.Clear()
If Not CurrentCust = vAcct Then
Dim vCredits As Decimal = BalanceDT.Compute("SUM(Credit)", "Acct = '" & vAcct & "'")
Dim vSelected() As DataRow = BalanceDT.Select("Acct = '" & vAcct & "'", Nothing)
For Each SubRow As DataRow In vSelected
If SubRow("Selected") = False Then
vCredits -= SubRow("Debit")
With TransactionDT.Rows
.Add(SubRow("Transaction"))
End With
If vCredits = 0 Then
ExitFor = True
Exit For
End If
End If
Next
If ExitFor = True Then
For Each SubRow As DataRow In vSelected
If SubRow("Credit") > 0 Then
SubRow("Selected") = True
End If
If SubRow("Debit") > 0 Then
For Each CustomerRow As DataRow In TransactionDT.Rows
If CustomerRow("ID") = SubRow("Transaction") Then
SubRow("Selected") = True
End If
Next
End If
Next
End If
End If
CurrentCust = vAcct
Next
For Each Row As DataRow In BalanceDT.Rows
Dim vAcct As String = Row("Acct")
If Not CurrentCust = vAcct Then
Dim vSelected() As DataRow = BalanceDT.Select("Acct = '" & vAcct & "' AND Selected = 'False'", "Credit")
For Each SubRow As DataRow In vSelected
If SubRow("Selected") = False Then
Dim vCredit As Decimal = SubRow("Credit")
For Each CustomerRow In vSelected
If CustomerRow("Selected") = False Then
Dim vDebit As Decimal = CustomerRow("Debit")
If Not vDebit = 0 And Not vCredit = 0 Then
If vDebit = vCredit Then
With TransactionDT.Rows
CustomerRow("Selected") = True
SubRow("Selected") = True
End With
Exit For
End If
End If
End If
Next
End If
Next
End If
CurrentCust = vAcct
Next
您是否尝试过使用linq查询将表连接到account上的自身#以及credit等于Debiety Conrad的位置-您能给出一个示例吗?我不存在账号的所有行都匹配的问题,即总和(贷方)=总和(借方)。。谢谢
For Each Row As DataRow In BalanceDT.Rows
Dim vAcct As String = Row("Acct")
Dim vDebits As Decimal = BalanceDT.Compute("SUM(Debit)", "Acct = '" & vAcct & "'")
Dim vCredits As Decimal = BalanceDT.Compute("SUM(Credit)", "Acct = '" & vAcct & "'")
If vDebits = vCredits Then
Row("Selected") = True
End If
Next
Dim CurrentCust As String = ""
Dim TransactionDT As New DataTable
Dim ExitFor As Boolean = False
With TransactionDT.Columns
.Add("ID", GetType(Integer))
End With
For Each Row As DataRow In BalanceDT.Rows
Dim vAcct As String = Row("Acct")
ExitFor = False
TransactionDT.Rows.Clear()
If Not CurrentCust = vAcct Then
Dim vCredits As Decimal = BalanceDT.Compute("SUM(Credit)", "Acct = '" & vAcct & "'")
Dim vSelected() As DataRow = BalanceDT.Select("Acct = '" & vAcct & "'", Nothing)
For Each SubRow As DataRow In vSelected
If SubRow("Selected") = False Then
vCredits -= SubRow("Debit")
With TransactionDT.Rows
.Add(SubRow("Transaction"))
End With
If vCredits = 0 Then
ExitFor = True
Exit For
End If
End If
Next
If ExitFor = True Then
For Each SubRow As DataRow In vSelected
If SubRow("Credit") > 0 Then
SubRow("Selected") = True
End If
If SubRow("Debit") > 0 Then
For Each CustomerRow As DataRow In TransactionDT.Rows
If CustomerRow("ID") = SubRow("Transaction") Then
SubRow("Selected") = True
End If
Next
End If
Next
End If
End If
CurrentCust = vAcct
Next
For Each Row As DataRow In BalanceDT.Rows
Dim vAcct As String = Row("Acct")
If Not CurrentCust = vAcct Then
Dim vSelected() As DataRow = BalanceDT.Select("Acct = '" & vAcct & "' AND Selected = 'False'", "Credit")
For Each SubRow As DataRow In vSelected
If SubRow("Selected") = False Then
Dim vCredit As Decimal = SubRow("Credit")
For Each CustomerRow In vSelected
If CustomerRow("Selected") = False Then
Dim vDebit As Decimal = CustomerRow("Debit")
If Not vDebit = 0 And Not vCredit = 0 Then
If vDebit = vCredit Then
With TransactionDT.Rows
CustomerRow("Selected") = True
SubRow("Selected") = True
End With
Exit For
End If
End If
End If
Next
End If
Next
End If
CurrentCust = vAcct
Next