• Image in AX 2009


    Insert some of Image to Database back on Dynamics AX 2009

    code as below

    remark : Jimmy Jun 18th 2010

    static void Jimmy_TemporaryfileName(Args _args)
    {
    /**
        Binary image files into picture temporary files
        remark by Jimmy Jun 21th 2010
    */
        BinData         binData;
        Filename        filename;
        FilePath        filePath;
        InventStdPic    InventStdPic;
        #WINAPI
        str endSlash(str _str)
        {
            return (strscan(_str, '\\',strlen(_str),-1)) ? _str : _str + '\\';
        }
    ;
        select firstonly InventStdPic where InventStdPic.PicsName != '';
        
        binData = new BinData();
        binData.setData(InventStdPic.Images);//load file info to BinData
    
        filePath = endSlash(true ? WinAPI::getFolderPath(#CSIDL_INTERNET_CACHE) : xInfo::directory(DirectoryType::Temp));
    
        filename = InventStdPic.Filename(filePath);
    
        binData.saveFile(filename);// saved to the temp file as binData file...
        
        info(filename);
        
        IF(WINAPI::fileExists(filename))
        
            winAPI::shellExecute(filename);
    
    }
    
    

    代码
    void clicked()
    {
    str filename;
    dll dll;
    FileNameFilter filter
    = ['Image Files','*.bmp;*.jpg;*.gif;*.jpeg'];
    Bindata binData
    = new BinData();
    Filename onlyFilename;
    Filename curFileExtension;
    InventStdPic mtInventStdPic;
    RecId _RecId;
    ;
    if (!inventStdPic.RecId)
    {
    info(strfmt(
    "@PIC24"));
    return;
    }

    filename
    = Winapi::getOpenFileName(element.hWnd(),filter,'', "@SYS53008", '','');
    if(!filename)
    return ;
    if(!WINAPI::fileExists(filename,false))
    return;

    if ((filename) && (StrScan(filename,".gif",1,strlen(filename)) > 0))
    {
    filename
    = "";
    checkFailed(strfmt(
    "@PIC25"));
    return;
    }

    _RecId
    = inventStdPic.RecId;
    if (binData.loadFile(filename))
    {
    [onlyFilename,curFileExtension]
    = Docu::splitFilename(filename);
    InventStdPic_ds.write();

    if (onlyFilename)
    {
    // backup existing record
    if (inventStdPic.PicsName != "")
    {
    ttsbegin;
    select forupdate mtInventStdPic;
    mtInventStdPic
    = inventStdPic.data();
    mtInventStdPic.ItemId
    = '';
    mtInventStdPic.DefaultPic
    = NoYes::No;
    mtInventStdPic.ItemType
    = InventTable.ItemType;
    mtInventStdPic.RefRecId
    = InventTable.RecId;
    mtInventStdPic.Images
    = binData.getData();
    mtInventStdPic.ImageSize
    = WINAPI::fileSize(filename) / 1024 / 1024;
    mtInventStdPic.RecId
    = 0;
    mtInventStdPic.insert();
    ttscommit;

    inventStdPic.Posted
    = NoYes::No;
    }
    // end - backup existing record

    InventStdPic.PicsExtension
    = curFileExtension;
    InventStdPic.PicsName
    = NumberSeq::newGetNum(NumberSeqReference::findReference(TypeId2ExtendedTypeId(typeid(JIB_ItemPicsFileName)))).num();
    inventStdPic.ItemId
    = inventTable.ItemId;
    inventStdPic.Images
    = binData.getData();
    inventStdPic.ImageSize
    = WINAPI::fileSize(filename) / 1024 / 1024;
    inventStdPic.ItemType
    = InventTable.ItemType;
    inventStdPic.RefRecId
    = InventTable.RecId;
    inventStdPic.PrintItemId
    = inventTable.ItemId;
    }
    }
    InventStdPic_ds.active();


    inventStdPic_ds.executeQuery();
    inventStdPic_ds.research();
    inventStdPic_ds.findRecord(InventStdPic::findByRecId(_RecId));
    element.redraw();
    }

    Changed Images

    代码
    void ChangedImages()
    {
    #WINAPI
    FilePath _FilenameOpen;
    Container con;
    FileNameFilter filter
    = ["Image Files","*.bmp;*.jpg;*.gif;*.jpeg"];
    Image logoImage
    = new Image();
    ;
    try
    {
    _FilenameOpen
    = WinAPI::getOpenFileName(element.hWnd(),filter,WinAPI::getFolderPath(#CSIDL_Personal),
    "@SYS53008", '','');
    if(!_FilenameOpen || !WINAPI::fileExists(_FilenameOpen))
    return ;
    logoImage.loadImage(_FilenameOpen);

    con
    = global::fileNameSplit(_FilenameOpen);
    ttsbegin;

    DocuTest
    = QVS_DocuTest::find(QVS_DocuTest.ItemId, QVS_DocuTest.ConfigId,true);

    if(!DocuTest)
    {
    DocuTest.ItemId
    = QVS_DocuTest.ItemId;
    DocuTest.ConfigId
    = QVS_DocuTest.ConfigId;
    DocuTest.FilePath
    = _FilenameOpen;

    DocuTest.FileName
    = Conpeek(con,2);
    DocuTest.FileType
    = Conpeek(con,3);

    DocuTest.Image
    = logoImage.getData();
    DocuTest.insert();
    }
    else
    {
    DocuTest.Image
    = logoImage.getData();
    DocuTest.update();
    }
    ttscommit;
    }
    catch(exception::Error)
    {
    throw error("Insert Images Error!");
    }
      QVS_DocuTest_ds.reread();
       QVS_DocuTest_ds.refresh();
       QVS_DocuTest_ds.findRecord(QVS_DocuTest);


    }

    display Images

    代码
    void ShowImages()
    {
    Bindata binData
    = new BinData();
    Image logoImage
    = new Image();
    container PicContainer;
    real PicRatio;
    ;
    element.
    lock();

    binData.setData(QVS_DocuTest.Image);

    PicContainer
    = binData.getData();
    logoImage.setData(PicContainer);


    if (logoImage.height() > 360 || logoImage.width() > 360)
    {
    if (logoImage.height() > logoImage.width())
    PicRatio
    = 360/logoImage.height();
    else
    PicRatio
    = 360/logoImage.width();
    }

    Images.widthValue( logoImage.width()
    * PicRatio);
    Images.heightValue( logoImage.height()
    * PicRatio);
    Images.image(logoImage);

    element.redraw();
    element.unLock();

    }

    browse Images(writed to actived method on the current datasource)

    代码
    void ShowImage()
    {
    Image logoImage
    = new Image();
    real PicRatio
    = 1.0;
    ;
    element.
    lock();

    logoImage.setData(InventStdPic.Images);
    /*
    if (logoImage.height() > 360 || logoImage.width() > 360)
    {
    if (logoImage.height() > logoImage.width())
    PicRatio = 360 / logoImage.height();
    else
    PicRatio = 360 / logoImage.width();
    }
    */
    Images.widthValue( logoImage.width());
    // * PicRatio);
    Images.heightValue( logoImage.height());// * PicRatio);
    Images.image(logoImage);

    element.redraw();
    element.unLock();

    }
    public void executeQuery()
    {
    ;
    this.query().dataSourceNo(1).addRange(fieldnum(InventStdPic,recid)).value(queryvalue(_recId));

    super();
    }
    public int active()
    {
    int ret;

    ret
    = super();
    element.ShowImage();
    return ret;
    }
    代码
    public void init()
    {

    ;
    if (this.args().caller().name() != formstr(InventTable))
    {
    return;
    }
    super();
    _recId
    = this.args().caller().PictureTable();

    select firstonly InventStdPic
    where InventStdPic.RecId ==_recId;

    //element.ShowImage();
    }

    customization Imporm to the ERP system (Select a picture path with button on the FORM)

    Jimmy July 29th 2010

    void clicked()
    {
    
        FilePath                FilePath;
        System.IO.DirectoryInfo DirInfo;
        System.IO.FileInfo[]    Fileinfos;
        System.IO.FileInfo      FI;
        int                     i,Length,m;
        BinData                 binData = new BinData();
        InventStdPic            InventStdPic;
        Test                    _Test;
        name                    name;
        Container               con;
        InventTable             InventTable;
    ;
        filePath = WinAPI::browseForPath(element.hWnd(),"selection file path");//FilePath = @"d:\Pic0608\";
        if(!filePath)
            throw error("please selection picture folder path!");
        if(!box::yesNo(strfmt("Are you sure Import some picture (%1 )to ERP system",filePath),dialogButton::No,'Import picture'))
            return ;
        DirInfo     = new System.IO.DirectoryInfo(FilePath);
        Fileinfos   = DirInfo.GetFiles();
        Length      = Fileinfos.get_Length();
    
        delete_from _test ;
    
        for (i = 0; i < Length; i++)
        {
            FI           = Fileinfos.GetValue(i);
            FI.get_DirectoryName();
            name         = FI.get_FullName();
            _test.Name   = name;
            _test.ItemId = global::StrDelete(fi.get_Name(),'.JPG');//CPP-259000.jpg - > get Item number
    
            if(_test.ItemId != 'Thumbs.db')
            {
                InventTable = InventTable::find(_test.ItemId);
                if(InventTable)
                {
                    con = global::fileNameSplit(name);//[filepath, _filename, fileExt];
                    binData.loadFile(name);
                    InventStdPic.ItemId         = InventTable.ItemId;
                    InventStdPic.PrintItemId    = InventTable.ItemId;
                    InventStdPic.WithItem       = NoYes::Yes;
                    InventStdPic.ItemType       = inventTable.ItemType;
                    InventStdPic.RefRecId       = inventTable.RecId;
                    InventStdPic.RefTableId     = tablenum(InventTable);
                    InventStdPic.PicsName       = conpeek(Con,2);
                    InventStdPic.PicsExtension  = conpeek(Con,3);
                    InventStdPic.Images         = binData.getData();
                    InventStdPic.ImageSize      = WINAPI::fileSize(name) / 1024 / 1024;
                    InventStdPic.TempFilePath   = name;
                    InventStdPic.LineNum        = 1;
                    InventStdPic.PicsName       = NumberSeq::newGetNum(NumberSeqReference::findReference(TypeId2ExtendedTypeId(typeid(JIB_ItemPicsFileName)))).num();
                    InventStdPic.insert();
                    
                    _test.Pirce = InventStdPic.ImageSize;
                    _test.IsPic = Noyes::Yes;
                    _test.insert();
                    m++;
                }
                else
                    info(_test.ItemId);
            }
        }
        info(strfmt("total import picture %1 per!",m));
    }
    

  • 相关阅读:
    二进制流 最后一段数据是最后一次读取的byte数组没填满造成的
    java中的匿名内部类总结
    决策树构建算法之—C4.5
    Segment公司--整合数据进行分析
    UBuntu安裝使用PIP
    undefined reference to “boost” in Qt—Ubuntu
    Ubuntu14.04引导菜单修复
    ubuntu16.04下编译安装OpenCV
    PCL:Ubuntu下安装配置PCL
    Ubuntu安装配置Python.pyDev
  • 原文地址:https://www.cnblogs.com/Fandyx/p/1760535.html
Copyright © 2020-2023  润新知