home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Special / chip-cd_2001_spec_05.zip / spec_05 / apps / crystal / disk24 / Xasp24 < prev    next >
Text File  |  1999-08-23  |  15KB  |  548 lines

  1. <%
  2.  
  3. '    This script assumes that the Session contains the following Crystal Report Engine
  4. '    Objects:
  5. '
  6. '    "oApp" - Crystal Report Engine Application Object
  7. '    "oRpt" - Crystal Report Engine Report Object
  8. '    "oPageEngine - Crystal Report Engine Page Engine Object
  9. '
  10. '    Note:  Before creating the PageEngine object, call ReadRecords on the 
  11. '    report object to that all the database records have been read.
  12.  
  13.  
  14.  
  15.  
  16.  On Error Resume Next
  17.  
  18. '  The oEMF object is a helper object to create EMFs (Ecapsulated Messages) for the viewers.
  19. '  The viewers use EMFs to display errors and navigate to specific pages of the report.
  20.  
  21. If Not IsObject(session("oEMF")) then
  22.     Set session("oEMF") = Server.CreateObject("CREmfgen.CREmfgen.1")
  23. End if
  24.  
  25.  
  26. '    Initialize all Global variables
  27. '    These will contain the page generator and page collection
  28.  
  29.     Dim goPageGenerator        ' page generator object
  30.     Dim goPageCollection    ' page collection object
  31.     Dim goPageGeneratorDrill' page generator object in Drill Down Context
  32.     Dim goPage                ' the page object
  33.     Dim gvGroupPathDD        ' drill down group path, this is an array.
  34.     Dim gvGroupPath            ' this is branch, aka Group Path converted from string passed on the QS, it is an Array
  35.     Dim gvGroupLevel        ' this is the Group level, converted from the string passed on the QS, it is an Array
  36.     Dim gvMaxNode            ' this represents the number of nodes to retrieve for the totaller, it is set to an empty array
  37.     Dim glX                    ' this is the X Coordinate for a drill down on a graph
  38.     Dim glY                    ' this is the Y Coordinate for a drill down on a graph
  39.     Dim gvPageNumber        ' holds the requested page number
  40.     Dim gvURL                ' URL to redirect to
  41.     Dim gsErrorText
  42.  
  43. ' Vaiables that represent what was passed on the Query String
  44.     Dim CMD                    ' This determines the main function to perform
  45.     Dim PAGE                ' the page to return
  46.     Dim BRCH                ' the branch is a mechanism to determine the drill down level.
  47.                             ' A drill down level is like a view of the report, a new tab
  48.                             ' is created to indicate that it is a new view
  49.     Dim VIEWER                ' This is the viewer that is calling the server
  50.     Dim VFMT                ' the format that the viewer understands
  51.     Dim NODE                ' Currently not used??
  52.     Dim GRP                    ' this is a way of specifing the actual group
  53.     Dim COORD                ' these are the coordinates on the graph to process
  54.     Dim DIR                    ' this is the search direction
  55.     Dim CSE                    ' indicates if the search is case sensitive
  56.     Dim TEXT                ' this is the text to search for.
  57.     Dim INIT                ' used to build the frames for the html viewer
  58.  
  59. '    Initialize Arrays
  60.     gvGroupPath = Array()
  61.     gvGroupLevel = Array()
  62.     gvMaxNode = Array() ' reteive all nodes
  63.  
  64. ' Parse Query String for paramaters
  65.  
  66. Call ParseQS()
  67.  
  68. ' INIT is a special QS case, we only care about HTML viewer, if it is then save send page and branch info
  69. ' to the frame page
  70.  
  71. if INIT = "HTML_FRAME" then
  72.     ' build URL and send the QS
  73.     if BRCH <> "" then
  74.         ' htmstart is the base page that creates the frames for the HTML viewer
  75.         ' if there is branch information it needs to be passed along.
  76.         gvURL = "htmstart.asp?brch=" & BRCH
  77.     else
  78.         gvURL = "htmstart.asp"
  79.     end if
  80.     response.redirect gvURL
  81. end if
  82.  
  83.  
  84.     
  85. ' If there is a BRCH then create the gvGroupPath array that represents it.
  86.  
  87. if BRCH <> "" then
  88.     gvGroupPath = CreateArray(BRCH)
  89. end if 
  90.  
  91. ' If there is a GRP then create the gvGroupLevel array that represents it.
  92.  
  93. if GRP <> "" then
  94.     gvGroupLevel = CreateArray(GRP)
  95. end if
  96.  
  97. ' If there are COORDs, then get them
  98. if COORD <> "" then
  99.     Call GetDrillDownCoordinates()
  100. end if
  101.     
  102. ' This case statement determines what action to perform based on CMD
  103. ' there are sub cases for each viewer type
  104.         
  105. Select Case CMD
  106.  
  107. Case "GET_PG"
  108.  
  109.     Call RetrieveObjects
  110.     
  111.     ' create the actual page
  112.     Set goPage = goPageCollection(PAGE)
  113.     ' check for an exception on the page number 
  114.     if err.number <> 0 then
  115.         if err.number = 9 then 
  116.             ' just return the last page
  117.             PAGE = goPageCollection.count
  118.             Set goPage = goPageCollection(PAGE)
  119.             ' these session variables are used for the HTML Frame viewer
  120.             session("LastPageNumber") = PAGE
  121.             session("CurrentPageNumber") = PAGE
  122.             err.clear
  123.         else
  124.             ' abort the script
  125.             response.end
  126.         end if
  127.     end if
  128.  
  129.     ' 0 is for epf, 8209 is a SafeArray
  130.     Select Case VFMT
  131.  
  132.         Case "ENCP"
  133.             session("oPageEngine").ImageOptions = 1
  134.             response.binarywrite goPage.Renderepf(8209)
  135.         
  136.         Case "HTML_FRAME"
  137.             session("oPageEngine").ImageOptions = 1
  138.             response.binarywrite goPage.Renderhtml(1,2,1,request.ServerVariables("SCRIPT_NAME"),8209)
  139.             ' Need to know if it is the last page to construct the toolbar correctly
  140.             if goPage.IsLastPage then
  141.                 session("LastPageNumber") = goPage.pagenumber
  142.                 session("CurrentPageNumber") = session("LastPageNumber")
  143.             end if    
  144.         Case "HTML_PAGE"
  145.             session("oPageEngine").ImageOptions = 1
  146.             response.binarywrite goPage.Renderhtml(1,1,3,request.ServerVariables("SCRIPT_NAME"),8209)
  147.         
  148.         end select
  149.     
  150. Case "GET_TTL"
  151.     
  152.     Select Case VFMT
  153.  
  154.     Case "ENCP"
  155.         response.binarywrite session("oPageEngine").RenderTotallerETF(gvGroupPath, 0, 0, gvMaxNode, 8209)
  156.     
  157.     Case "HTML_FRAME"
  158.         response.binarywrite session("oPageEngine").RenderTotallerHTML(gvGroupPath, 1, 0, gvMaxNode, gvGroupLevel, 1, request.ServerVariables("SCRIPT_NAME"), 8209)
  159.     
  160.     end select
  161.  
  162.  
  163. Case "RFSH"
  164.     
  165.     ' This commard does not force the engine to read records again
  166.     ' to do that you will need to manipulate the oRpt object outside
  167.     ' of this script.
  168.     
  169.     Call RetrieveObjects
  170.     Set goPage = goPageCollection(PAGE)
  171.  
  172.     Select Case VFMT
  173.     
  174.     Case "ENCP"
  175.     ' just send a no error message to the browser, you will need
  176.     ' to implement refresh code here.
  177.     session("oEMF").SendErrorMsg 54, "No Error"
  178.         
  179.     Case "HTML_FRAME"
  180.         gvURL = "htmstart.asp"
  181.         response.redirect gvURL
  182.  
  183.     Case "HTML_PAGE"
  184.     session("oPageEngine").ImageOptions = 1
  185.     response.binarywrite goPage.Renderhtml(1,1,3,request.ServerVariables("SCRIPT_NAME"),8209)
  186.         
  187.     end select
  188.  
  189.  
  190. Case "NAV"
  191.     Call RetrieveObjects
  192.     ' Get the page number that the group in on, for this particular branch
  193.     gvPageNumber = goPageGenerator.GetPageNumberForGroup(gvGroupLevel)
  194.             
  195.     Select Case VFMT
  196.     ' 0 is for epf, 8209 is a SafeArray, 8 is a BSTR
  197.     Case "ENCP"
  198.         ' Create a byte array for the EMF, which will contain the page number
  199.         session("oEMF").sendpagenumberrecord(gvPageNumber)
  200.     
  201.     Case "HTML_FRAME"
  202.         ' for html browser send back the page
  203.         session("CurrentPageNumber") = gvPageNumber
  204.         response.redirect "framepage.asp"
  205.     
  206.     end select
  207.  
  208.  
  209. Case "CHRT_DD"
  210.     ' only support in smart viewers
  211.     Select Case VFMT
  212.  
  213.     Case "ENCP"
  214.  
  215.         '  Get page collection
  216.         Call RetrieveObjects
  217.         ' Pass the coordinates to the report engine to determine what
  218.         ' branch the drill down goes to.
  219.         Set goPageGeneratorDrill = goPageGenerator.DrillOnGraph(PAGE, glX, glY)
  220.         ' Check for an exception because of coordinates
  221.         if err.number <> 0 then
  222.             gsErrorText = "Not part of the Graph"
  223.             session("oEMF").SendErrorMsg 40, gsErrorText        
  224.             err.clear
  225.             response.end
  226.         end if
  227.         ' pass the group level and group path to helper function to create 
  228.         ' the EMF message, this tells the viewer where to get the page.
  229.  
  230.         gvGroupPathDD = goPageGeneratorDrill.grouppath
  231.         gvGroupNameDD = goPageGeneratorDrill.groupname
  232.  
  233.         if err.number <> 0 then
  234.             gsErrorText = "Not part of the Graph"
  235.             session("oEMF").SendErrorMsg 40, gsErrorText        
  236.             err.clear
  237.             response.end
  238.         end if    
  239.         
  240.         'session("oEMF").sendbranchesemf(gvGroupPathDD,gvGroupNameDD)\
  241.         session("oEMF").GroupName = gvGroupNameDD        
  242.         session("oEMF").sendbranchesemf(gvGroupPathDD)        
  243.             
  244.  
  245.     end select
  246.  
  247. Case "GET_LPG"
  248.     
  249.     ' only support in smart viewers
  250.     Select Case VFMT
  251.  
  252.     Case "ENCP"
  253.         ' this command returns the page number of the last page
  254.         ' Get page collection
  255.         Call RetrieveObjects
  256.         ' Get the count from the Pages collection
  257.         gvPageNumber = goPageCollection.Count
  258.  
  259.         ' Send the EMF representing the page number
  260.         session("oEMF").sendpagenumberrecord(gvPageNumber)
  261.     end select
  262.  
  263. Case "SRCH"
  264.     Call RetrieveObjects
  265.     ' create page variable
  266.     gvPageNumber = CInt(PAGE)
  267.     
  268.     Select Case VFMT
  269.     Case "ENCP"
  270.         if goPageGenerator.SearchForText(TEXT, 0, gvPageNumber) then
  271.             session("oEMF").sendpagenumberrecord(gvPageNumber)
  272.         else
  273.             gsErrorText = "The specified text, '" & TEXT & "' was not found in the report"
  274.             session("oEMF").SendErrorMsg 33, gsErrorText
  275.         end if
  276.                     
  277.     Case "HTML_FRAME"
  278.         ' We are being called by HTML viewer
  279.         ' need to get the text from the form post
  280.         TEXT = request.form("text")
  281.         ' Now find out what page the text is on
  282.         goPageGenerator.SearchForText TEXT, 0, gvPageNumber
  283.         session("CurrentPageNumber") = gvPageNumber
  284.         if BRCH <> "" then
  285.             gvURL = "framepage.asp?brch=" & BRCH
  286.         else
  287.             gvURL = "framepage.asp"
  288.         end if
  289.         response.redirect gvURL
  290.  
  291.     Case "HTML_PAGE"
  292.         ' We are being called by HTML viewer
  293.         ' need to get the text from the form post
  294.         TEXT = request.form("text")
  295.         ' Now find out what page the text is on
  296.         goPageGenerator.SearchForText TEXT, 0, gvPageNumber
  297.         Set goPage = goPageCollection(gvPageNumber)
  298.         session("oPageEngine").ImageOptions = 1
  299.         response.binarywrite goPage.Renderhtml(1,1,3,request.ServerVariables("SCRIPT_NAME"),8209)
  300.     end select
  301.  
  302.                 
  303. Case "TOOLBAR_PAGE"
  304.     
  305.     ' Redirect to the framepage, need to know if we are 
  306.     ' on the last page.
  307.  
  308.     if session("LastPageNumber") <> "" then
  309.         if CInt(PAGE) > CInt(session("LastPageNumber")) then
  310.             session("CurrentPageNumber") = session("LastPageNumber")
  311.         else
  312.             session("CurrentPageNumber") = PAGE
  313.         end if
  314.     else 
  315.         Call RetrieveObjects
  316.         
  317.         ' create the actual page
  318.         Set goPage = goPageCollection(PAGE)
  319.         ' check for an exception on the page number 
  320.         if err.number <> 0 then
  321.             if err.number = 9 then 
  322.                 ' just return the last page
  323.                 PAGE = goPageCollection.count
  324.                 Set goPage = goPageCollection(PAGE)
  325.                 session("LastPageNumber") = PAGE
  326.                 session("CurrentPageNumber") = PAGE
  327.                 err.clear
  328.             else
  329.                 ' abort the script
  330.                 response.end
  331.             end if
  332.         end if
  333.         if goPage.IsLastPage then
  334.             session("LastPageNumber") = goPage.pagenumber
  335.             session("CurrentPageNumber") = session("LastPageNumber")    
  336.         else
  337.             session("CurrentPageNumber") = PAGE
  338.         end if    
  339.     end if
  340.     if BRCH <> "" then
  341.         gvURL = "framepage.asp?brch=" & BRCH
  342.     else
  343.         gvURL = "framepage.asp"
  344.     end if
  345.  
  346.     response.redirect gvURL
  347.  
  348. end select
  349.  
  350.  
  351.  
  352. SUB RetrieveObjects() 
  353. ' this procedure simply retrieves the session objects into 
  354. ' global variables
  355.     Dim oRptOptions 'Report Options 
  356.  
  357.     if IsObject(session("oPageEngine")) then
  358.         ' make sure dialogs have been disabled
  359.         Set oRptOptions = session("oRpt").Options
  360.         oRptOptions.MorePrintEngineErrorMessages = 0
  361.  
  362.         Set goPageGenerator = session("oPageEngine").CreatePageGenerator(gvGroupPath)
  363.         Set goPageCollection = goPageGenerator.Pages
  364.     else
  365.         ' must have timed out return an error, you may wan to Append to the
  366.         ' IIS log here.
  367.         if VFMT = "ENCP" then 
  368.             session("oEMF").SendErrorMsg 54, "User Session has expired"
  369.         else
  370.             response.write "User Session has expired"
  371.             
  372.         end if
  373.         response.end
  374.     end if
  375.  
  376. END SUB
  377.  
  378. SUB ParseQS()
  379.     ' Parse the Query String 
  380.     CMD = UCase(request.querystring("cmd"))        ' This determines the main function to perform
  381.     PAGE = UCase(request.querystring("page"))    ' the page to return
  382.     BRCH = UCase(request.querystring("BRCH"))    ' the branch is a mechanism to determine the drill down level.
  383.                                                 ' A drill down level is like a view of the report, a new tab
  384.                                                 ' is created to indicate that it is a new view
  385.     VIEWER = UCase(request.querystring("VIEWER"))    ' This is the viewer that is calling the server
  386.     VFMT = UCase(request.querystring("VFMT"))    ' the format that the viewer understands
  387.     NODE = UCase(request.querystring("NODE"))
  388.     GRP = UCase(request.querystring("GRP"))        ' this is a way of specifing the actual group
  389.     COORD = UCase(request.querystring("COORD"))    ' these are the coordinates on the graph to process
  390.     DIR = UCase(request.querystring("DIR"))        ' this is the search direction
  391.     CSE = UCase(request.querystring("CASE"))    ' indicates if the search is case sensitive
  392.     TEXT = request.querystring("TEXT")            ' this is the text to search for.
  393.     INIT = UCase(request.querystring("INIT"))    ' used to build the frames for the html viewer
  394.  
  395.  
  396.     ' Initialize variables to a default if they are not provided on the query string.
  397.  
  398.  
  399.     if CMD = "" then
  400.         CMD = UCase(request.form("cmd"))    
  401.         if CMD = "" then
  402.             CMD = "GET_PG"
  403.         end if
  404.     end if
  405.     
  406.     if BRCH = "" then
  407.         BRCH = UCase(request.form("BRCH"))
  408.     end if
  409.  
  410.     if VIEWER = "" then
  411.         VIEWER = UCase(request.form("VIEWER"))
  412.         if VIEWER = "" then
  413.             VIEWER = "HTML"
  414.         end if
  415.     end if
  416.  
  417.     if VFMT = "" then 
  418.         VFMT = UCase(request.form("VFMT"))
  419.         if VFMT = "" then 
  420.             VFMT = "HTML_PAGE"
  421.         end if
  422.     end if
  423.  
  424.     if GRP = "" then
  425.         GRP = UCase(request.form("GRP"))    
  426.     end if
  427.  
  428.     if COORD = "" then
  429.         COORD = UCase(request.form("COORD"))
  430.     end if
  431.  
  432.     if NODE = "" then
  433.         NODE = UCase(request.form("NODE"))
  434.     end if
  435.  
  436.     if DIR = "" then
  437.         DIR = UCase(request.form("DIR"))
  438.         if DIR = "" then
  439.             DIR = "FOR" ' forward
  440.         end if
  441.     End if
  442.  
  443.     if CSE = "" then
  444.         CSE = UCase(request.form("CASE"))
  445.         if CSE = "" then
  446.             CSE = "0" ' case insensitive
  447.         end if
  448.     end if
  449.  
  450.     if TEXT = "" then
  451.         TEXT = request.form("TEXT")
  452.     end if
  453.  
  454.     if INIT = "" then
  455.         INIT = UCase(request.form("INIT"))
  456.     end if
  457.  
  458.     ' Check to make sure there is a page requested, if not use 1 as a default
  459.     if PAGE = "" then
  460.         PAGE = UCase(request.form("page"))
  461.         if PAGE = "" then
  462.             PAGE = "1"
  463.         end if
  464.     end if
  465.  
  466. END SUB
  467.  
  468. Function CreateArray(ByVal vsStringArray)
  469. ' this function takes an string like 0-1-1-0 and converts
  470. ' it into an array of integers
  471.  
  472.     Dim lvArray
  473.     Dim lvNewArray
  474.     Dim liCount
  475.     Dim liCurrentPos
  476.     Dim lsBuf
  477.     lvArray = Array()
  478.     lvNewArray = Array()
  479.     ReDim lvArray(256)
  480.     
  481.     liStringLength = Len(vsStringArray)
  482.     liCount = 0
  483.     liCurrentPos = 1
  484.     lsBuf = ""
  485.     
  486.     While liCurrentPos <= liStringLength
  487.          
  488.          'ignore this character
  489.         If Mid(vsStringArray, liCurrentPos, 1) <> "-" Then
  490.             lsBuf = lsBuf & Mid(vsStringArray, liCurrentPos, 1)
  491.             If liCurrentPos = liStringLength Then
  492.                 lvArray(liCount) = CInt(lsBuf)
  493.                 lsBuf = ""
  494.                 liCount = liCount + 1
  495.             End If
  496.             
  497.         Else
  498.             lvArray(liCount) = CInt(lsBuf)
  499.             lsBuf = ""
  500.             liCount = liCount + 1
  501.         End If
  502.         liCurrentPos = liCurrentPos + 1
  503.     Wend
  504.     
  505.     ReDim lvNewArray(liCount - 1)
  506.     
  507.     For x = 0 To (liCount - 1)
  508.         lvNewArray(x) = lvArray(x)
  509.     Next
  510.     
  511.     
  512.     CreateArray = lvNewArray
  513.  
  514. End Function
  515.  
  516. SUB GetDrillDownCoordinates()
  517.     Dim liStringLength
  518.     Dim lbDone
  519.     Dim lsBuf
  520.  
  521.     liStringLength = Len(COORD)
  522.     lbDone = FALSE
  523.     lsBuf = ""
  524.     glX = ""
  525.     glY = ""
  526.     For x = 1 To liStringLength
  527.         lsBuf = Mid(COORD, x, 1)
  528.         
  529.         'ignore this character
  530.         If lsBuf = "-" Then
  531.             lsBuf = ""
  532.             lbDone = TRUE
  533.         End if
  534.         
  535.         if lbDone then
  536.             glY = glY + lsBuf
  537.         else
  538.             glX = glX + lsBuf
  539.         end if
  540.             
  541.     Next
  542.     
  543. END SUB
  544.  
  545. %>
  546.  
  547.  
  548.