private static void GetParentProductInfo(string productId, List <string> parentProductIds) { IList <Model.BomComponentInfo> bomComponentList = bomComponentInfoManager.SelectBomIdAndUseQty(productId); if (bomComponentList == null || bomComponentList.Count == 0) { return; } string bomIds = ""; foreach (var component in bomComponentList) { bomIds += "'" + component.BomId + "',"; } bomIds = bomIds.TrimEnd(','); IList <Model.BomParentPartInfo> bomParentList = bomParentPartInfoManager.SelectProducts(bomIds); string productIds = ""; foreach (var comInfo in bomComponentList) { Model.BomParentPartInfo parent = bomParentList.First(P => P.BomId == comInfo.BomId); productIds += "'" + parent.ProductId + "',"; if (!parentProductIds.Contains(parent.ProductId)) { parentProductIds.Add(parent.ProductId); } } productIds = productIds.TrimEnd(','); GetParentProductInfo(productIds, parentProductIds); //递归调用 }
private void GetParentProductInfo(string productId, Dictionary <string, double> parentProductDic) { IList <Model.BomComponentInfo> bomComponentList = bomComponentInfoManager.SelectBomIdAndUseQty(productId); if (bomComponentList == null || bomComponentList.Count == 0) { return; } string bomIds = ""; foreach (var component in bomComponentList) { bomIds += "'" + component.BomId + "',"; } bomIds = bomIds.TrimEnd(','); IList <Model.BomParentPartInfo> bomParentList = bomParentPartInfoManager.SelectProducts(bomIds); string productIds = ""; #region 新版,一个子件没母件引用N次,叠加计算 foreach (var comInfo in bomComponentList) { Model.BomParentPartInfo parent = bomParentList.First(P => P.BomId == comInfo.BomId); productIds += "'" + parent.ProductId + "',"; if (!parentProductDic.Keys.Contains(parent.ProductId)) { double value = Convert.ToDouble(comInfo.UseQuantity); if (parentProductDic.Keys.Contains(comInfo.ProductId)) { value = value * parentProductDic[comInfo.ProductId]; } parentProductDic.Add(parent.ProductId, value); } else { double value = Convert.ToDouble(comInfo.UseQuantity); if (parentProductDic.Keys.Contains(comInfo.ProductId)) { value = value * parentProductDic[comInfo.ProductId]; } parentProductDic[parent.ProductId] = parentProductDic[parent.ProductId] + value; } } #endregion productIds = productIds.TrimEnd(','); GetParentProductInfo(productIds, parentProductDic); //递归调用 }