mercoledì 28 settembre 2022

AX 2012 - QR code su SSRS

In questo post vediamo come aggiungere un QR ad un report SSRS. Per fare ciò AX mette a disposizione un componente esterno.

Per prima cosa occorre creare nella tabella temporanea del report un campo di tipo Bitmap che chiameremo QRCode (possiamo per esempio copiare il campo CompanyLogo presente nella tabella del report della fattura).

Con questo metodo inserito nella nostra DP possiamo generare il BitMap da associare al nostro campo QRCode:

protected Bitmap getQRCode()
{
    Bindata                 bindata = new Bindata();
    System.Drawing.Bitmap   obj;
    Filepath                filepath,
                        filePathName;                
    container               con;
    Microsoft.Dynamics.QRCode.Encoder   encoder;
    FileIoPermission  filepermission; 

    filepath = @'\\MyServer\Temp\';
        
    filePathName = System.IO.Path::Combine(filepath
                                            ,strFmt("%1.bmp","img"));
        
    filepermission = new FileIoPermission(filePathName, 'rw');
    filepermission.assert();
        
    encoder   = new Microsoft.Dynamics.QRCode.Encoder();
    obj = new System.Drawing.Bitmap(encoder.Encode("StringToEncode"));
    obj.Save(filePathName,System.Drawing.Imaging.ImageFormat::get_Bmp());
    bindata.loadFile(filePathName);
    con = bindata.getData();
        
    CodeAccessPermission::revertAssert();
   
    return con;
} 

Sul Design del report dobbiamo poi definire un controllo di tipo image, possiamo copiare dai report standard che visualizzano i loghi (Conferma ordine, Fattura etc...). Ecco il risultato: