物料清单-成本更新 [英] Bill of material - cost update

查看:106
本文介绍了物料清单-成本更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理产品BOM(物料清单),但被卡住了.这是我的课程图:
•组件具有ComponentItems. ComponentItem具有一个Component和一个数量.示例:组件ABC具有3个组件C1和2个组件C2.
•产品具有ComponentItems和ProductItems(类似于ComponentItems,但针对Products).

每个组件都有一个单位成本,因此ComponentItem拥有一个总成本.而且由ComponentItems组成的Component也具有总成本(ComponentItems成本的总和).

这种结构使我可以创建任何产品/组件层次结构.我正在验证产品和组件的插入/更新中的循环.

我想在数据库中更新每个成本,我不想每次必须使用产品/组件时都使用对象来计算成本.我的意思是,如果我更新组件ABC的单位成本,则应更新其父组件成本,依此类推->更新将在层次结构中传播.

实现此目的的最佳方法是什么?我当时在想用树表示.更新组件后,我将检索所有相关的组件/产品并构建一棵树.然后,我必须更新组件的第一级父级,并对此父级的父级执行相同的操作.

这很难解释,我希望它足够清楚.

在此先感谢.

I''m working on a Product BOM (bill of material) and I''m stucked. This is my class diagram:
•A Component has ComponentItems. A ComponentItem has a Component and a quantity. Example: Component ABC has 3 Component C1 and 2 Component C2.
•A Product has ComponentItems and ProductItems (similar to ComponentItems but for Products).

Each Component has a unit cost so a ComponentItem has a total cost. And a Component composed by ComponentItems has a total cost too (sum of ComponentItems cost).

This structure lets me create any Product/Component hierarchy. I''m validating loops in insert/update of products and components.

I want to have each cost updated in database, I don''t want to calculate cost using objects every time I have to use a Product/Component. I mean, if I update the unit cost of Component ABC, his parent component cost should be updated and so on --> the update is propagated in the hierarchy.

What''s the best way to implement this? I was thinking of a tree representation. When a component is updated, I retrieve all related components/products and build a tree. Then I have to update first level parents of the component and do the same with parents of this parents.

This wasn''t easy to explain, I hope it''s clear enough.

Thanks in advance.

推荐答案

第一个问题:您的组件有多复杂?每次重新计算价格可能都不是问题,这意味着您在缓存和确保更新有效方面没有任何问题.

您实质上想要重建价格的是一棵反向树:从更改价格的组件开始,查找其所有祖先并更新其价格.伪码:
First question: how complex are your components? Recalculating the price each time may not be a problem, and means that you have no issues with caching and making sure updates work.

What you essentially want for rebuilding the prices is a reverse tree: starting from the component that you changed the price on, look up all its ancestors and update their prices. Pseudocode:
void UpdatePrice(Component target, decimal newPrice){
 target.Price = newPrice;
 List<Component> parents = select from components where componentWithUpdatedPrice in Children;
 foreach(Component p in parents){
  UpdatePrice(p, p.RecalculatePrice());
 }
}



您可能可以将该查询写为真正的LINQ查询,但我忘记了语法.我看不到任何避免递归的方法,因为它是在树上行走.如果您的系统允许循环引用,那么您还需要给自己留下通过注释",以免陷入无限循环.



You can probably write that query as a bona fide LINQ query but I forget the syntax. I don''t see any way to avoid recursion as it''s tree walking. If your system permits circular references then you also need to leave yourself a ''passing note'' so you don''t get into an infinite loop.


这篇关于物料清单-成本更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆