1
1. I have created a table with data as you provide.
RowMaterialMaster |
|
|
ID | Name | Price | HasParent |
1 | M1 | 500 | 0 |
2 | M2 | 750 | 0 |
3 | M9 | 500 | 0 |
4 | M57 | 1750 | 0 |
5 | Master Part 1 | 0 | 1 |
6 | Master Part 2 | 0 | 1 |
7 | Master Part 3 | 0 | 1 |
8 | Master Part 4 | 0 | 1 |
9 | Master Part 5 | 0 | 1 |
10 | Master Part 6 | 0 | 1 |
11 | Master Part 7 | 0 | 1 |
RowMaterialMapping |
|
RowMaterialID | ParentRowMaterialID |
5 | 1 |
5 | 2 |
6 | 3 |
6 | 5 |
10 | 4 |
10 | 6 |
2. Now take row materials which have no parent means which is not dependent on another materials like M1, M2, M9 etc...
3. Create a method in c# which will update price of all the row materials based on its 0 level child materials...
this method will take all rows () and
- var ids = GetAllIDs("select ID from RowMaterialMaster where HasParent = 1");
-
- declare @price as decimal(18,0);
-
- select @price += ParentRowMaterialID from RowMaterialMapping map
- INNER JOIN RowMaterialMaster part ON part.ID = map.ParentRowMaterialID
- where map.RowMaterialID = ids[i];
-
- select @price as Price;
-
-
- update RowMaterialMaster set Price = @price where ID = ids[i];
-
4. you should call evertime Step 3 whenever price update of independent materials. Then you will get up to date data as expected...
That it. Try to understand my suggetion and I hope above rough logic will helpful for you. Please Ignore syntax and put exact logic as per your understanding...

0
Ohkay I got the difference... then It will fine by suggested structure... You can obviously loop over. Did you implete that or any other logic then show me when you are stucked?
0
Difference between M1 and Master Part1 is
Some time Master Part1 could be a raw material for any part or it could be a final product as well.
And M1 is raw material which is not final product.
Example If we manufacture Electric Switch Board, Electric Switch board is final product
To make it we need switches.
And if we change the price of light inside used into switches we can say it is M1. so the all price will get affected which are uses M1.
0
Ohkay, I am little bit confuse that what is difference between Master Part 1 and M1? Is it not possible to store them together in same table?
0
Hi Dharmaraj,
Thanks for your effort,
Problem i am facing that how to loop all nested layer
i.e. if i will update Master Part 1 how i will reach to Master Part 7.
And i cannot loop all raw material or part due to it has more than 1lc parts or material.
0
Here is the detailed graph
There is Master Part 1 and to create it two raw materials are required
M1 - 500 Rs.
M2 - 750 Rs.
If we change the price of raw materials of M1 500 Rs to 600 Rs. so the cost of master part 1 is now 1350.
And in hierarchy, as you can see to create Master part 2 as a raw material used as master part 1 - so that price of master part 2 will also get affected.
and to create Master part 6 as raw material Master part 2 is used to it will also get affect and it is so on nth number it is not defined how much deep it could be.
It suppose to update all price of raw material which is in hierarchy
0
It means all nested childs will have dependent price of parent. Please clarify that If Master Par 1 having 100 Rs then how much of part 2 to 5?