Monday, November 29, 2021

Generate QR code using x++ in SSRS report

 Hi guys, Today we see how to Generate QR codes using x++ in D365FO SSRS reports. We can generate QR codes in two ways. Please check below.


Steps :

            1. Need to create container filed in Temp table.


            2. Add Way1/Way2 code in DP class and calling that method while inserting data into temp table. Like below.

                    headerTmp.Image = this.QRCode('TEST');// Your method.

                     headerTmp.insert();

            3.click restore on report

            4. Add image field in design                          


            5. Image Properties :

      • Select the image source : Database
      • Use this field : Field from Table
      • Use this MIME type : image/bmp               



Way 1:

using QRCoder;
public class GetQRCode
{
public static container QRCode(JournalTable  _jour)
{
    Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder   qrCode;
    str                                 QrCodeBase64String;
    System.String                       netString;
    str                                 tempFileName;
    System.Drawing.Bitmap               netBitmap;
    Bitmap                              imageQR;
    FileIOPermission                    perm;
    BinData                             binData;
    container                           imageContainer;
    Str1260                             qrString;
    real                                taxWithoutVat;
    QRCodeGenerator.ECCLevel            eccLevel;
    QRCodeGenerator                     qrGenerator = new QRCodeGenerator();
    ;

    qrCode          = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();
    //qrString        = strFmt("https://www.google.com/");
    qrString        = strFmt("Supplier name: %1", CompanyInfo::findDataArea(_jour.DataAreaId).Name);
    qrString        += strFmt("\nInvoice number: %1", _jour.InvoiceId);
    qrString        += strFmt("\nInvoice Date: %1", _jour.InvoiceDate);
    qrString        += strFmt("\nTotal amount with VAT: %1", _jour.InvoiceAmount);

    netBitmap       = qrCode.Encode(qrString);

    binData         = new binData();

    QrCodeBase64String  = qrString;
    tempFileName        = qrCode.GetTempFile(QrCodeBase64String);

    perm  = new FileIOPermission(tempFileName,'RW');

    perm.assert();
    binData.loadFile(tempFileName);
    imageContainer          = binData.getData();

    // header.QRValue = imageContainer;
    return imageContainer;
}
}

==============================================================================

Way 2:

using QRCoder;
public class GetQRCode
{
    public static container QRCode(SalesId _salesId)
    {
        Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder  
            qrCode = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();
        System.Drawing.Bitmap       bitmap;
        container                   imageContainer;
        str                         url= strFmt("%1'%2'", Parameters::find().QRCodeUrl, _salesId);
        ;        

        System.IO.MemoryStream memoryStream = new System.IO.MemoryStream();

        bitmap = qrCode.Encode(url);

        bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat::get_Png());
        //bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat::Png);

        imageContainer = Binary::constructFromMemoryStream(memoryStream).getContainer();

        return imageContainer;
    }
}
-------------------oR------------------------------------
    private container QRCode(str _value) { Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder qrCode = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder(); System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(); System.Drawing.Bitmap bitmap; bitmap = qrCode.Encode(_value); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat::Png); return Binary::constructFromMemoryStream(memoryStream).getContainer();; }


Keep daxing!!

No comments:

Post a Comment