以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 求助:关于计算问题 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=95152) |
-- 作者:李孝春 -- 发布时间:2017/1/11 15:54:00 -- 求助:关于计算问题 求助:关于计算问题 余额=收入-支出 可用额度=额度-(收入+支出) 特么感觉我的可用额度是不对的 貌似计算方法不对 是不是应该是 第一条数据后可用额度是4400 那么第二条收入15597 那么可用额度应该是15597+4400 而不是4402 是不是我的思路出现了错误呢? 我是不是应该采用余额的代码写法来实现可用额度的计算呢? 当前表事件代码如下: Select Case e.DataCol.Name Case "固定额度","临时额度" e.DataRow("额度")=e.DataRow("固定额度")+e.DataRow("临时额度") Case "余额" If e.DataRow("银行卡类别")="信用卡" Then e.DataRow("可用额度")=e.DataRow("额度")-(e.DataRow("收入")+e.DataRow("支出")) If e.DataRow("可用额度")<0 Then MessageBox.Show("当前透支" & e.DataRow("可用额度") & "元") End If End If Case "收入","支出","银行卡卡号","额度" Dim drs As List(of DataRow) Dim Filter As String Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & "And [银行卡卡号] = \'" & e.DataRow("银行卡卡号") & "\'" drs = e.DataTable.Select(Filter) For Each dr As DataRow In drs Filter = "[_SortKey] <= " & dr("_SortKey") & " And [银行卡卡号] = \'" & e.DataRow("银行卡卡号") & "\'" Dim Val1 As Double = e.DataTable.Compute("Sum(收入)",Filter) Dim Val2 As Double = e.DataTable.Compute("Sum(支出)",Filter) dr("余额") = Val1 - Val2 Next If e.DataCol.Name = "银行卡卡号" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [银行卡卡号] = \'" & e.OldValue & "\'" drs = e.DataTable.Select(Filter) For Each dr As DataRow In drs Filter = "[_SortKey] <= " & dr("_SortKey") & " And [银行卡卡号]= \'" & e.DataRow("银行卡卡号") & "\'" Dim Val1 As Double = e.DataTable.Compute("Sum(收入)",Filter) Dim Val2 As Double = e.DataTable.Compute("Sum(支出)",Filter) dr("余额") = Val1 - Val2 Next End If End Select 烦请老师们多多指正,谢谢!
[此贴子已经被作者于2017/1/11 16:03:44编辑过]
|
-- 作者:有点色 -- 发布时间:2017/1/11 16:03:00 -- 1、先计算得出余额
2、 可用额度,不就是等于 额度+余额 么?余额不是计算了收入和支出了么? |
-- 作者:李孝春 -- 发布时间:2017/1/11 16:09:00 -- 回复:(有点色)?1、先计算得出余额?&... 谢谢有点色老师 已经解决了 采用了下列代码: Select Case e.DataCol.Name Case "固定额度","临时额度" e.DataRow("额度")=e.DataRow("固定额度")+e.DataRow("临时额度") Case "余额" If e.DataRow("银行卡类别")="信用卡" Then If e.DataRow("可用额度")<0 Then MessageBox.Show("当前透支" & e.DataRow("可用额度") & "元") End If End If Case "收入","支出","银行卡卡号","额度" Select Case e.DataCol.Name Case "银行卡卡号","收入","支出" 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("银行卡卡号") & "\'", "[_SortKey] Desc") If dr Is Nothing Then mr("余额") = mr("收入") - mr("支出") mr("可用额度") = mr("额度")+(mr("收入") - mr("支出")) dr = mr End If drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [银行卡卡号] = \'" & dr("银行卡卡号") & "\'", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("余额") = drs(i-1)("余额") + drs(i)("收入") - drs(i)("支出") drs(i)("可用额度") = drs(i-1)("可用额度") + drs(i)("收入") - 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 & "\'", "[_SortKey] Desc") If dr Is Nothing Then dr = e.DataTable.Find("[银行卡卡号] = \'" & e.OldValue & "\'", "[_SortKey]") If dr IsNot Nothing Then dr("余额") = dr("收入") - dr("支出") End If End If If dr IsNot Nothing Then drs = e.DataTable.Select("[_SortKey] >= " & dr("_SortKey") & " And [银行卡卡号] = \'" & dr("银行卡卡号") & "\'", "[_SortKey]") For i As Integer = 1 To drs.Count - 1 drs(i)("余额") = drs(i-1)("余额") + drs(i)("收入") - drs(i)("支出") drs(i)("可用额度") = drs(i-1)("可用额度") + drs(i)("收入") - drs(i)("支出") Next End If End If End Select End Select [此贴子已经被作者于2017/1/11 16:34:41编辑过]
|