HomeProductsServicesPurchasePortfolioSupportDownloadsCompany
 


 
Overview
Features
What's new
Editions
Symbologies
Toolkit components
Tutorials
Samples
Faq
Licensing
Purchase
Download

< back to tutorials list
Barcode4NET and Windows Forms local reports
This tutorial presents how to display barcodes, created with Barcode4NET, in Windows Forms local reports.

Local reports, also known as RDLC reports (Report Definition Language Client-side processing), are a new type of reports that have been introduced in Visual Studio .Net 2005. They use the same definition language like the SQL Reporting Services reports, but they do not need the SQL Reporting Services complex infrastructure in order to run. The ReportViewer control take care of processing and displaying these reports.

Requirements
Before starting to work on this tutorial, make sure the following items are available:

  • Barcode4NET toolkit, any of Windows Forms & Mobile Devices or .Net editions.
  • Visual Studio .Net 2005
  • MS SQL 2005 + AdventureWorks database (other data sources can work as well).
Building the Vendors report

Please follow the steps in the sequence they are presented in order for this tutorial to work.

1. Start Visual Studio .Net 2005. Create a new Windows Forms application. Using the Data menu, add a new Data Source to the project.

This tutorial uses the AdventureWorks database that comes with MS SQL 2005. The Data Source that has been added to the project uses the Purchasing.vVendor view that already exists in the database. After adding the data source, the Visual Studio window should look like in the screenshot below.



2. Using the Project menu (Project > Add new item...), add a new Report to the application. Name the report VendorReport.rdlc.



3. Make sure the report is opened in design mode. Using the Report menu, display the report properties (Report > Report properties...) and select the References tab. In the References list, click on the first empty line and type this:
Barcode4NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fdeffed0f6085085

IMPORTANT: Make sure that Barcod4NET.dll assembly (located in Bin\Net 2.0) is registered in Global Assembly Cache. If it is not registered, use the gacutil.exe utility to register the assembly in GAC.



4. Select the Code tab and type the following function:

Public Function GetBarcodeImage(ByVal data As String) As Byte()
    'Create the barcode
    Dim c39 As New O2S.Barcode4NET.Code39Barcode(data)
    'Set the barcode size
    c39.DimensionUnit = O2S.Barcode4NET.XYDimensionUnit.Pixel
    c39.XDimension = 1
    c39.YDimension = 30
    'Get the barcode image as a gif image
    Return c39.GetImageData(O2S.Barcode4NET.BarcodeImageFormat.Gif, 0)
End Function

This tutorial uses a Code 39 (Code 3 of 9) barcode, but ANY barcode symbology that is supported by Barcode4NET toolkit can be used.



Click OK to save the changes made to report properties.

5. With the report opened in design mode, select the Table object in the toolbox and drag it on the report. Right click on the gray header and insert a new column. You should have now 4 columns. In the header row type Vendor name in the 1st column, First name in the 2nd column, Last name in the 3rd column and Phone in the 4th column.



6. Make sure the Data Sources window is visible (main menu: Data > Show Data Sources...) and vVendor view is expanded (like in Step 1 screenshot). Click on Name field and drag it on the details row in the 1st column. Click on First name field and drag it on the details row in the 2nd column. Click on Last name field and drag it on the details row in the 3nd column. Display the toolbox again, select the Image object and drag it on the details row in the 4th column.



7. Select the Image object in Phone column and set its properties:
MIMEType = image/gif (the image format here must match the first parameter of GetImageData method in the code at Step 4)
Source = Database
Value = =Code.GetBarcodeImage(Fields!Phone.Value) (the = sign must appear in front of Code keyword).
Sizing = AutoSize



8. Display the application's main form in design mode. Select the ReportViewer control in the toolbox and drag it on the form. Select VendorReport to be displayed in the control.



9. Add the following code line at the beginning of Form1_Load method:

C#:

reportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Barcode4NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fdeffed0f6085085");

VB.NET:

reportViewer1.LocalReport.AddTrustedCodeModuleInCurrentAppDomain("Barcode4NET, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fdeffed0f6085085")



10. Compile the application and run it.



11. The report can be exported as PDF and Excel files and the barcodes are preserved.
VendorReport exported as a PDF document.



VendorReport exported as an Excel document.



< back to tutorials list

NOTE: These tutorials provided here are for educational purposes only, to help developers understand and use Barcode4NET toolkit more effectively. However, they are provided AS-IS with not support or warranties expressed or implied. If you discover a problem, send an email to techsupport@o2sol.com and we'll try to fix it.


to top

News Archive | Company | Site Map | Privacy Policy | Contact Us
© 2003 - 2021 O2 solutions. All rights reserved