1
Jianw
9 天以前 70f29da38121b9a467841253e3268feb5df02902
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--[[
    编码: WMS-40-03
    名称: 显示前
    作者:HAN    
    日期:2025-1-29
 
    入口函数:BeforeGridShow
 
    功能说明:
        如果作业状态=错误,显示红色
 
    更改记录:
    V2.0 HAN 2025-2-23 采用新的程序风格
--]]
wms_wh = require( "wms_wh" )
 
function BeforeGridShow ( strLuaDEID ) 
    local nRet, strRetInfo
    local arobjs, attrs
    local n, nCount
    
    nRet, arobjs = m3.GetSysDataJson( strLuaDEID )
    if ( nRet ~=0 ) then 
        lua.Stop( strLuaDEID, arobjs ) 
        return
    end
 
    nCount = #arobjs
    if (nCount == 0) then  return end
 
    local obj, attrs
    local strCurYear = os.date("%Y")
    local area = {}
    strCurYear = strCurYear.."--"
 
    local row_data_set = {}
    local state_cell_set = {
        { b_state = 0, state_name = "待启动", bk_color = "", text_color = ""},
        { b_state = 1, state_name = "执行", bk_color = "#BDB76B", text_color = "#000000"},
        { b_state = 2, state_name = "完成", bk_color = "#00FF00", text_color = "#008000"},
        { b_state = 3, state_name = "错误", bk_color = "#FF0000", text_color = "#FFFFFF"},
        { b_state = 4, state_name = "启动失败", bk_color = "#FF0000", text_color = "#FFFFFF"},
        { b_state = 5, state_name = "暂停", bk_color = "#FFFACD", text_color = "#008000"},
        { b_state = 6, state_name = "等待", bk_color = "", text_color = ""},
        { b_state = 7, state_name = "取消", bk_color = "#DCDCDC", text_color = "#008000"},
        { b_state = 8, state_name = "待启动前", bk_color = "", text_color = ""},
    }
    local b_state, state_index, strValue
 
    for n = 1, nCount do
        local row_item = {}     
 
        obj = arobjs[n]
        row_item.id = obj.id
        row_item.attrs = {}
        row_item.row_button_hidden = "错误重置;取消"
 
        -- 获取 物料编码 和 库区编码
        for nIndex = 1, #obj.attrs do
            local attr_value = {}
 
            attr_value.attr  = obj.attrs[nIndex].attr
            attr_value.value = obj.attrs[nIndex].value
 
            -- 作业状态
            if (attr_value.attr == 'N_B_STATE') then
                b_state = lua.StrToNumber( attr_value.value )
                state_index = b_state+1
                attr_value.value = state_cell_set[state_index].state_name
                attr_value.bk_color = state_cell_set[state_index].bk_color
                attr_value.text_color = state_cell_set[state_index].text_color  
 
                -- 设置行按钮是否显示
                if ( b_state == OPERATION_STATE.Error or  b_state == OPERATION_STATE.Paused ) then
                    row_item.row_button_hidden = ""
                elseif b_state == OPERATION_STATE.Cancel or b_state == OPERATION_STATE.Finish then 
                    row_item.row_button_hidden = "错误重置;取消"
                else
                    row_item.row_button_hidden = "错误重置"
                end
            elseif (attr_value.attr == 'T_START_TIME' or attr_value.attr == 'T_END_TIME' or attr_value.attr == 'T_CREATE') then
                -- 对时间的处理
                if (attr_value.value == "1900-1-1 0:0:0") then 
                    attr_value.value = ""
                else
                    -- 如果是本年就不显示 本年年份
                    attr_value.value = string.gsub(attr_value.value, strCurYear, "")
                end
            elseif (attr_value.attr == 'S_ERR' or attr_value.attr == 'S_EXT_DATA') then
                strValue = string.gsub(attr_value.value, "\\", "/")
                strValue = string.gsub(strValue, '"','\\\"')
                strValue = string.gsub(strValue, "'",'\\\"')
                strValue = string.gsub(strValue, " ","")
                attr_value.value = strValue
            -- V8.0 MDF BY HAN 20241120
            elseif (attr_value.attr == 'S_END_AREA' ) then
                -- 如果是库区编码,把库区名称获取后加另外一个特别的属性列
                nRet, area = wms_wh.GetAreaInfo( attr_value.value )    
                if ( nRet == 0 ) then      
                    local attr_value = {
                        attr = "CUSTOM_E_AREA_NAME", value = area.name
                    }
                    table.insert( row_item.attrs, attr_value )
                end
            elseif (attr_value.attr == 'S_START_AREA' ) then
                nRet, area = wms_wh.GetAreaInfo( attr_value.value )    
                if ( nRet == 0 ) then            
                    local attr_value = {
                        attr = "CUSTOM_S_AREA_NAME", value = area.name
                    }
                    table.insert( row_item.attrs, attr_value )                    
                end  
            -- END MDF              
            end
            table.insert( row_item.attrs, attr_value )
        end
        table.insert( row_data_set, row_item)
    end
 
    local action = {
        {
            action_type = "reset_data_attr",
            value = row_data_set
        }    
    }
 
    nRet, strRetInfo = mobox.setAction(strLuaDEID, lua.table2str(action))
    if ( nRet ~= 0 ) then 
        lua.Stop( strLuaDEID, "setAction错误: "..strRetInfo) 
        return
    end     
end