Entry

"In priority AX2012. Spread useful projects and materials for the development of business applications. Good luck!"

пятница, 27 декабря 2013 г.

Electronic signature and AX. Part 1: Check Office file on exists signatures [AX2012]

How check to exists signatures in Word or Excel file:
void veryfyDocuFile(Common  _common)
{
    DocuRef                 docuRef;
    ComExcelDocument_RU     excelDocument;
    ComWordDocument_RU      wordDocument;
    COM                     document;
    COM                     signatures;
    COM                     sign;
    FilePath                filePath;
    Filename                fileName;
    str endSlash(str _str)
    {
        return (strscan(_str, '\\',strlen(_str),-1)) ? _str : _str + '\\';
    }
    
    while select docuRef
        order by TypeId desc
        where docuRef.RefCompanyId == _common.dataAreaId
           && docuRef.RefTableId   == _common.TableId
           && docuRef.RefRecId     == _common.RecId
    {
        if (docuRef.isValueAttached())
        {
            if(docuRef.docuType().FilePlace != DocuFilePlace::Database && docuRef.docuValue().Type != DocuValueType::URL)
            {
                fileName = docuRef.completeFilename();
            }
            else if(docuRef.docuType().FilePlace == DocuFilePlace::Database)
            {
                fileName = DocuActionFile::saveTempFile(docuRef);
            }
            try
            {
                switch(docuRef.docuValue().FileType)
                {
                    case 'xls', 'xlsm', 'xlsx', 'xltm':
                        excelDocument = new ComExcelDocument_RU();
                        #StartSafeCall_RU
                        excelDocument.open(fileName, false);
                        #EndSafeCall_RU
                        if(excelDocument.getComDocument() != null)
                            document = excelDocument.getComDocument();
                        if(document)
                        {
                            #StartSafeCall_RU
                            signatures = document.Signatures();
                            #EndSafeCall_RU
                        }
                        if(signatures && signatures.Count() >= 1)
                            info(strFmt("Docu %1 have a sign!", docuRef.docuValue().OriginalFileName));
                        else
                            info(strFmt("Docu %1 don't have a sign!", docuRef.docuValue().OriginalFileName));
                        excelDocument.saved(false);
                        excelDocument.closeDocument();
                        excelDocument.Quit();
                        break;
                    case 'doc', 'docx':
                        wordDocument = new ComWordDocument_RU();
                        wordDocument.open(fileName, true);
                        document = wordDocument.getComDocument();
                        signatures = document.Signatures();
                        if(signatures.Count() >= 1)
                            info(strFmt("Docu %1 have a sign!", docuRef.docuValue().OriginalFileName));
                        else
                            info(strFmt("Docu %1 don't have a sign!", docuRef.docuValue().OriginalFileName));
                        wordDocument.saved(false);
                        wordDocument.closeDocument();
                        wordDocument.quitApplication();
                        break;
                    default : error("Check error");
                }
            }
            catch(Exception::Error)
            {
                error('ExceptionError');
            }
        }
        else
            info("@SYS26665");
    }
}