九宫格控件使用例子
m_p9Paint=CLua9paint();
m_p9Paint:setWnd(ui:getDialogName(), 'id_9point');
m_helpPaintReason=CSelectHelp() ;
m_sFilePath='' ;
m_sRow='3'
m_sCol='3'
m_sArea = 'A' ;
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;
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
local help = CSelectHelp();
if bCheck == '1' then
bCheck = true;
else
m_p9Paint:setCheckOne(iRow,iCol,false,'');
bCheck = false;
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
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');
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 = '';
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('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();