--2020-11-12   by:liang
--甘特图主要有两个help数据,一个是左侧的表格数据,另外一个是右侧的甘特图数据
--表格help必须有一列名为grid_id
--右侧的甘特图必须有一个列task_id
--设置setTaskHelp之前,必须先setDateRange设置日期范围


m_pGantt = CLuaGantUtil();
m_pGantt:SetGant(ui:getDialogName(), 'id_gantt');

function get_gird_help(helpGrid)
    helpGrid:reset();
    helpGrid:addField('grid_id');
    helpGrid:addField('test_name1');
    helpGrid:addField('test_name2');
    for i=1,50 do
        help_add_line(helpGrid, 'grid_'..i, 'test'..math.random(1, 99), 'test'..math.random(1, 99));
    end
end

function help_add_line(help, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12)
    local line = CVector();
    line:push_back(s1)
    while true do
        if s2 == nil then    break;    end    line:push_back(s2)
        if s3 == nil then    break;    end    line:push_back(s3)
        if s4 == nil then    break;    end    line:push_back(s4)
        if s5 == nil then    break;    end    line:push_back(s5)
        if s6 == nil then    break;    end    line:push_back(s6)
        if s7 == nil then    break;    end    line:push_back(s7)
        if s8 == nil then    break;    end    line:push_back(s8)
        if s9 == nil then    break;    end    line:push_back(s9)
        if s10 == nil then    break;    end    line:push_back(s10)
        if s11 == nil then    break;    end    line:push_back(s11)
        if s12 == nil then    break;    end    line:push_back(s12)
        break;
    end
    help:addVectorValue(line);
end

function get_task_help(helpTask)
    helpTask:reset();
    helpTask:addField("task_id");--*必须字段
    helpTask:addField("grid_id");--*必须字段
    helpTask:addField("start_time");--*必须字段
    helpTask:addField("end_time");--*必须字段
    helpTask:addField("text");--任务块显示文本
    --helpTask:addField("color");--任务块文本颜色
    --helpTask:addField("allow_move");--是否允许移动,这一列可以不要
    helpTask:addField("bg_color");--任务块颜色
    helpTask:addField("tip");--鼠标停靠以后出现的浮窗1\n是换行
    --还有四个角可以选择 (左上角text_1,color_1)(右上角text_2,color_2)(右下角text_3,color_3)(左下角text_4,color_4)
    --每个角可以显示文本和自定义颜色
    help_add_line(helpTask, 'task_1','grid_1','2020-11-11 07:00:00', '2020-11-12 08:00:00', 'task内容',  '3534663', '第一行\n第二行');
    help_add_line(helpTask, 'task_2','grid_1','2020-11-14 12:00:00', '2020-11-15 08:00:00', '显示task_2', '643525234', '鼠标停靠浮窗1...');
    help_add_line(helpTask, 'task_3','grid_2','2020-11-13 07:00:00', '2020-11-13 11:00:00', '显示task_3', '456745672', '鼠标停靠浮窗1...');
    help_add_line(helpTask, 'task_4','grid_3','2020-11-14 07:00:00', '2020-11-14 15:00:00', '显示task_4', '182345', '鼠标停靠浮窗1...');
    help_add_line(helpTask, 'task_5','grid_4','2020-11-15 07:00:00', '2020-11-15 16:00:00', '显示task_5', '196758', '鼠标停靠浮窗1...');
    help_add_line(helpTask, 'task_6','grid_4','2020-11-16 07:00:00', '2020-11-16 17:00:00', '显示task_6', '9976786', '鼠标停靠浮窗1...');
    help_add_line(helpTask, 'task_7','grid_3','2020-11-17 07:00:00', '2020-11-17 20:00:00', '显示task_7', '9234534', '鼠标停靠浮窗1...');
    help_add_line(helpTask, 'task_8','grid_4','2020-11-18 07:00:00', '2020-11-18 22:00:00', '显示task_8', '8765832', '鼠标停靠浮窗1...');
    help_add_line(helpTask, 'task_9','grid_5','2020-11-19 01:00:00', '2020-11-19 08:00:00', '显示task_9', '478563445', '鼠标停靠浮窗1...');

end

function init_gantt()
    ui:setProp('id_gantt', "time_accuracy", '1');--右侧甘特图单元格精度为天或小时 1为小时,0为天
    ui:setProp('id_gantt', "split_hour", '4');--小时刻度线以几小时一个刻度,24能整除的数1,2,3,4,6,8,12
    ui:setProp('id_gantt', "row_height", '30');--行高
    ui:setProp('id_gantt', "task_height", '26');--任务条高度
    ui:setProp('id_gantt', "task_width", '120');--单个任务条宽度
    ui:setProp('id_gantt', "allowed_drag_horizontal", '1');--是否允许左右拖动
    ui:setProp('id_gantt', "allowed_drag_vertical", '1');--是否允许上下拖动
    ui:setProp('id_gantt', "mult_sel_model", '0');--多选模式   0或其它值不能多选  1为只能选同行  2为只能选同列   3为多选
end

function test_gantt_main()
    init_gantt()
    local helpGrid = CSelectHelp();
    local helpTask = CSelectHelp();
    get_gird_help(helpGrid);--获取左侧表格的help
    get_task_help(helpTask);--获取右侧task的help
    m_pGantt:setGridHelp(helpGrid);

    --设置右侧甘特图显示的时间范围
    m_pGantt:setDateRange('2020-11-11', '2020-11-30');
    m_pGantt:setTaskHelp(helpTask, true);--第二个参数为是否清除已有的task

    --增加一些右键菜单
    --最后一个参数为增加到什么位置,0为表格表头, 1为表格单元格,    2为甘特图表头   3为甘特图单元格   4为甘特图task
    ui:addRightMenu('id_gantt', 'test_grid_header_1', '/picture/common/toolbar/com_tool_debug.png', '表头1', 0);
    ui:addRightMenu('id_gantt', 'test_grid_header_2', '/picture/common/toolbar/com_tool_debug.png', '表头2', 0);

    ui:addRightMenu('id_gantt', 'test_grid_1', '/picture/common/toolbar/com_tool_debug.png', '表格单元格1', 1);
    ui:addRightMenu('id_gantt', 'test_grid_2', '/picture/common/toolbar/com_tool_debug.png', '表格单元格1', 1);

    ui:addRightMenu('id_gantt', 'test_gantt_header_1', '/picture/common/toolbar/com_tool_debug.png', '甘特图表头1', 2);
    ui:addRightMenu('id_gantt', 'test_gantt_header_2', '/picture/common/toolbar/com_tool_debug.png', '甘特图表头2', 2);

    ui:addRightMenu('id_gantt', 'test_gantt_1', '/picture/common/toolbar/com_tool_debug.png', '甘特图单元格1', 3);
    ui:addRightMenu('id_gantt', 'test_gantt_2', '/picture/common/toolbar/com_tool_debug.png', '甘特图单元格2', 3);

    ui:addRightMenu('id_gantt', 'test_gantt_task_1', '/picture/common/toolbar/com_tool_debug.png', '甘特图task1', 4);
    ui:addRightMenu('id_gantt', 'test_gantt_task_2', '/picture/common/toolbar/com_tool_debug.png', '甘特图task2', 4);

    --右键菜单事件绑定到函数
    ui:setRightMenuCilckEvent('id_gantt', 'click_gantt_right_munu');
end

function click_gantt_right_munu(sCid, sMenuID)
    if sMenuID == 'test_grid_1' then

    elseif sMenuID == 'test_gantt_task_1' then

    end
end


function click_gant_id_gantt(sCid, sType, sValue)
    if sType == 'grid' then--点击在左侧表格某一行上
        local sGridID = sValue;
    elseif sType == 'gantt' then--点击在右侧甘特图某一行上
        local sGridID = sValue;
    elseif sType == 'task' then--点击在task上
        local sTaskID = sValue;
    end
end

function double_click_id_gantt(sCid, sType, sTaskID)
    if sType == 'task' then--双击在task上
        print(sTaskID)
    end
end

function process_gantt_change(sCid, sCmd, itString)
    if sCmd == 'move_task' then--task移动事件
        local itTask = CIntent();
        itTask:fromString(itString);
        itTask:dump();
    end
end

test_gantt_main();

ui:setClickEvent('id_gantt', 'click_gant_id_gantt');
ui:setDoubleClickEvent('id_gantt', 'double_click_id_gantt');
ui:setValueChangeEvent('id_gantt', 'process_gantt_change');
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:04

results matching ""

    No results matching ""