Actuate報表開發總結

Actuate報表開發總結

如何測量性能
       1 選擇包含報表數據源的數據流組件。
       2 以“雙精度”數據類型的形式創建變量 Start_Time。
       3 在 Start( ) 方法中鍵入以下代碼:
 

Function Start( )
  Super::Start( )
  ShowFactoryStatus(“Starting report”)
  Start_Time 
= Now
End Function

 4 在 Finish( ) 方法中鍵入以下代碼: 

 
Sub Finish( )
     
Dim Finish_Time as Double, Elaspsed_Time as Double
     
Dim Duration as String
     Super::Finish( )
     Finish_time 
= Now( )
     Elapsed_Time 
= Finish_Time - Start_Time
     Elapsed_Time 
= Elapsed_Time * (24 * 3600)
     Elapsed_Time 
= CInt(Elapsed_Time)
     Duration 
= CStr(Elapsed_Time)
     ShowFactoryStatus(“Elapsed 
time (seconds): “ + Duration)
 
End Sub

查看檢索的sql語句
         在DataStream中修改ObtainSelectStatement( ) 函數


Function ObtainSelectStatement( ) As String
    WhereClause 
= WhereClause & " AND (" & where & ")"
    FromClause 
= parseSchema(FromClause)
    ObtainSelectStatement 
= Super::ObtainSelectStatement( )
    
' Insert your code here
    'showfactorystatus(ObtainSelectStatement )
End Function

 

 
操作數據庫方面
 首先在DataStream中建立變量如下:
 aConnection AcDBConnection
 aCursor     AcDBCursor
 aDataSource AcDatabaseSource
 aRow        AcDataRow
 aStmt       AcDBStatement
 
 在DataStream->Start( ) 中加入以下代碼(DataRow2 爲當前DataStream對應的DataRow):

 
Function Start( ) As Boolean
     Start 
= Super::Start( )
     
' Insert your code here
     Set aConnection = new Connection
     aConnection.connect()
     
Set aRow = New DataRow2
 
End Function



 
 現測試,建立一個Function,檢索數據  


Function GetGccb(awoum as String ) As String
     
' Insert your code here
     Dim str as String
      str 
= "SELECT WPLABOR.LABORCODE from " & Schema &".wplabor, " & Schema & ".labor"  
      str 
= str & " where  wplabor.laborcode=labor.laborcode and wplabor.wonum='" & awoum &"'"
     
'ShowFactoryStatus(str)
     set aStmt = aConnection.prepare(str) 
       
if dbstmt is nothing then 
   
exit function 
   
end if 
 
   
set aCursor = dbStmt.allocateCursor() 
 
   
if aCursor is nothing then 
   
exit function 
   
end if 
 
   
if Not aCursor.openCursor() then 
   aDataSource.getDBConnection().raiseError() 
   
set aCursor = nothing 
   
end if 
     aCursor.BindColumn(
1"NewReportApp::DataRow2""namesum_wplabor")  
     aCursor.Fetch(aRow)
     GetGccb
=aRow.GetValue("namesum_wplabor")
     
'ShowFactoryStatus(" "&getGccb)    
 End Function


 或者建立兩個function 


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 GetGccb(awoum as String ) As String
     
' Insert your code here
      '檢索數據
     Dim str as String
      str 
= "SELECT WPLABOR.LABORCODE from " & Schema &".wplabor, " & Schema & ".labor"  
      str 
= str & " where  wplabor.laborcode=labor.laborcode and wplabor.wonum='" & awoum &"'"
     
'ShowFactoryStatus(str)
    Set aCursor = SetSql(astr)
     aCursor.BindColumn(
1"NewReportApp::DataRow2""namesum_wplabor")  
     aCursor.Fetch(aRow)
     GetGccb
=aRow.GetValue("namesum_wplabor")
     
'ShowFactoryStatus(" "&getGccb)    
 
 
End Function

 
 修改數據庫代碼如下: 


Function UpdateMat( num as String ) As Double
          
Dim stmt1 As AcDBStatement 
          
Dim stmt2 As AcDBStatement 
          
Dim conn As AcDBConnection
 
 
        
Dim str as String
        str 
= "UPDATE " & schema & ".matrectrans"
     str 
= str & " SET matrectrans.it6 = 'Y' "
     str 
= str & " WHERE ponum = '" & num & "'" 
        
'ShowFactoryStatus(str)
        Set conn = new Connection
        conn.connect()
 
   
 
        
Set stmt1 = New AcDBStatement(conn) 
        stmt1.prepare(str)
        stmt1.execute()
   
        
Set stmt2 = New AcDBStatement(conn) 
        stmt2.prepare(
"commit")
        stmt2.execute()
 
End Function

 

每頁統計數據
 功能需求:每頁顯示四條記錄,每頁統計一次[MATRECTRANS.LINECOST]字段
 解決如下:
 在報表Tool->Parameters中定義變量:
 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 IntegerAs 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::DataRow3","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::DataRow3","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 nothingthen
        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 nothingand 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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章