BOM重复检测

随着产品数量的增加,用户在输入创建一个产品时总是担心这个产品在系统中是否已经存在?
说起来检测系统中是否已经存在某个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

None.gif public   void  write()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    BOMVersion  localBOMVersion;
InBlock.gif    BOM         localBOM;
InBlock.gif    Set 
set     = new Set(Types::String);
InBlock.gif    SetIterator  si;
InBlock.gif    super();
InBlock.gif
InBlock.gif    BOMTable.clear();
InBlock.gif
InBlock.gif    
while select BOMId from localBOM
InBlock.gif    where localBOM.ItemId 
== tmpBOMInput.ItemId &&
InBlock.gif          localBOM.BOMQty 
== tmpBOMInput.Qty
ExpandedSubBlockStart.gifContractedSubBlock.gif          
dot.gif{
InBlock.gif                
if(!set.in(localBOM.BOMId))
InBlock.gif                    
set.add(localBOM.BOMId);
ExpandedSubBlockEnd.gif          }

InBlock.gif    map.insert(tmpBOMInput.RecId,
set);
InBlock.gif
InBlock.gif    element.UpdateBOMTableDs();
InBlock.gif
ExpandedBlockEnd.gif}

将记录存放在Map中,调用UpdateBOMTable方法

None.gif void  UpdateBOMTableDs()
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    MapIterator     mi;
InBlock.gif    BOMVersion      localBOMVersion;
InBlock.gif    Set             totalSet;
InBlock.gif    Set             
set;
InBlock.gif    SetIterator     si;
InBlock.gif    Boolean         firstIn 
= true;
InBlock.gif    ;
InBlock.gif
InBlock.gif    delete_from BOMTable;
InBlock.gif    mi 
= new MapIterator(map);
InBlock.gif    
while(mi.more())
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
if(firstIn)
InBlock.gif            totalSet 
= mi.value();
InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            si 
= new SetIterator(totalSet);
InBlock.gif            
while(si.more())
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
set = mi.value();
InBlock.gif                
if(!set.in(si.value()))
InBlock.gif                    totalSet.remove(si.value());
InBlock.gif
InBlock.gif                si.next();
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif        mi.next();
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
if(totalSet)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        si 
= new SetIterator(totalSet);
InBlock.gif
InBlock.gif        
while(si.more())
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
while select  ItemId,Name from localBOMVersion
InBlock.gif            where localBOMVersion.BOMId 
== si.value()
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                BOMTable.BOMId      
= si.value();
InBlock.gif                BOMTable.ItemId     
= localBOMVersion.ItemId;
InBlock.gif                BOMTable.Name       
= localBOMVersion.Name;
InBlock.gif                BOMTable.doInsert();
ExpandedSubBlockEnd.gif            }

InBlock.gif            si.next();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    BOMTable_ds.executeQuery();
InBlock.gif
InBlock.gif
ExpandedBlockEnd.gif}

实现取交集的。
XPO文件下载

转载于:https://www.cnblogs.com/Farseer1215/archive/2007/06/08/777098.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值