Inspirone
"I maintain that Truth is a pathless land, and you cannot approach it by any path whatsoever, by any religion, by any sect. Truth, being limitless, unconditioned, unapproachable by any path whatsoever, cannot be organized; nor should any organization be formed to lead or to coerce people along any particular path. You must climb towards the Truth. It cannot be 'stepped down' or organized for you." - author: Jiddu Krishnamurthi
Saturday, January 27, 2007
Tuesday, January 09, 2007
Loading images dynamically in Crystal Report
Having come across a few issues related to the above I thought it might be worth to post the solution here so as to share it with other delvelopers.
Visual Studio 2003/2005 does not readily allow you to load an image file on a Crystal Report dynamically unless you use "Dynamic Image Location" feature which is available in Crystal Reports Developer XI. But there is a cheaper work around for this. The solution is to dynamically add an binary column to the XSD dataset and in the dataset containing the data to be printed. Then load the image file as binary data into the dataset.
1. In a column in your database table store the path to the image that needs to be displayed in a crystal report document, in this example the image path column name is "ImagePath".
2. Create a new Dataset/XML schema(xsd) in VS.Net that maps the fields in the database table. This should be the normal procedure when creating a report. In this XSD DataSet add an additional field that is not in the table and which is of type base64Binary :
xs:element name="Image" type="xs:base64Binary" minOccurs="0"
Note that the opening and closing tags are missing above since it won't be printed on this site. Just add enclose the above in "< />"
3. When designing the report based on this DataSet, drag and drop the "Image" field in the region where you want it to appear.
4. Add the following procedures to your code:
Private Sub AddImageColumn(ByVal objDataTable As DataTable, ByVal strFieldName As String)
Try
'create the column to hold the binary image
Dim objDataColumn As DataColumn = New DataColumn(strFieldName, Type.GetType("System.Byte[]"))
objDataTable.Columns.Add(objDataColumn)
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
'*... and this one to load the image in the above added field:
Private Sub LoadImage(ByVal objDataRow As DataRow, ByVal strImageField As String, ByVal FilePath As String)
Try
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim Image() As Byte = New Byte(fs.Length) {}
fs.Read(Image, 0, CType(fs.Length, Integer))
fs.Close()
objDataRow(strImageField) = Image
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
5. Before assigning the dataset to the "SetDataSource" of your report, add the following code:
' Fill the dataset "DS" as required with data to be displayed on the report
'* Begin code to add
AddImageColumn(DS.Tables(0), "Image")
' Loop to load the image for each row
For index As Integer = 0 To DS.Tables(0).Rows.Count - 1
If Not String.IsNullOrEmpty(DS.Tables(0).Rows(index).Item("ImagePath").ToString) Then
LoadImage(DS.Tables(0).Rows(index), "Image", _
DS.Tables(0).Rows(index).Item("ImagePath").ToString)
Else
'* You could load a default image here, like "no image to display"
'* if you have a standard one then un-comment the code below and change the image path
'LoadImage(DS.Tables(0).Rows(index), "Image", "c:\MyDefaultImage.JPG")
End If
Next
'* End code to add
rptDoc.SetDataSource(DS.Tables(0))
' Display report in a report viewer control
Thursday, January 04, 2007
Deception or surprise
How does one feel, when one has no news from someone one cares for? No phone calls, no mails, nothing, just void. It surely is a feeling of frustration, unbearable agony, emptiness, helplessness. Sometimes it happens that a person is so close but still very far away or even unreachable. Is hope a solution? Hope is meaningless and has nothing concrete in it, whereas facts are realistic. One has to be realistic in life and never live on hopes...
Tuesday, January 02, 2007
What's in a number?
Anyways one interesting use of numbers and maths is a little card trick that I learned some time ago, though I can't remember when, from whom or where. The trick is simple but yet very puzzling. Since I probably got it for free I guess its best to share it. Knowledge is not new, it can only be shard across humanity. Therefore everything we learn is old. Even when we come across new knowledge, the moment we realise this, it is already old. Thought being source of knowledge, thought being an action of the past since by the time we react time has already elapsed, we are constantly living in the past. So be it.
e.g:
Labels: Card trick, Magic, Numbers