以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 参考高效流水账 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=141071) |
-- 作者:fubblyc -- 发布时间:2019/9/20 17:32:00 -- 参考高效流水账 老师,我这个余额的做成这样,可以正常运行,您帮忙看下,是否可有优化或者更高效的办法: Dim cmd As new sqlcommand cmd.c \'Dim r As DataRow = e.DataRow 之前写在 表事件 beforesave,现在改成写在服务器处理,改成for each cmd.CommandText = "selec t * from 资金日报账户表 where 日期 = \'2019-01-01\'" Dim t As DataTable = cmd.ExecuteReader For Each r As DataRow In t.DataRows cmd.CommandText = "Selec t * From {资金日报账户表} where 日期 > \'" & r("日期") & "\'" & _ " And 分销商 = \'" & r("分销商") & "\' And 类型 = \'" & r("类型") & "\' and 项目 = \'" & r("项目") & "\' order by 日期" Dim dt As DataTable = cmd.ExecuteReader(True) Dim i As Integer = 0 For Each dr As DataRow In dt.Selec t("","日期") output.show(i & ": 日期1: " & dr("日期") & " 日期2: " & r("日期")) If i = 0 Then dr("上日余额") = r("本日余额") dr("本日余额") = r("本日余额")+dr("本日增加")-dr("本日减少") Else dr("上日余额") = dt.Selec t("","日期")(i-1)("本日余额") dr("本日余额") = dt.Selec t("","日期")(i-1)("本日余额")+dr("本日增加")-dr("本日减少") End If i +=1 Next dt.save Next [此贴子已经被作者于2019/9/20 17:32:38编辑过]
|
-- 作者:有点蓝 -- 发布时间:2019/9/20 20:31:00 -- cmd.CommandText = "selec t * from 资金日报账户表 where 日期 = \'2019-01-01\'" Dim t As DataTable = cmd.ExecuteReader For Each r As DataRow In t.DataRows dim filter as string = "日期 > \'" & r("日期") & "\'" & _ " And 分销商 = \'" & r("分销商") & "\' And 类型 = \'" & r("类型") & "\' and 项目 = \'" & r("项目") & "\'" Dim i As Integer = 0 For Each dr As DataRow In t.Selec t(filter,"日期") output.show(i & ": 日期1: " & dr("日期") & " 日期2: " & r("日期")) If i = 0 Then dr("上日余额") = r("本日余额") dr("本日余额") = r("本日余额")+dr("本日增加")-dr("本日减少") Else dr("上日余额") = dt.Selec t("","日期")(i-1)("本日余额") dr("本日余额") = dt.Selec t("","日期")(i-1)("本日余额")+dr("本日增加")-dr("本日减少") End If i +=1 Next dt.save Next
|