Barcodes have been around for a long time. And despite newer technologies, they remain popular. Deservedly! You can use barcodes in production environments, for coding your invoices, in retail, POS, … The programmers of Ax have made it easy for you to use them. Fonts and classes have been provided in Ax to get you up and running with barcodes quickly. In this post I’ll show you how you can use barcodes in your report.
This is post 1 of 2. In this post, we’ll cover the very basics. And for that, we’ll use barcodes of type Code 39. Why Code 39? Because they are commonly used, read by almost every scanner and very easy to implement.
Code 39 supports alphanumeric characters, and some special characters like – . $ / + % SPACE. Unlike with most other type of barcodes, no real encoding is needed (no check digit either). All you really have to do is set the right font. This means you can even use this barcode type easily in for example Word! Altough Ax supports encoding of Code 39, we are not going to use it now, for reasons of simplicity. (Encoding will be dealt with in part 2 of this post.)
Let’s assume we have a report in Ax, showing all our inventory items. This reports uses InventTable as a base. We would like the barcode to consist of the ItemId. For that purpose, we create a display method, like this:
Display str ShowBarcode()
{
return "*"+strupr(InventTable.ItemId)+"*";
}
The asterisk (*) is the start and stop character in Code 39, that’s why we add it. We add this display method to the body of our report. Next up, we set the appropriate font for our report control.
Make sure you set the width of the report control big enough! (Make it center aligned as well.)
And that’s all there is to it. Have a look at the result, as seen in our print preview:
Note that the readible text below the barcode is printed with a separate report control. It’s not included with the actual barcode.
we’ll have a look at another barcode type. We gonna see how to use barcodes of type Code 128 in your report. This is a high density barcode type, with checksum digit, supporting alphanumeric symbols. Very commonly used.We gonna use the same example as in the previous post, an inventory report, with InventTable as the datasource.We’ll start off with our class declaration. In this, we’ll create an object for class BarcodeCode128. This class is used for encoding the barcode, checking/calculating check digit.
public class ReportRun extends ObjectRun
{
BarcodeCode128 MyBarcode;
}
In the init method of our report, we instantiate the class.
public void init()
{ ;
MyBarcode= BarcodeCode128::construct();
super();
}
As opposed to Code 39 (see previous post), we now have to do some actual encoding. But no worries, the barcode class does this for us.
We’ll create our display method in which we’ll do the encoding:
Display BarcodeStr ShowBarcode()
{
MyBarCode.string(true,InventTable.ItemId);
MyBarCode.encode();
return MyBarCode.barcodeStr();
}
Remember to set the report control properties with the appropriate font, something like this:
And this is what your result looks like when you call the report.
As you can see from the other classes in the AOT named Barcode*, Ax supports barcodes of type EAN, Interleaved 2 of 5, UPC, …
原文地址(GFW):http://dynamics-ax-live.blogspot.com/2010/05/how-to-use-barcodes-in-your-ax-report.html
http://dynamics-ax-live.blogspot.com/2010/05/how-to-use-barcodes-in-your-ax-report_15.html
转载请注明:ww12345678 的部落格 | AX Helper » [转]How to use barcodes in your Ax report