九宫格控件使用例子

m_p9Paint=CLua9paint();
m_p9Paint:setWnd(ui:getDialogName(), 'id_9point');
m_helpPaintReason=CSelectHelp() ;-- 九宫格多面选择原因
m_sFilePath='' ; -- 文件路径
m_sRow='3'
m_sCol='3'
m_sArea = 'A' ; --当前操作的铸件面,默认A

--初始化九宫格及原因help
function init_PaintReason()
    m_helpPaintReason:reset()

    m_helpPaintReason:addField('unique_id')
    m_helpPaintReason:addField('area')
    m_helpPaintReason:addField('x')
    m_helpPaintReason:addField('y')
    m_helpPaintReason:addField('id')
    m_helpPaintReason:addField('name')
end

--获取工艺文档的图片
function get_file_path(sMaterialId,sArea,help)
    local sql = [[
        select * from pdm_material_file_v2  
        where 1=1 
        and file_type='comp' 
        and material_id='%s'
        and doc_loc = '%s'
    ]];
    sql = string.format(sql,sMaterialId,sArea)
    print(sql)
    if db:select(sql,'',help) < 0 then 
        return false;
    end
    return true;
end

--根据铸件信息加载工艺文件()
function load_process_file(sFilePath)
    if   #sFilePath<=1 then --空白会返回斜杠
        ui:tip('未获取到产品工艺文件!')
        return 
    end 

    m_sFilePath = sFilePath;
    local it = CIntent();
    it:set("pic_path", m_sFilePath);
    it:set("row_count",m_sRow);
    it:set("col_count",m_sCol);
    it:set("checked", "")
    it:set("resize_type", "2")
    ui:set('id_9point', it:toString());    
    ui:set('id_info','')
end

--九宫格数据处理
function handle_paint(help)
    local line = CVector();

    if help:size() == 0 then 
        return;
    end 

    for i=0,help:size()-1 do 
        local sv = help:vs(i,'info');
        local iCol = cutil:toNumber(help:vs(i,'col'))+1;
        local iRow = cutil:toNumber(help:vs(i,'row'))+1;
        -- help:setValueString(i,'col',string.char(65+iCol));
        -- help:setValueString(i,'col',iCol+1);
        -- help:setValueString(i,'row',iRow+1);
        local sv = cutil:fromBase64(sv);
        local helpTmp=CSelectHelp();
        helpTmp:fromString(sv);

        if helpTmp:size() == 0 then 
            local sUniqueArea = string.format('%s%s%s',m_sArea,iRow,iCol);    
            if m_helpPaintReason:size () > 0 then 
                for i=0 , m_helpPaintReason:size () do 
                    local sUniqueId = m_helpPaintReason:vs(i,'unique_id');
                    local iStart,iEnd = string.find(sUniqueId,sUniqueArea);
                    if iStart ~= nil and iStart > 0 then 
                        help_delete_row(m_helpPaintReason,'unique_id',sUniqueArea)
                    end         
                end 
            end 
        end 

        for j=0,helpTmp:size()-1 do 
            local sId = helpTmp:vs(j,'id');
            local sName = helpTmp:vs(j,'name');
            local sUniqueId = '' ;
            local idx = -1 ;

            sUniqueId = m_sArea..iRow..iCol..sId;

            line:clear();
            line:push_back(sUniqueId);
            line:push_back(m_sArea);
            line:push_back(iRow);
            line:push_back(iCol);
            line:push_back(sId);
            line:push_back(sName);

            idx = m_helpPaintReason:searchIndex('unique_id',sUniqueId)
            if idx < 0 then 
                m_helpPaintReason:addVectorValue(line)
            else
                m_helpPaintReason:setValueString(idx,'id',sId)
                m_helpPaintReason:setValueString(idx,'name',sName)
            end 
        end
        print('-------')
        m_helpPaintReason:dump()
        print('=======')
    end
end

--取消九宫格选择,数据过滤
function delete_paint(iRow,iCol)
    if m_helpPaintReason:size() == 0 then 
        return;
    end 

    local sUniqueArea = string.format('%s%s%s',m_sArea,iRow+1,iCol+1);
    help_delete_row(m_helpPaintReason,'unique_id',sUniqueArea)

end 

function help_delete_row(help,sFieldName,sValue)
    if help:size() == 0 then 
        return ;
    end 

    local helpTmp = CSelectHelp();
    local line = CVector();
    helpTmp:copy (help);
    help:resetValue();

    for i=0,helpTmp:size()-1 do 
        local sFieldValue = helpTmp:vs(i,sFieldName);
print('sFieldValue===='..sFieldValue..
        'sValue===='..sValue)
        local iStart,iEnd = string.find(sFieldValue,sValue);
        if iStart == nil then 
            line:clear();
            for j = 0 ,helpTmp:cols() -1 do 
                line:push_back(helpTmp:valueStringByCol(i,j));
            end 
            help:addVectorValue(line)
        end 
    end 
end 

--将选择的九宫格和选择的原因进行相互关联
function click_id_get_reason(sID,iRow,iCol,bCheck) 
    if m_sProcessId == nil or #m_sProcessId ==0 then 
        ui:tip('报废工序未选择!')
        return;
    end 
    -- if m_helpProcessReason:size() == 0 then 
        -- ui:tip('当前报废工序未配置报废原因!')
        -- return;
    -- end 

    local help = CSelectHelp();
    if bCheck == '1' then 
        bCheck = true;
    else
        m_p9Paint:setCheckOne(iRow,iCol,false,'');
        bCheck = false;
        -- m_p9Paint:getHelp(help);
        -- handle_paint(help);
        delete_paint(iRow,iCol);
        return;
    end
    local itIn = CIntent()
    local itOut = CIntent()
    itIn:set('select','help');
    itIn:set('check','0');
    itIn:set('is_more_check','1');
    itIn:set('fixed_size', '1');
    itIn:setHelp('help',m_helpProcessReason);
     itIn:set('ui_code','std_busi_base_select_more');
    ui:execDialog('busi_base_t_select','选择原因',itIn,itOut)--打开对话框
    if itOut:get('return_code') == '1' then    -- 
        local helpGet=CSelectHelp()
        itOut:getHelp('help',helpGet);

        local sBase64 = cutil:toBase64(helpGet:toString());
        m_p9Paint:setCheckOne(iRow,iCol,bCheck,sBase64);
        m_p9Paint:getHelp(help);
        handle_paint(help)
    else
        if bCheck then 
            m_p9Paint:setCheckOne(iRow,iCol,false,'');
            delete_paint(iRow,iCol);
        end
    end
end 
ui:setClickEvent('id_9point', 'click_id_get_reason')

--选择铸件面,加载九宫格
function click_id_btn_area(sCid)
    local idx = -1 ;
    local sMaterialId = '';
    local sFilePath = '';
    local sFileSize = '';

    --判断选择的工艺面
    if sCid == 'id_btn_A' then 
        m_sArea = 'A';
        sFilePath = 'C:/Users/tn/Pictures/Saved Pictures/home/busi_eqpt_work_2.png'
    elseif sCid == 'id_btn_B' then 
        m_sArea = 'B';    
        sFilePath = 'C:/Users/tn/Pictures/Saved Pictures/home/busi_overview1.png'
    elseif sCid == 'id_btn_C' then 
        m_sArea = 'C';
        sFilePath = 'C:/Users/tn/Pictures/Saved Pictures/home/busi_overview2.png'
    elseif sCid == 'id_btn_D' then 
        m_sArea = 'D';
        sFilePath = 'C:/Users/tn/Pictures/Saved Pictures/home/busi_lock.png'
    elseif sCid =='id_btn_E' then 
        m_sArea = 'E';
        sFilePath = 'C:/Users/tn/Pictures/Saved Pictures/home/busi_bs_sms_def.png'
    elseif sCid == 'id_btn_F' then 
        m_sArea = 'F';
        sFilePath = 'C:/Users/tn/Pictures/Saved Pictures/home/busi_plan_monitor.png'
    end

    --铸件是否选择
    idx = m_pGrid:getSelectedRow()
    if idx < 0 then 
        ui:tip('铸件未选择!');
        return;
    end 

    -- m_sMaterialId = m_pGrid:GetValueByName(idx,'material_id');

    local help = CSelectHelp();
    get_file_path(m_sMaterialId,m_sArea,help);
    if help:size() == 0 then 
        ui:tip('获取工艺文件路径失败!');
        return;
    end 

    sFilePath = help:valueString(0,'file_path')
    sFileSize = help:valueString(0,'file_size')

    local bok,sFile = download_file(sFilePath,sFileSize);
    print('eeee: ' .. sFile)
    load_process_file(sFile);

    --重置九宫格坐标
    for i=0 ,2 do 
        for j = 0,2 do 
            m_p9Paint:setCheckOne(i,j,false,'');
        end 
    end 

    --产品工艺面赋值
    local helpSub = CSelectHelp();
    m_helpPaintReason:sortV2('unique_id');
    m_helpPaintReason:lookup('area',m_sArea,helpSub)

    local helpTmp = CSelectHelp();
    local line = CVector();
    helpTmp:addField('id')
    helpTmp:addField('name')

    for i=0,helpSub:size()-1 do 
        local x = helpSub:vi(i,'x');
        local y = helpSub:vi(i,'y');    
        local sId = helpSub:valueString(i,'id');
        local sName = helpSub:valueString(i,'name');

        if i == 0 then 
            line:clear();
            line:push_back(sId);
            line:push_back(sName);
            helpTmp:addVectorValue(line);
        else 
            local xTmp =  helpSub:vi(i-1,'x');
            local yTmp =  helpSub:vi(i-1,'y');    

            --同坐标报废原因加载help
            if x == xTmp and y == yTmp then 
                line:clear();
                line:push_back(sId);
                line:push_back(sName);
                helpTmp:addVectorValue(line);
            else
                local sBase64 = cutil:toBase64(helpTmp:toString());
                m_p9Paint:setCheckOne(xTmp-1,yTmp-1,true,sBase64);

                helpTmp:resetValue();
                line:clear();
                line:push_back(sId);
                line:push_back(sName);
                helpTmp:addVectorValue(line);
            end 
        end

        if i == helpSub:size()-1 then 
            local sBase64 = cutil:toBase64(helpTmp:toString());
            m_p9Paint:setCheckOne(x-1,y-1,true,sBase64);
        end 

    end 

end 

--铸件面切换
for i=1 ,6 do 
    local sArea = '';
    if i==1 then 
        sArea = 'A';
    elseif i ==2 then 
        sArea = 'B';    
    elseif i ==3 then 
        sArea = 'C';
    elseif i ==4 then 
        sArea = 'D';
    elseif i ==5 then 
        sArea = 'E';
    elseif i ==6 then 
        sArea = 'F';
    end
    ui:setClickEvent('id_btn_'..sArea, 'click_id_btn_area');
end

--加载工艺文件
m_sArea = 'A';
local sFilePath = '';
local sFileSize = '';
-- m_sMaterialId = help:valueString(0,'material_id')

local help = CSelectHelp();
get_file_path(m_sMaterialId,m_sArea,help);
if help:size() == 0 then 
    ui:tip('获取工艺文件路径失败!');
    return;
end 

sFilePath = help:valueString(0,'file_path')
sFileSize = help:valueString(0,'file_size')

local bok,sFile = download_file(sFilePath,sFileSize);
--sFilePath = 'C:/Users/tn/Pictures/Saved Pictures/home/busi_eqpt_work_2.png'
print('44444: ' .. sFile)
load_process_file(sFile);
--初始化九宫格
for i=0 ,2 do 
    for j = 0,2 do 
        m_p9Paint:setCheckOne(i,j,false,'');
    end 
end 
init_PaintReason();
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:04

results matching ""

    No results matching ""