|
|
发表于 2007/8/24 11:02:32
|
显示全部楼层
每页统计数据
功能需求:每页显示四条记录,每页统计一次[MATRECTRANS.LINECOST]字段
解决如下:
在报表Tool-> arameters中定义变量:
Sum1 Double
在DataStream中建立变量如下:
aConnection AcDBConnection
aCursor AcDBCursor
aDataSource AcDatabaseSource
aRow AcDataRow
aStmt AcDBStatement
tmp1 Integer '记录总数与4取余的值
tmp2 Integer
i1 Integer
新建函数
Function SetSql( str As String ) As AcDBCursor
' Insert your code here
' 数据库操作
set aStmt = aConnection.prepare(str)
if aStmt is nothing then
exit function
end if
set aCursor = aStmt.allocateCursor()
if aCursor is nothing then
exit function
end if
if Not aCursor.openCursor() then
aDataSource.getDBConnection().raiseError()
set aCursor = nothing
end if
Set SetSql = aCursor
End Function
Function GetSum(code as String,xend as Integer) As Double
' Insert your code here
'统计前xend的总数
Dim str as String
str = "select Sum(matrectrans.LINECOST) from " & Schema & ".matrectrans"
str = str & " where MATRECTRANS.ITIN1 = '工程采购' and matrectrans.ponum='" & CODE & "' "
str = str & " and rownum<=" & xend & " "
str = str & " and TRANSDATE >to_date('" & aStart & "','YYYY-MM-DD') "
str = str & " and TRANSDATE <to_date('" & aEnd & "','YYYY-MM-DD') "
'showfactorystatus(str)
Set aCursor = SetSql(str)
aCursor.BindColumn(1, "NewReportApp:[s:4]ataRow3","sum_1")
aCursor.Fetch(aRow)
GetSum= aRow.GetValue("sum_1")
End Function
Function GetCount( code as String ) As Integer
' Insert your code here
Dim str as String
str = "select count(*) from " & Schema & ".matrectrans"
str = str & " where MATRECTRANS.ITIN1 = '工程采购' and matrectrans.ponum='" & CODE & "' "
str = str & " and TRANSDATE >to_date('" & aStart & "','YYYY-MM-DD') "
str = str & " and TRANSDATE <to_date('" & aEnd & "','YYYY-MM-DD') "
'showfactorystatus(str)
Set aCursor = SetSql(str)
aCursor.BindColumn(1, "NewReportApp:[s:4]ataRow3","count_1")
aCursor.Fetch(aRow)
GetCount= aRow.GetValue("count_1")
End Function
修改Start( )
Function Start( ) As Boolean
Start = Super::Start( )
' Insert your code here
Dim count1,i as Integer
Set aConnection = new Connection
aConnection.connect()
Set aRow = New DataRow3
count1=GetCount(code)'求列数
if (count1 mod 4) >=1 then
tmp1=4-(count1 mod 4)
tmp2=1
else
tmp2=5
end if
i1=0
'showfactorystatus("tmp1 "&tmp1)
’此处赋最后一页的总数
if count1 <4 then
sum3=GetSum(code,4)
'showfactorystatus("sum3 "&sum3)
elseif (count1 mod 4) <> 0 then
i=count1 mod 4
sum3=GetSum(code,count1) - GetSum(code,count1-i)
'showfactorystatus("sum3 "&sum3)
elseif (count1 mod 4) = 0 then
sum3=GetSum(code,count1) - GetSum(code,count1-4)
end if
End Function
修改Fetch( )
Function Fetch( ) As AcDataRow
'Set Fetch = Super::Fetch( )
' Insert your code here
Dim myrow as DataRow3
Dim ponum as String
Dim i2 as Integer
Dim count1,i as Integer
Set myrow = Super::Fetch()
if(not myrow is nothing) then
ponum = myrow.GetValue("PO_PONUM")
'计算总计数,每页总计
if i1<4 then
i1=i1+1
'showfactorystatus("**i1 "&i1 &"RowNumber "&myrow.GetValue("RowNumber"))
elseif i1=4 then
i2=myrow.GetValue("RowNumber")
sum1=GetSum(ponum,i2-1)-GetSum(ponum,i2-5)
i1=1
'showfactorystatus("sum1 "&sum1)
'showfactorystatus("i1 "&i1 &"RowNumber "&myrow.GetValue("RowNumber"))
end if
elseif (myrow is nothing) and tmp2 <= tmp1 then
Set myrow = new DataRow3
'showfactorystatus(code)
myrow.SetValue("PO_PONUM",code)
myrow.SetValue("MATRECTRANS_QUANTITY",null)
myrow.SetValue("MATRECTRANS_ACTUALCOST",null)
myrow.SetValue("MATRECTRANS_LINECOST",null)
myrow.SetValue("deptment_wappr","")
myrow.SetValue("name_wappr","")
myrow.SetValue("name_appr","")
myrow.SetValue("name_enterby","")
tmp2=tmp2+1
end if
Set Fetch=myrow |
|