Sunday, December 24, 2023

QR Code & BarCode generator in D 365 F&O x++

 How To create QR Code in Report ?


1.write  a contract class like below Exp!


[DataContractAttribute]

Public class QRCodeCreationContract

{

   CustomerNameEDT   customerName;

 

   [DataMemberAttribute]

   public str parmCustomerName(str _customerName = customerName)

   {

       customerName = _customerName;

       return  customerName;

   }

 

}


2.Write a Dp class ?


[SRSReportParameterAttribute(classStr(QRCodeCreationContract))]

public class QRCodeCreationDp extends  SRSReportDataProviderBase

{

   WRE_QRCodeCreationTempTable       qRCodeCreationtemp;

 

   CustomerNameEDT      CustomerName;

 

 

   [SRSReportDataSetAttribute(tableStr('WRE_QRCodeCreationTempTable'))]

   public WRE_QRCodeCreationTempTable   getqRCodeCreationtemp()

   {

       select  qRCodeCreationtemp;

       return  qRCodeCreationtemp;

   }

 

   public static container QRCode(Str _QRContents)

   {

       // QRContents is a formatted string provided as input to this function.

       // For example _QRContents= ?name='Customer name'&rr='RFCno'&tt='totalInvoiceAmount';

 

       System.Drawing.Bitmap bm = null;

       try

       {

           //var qrCodeEncoder = new Encoder();

           Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder qrCodeEncoder = new Microsoft.Dynamics.ApplicationSuite.QRCode.Encoder();

           bm = qrCodeEncoder.Encode(_QRContents);

       }

       catch (Exception::CLRError)

       {

           error(CLRInterop::getLastException().ToString());

       }

       using (var stream = new System.IO.MemoryStream())

       {

           bm.Save(stream, System.Drawing.Imaging.ImageFormat::Bmp);

           bm.Dispose();

           return Binary::constructFromMemoryStream(stream).getContainer();

       }

   }

 

   public void processReport()

   {

      

       WRE_QRCodeCreationTable                  qrcodecreationTable;

       CompanyInfo                                          companyinfo;

                                                       

       companyinfo =  CompanyInfo::find();

 

       Query                                      query   = new Query();

       QueryBuildDataSource           qbds1;

       QueryBuildRange                    qbr;

       QueryRun                                qRun;

                                      

       QRCodeCreationContract       contract;

       contract = this.parmDataContract();

       customerName = contract.parmCustomerName();

 

       qbds1 = query.addDataSource(tableNum(WRE_QRCodeCreationTable));

       qbr   = qbds1.addrange(fieldNum(WRE_QRCodeCreationTable, CustomerName));

       qbr.value(CustomerName);

 

      

       qRun = new QueryRun(query);

       while(qRun.next())

       {

           

           qrcodecreationTable            = qRun.get(tableNum(WRE_QRCodeCreationTable));

         

           //qRCodeCreationtemp.clear();

           

         

           qRCodeCreationtemp.QRCode           = AA_CreateBarcodeHelper::generateQRCodeFromBase64(qrcodecreationTable.CustomerID);

           qRCodeCreationtemp.CustomerAddress  = qrcodecreationTable.CustomerAddress;

           qRCodeCreationtemp.CustomerID           = qrcodecreationTable.CustomerID;

           qRCodeCreationtemp.CustomerName     = qrcodecreationTable.CustomerName;

           qRCodeCreationtemp.CustomerMobileNo = qrcodecreationTable.CustomerMobileNo;

           qRCodeCreationtemp.BarCode          = AA_CreateBarcodeHelper::showBarcode(qrcodecreationTable.CustomerName);

           qRCodeCreationtemp.CurrentDate      = today();

           

           

           qRCodeCreationtemp.insert();

 

       }

   }

 

}


3.Create A  New Class   AA_CreateBarcodeHelper (For QRCode&BarCode)

class AA_CreateBarcodeHelper

{

   /// <summary>

   /// Barcode creation

   /// </summary>

   /// <param name = "barcodeText">Pass the text that you want to scan while scanning Bar Code</param>

   /// <returns>Barcode</returns>

   public static BarCodeString showBarcode(str barcodeText)

   {

       Barcode barcode;

 

 

       barcode = Barcode::construct(BarcodeType::Code39);

       barcode.string(true, barcodeText);

       barcode.encode();

 

 

       return barcode.barcodeStr();

   }

 

   public static Bitmap generateQRCodeFromBase64(str qrCodeText)

   {

       Bitmap qrCode;

 

 

       EFDocQRCode_BR generateQR = new EFDocQRCode_BR();

       generateQR.parmErrorCorrectionLevel(QRCodeErrorCorrectionLevel::Medium);

 

 

       try

       {

           qrCode = generateQR.generateQRCode(qrCodeText);

       }

       catch (Exception::CLRError)

       {

           warning("@ApplicationSuite_Localization:QRCodeIsDamaged");

       }

 

 

       return qrCode;

   }

 

}


4.Create Report Design As per Your Requirement ??


  QR CODE 

  




What you need to do?

  1. Create two simple classes, one is for QR code creation helper and other is for Bar code generation helper and paste the below code in it.
  2. Now, you can use these classes where you need to add the bar code or Qr code by simply calling it.

1. Create a new field in tmp table of the SSRS report

Field type: Extends
Extends: Bitmap
TmpTableQRCodeBitmap




  1. 2. Call above created function in DP class

    Provide formatted string for which QR code needs to be created and
    populate the tmp.QRCode =QRHelper::QRCode(_FormattedString)



  1. 3. Insert Image in RDLC design part of SSRS ??

  2. QRCodeImageRDLC


  1. 4.Build the project and deploy the report

    The report is now generated with a QR code.
    QRCodeSSRS


No comments:

Post a Comment

How To Create A WorkFlow In D365F&O

  How To Create Work Flow In D-365 F&O ? What is workflow? A workflow in the dynamics 365 apps is a way that automate business processes...