以文本方式查看主题
- Foxtable(狐表) (http://foxtable.com/bbs/index.asp)
-- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2)
---- [求助]平均价 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=71530)
|
-- 作者:江南小城
-- 发布时间:2015/7/13 15:15:00
-- [求助]平均价
此主题相关图片如下:图像 1.png
 Select Case e.DataCol.name Case "买入_买入价","买入_数量","卖出_卖出价","卖出_数量" Dim filter As String = "股票名称=\'" & e.DataRow("股票名称") & "\'" Dim sum1 As Double = 0 Dim sum2 As Double = 0 Dim count1 As Double = 0 Dim count2 As Double = 0 Dim pinavg As Double = 0 For Each dr As DataRow In e.DataTable.Select(filter, "_Identify") sum1 += dr("买入_买入价") * dr("买入_数量") sum2 += pinavg * dr("卖出_数量") count1 += dr("买入_数量") count2 += dr("卖出_数量") If dr.IsNull("卖出_卖出价") Then dr("买入_平均价") = (sum1-sum2) / (count1-count2) dr("卖出_平均价") = Nothing pinavg = dr("买入_平均价") Else dr("买入_平均价") = Nothing End If Next End Select
|
-- 作者:大红袍
-- 发布时间:2015/7/13 15:21:00
--
Select Case e.DataCol.name Case "买入_买入价","买入_数量","卖出_卖出价","卖出_数量" Dim filter As String = "股票名称=\'" & e.DataRow("股票名称") & "\'" Dim sum1 As Double = 0 Dim sum2 As Double = 0 Dim count1 As Double = 0 Dim count2 As Double = 0 Dim pinavg As Double = 0 For Each dr As DataRow In e.DataTable.Select(filter, "_Identify") sum1 += dr("买入_买入价") * dr("买入_数量") sum2 += pinavg * dr("卖出_数量") count1 += dr("买入_数量") count2 += dr("卖出_数量") dr("买入_平均价") = (sum1-sum2) / (count1-count2) dr("卖出_平均价") = Nothing pinavg = dr("买入_平均价") Next End Select
|
-- 作者:江南小城
-- 发布时间:2015/7/13 17:12:00
--
此主题相关图片如下:图像 3.png
 老师,下面是原来统计的代码,我要修改成上图显示的样式,谢谢
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("[_Identify] < " & mr("_Identify") & " And [股票名称] = \'" & mr("股票名称") & "\'", "[_Identify] Desc") If dr Is Nothing Then mr("仓储_金额1") = mr("卖出_金额") - mr("买入_金额") dr = mr Else mr("仓储_金额1") = dr("仓储_金额1") End If drs = e.DataTable.Select("[_Identify] >= " & dr("_Identify") & " And [股票名称] = \'" & dr("股票名称") & "\'", "[_Identify]") For i As Integer = 1 To drs.Count - 1 drs(i)("仓储_金额1") = drs(i-1)("仓储_金额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("[_Identify] < " & mr("_Identify") & " And [股票名称] = \'" & e.OldValue & "\'", "[_Identify] Desc") If dr Is Nothing Then dr = e.DataTable.Find("[股票名称] = \'" & e.OldValue & "\'", "[_Identify]") If dr IsNot Nothing Then dr("仓储_金额1") = dr("卖出_金额") - dr("买入_金额") End If End If If dr IsNot Nothing Then drs = e.DataTable.Select("[_Identify] >= " & dr("_Identify") & " And [股票名称] = \'" & dr("股票名称") & "\'", "[_Identify]") For i As Integer = 1 To drs.Count - 1 drs(i)("仓储_金额1") = drs(i-1)("仓储_金额1") + drs(i)("卖出_金额") - drs(i)("买入_金额") Next End If End If
|
-- 作者:大红袍
-- 发布时间:2015/7/13 17:27:00
--
这个意思?
Select Case e.DataCol.Name Case "股票名称","买入_金额","卖出_金额" Dim fdr As DataRow = e.DataTable.Find("[股票名称] = \'" & e.DataRow("股票名称") & "\'", "[_Identify] Desc") If fdr IsNot Nothing Then e.DataTable.replaceFor("仓储_金额1", Nothing, "[股票名称] = \'" & e.DataRow("股票名称") & "\'") Dim sum1 As Double = e.DataTable.compute("sum(买入_金额)", "[股票名称] = \'" & e.DataRow("股票名称") & "\'") Dim sum2 As Double = e.DataTable.compute("sum(卖出_金额)", "[股票名称] = \'" & e.DataRow("股票名称") & "\'") fdr("仓储_金额1") = sum2 - sum1 End If End Select
|
-- 作者:江南小城
-- 发布时间:2015/7/13 19:09:00
--
谢谢老师,4楼的代码可以的。
此主题相关图片如下:图像 4.png

下面的代码,看上去数据有点乱,想修改成上图一样。
Select Case e.DataCol.Name Case "卖出_数量","卖出_卖出价","卖出_金额","仓储_数量","仓储_金额" Dim pdr As DataRow = e.DataTable.Find("股票名称 = \'" & e.DataRow("股票名称") & "\' and _Identify < " & e.DataRow("_Identify"), "_Identify desc") If pdr IsNot Nothing Then e.DataRow("仓储_盈亏") = e.DataRow("卖出_金额") + e.DataRow("仓储_金额") - pdr("仓储_金额") End If End Select
|
-- 作者:大红袍
-- 发布时间:2015/7/13 19:22:00
--
Select Case e.DataCol.Name Case "卖出_数量","卖出_卖出价","卖出_金额","仓储_数量","仓储_金额" Dim pdr As DataRow = e.DataTable.Find("股票名称 = \'" & e.DataRow("股票名称") & "\' and _Identify < " & e.DataRow("_Identify"), "_Identify desc") If pdr IsNot Nothing Then e.DataTable.ReplaceFor("仓储_盈亏", Nothing, "股票名称 = \'" & e.DataRow("股票名称") & "\' ") e.DataRow("仓储_盈亏") = e.DataRow("卖出_金额") + e.DataRow("仓储_金额") - pdr("仓储_金额") End If End Select
|
-- 作者:江南小城
-- 发布时间:2015/7/13 20:34:00
--
此主题相关图片如下:图像 4.png

老师,打框的数据希望能显示。
Select Case e.DataCol.Name Case "卖出_数量","卖出_卖出价","卖出_金额","仓储_数量","仓储_金额" Dim pdr As DataRow = e.DataTable.Find("股票名称 = \'" & e.DataRow("股票名称") & "\' and _Identify < " & e.DataRow("_Identify"), "_Identify desc") If pdr IsNot Nothing Then e.DataTable.ReplaceFor("仓储_盈亏", Nothing, "股票名称 = \'" & e.DataRow("股票名称") & "\' ") e.DataRow("仓储_盈亏") = e.DataRow("卖出_金额") + e.DataRow("仓储_金额") - pdr("仓储_金额") End If End Select
|
-- 作者:大红袍
-- 发布时间:2015/7/13 20:53:00
--
Select Case e.DataCol.Name Case "卖出_数量","卖出_卖出价","卖出_金额","仓储_数量","仓储_金额" Dim pdr As DataRow = e.DataTable.Find("股票名称 = \'" & e.DataRow("股票名称") & "\' and _Identify < " & e.DataRow("_Identify"), "_Identify desc") If pdr IsNot Nothing Then e.DataTable.ReplaceFor("仓储_盈亏", Nothing, "股票名称 = \'" & e.DataRow("股票名称") & "\' and 卖出_数量 is not null ") e.DataRow("仓储_盈亏") = e.DataRow("卖出_金额") + e.DataRow("仓储_金额") - pdr("仓储_金额") End If End Select
|
-- 作者:江南小城
-- 发布时间:2015/7/13 21:52:00
--
谢谢老师
|