 |
|
 |
|
|
Author: |
host |
Created: |
3/6/2006 9:55 PM |
 |
|
Adventures in .NET |
|
Dynamic Images in Crystal Reports .NET |
|
|
By Andy Beaulieu on
1/27/2005 8:10 PM
|
|
|
|
You would think this is a simple task: let's say you have a Crystal Report and you want to dynamically change an image in the report by loading an image from disk. Well, as it turns out, this functionality is not available in CR for .NET!
But here is a work-around; Crystal for .NET does support displaying images from a DB. And it does support accepting a disconnected ADO DataSet as a data source. So you can trick Crystal into thinking it loaded an image from disk and presto, you have dynamic images from disk. Here's the process:
(1) Create an XSD file (you'll use this as your report data source in step 2) with a binary column definition like so:
<xs:element name="AnImage" type="xs:base64Binary" minOccurs="0" />
(2) Create your Crystal Report and use an ADO.NET (XML) DataSource as your Crystal Report Data Source.
(3) Fill your DataSet, and then set the binary “image” column to an image file from disk using a MemoryStream like so:
Dim oLogo As System.Drawing.Image Dim msX As New MemoryStream Dim dsReportSource As New DataSet ' TODO: Fill your DataSet, dsReportSource, with your Report Data
' Load your image from disk oLogo = oLogo.FromFile("C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Blue hills.jpg") ' Save the image data to a Memory Stream oLogo.Save(msX, System.Drawing.Imaging.ImageFormat.Bmp) ' Set the binary "image" column in your DataSet to the image data (note dsReportSource is a typed DS here) dsReportSource.TestImage(0).AnImage = msX.GetBuffer
(4) Load your Crystal Report and assign the Data Source as usual:
Dim oRpt As New ReportDocument oRpt.Load("CrystalReport1.rpt") oRpt.SetDataSource(DsTestImage1) CrystalReportViewer1.ReportSource = oRpt
|
 |
|
Comments (6)
|
|
|
|
Streaming Crystal Output to a Browser |
|
|
By Andy Beaulieu on
12/14/2004 7:19 PM
|
|
|
|
This is a handy function that accepts an Export Format (i.e. PDF, Word or Excel) and streams a Crystal Report output back to the browser client.
Private Sub ExportReport(ByVal iFormatType As ExportFormatType) Dim sTargetPath As String, sTargetExt As String, sContentType As String Dim fs As FileStream Dim FileSize As Long Dim GenDS As DataSet Dim oRD As New ReportDocument() Dim crReportObject As ReportObject Dim oExO As ExportOptions Dim oExDo As New DiskFileDestinationOptions()
'Build Target Filename Select Case iFormatType Case ExportFormatType.Excel sTargetExt = ".xls" sContentType = "application/vnd.ms-excel" Case ExportFormatType.PortableDocFormat sTargetExt = ".pdf" sContentType = "application/pdf" Case ExportFormatType.WordForWindows sTargetExt = ".doc" sContentType = "application/msword"
End Select
sTargetPath = Server.MapPath("") & "\Export\" & Session.SessionID & sTargetExt
oRD = GetReportDocument() 'Export to PDF oExDo.DiskFileName = sTargetPath oExO = oRD.ExportOptions oExO.ExportDestinationType = ExportDestinationType.DiskFile oExO.ExportFormatType = iFormatType oExO.DestinationOptions = oExDo oRD.Export() oRD.Close()
'Send the file to the user that made the request Response.Clear() Response.Buffer = True Response.AddHeader("Content-Type", sContentType) Response.AddHeader("Content-Disposition", "file;filename=" & Left(ViewState("ReportName"), Len(ViewState("ReportName")) - 4) & sTargetExt) fs = New FileStream(sTargetPath, FileMode.Open) FileSize = fs.Length Dim bBuffer(CInt(FileSize)) As Byte fs.Read(bBuffer, 0, CInt(FileSize)) fs.Close()
Response.BinaryWrite(bBuffer) Response.Flush() Response.Close()
End Sub
|
 |
|
Comments (3)
|
|
|
|
|
|
|
Retrieving DB2 Index Info |
|
|
By Andy Beaulieu on
10/20/2004 9:09 AM
|
|
|
|
The Visual Studio.NET add-in for DB2, which is part of the “Stinger“ release, offers a much better implementation of the Server Explorer for DB2 users. But I recently found myself needing Index information from a DB2 database without any good schema exploration tool...
SELECT SYSCOLUMNS.TBNAME, SYSCOLUMNS.TBCREATOR, SYSKEYS.IXNAME, SYSKEYS.COLNAME, SYSKEYS.COLSEQ, SYSCOLUMNS.NAME, SYSCOLUMNS.TBNAME, SYSCOLUMNS.TBCREATOR, SYSCOLUMNS.COLNO, SYSCOLUMNS.COLTYPE, SYSCOLUMNS.LENGTH,SYSCOLUMNS.SCALE, SYSCOLUMNS.NULLS FROM SYSIBM.SYSKEYS SYSKEYS ,SYSIBM.SYSCOLUMNS SYSCOLUMNS INNER JOIN SYSIBM.SYSINDEXES SYSINDEXES ON SYSINDEXES.NAME = SYSKEYS.IXNAME WHERE SYSKEYS.IXCREATOR = SYSCOLUMNS.TBCREATOR AND SYSKEYS.COLNAME = SYSCOLUMNS.NAME AND SYSKEYS.COLNO = SYSCOLUMNS.COLNO AND SYSKEYS.IXCREATOR = '<CREATOR>' AND SYSINDEXES.TBNAME ='<TABLENAME>' AND SYSCOLUMNS.TBNAME = SYSINDEXES.TBNAME AND SYSINDEXES.CREATOR = '<CREATOR>' ORDER BY TBNAME,IXNAME,COLSEQ
|
 |
|
Comments (0)
|
|
|
|
Remoting DataSets |
|
|
By Andy Beaulieu on
10/15/2004 1:44 PM
|
|
|
|
I think this is an inside joke with the folks who coded DataSet Serialization and Remoting at Microsoft ;-)
Q: Why did the DataSet cross the Remoting Channel in Binary Format?
A: To get serialized as XML!
(crowd laughs)... When you serialize a DataSet, say through remoting, the DataSet gets serialized as XML. So if you're trying to eek out some performance by using Binary Formatting under Remoting, and you pass a DataSet, (here's the punchline), it gets passed as bloated XML.
Luckily, there are a couple of work-arounds presented in these articles ---
http://support.microsoft.com/?id=829740
http://msdn.microsoft.com/msdnmag/issues/02/12/cuttingedge/
|
 |
|
Comments (0)
|
|
|
|
Finding the CPU Hog |
|
|
By Andy Beaulieu on
10/13/2004 1:38 PM
|
|
|
|
This is really a fun game. You have a bunch of services running on a box, and users are reporting sluggish response during off hours. You have a hunch that one of the services is hogging the CPU, but how do you figure out which one is the hog?
Here is a quick step-by-step on finding the CPU hog using performance monitor (XP or W2k):
(1) Goto Control Panel/Administrative Tools/Performance
(2) Select Performance Logs and Alerts, then Counter Logs.
(3) Right-click Counter Logs and select “New Log Settings...” and give the Log a name.
(4) Select Thread from Performance Object, then % Processor Time.
(5) Select the All Instances radio button, then click the Add button, then Close.
(6) For the Log File Type DropDown, you probably want to select CSV so you can toy with the data in Excel afterwards ;-)
|
 |
|
Comments (0)
|
|
|
|
|
|
|
 |
|
 |
|
|