隨著產品數量的增加,使用者在輸入建立一個產品時總是擔心這個產品在系統中是否已經存在?
說起來檢測系統中是否已經存在某個BOM,應該很簡單。AX用BOM這個表存放BOM清單,某個BOM由什麼產品組成的都在這個表中存著,只要看一下這個表是否存在記錄就可以了。
BOM表中的三個重要欄位是BOMId,ItemId,BOMQty.一個BOM由多個產品組成,比如有兩個BOM
BOMId ItemId BOMQty
1 A 3
1 B 4
1 C 2
2 A 3
2 B 4
使用者的要求很簡單,當在BOM的輸入介面輸入
ItemId BOMQty
A 3
就要顯示出所有包含料品A,且數量為3的BOM,這時就需要顯示
BOMId ItemId BOMQty
1 A 3
1 B 4
1 C 2
2 A 3
2 B 4
當使用者繼續輸入
ItemId BOMQty
C 2
就需要顯示包含料品A,數量為3並且包含料品B,數量為2的BOM,這時需要顯示
BOMId ItemId BOMQty
1 A 3
1 B 4
1 C 2
這樣的看起來聽容易實現的,不過俺實在沒找到好的實現方法,用了Map和Set搞了半天,最後用取交集才搞定,應該有更好的實現方式。
說一下我的實現思路:
在使用者輸入BOM行記錄時,比如輸入
BOMId ItemId BOMQty
1 A 3
在表的DataSource的Create方法中從表BOM中擷取ItemId為A且BOMQty為3的BOMId
public void write()
{
BOMVersion localBOMVersion;
BOM localBOM;
Set set = new Set(Types::String);
SetIterator si;
super();
BOMTable.clear();
while select BOMId from localBOM
where localBOM.ItemId == tmpBOMInput.ItemId &&
localBOM.BOMQty == tmpBOMInput.Qty
{
if(!set.in(localBOM.BOMId))
set.add(localBOM.BOMId);
}
map.insert(tmpBOMInput.RecId,set);
element.UpdateBOMTableDs();
}
將記錄存放在Map中,調用UpdateBOMTable方法
void UpdateBOMTableDs()
{
MapIterator mi;
BOMVersion localBOMVersion;
Set totalSet;
Set set;
SetIterator si;
Boolean firstIn = true;
;
delete_from BOMTable;
mi = new MapIterator(map);
while(mi.more())
{
if(firstIn)
totalSet = mi.value();
else
{
si = new SetIterator(totalSet);
while(si.more())
{
set = mi.value();
if(!set.in(si.value()))
totalSet.remove(si.value());
si.next();
}
}
mi.next();
}
if(totalSet)
{
si = new SetIterator(totalSet);
while(si.more())
{
while select ItemId,Name from localBOMVersion
where localBOMVersion.BOMId == si.value()
{
BOMTable.BOMId = si.value();
BOMTable.ItemId = localBOMVersion.ItemId;
BOMTable.Name = localBOMVersion.Name;
BOMTable.doInsert();
}
si.next();
}
}
BOMTable_ds.executeQuery();
}
實現取交集的。
XPO檔案下載