以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  请帮代码减肥,新手边问边学  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=2803)

--  作者:shixia
--  发布时间:2009/5/15 20:50:00
--  请帮代码减肥,新手边问边学

在“支出”表的DataColChanged事件中

Dim dr As DataRow = e.DataRow

Select Case e.DataCol.Name
    case "开支日期"
        if dr.IsNull("开支日期") Then
            dr("年度")=nothing
            dr("月份")=nothing
        else
            dr("年度")=dr("开支日期").year
            dr("月份")=dr("开支日期").Month
        End If
    Case "待摊","实报金额"
        If dr("待摊") = false Then
            dr("月1")=nothing
            dr("月2")=nothing
            dr("月3")=nothing
            dr("月4")=nothing
            dr("月5")=nothing
            dr("月6")=nothing
            dr("月7")=nothing
            dr("月8")=nothing
            dr("月9")=nothing
            dr("月10")=nothing
            dr("月11")=nothing
            dr("月12")=nothing
        else
           
            Dim d1 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =1"& "And [业务分块]=\'公有部分\'" )
            Dim d2 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =2"& "And [业务分块]=\'公有部分\'" )
            Dim d3 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =3"& "And [业务分块]=\'公有部分\'" )
            Dim d4 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =4"& "And [业务分块]=\'公有部分\'" )
            Dim d5 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =5"& "And [业务分块]=\'公有部分\'" )
            Dim d6 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =6"& "And [业务分块]=\'公有部分\'" )
            Dim d7 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =7"& "And [业务分块]=\'公有部分\'" )
            Dim d8 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =8"& "And [业务分块]=\'公有部分\'" )
            Dim d9 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =9"& "And [业务分块]=\'公有部分\'" )
            Dim d10 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =10"& "And [业务分块]=\'公有部分\'" )
            Dim d11 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] =11"& "And [业务分块]=\'公有部分\'" )
           
            Dim t1 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <1"& "And [业务分块]=\'公有部分\'" )
            Dim t2 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <2"& "And [业务分块]=\'公有部分\'" )
            Dim t3 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <3"& "And [业务分块]=\'公有部分\'" )
            Dim t4 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <4"& "And [业务分块]=\'公有部分\'" )
            Dim t5 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <5"& "And [业务分块]=\'公有部分\'" )
            Dim t6 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <6"& "And [业务分块]=\'公有部分\'" )
            Dim t7 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <7"& "And [业务分块]=\'公有部分\'" )
            Dim t8 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <8"& "And [业务分块]=\'公有部分\'" )
            Dim t9 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <9"& "And [业务分块]=\'公有部分\'" )
            Dim t10 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <10"& "And [业务分块]=\'公有部分\'" )
            Dim t11 As Integer = DataTables("收入").Compute("Sum(实收费额)","[年度] = "& dr("年度") & "And [月份] <11"& "And [业务分块]=\'公有部分\'" )
           
            Dim dm As Integer = 250000
            dr("月1") = dr("实报金额")*d1/(dm-t1)
            dr("月2") =  dr("实报金额")*d2/(dm-t2)
            dr("月3") =  dr("实报金额")*d3/(dm-t3)
            dr("月4") =  dr("实报金额")*d4/(dm-t4)
            dr("月5") =  dr("实报金额")*d5/(dm-t5)
            dr("月6") =  dr("实报金额")*d6/(dm-t6)
            dr("月7") =  dr("实报金额")*d7/(dm-t7)
            dr("月8") =  dr("实报金额")*d8/(dm-t8)
            dr("月9") =  dr("实报金额")*d9/(dm-t9)
            dr("月10") =  dr("实报金额")*d10/(dm-t10)
            dr("月11") =  dr("实报金额")*d11/(dm-t11)
            dr("月12")=dr("实报金额")-dr("月1")-dr("月2")-dr("月3")-dr("月4")-dr("月5")-dr("月6")-dr("月7")-dr("月8")-dr("月9")-dr("月10")-dr("月11")
           
        End if
End select

[此贴子已经被作者于2009-5-15 20:54:13编辑过]

--  作者:mr725
--  发布时间:2009/5/15 21:26:00
--  
 [月份] <1  这个是几月 ~?

And [月份] = 1"& " And .....      1"& " 是什么意思?
[此贴子已经被作者于2009-5-15 21:35:23编辑过]

--  作者:八婺
--  发布时间:2009/5/15 22:12:00
--  
这段这样不知行不行?


Else
    Dim dt As DataTable = DataTables("收入")
    Dim dr As DataRow = e.DataRow
    Dim str As String = "[业务分块]=\'公有部分\' And [年度] = \'" & dr("年度") & "\'And [月份]"
    dr("月1") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 1")/(250000 - dt.Compute("Sum(实收费额)",str & "< 1"))
    dr("月2") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 2")/(250000 - dt.Compute("Sum(实收费额)",str & "< 2"))
    dr("月3") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 3")/(250000 - dt.Compute("Sum(实收费额)",str & "< 3"))
    dr("月4") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 4")/(250000 - dt.Compute("Sum(实收费额)",str & "< 4"))
    dr("月5") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 5")/(250000 - dt.Compute("Sum(实收费额)",str & "< 5"))
    dr("月6") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 6")/(250000 - dt.Compute("Sum(实收费额)",str & "< 6"))
    dr("月7") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 7")/(250000 - dt.Compute("Sum(实收费额)",str & "< 7"))
    dr("月8") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 8")/(250000 - dt.Compute("Sum(实收费额)",str & "< 8"))
    dr("月9") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 9")/(250000 - dt.Compute("Sum(实收费额)",str & "< 9"))
    dr("月10") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 10")/(250000 - dt.Compute("Sum(实收费额)",str & "< 10"))
    dr("月11") = dr("实报金额")*dt.Compute("Sum(实收费额)",str & "= 11")/(250000 - dt.Compute("Sum(实收费额)",str & "< 11"))
    dr("月12")=dr("实报金额")-dr("月1")-dr("月2")-dr("月3")-dr("月4")-dr("月5")-dr("月6")-dr("月7")-dr("月8")-dr("月9")-dr("月10")-dr("月11")
End If

--  作者:八婺
--  发布时间:2009/5/15 22:19:00
--  
For...Next语句可以真正减肥。
--  作者:don
--  发布时间:2009/5/15 23:19:00
--  [求助]
Dim dr As DataRow = e.DataRow
Dim m,md,mx,dj as Double
Select Case e.DataCol.Name
    case "开支日期"
        if dr.IsNull("开支日期") Then
            dr("年度") = nothing
            dr("月份") = nothing
        else
            dr("年度") = dr("开支日期").year
            dr("月份") = dr("开支日期").Month
        End If
    Case "待摊","实报金额"
        If dr("待摊") = false Then
            for m = 1 to 12
                dr("月" & m) = nothing
             Next
        else           
            Dim td,tx as String
            dj = dr("实报金额")
            for m = 1 to 11
                td = "[年度] = "& dr("年度") & And [业务分块]=\'公有部分\'And [月份] = " & m
                tx = "[年度] = "& dr("年度") & And [业务分块]=\'公有部分\'And [月份] < " & m
                md = DataTables("收入").Compute("Sum(实收费额)",td)
                mx = DataTables("收入").Compute("Sum(实收费额)",tx)
                dr("月" & m) = dr("实报金额")*md/(250000-mx)
                dj = dj - dr("月" & m)
            Next
            dr("月12") = dj             
        End if
End select

--  作者:shixia
--  发布时间:2009/5/16 9:39:00
--  
 谢谢