private IHierarchicalBOM GetHierarchicalBOMByModel_DB(string model) { try { IHierarchicalBOM ret = null; //IPart rootPart = PrtRepository.Find(model); IPart rootPart = null; IBOMNode root = new BOMNode(rootPart, 1); ret = new HierarchicalBOM(root); IDictionary<int, IList<IPart>> allPartList = new Dictionary<int, IList<IPart>>(); IList<IBOMNode> allNodes = new List<IBOMNode>(); ret.Nodes = allNodes; ret.Model = model; //IList<MoBOMInfo> rootChildren = GetChildrenInModelBOM(model); IList<ModelBOM> modelBOMList = GetModelBOM(model); var rootChildren = modelBOMList.Where(x => x.Level == 1 && x.Flag == 1).ToList(); if (rootChildren != null && rootChildren.Count > 0) { var partNoList = rootChildren.Select(x => x.Component).Distinct().ToList(); IList<IPart> rootPartList = PrtRepository.FindPart(partNoList); allPartList.Add(1, rootPartList); foreach (ModelBOM childItem in rootChildren) { //IPart nodePart = PrtRepository.Find(childItem.Component); IPart nodePart = rootPartList.Where(x => x != null && x.PN == childItem.Component).FirstOrDefault(); if (nodePart != null) { IBOMNode newNode = new BOMNode(nodePart, int.Parse(childItem.Quantity), childItem.Alternative_item_group); root.AddChild(newNode); allNodes.Add(newNode); int iDeepLimit = 20; try { RecursivelyConstructHierarchicalBOM(newNode, childItem, allNodes, modelBOMList, iDeepLimit - 1, 2, allPartList); } catch (FisException fex) { if (fex.mErrcode == "BOML01") { throw new FisException("BOML01", new string[] { iDeepLimit.ToString(), model }); } } } } } return ret; } catch (Exception) { throw; } }
public IList<IBOMNode> GetParentBomNodeByPnListAndBomNodeType(IList<string> pnList) { try { IList<IBOMNode> ret = null; IDictionary<string, IList<MoBOMInfo>> parents = GetChildrenInModelBOMReverse(pnList); if (parents != null) { ret = new List<IBOMNode>(); foreach (KeyValuePair<string, IList<MoBOMInfo>> kvp in parents) { IPart parentPart = PrtRepository.Find(kvp.Key); if (parentPart != null) { foreach(MoBOMInfo item in kvp.Value) { IBOMNode parentItem = new BOMNode(parentPart, int.Parse(item.quantity), item.alternative_item_group); IPart childPart = PrtRepository.Find(item.component); if (childPart != null) { IBOMNode childItem = new BOMNode(childPart, -1); parentItem.AddChild(childItem); } ret.Add(parentItem); } } } } return ret; } catch (Exception) { throw; } }