Jianw
2025-05-14 29f8b36ebb718d2051bf0e7e701973ec4419ee80
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
--[[
    编码: WMS-01-13#2
    名称: 批量新增-确定后
    作者:HAN  
    日期:2025-01-29
    
    级别:固定 (说明本段代码在项目中不太会变化)
    
    函数: ClickOK
 
    功能:
         -- 根据输入的容器规格和数量创建 num 个容器
         -- 来源在“巨沃”系统
 
    来源项目: 巨星料箱库
             适合带料格的料箱创建
    更改记录:
        V2.0 HAN 20250510   新增容器类型的判断和处理 ctd_code
 
--]]
 
wms_base = require( "wms_base" )
 
function ClickOK ( strLuaDEID ) 
    local nRet, strRetInfo
 
    -- 获取输入界面中的属性
    nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_SPEC", "Number", "S_CTD_CODE" )  
    if ( nRet ~= 0 )  then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end 
 
    local obj_attrs = json.decode( strRetInfo ) 
    local spec = obj_attrs[1].value 
    local num = lua.StrToNumber( obj_attrs[2].value )
    local ctd_code = lua.Get_StrAttrValue( obj_attrs[3].value )
    local n
 
    if ( spec == nil or spec == '' ) then
        mobox.Stop( strLuaDEID, "容器规格必须有值!")
        return
    end
    if ( ctd_code == nil or ctd_code == '' ) then
        mobox.Stop( strLuaDEID, "容器类型必须有值!")
        return
    end
    -- ctd_code 处理  CTD-001/巨沃料箱
    local seg = lua.split( ctd_code, "/" )
    ctd_code = seg[1]
 
    -- V2.0 获取容器类型定义数据对象
    local ctd_data
 
    nRet, ctd_data = m3.GetDataFromCache( "Container_Type_Def", ctd_code )
    if ( nRet ~= 0 ) then
        lua.Stop( strLuaDEID, ctd )
        return
    end
 
    local container
 
    for n = 1, num do
        container = m3.AllocObject( strLuaDEID, "Container" )
        container.ctd_code = ctd_code
        container.type = ctd_data.S_TYPE
        container.subtype = ctd_data.S_SUBTYPE
        container.spec = spec
        container.source = ctd_data.S_SOURCE
        container.virtual = ctd_data.C_IS_VIRTUAL
        nRet, container = m3.CreateDataObj(strLuaDEID, container)
        if (nRet ~= 0 ) then 
            lua.Stop( strLuaDEID, "创建【容器】失败!"..container )
            return
         end           
    end
end