我有一个如下产品结构表:
<table>
<tr>
<td>Parent</td>
<td>Component</td>
<td>Quantity</td>
</tr>
<tr>
<td>123100A</td>
<td>123302A</td>
<td>1</td>
</tr>
<tr>
<td>123100A</td>
<td>123401A</td>
<td>1</td>
</tr>
<tr>
<td>123100A</td>
<td>123402A</td>
<td>1</td>
</tr>
<tr>
<td>123100A</td>
<td>123403A</td>
<td>1</td>
</tr>
</table>
目前,我使用我的产品结构填充列表,并递归循环遍历它以获得已完成的好项目的所有基本级别组件。完成的好项目将是123100A,或任何未显示为列表中的组件的父项。最后,我得到一个如下所示的列表:
public void getCapacityComponents(string parPart, string partNum, decimal qtyMultiplier)
{
//Start of recursion to get child items
List<ProductStructure> capacity = new List<ProductStructure>();
var result = from x in psList
join y in partsList on x.parent equals y.part
where x.parent == partNum
select x;
//recursive loop through components
foreach (var x in result)
{
ProductStructure mrpProduct = new ProductStructure();
mrpProduct.parent = x.parent;
mrpProduct.component = x.component;
if (x.quantity == 0)
mrpProduct.quantity = qtyMultiplier;
else
mrpProduct.quantity = x.quantity * qtyMultiplier;
capacity.Add(mrpProduct);
}
if (capacity.Count > 0)
{
foreach (var part in capacity)
{
getCapacityComponents(parPart, part.component, part.quantity);
}
}
else
{
ProductStructure capacityPart = new ProductStructure();
capacityPart.parent = parPart;
capacityPart.component = partNum;
capacityPart.quantity = qtyMultiplier;
mrpProductList.Add(capacityPart);
}
//End of current solution to get child items
}
这是我用来递归循环以找到每个结束组件的代码:
{{1}}
我发送此功能一个已完成的好零件清单,并使用MRPProductList将组件与所有成品进行比较。我得到了我想要的结果,但这需要很长时间才能运行。我通常有大约2700个成品好的零件,我需要循环才能获得所有最终组件。
有没有更有效的方法来查看这些项目而不进行递归循环?