March 22, 2016 at 7:58 am
This one has been a head scratcher for 2 days now. I have code that I want to show a bar code or show a default image. I want to show the default image if the value I am using to generate the barcode is blank. I am using a DLL from CodeProject to generate the barcode and the default image is stored in SQL Server. This is done in image properties using an expression. The strangeness is that I can render either one via the expression as long as it is by itself. As soon as I put them together, the barcode will generate but NOT the image I have stored in the DB. I started using the IIF which should work but when it was not working I moved to using SWITCH. I get the same results. If the value to produce the barcode is blank, instead of the image from the DB, it just shows a thumbnail. Otherwise, the Barcode image ALWAYS shows if the condition is true.
Below is the code I currently have that is NOT working:
=SWITCH
(
Len(First(Fields!PRO.Value, "Carrier")) <= 0, First(Fields!PROLabelImage.Value, "Carrier"),
Len(First(Fields!PRO.Value, "Carrier")) >= 0, Code.Convert(First(Fields!PRO.Value, "Carrier"))
)
If I run it like this (Value from the DB):
=SWITCH
(
Len(First(Fields!PRO.Value, "Carrier")) <= 0, First(Fields!PROLabelImage.Value, "Carrier")
)
or this (DLL function to create Barcode):
=SWITCH
(
Len(First(Fields!PRO.Value, "Carrier")) >= 0, Code.Convert(First(Fields!PRO.Value, "Carrier"))
)
It will render ( giving that the condition exists)
Has anyone else ran into this?
Greatly appreciate any assistance.
March 23, 2016 at 4:15 pm
Resolved the issue. Logically what I was doing was correct from an IIF and SWITCH perspective but it did not like having the other function (custom code) mixed with it. In order to make it work I had to slightly modify the code on the "Report Properties" and what I was doing with the Image's expression code.
Below is the custom code and what I added to it. I needed to add the Image itself as a parameter and check to see if the driver field to produce the barcode was blank. If it was then return the stock image else produce a barcode.
Public Function Convert(Text As String, PROLabel As Byte()) As Byte()
If Text = "" Then
Return PROLabel
End If
Dim b As System.Drawing.Bitmap
' Dim bar As New BarcodeLib.Barcode
bar.Alignment = BarcodeLib.AlignmentPositions.LEFT
bar.IncludeLabel = False
bar.RotateFlipType = Drawing.RotateFlipType.RotateNoneFlipNone
b = bar.Encode(BarcodeLib.TYPE.CODE39Extended, Text, 400, 30)
Dim bitmapData As Byte() = Nothing
Using ms As New System.IO.MemoryStream()
b.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
bitmapData = ms.ToArray()
End Using
Return bitmapData
End Function
Now I just needed to pass the new parameter in the expression:
=Code.Convert(First(Fields!PRO.Value, "Carrier"),First(Fields!PROLabelImage.Value, "Carrier"))
The Image now renders if the value is blank (no thumbnail) and returns the Barcode if <> to blank
March 24, 2016 at 8:06 am
wow, nice
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply