/// <summary> /// /// </summary> /// <param name="hierarchical_bom"></param> /// <param name="station"></param> /// <param name="main_object"></param> /// <returns></returns> public object FilterBOM(object hierarchical_bom, string station, object main_object) { //根据Model展3阶,得到第一阶是BM和P1的part其下阶和下下阶(注意Qty需要相乘) [ BM->KP->VC]或者[ P1->KP->VC],即KP和VC, //以及第一阶是KP的part的第一阶及其下阶[KP->VC],即KP和VC,第一阶的Descr描述为Descr like 'Fiber%' IFlatBOM ret = null; IList<IFlatBOMItem> flat_bom_items = new List<IFlatBOMItem>(); //var kp_parts = new List<IPart>(); if (hierarchical_bom == null) { throw new ArgumentNullException(); } var bom = (HierarchicalBOM)hierarchical_bom; var tree_traversal = new TreeTraversal(); Hashtable share_parts_set = new Hashtable(); Hashtable descr_kp_part_set = new Hashtable(); Hashtable info_value_string_set = new Hashtable(); Hashtable mb_qty_set = new Hashtable(); try { //处理BM->KP情况 // IList<QtyParts> bm_check_conditon_nodes = tree_traversal.BreadthFirstTraversalForHD(bom.Root, "BM->KP", "KP", this,"BM"); IList<QtyParts> bm_check_conditon_nodes = tree_traversal.BreadthFirstTraversal(bom.Root, "BM->KP", "KP", this, "BM"); //IList<ShareMaterialType> material_type = FilterShareMaterialType(bm_check_conditon_nodes); if (bm_check_conditon_nodes != null && bm_check_conditon_nodes.Count > 0) { Hashtable temp_share_parts_set = new Hashtable(); foreach (QtyParts bm_check_conditon_node in bm_check_conditon_nodes) { if (bom.FirstLevelNodes != null) //当bom.Root.Part不为空时,Root是首阶 { IList<IBOMNode> bom_nodes = bom.FirstLevelNodes; foreach (IBOMNode bom_node in bom_nodes) { if (bom_node.Part.BOMNodeType.Equals("BM")) { IList<IBOMNode> child_nodes = bom_node.Children; if (child_nodes != null) { foreach (IBOMNode child_node in child_nodes) { if (child_node.Part != null && child_node.Part.BOMNodeType.Equals("KP") && child_node.Part.Attributes != null) { if (PartCompare(bm_check_conditon_node.Parts, child_node.Part)) { String share_material_key = bm_check_conditon_node.Qty.ToString() + child_node.Part.Descr + bom_node.Part.PN; if (!descr_kp_part_set.ContainsKey(share_material_key)) { descr_kp_part_set.Add(share_material_key, child_node.Part.Descr); } else { if(!((String)descr_kp_part_set[share_material_key]).Contains(child_node.Part.Descr)) { descr_kp_part_set[share_material_key] += "," + child_node.Part.Descr; } } IList<PartInfo> part_infos = child_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { if(!info_value_string_set.ContainsKey(share_material_key)) { info_value_string_set.Add(share_material_key, part_info.InfoValue); mb_qty_set.Add(share_material_key, bm_check_conditon_node.Qty); IList<IPart> share_parts = new List<IPart>(); share_parts.Add(child_node.Part); temp_share_parts_set.Add(share_material_key, share_parts); } else { if (!((String)info_value_string_set[share_material_key]).Contains(part_info.InfoValue)) { info_value_string_set[share_material_key] += "," + part_info.InfoValue; ((IList<IPart>)temp_share_parts_set[share_material_key]).Add(child_node.Part); } } } } } } } } } } } } } if (temp_share_parts_set.Count > 0) { IList<Object> keys_sort = new List<Object>(); foreach (DictionaryEntry dictionary_entry in info_value_string_set) { if (keys_sort.Count == 0) { keys_sort.Add(dictionary_entry.Key); } else { int index = 0; bool is_little = false; foreach (Object entry in keys_sort) { index++; int keys_sort_info_value_length = ((string) info_value_string_set[entry]).Length; int info_value_string_length = ((string)info_value_string_set[dictionary_entry.Key]).Length; if (info_value_string_length < keys_sort_info_value_length) { is_little = true; break; } } if (index > 0) { if (is_little) { keys_sort.Insert(index - 1, dictionary_entry.Key); } else { keys_sort.Add(dictionary_entry.Key); } } } } foreach (Object de in keys_sort) { share_parts_set.Add(de, temp_share_parts_set[de]); } } foreach (DictionaryEntry de in share_parts_set) { var kp_flat_bom_item = new FlatBOMItem((int)mb_qty_set[de.Key], part_check_type, (IList<IPart>)share_parts_set[de.Key]); kp_flat_bom_item.PartNoItem = (String)info_value_string_set[de.Key]; kp_flat_bom_item.Descr = (String)descr_kp_part_set[de.Key]; flat_bom_items.Add(kp_flat_bom_item); } } share_parts_set.Clear(); info_value_string_set.Clear(); mb_qty_set.Clear(); //处理P1->KP情况 //descr_kp_part_set.Clear(); //info_value_string_set.Clear(); //share_parts_set.Clear(); IList<ShareMaterialType> material_type = new List<ShareMaterialType>(); IList<QtyParts> p1_check_conditon_nodes = tree_traversal.BreadthFirstTraversal(bom.Root, "P1->KP", "KP", this, "P1"); IList<ShareMaterialType> p1_material_type = FilterShareMaterialType(p1_check_conditon_nodes); // foreach (ShareMaterialType type in p1_material_type) // { // Boolean is_add = true; // foreach (ShareMaterialType mtype in material_type) // { // if (mtype.Descr.Trim().Equals(type.Descr.Trim()) && mtype.Qty == type.Qty) // { // is_add = false; // break; // } // } // if (is_add) // { // material_type.Add(type); // } // } if (p1_check_conditon_nodes != null && p1_check_conditon_nodes.Count > 0) { Hashtable temp_share_parts_set = new Hashtable(); foreach (QtyParts bm_check_conditon_node in p1_check_conditon_nodes) { if (bom.FirstLevelNodes != null) { IList<IBOMNode> bom_nodes = bom.FirstLevelNodes; foreach (IBOMNode bom_node in bom_nodes) { if (bom_node.Part.BOMNodeType.Equals("P1")) { IList<IBOMNode> child_nodes = bom_node.Children; if (child_nodes != null) { foreach (IBOMNode child_node in child_nodes) { if (child_node.Part != null && child_node.Part.BOMNodeType.Equals("KP") && child_node.Part.Attributes != null) { if (PartCompare(bm_check_conditon_node.Parts, child_node.Part)) { // if (material_type.Count > 0) // { // foreach (ShareMaterialType type in material_type) // { // if (child_node.Part.Descr.Equals(type.Descr) && bm_check_conditon_node.Qty == type.Qty) // { // String share_material_key = type.Qty.ToString() + type.Descr; // // //if (!share_parts_set.ContainsKey(share_material_key)) // //{ // // IList<IPart> share_parts = new List<IPart>(); // // share_parts.Add(child_node.Part); // // share_parts_set.Add(share_material_key, share_parts); // //} // //else // //{ // // ((IList<IPart>)share_parts_set[share_material_key]).Add(child_node.Part); // //} // if (!descr_kp_part_set.ContainsKey(share_material_key)) // { // descr_kp_part_set.Add(share_material_key, child_node.Part.Descr); // } // else // { // if (!((String)descr_kp_part_set[share_material_key]).Contains(child_node.Part.Descr)) // { // descr_kp_part_set[share_material_key] += "," + child_node.Part.Descr; // } // } // // IList<PartInfo> part_infos = child_node.Part.Attributes; // if (part_infos != null && part_infos.Count > 0) // { // foreach (PartInfo part_info in part_infos) // { // if (part_info.InfoType.Equals("VendorCode")) // { // if (!info_value_string_set.ContainsKey(share_material_key)) // { // info_value_string_set.Add(share_material_key, part_info.InfoValue); // // IList<IPart> share_parts = new List<IPart>(); // share_parts.Add(child_node.Part); // share_parts_set.Add(share_material_key, share_parts); // } // else // { // if (!((String)info_value_string_set[share_material_key]).Contains(part_info.InfoValue)) // { // info_value_string_set[share_material_key] += "," + part_info.InfoValue; // ((IList<IPart>)share_parts_set[share_material_key]).Add(child_node.Part); // } // } // } // } // } // } // } // } //------------------------------------------------------------------------------------------ String share_material_key = bm_check_conditon_node.Qty.ToString() + child_node.Part.Descr + bom_node.Part.PN; if (!descr_kp_part_set.ContainsKey(share_material_key)) { descr_kp_part_set.Add(share_material_key, child_node.Part.Descr); } else { if (!((String)descr_kp_part_set[share_material_key]).Contains(child_node.Part.Descr)) { descr_kp_part_set[share_material_key] += "," + child_node.Part.Descr; } } IList<PartInfo> part_infos = child_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { if (!info_value_string_set.ContainsKey(share_material_key)) { info_value_string_set.Add(share_material_key, part_info.InfoValue); mb_qty_set.Add(share_material_key, bm_check_conditon_node.Qty); IList<IPart> share_parts = new List<IPart>(); share_parts.Add(child_node.Part); temp_share_parts_set.Add(share_material_key, share_parts); } else { if (!((String)info_value_string_set[share_material_key]).Contains(part_info.InfoValue)) { info_value_string_set[share_material_key] += "," + part_info.InfoValue; ((IList<IPart>)temp_share_parts_set[share_material_key]).Add(child_node.Part); } } } } } } } } } } } } } if (temp_share_parts_set.Count > 0) { IList<Object> keys_sort = new List<Object>(); foreach (DictionaryEntry dictionary_entry in info_value_string_set) { if (keys_sort.Count == 0) { keys_sort.Add(dictionary_entry.Key); } else { int index = 0; bool is_little = false; foreach (Object entry in keys_sort) { index++; int keys_sort_info_value_length = ((string)info_value_string_set[entry]).Length; int info_value_string_length = ((string)info_value_string_set[dictionary_entry.Key]).Length; if (info_value_string_length < keys_sort_info_value_length) { is_little = true; break; } } if (index > 0) { if (is_little) { keys_sort.Insert(index - 1, dictionary_entry.Key); } else { keys_sort.Add(dictionary_entry.Key); } } } } foreach (Object de in keys_sort) { share_parts_set.Add(de, temp_share_parts_set[de]); } } foreach (DictionaryEntry de in share_parts_set) { var kp_flat_bom_item = new FlatBOMItem((int)mb_qty_set[de.Key], part_check_type, (IList<IPart>)share_parts_set[de.Key]); kp_flat_bom_item.PartNoItem = (String)info_value_string_set[de.Key]; kp_flat_bom_item.Descr = (String)descr_kp_part_set[de.Key]; flat_bom_items.Add(kp_flat_bom_item); } } share_parts_set.Clear(); info_value_string_set.Clear(); mb_qty_set.Clear(); //处理首阶为KP情况 //descr_kp_part_set.Clear(); //info_value_string_set.Clear(); //share_parts_set.Clear(); List<IBOMNode> collect_gather_node = new List<IBOMNode>(); List<QtyParts> kp_check_conditon_nodes = new List<QtyParts>(); //String vendor_code_info_value_string = ""; //String descr_info_value_string = ""; //IList<QtyParts> kp_check_conditon_nodes = tree_traversal.BreadthFirstTraversal(bom.Root, "KP", "KP", this, "KP"); if (bom.FirstLevelNodes != null) { for (int i = 0; i < bom.FirstLevelNodes.Count; i++) { if (bom.FirstLevelNodes.ElementAt(i).Part != null) { if (bom.FirstLevelNodes.ElementAt(i).Part.BOMNodeType.Equals("KP")) { if (CheckCondition(bom.FirstLevelNodes.ElementAt(i))) { collect_gather_node.Add(bom.FirstLevelNodes.ElementAt(i)); List<IPart> parts = new List<IPart>(); parts.Add(bom.FirstLevelNodes.ElementAt(i).Part); QtyParts bom_item = new QtyParts(bom.FirstLevelNodes.ElementAt(i).Qty, parts); kp_check_conditon_nodes.Add(bom_item); } } } } } IList<ShareMaterialType> kp_material_type = FilterShareMaterialType(kp_check_conditon_nodes); foreach (ShareMaterialType type in kp_material_type) { Boolean is_add = true; foreach (ShareMaterialType mtype in material_type) { if (mtype.Descr.Trim().Equals(type.Descr.Trim()) && mtype.Qty == type.Qty) { is_add = false; break; } } if (is_add) { material_type.Add(type); } } if ( kp_check_conditon_nodes.Count > 0) { foreach (QtyParts bm_check_conditon_node in kp_check_conditon_nodes) { if (bom.FirstLevelNodes != null) { for (int i = 0; i < bom.FirstLevelNodes.Count; i++) { if (bom.FirstLevelNodes.ElementAt(i).Part != null) { if (bom.FirstLevelNodes.ElementAt(i).Part.BOMNodeType.Equals("KP") && bom.FirstLevelNodes.ElementAt(i).Part.Attributes != null) { IBOMNode kp_node = bom.FirstLevelNodes.ElementAt(i); //if (CheckCondition(bom.FirstLevelNodes.ElementAt(i))) if (PartCompare(bm_check_conditon_node.Parts, kp_node.Part)) { if (material_type.Count > 0) { foreach (ShareMaterialType type in material_type) { if (kp_node.Part.Descr.Equals(type.Descr) && bm_check_conditon_node.Qty == type.Qty) { String share_material_key = type.Qty.ToString() + type.Descr; if (!descr_kp_part_set.ContainsKey(share_material_key)) { descr_kp_part_set.Add(share_material_key, kp_node.Part.Descr); } else { if (!((String)descr_kp_part_set[share_material_key]).Contains(kp_node.Part.Descr)) { descr_kp_part_set[share_material_key] += "," + kp_node.Part.Descr; } } IList<PartInfo> part_infos = kp_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { if (!info_value_string_set.ContainsKey(share_material_key)) { info_value_string_set.Add(share_material_key, part_info.InfoValue); IList<IPart> share_parts = new List<IPart>(); share_parts.Add(kp_node.Part); share_parts_set.Add(share_material_key, share_parts); } else { if (!((String)info_value_string_set[share_material_key]).Contains(part_info.InfoValue)) { info_value_string_set[share_material_key] += "," + part_info.InfoValue; ((IList<IPart>)share_parts_set[share_material_key]).Add(kp_node.Part); } } if (!share_parts_set.ContainsKey(share_material_key)) { IList<IPart> share_parts = new List<IPart>(); share_parts.Add(kp_node.Part); share_parts_set.Add(share_material_key, share_parts); } else { ((IList<IPart>)share_parts_set[share_material_key]).Add(kp_node.Part); } } } } } } } } } } } } } //if (material_type.Count > 0) //{ // foreach (ShareMaterialType type in material_type) // { // String share_material_key = type.Qty.ToString() + type.Descr; // if (share_parts_set.ContainsKey(share_material_key)) // { // var kp_flat_bom_item = new FlatBOMItem(type.Qty, part_check_type, (IList<IPart>)share_parts_set[share_material_key]); // kp_flat_bom_item.PartNoItem = (String)info_value_string_set[share_material_key]; // kp_flat_bom_item.Descr = (String)descr_kp_part_set[share_material_key]; // flat_bom_items.Add(kp_flat_bom_item); // } // } //} } if (material_type.Count > 0) { foreach (ShareMaterialType type in material_type) { String share_material_key = type.Qty.ToString() + type.Descr; if (share_parts_set.ContainsKey(share_material_key)) { var kp_flat_bom_item = new FlatBOMItem(type.Qty, part_check_type, (IList<IPart>)share_parts_set[share_material_key]); kp_flat_bom_item.PartNoItem = (String)info_value_string_set[share_material_key]; kp_flat_bom_item.Descr = (String)descr_kp_part_set[share_material_key]; flat_bom_items.Add(kp_flat_bom_item); } } } if (flat_bom_items.Count > 0) { ret = new FlatBOM(flat_bom_items); } } catch (Exception e) { throw; } return ret; }
/// <summary> /// BOMNode树的遍历,得到所需的BOMNode列表。 /// </summary> /// <param name="node">遍历的开始节点</param> /// <param name="search_path">遍历的指定路径。以BOMNodeType为路径节点,用“->”将它们彼此隔开。</param> /// <param name="search_node_type">以给定的BOMNodeType收集BOMNode。</param> /// <param name="check_condition"></param> /// <param name="check_type"></param> /// <returns></returns> public IList<QtyParts> BreadthFirstTraversalForHD(IBOMNode node, string search_path, string search_node_type, ITreeTraversal check_condition, string check_type) { List<IBOMNode> collect_gather_node = new List<IBOMNode>(); List<QtyParts> ret = new List<QtyParts>(); Queue<IBOMNode> bom_node_queue = new Queue<IBOMNode>(30); try { if (string.IsNullOrEmpty(search_path)) { throw new FisException("CHK169", new string[] { "IMES.CheckItemModule.Utility.TreeTraversal.BreadthFirstTraversal" }); } else { if (!string.IsNullOrEmpty(search_node_type.Trim()) && search_path.Contains(search_node_type.Trim())) { IBOMNode bom_node = node; string[] trave_path = parse_paths(search_path); //if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level].Trim()))//由于Root.part为空,所以暂时去掉该句。 if (bom_node != null) { bom_node_queue.Enqueue(node); IBOMNode queue_node; //int obtain_depth = toDepth(trave_path, search_node_type); int search_depth = trave_path.Length; while (bom_node_queue.Count > 0) { queue_node = bom_node_queue.Dequeue(); if (queue_node.Children != null && queue_node.Children.Count > 0) { int offset = 1; for (int i = 0; i < queue_node.Children.Count; i++) { bom_node = queue_node.Children.ElementAt(i); if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level - offset].Trim()) && bom_node.Level <= search_depth) { if (string.IsNullOrEmpty(check_type)) { bom_node_queue.Enqueue(bom_node); if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (check_condition.CheckCondition(bom_node)) { collect_gather_node.Add(bom_node); } } } else { int check_level = toDepth(trave_path, check_type); if (bom_node.Level == check_level && bom_node.Part.BOMNodeType.Trim().Equals(check_type)) { if (check_condition.CheckCondition(bom_node)) { bom_node_queue.Enqueue(bom_node); } } else { bom_node_queue.Enqueue(bom_node); } if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (bom_node.Level == 1) { if (bom_node.Part.BOMNodeType.Trim().Equals(check_type)) { if (check_condition.CheckCondition(bom_node)) { collect_gather_node.Add(bom_node); } } } else { collect_gather_node.Add(bom_node); } } } } } } else { if (queue_node.Level == search_depth) { int check_level = toDepth(trave_path, check_type); if (queue_node.Part != null && queue_node.Level == check_level && queue_node.Part.BOMNodeType.Trim().Equals(check_type)) { if (check_condition.CheckCondition(queue_node)) { if (queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (!collect_gather_node.Contains(queue_node)) { collect_gather_node.Add(queue_node); } } } } else { if (queue_node.Part != null && queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (!collect_gather_node.Contains(queue_node)) { collect_gather_node.Add(queue_node); } } } } if (queue_node.Level < search_depth) { IBOMNode parent_node = queue_node; while (parent_node != null) { if (contains(collect_gather_node, parent_node)) { remove(collect_gather_node, parent_node); } parent_node = parent_node.Parent; } } } } Hashtable identical_vendor_code = new Hashtable(); for (int j = 0; j < collect_gather_node.Count(); j++) { bom_node = collect_gather_node.ElementAt(j); bom_node_queue.Enqueue(bom_node); BOMNode tmp = (BOMNode)bom_node; int qty = 0; string parent_descr = ""; string current_descr = ""; string vendor_code = ""; if (bom_node.Part.BOMNodeType.Trim().Equals(search_node_type)) { // qty = bom_node.Qty; qty = 1; current_descr = bom_node.Part.Descr; IList<PartInfo> part_infos = bom_node.Part.Attributes; if (part_infos != null) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { vendor_code = part_info.InfoValue; break; } } } } do { if (tmp.Parent != null) { int search_node_level = toDepth(trave_path, search_node_type); tmp = (BOMNode)tmp.Parent; if (tmp.Part != null && tmp.Part.BOMNodeType.Trim().Equals(search_node_type)) { qty = tmp.Qty; parent_descr = tmp.Part.Descr; } else { if (tmp.Level < search_node_level) { qty *= tmp.Qty; parent_descr = tmp.Part.Descr; } } } } while (tmp.Level != 1); // string identical_vendor_code_key = parent_descr + current_descr + vendor_code; string identical_vendor_code_key = current_descr + vendor_code; if (identical_vendor_code.ContainsKey(identical_vendor_code_key)) { ((QtyParts) identical_vendor_code[identical_vendor_code_key]).Qty += qty; } else { List<IPart> parts = new List<IPart>(); parts.Add(bom_node.Part); QtyParts qty_parts = new QtyParts(qty, parts); identical_vendor_code.Add(identical_vendor_code_key, qty_parts); } // List<IPart> parts = new List<IPart>(); // parts.Add(bom_node.Part); // QtyParts bom_item = new QtyParts(qty, parts); // ret.Add(bom_item); } if (identical_vendor_code.Count > 0) { foreach (DictionaryEntry de in identical_vendor_code) { ret.Add((QtyParts)de.Value); } } } } else { string[] param = { "IMES.CheckItemModule.Utility.BreadthFirstTraversal", "search_node" }; throw new FisException("CHK156", param); } } } catch (Exception e) { throw; } if (collect_gather_node.Count > 0) return ret; else return null; }
/// <summary> /// BOMNode树的遍历,得到所需的BOMNode列表。 /// </summary> /// <param name="node">遍历的开始节点</param> /// <param name="search_path">遍历的指定路径。以BOMNodeType为路径节点,用“->”将它们彼此隔开。</param> /// <param name="search_node_type">以给定的BOMNodeType收集BOMNode。</param> /// <param name="check_condition"></param> /// <param name="check_type"></param> /// <returns></returns> public IList<QtyParts> BreadthFirstTraversal(IBOMNode node, string search_path, string search_node_type, ITreeTraversal check_condition,string check_type) { List<IBOMNode> collect_gather_node = new List<IBOMNode>(); List<QtyParts> ret = new List<QtyParts>(); Queue<IBOMNode> bom_node_queue = new Queue<IBOMNode>(30); try { if (string.IsNullOrEmpty(search_path)) { throw new FisException("CHK169", new string[] { "IMES.CheckItemModule.Utility.TreeTraversal.BreadthFirstTraversal" }); } else { if (!string.IsNullOrEmpty(search_node_type.Trim()) && search_path.Contains(search_node_type.Trim())) { IBOMNode bom_node = node; string[] trave_path = parse_paths(search_path); //if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level].Trim()))//由于Root.part为空,所以暂时去掉该句。 if (bom_node != null) { bom_node_queue.Enqueue(node); IBOMNode queue_node; //int obtain_depth = toDepth(trave_path, search_node_type); int search_depth = trave_path.Length; while (bom_node_queue.Count > 0) { queue_node = bom_node_queue.Dequeue(); //if (queue_node.IsRoot && queue_node.Level == 0) //{ // if (queue_node.Part == null) //Root 为Model // { // if (queue_node.Children != null) // { // for (int i = 0; i < queue_node.Children.Count; i++) // { // bom_node = queue_node.Children.ElementAt(i); // if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level - 1].Trim()) && bom_node.Level <= search_depth) // { // if (string.IsNullOrEmpty(check_type)) // { // bom_node_queue.Enqueue(bom_node); // if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) // { // if (check_condition.CheckCondition(bom_node)) // { // collect_gather_node.Add(bom_node); // } // } // } // else // { // if (b) // { // } // bom_node_queue.Enqueue(bom_node); // if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) // { // if (check_condition.CheckCondition(bom_node)) // { // collect_gather_node.Add(bom_node); // } // } // } // } // } // } // } //} //else //{ if (queue_node.Children != null && queue_node.Children.Count > 0) { int offset = 1; //if (node.IsRoot && node.Part != null) //{ // offset = 0; // search_depth -= 1; //} for (int i = 0; i < queue_node.Children.Count; i++) { bom_node = queue_node.Children.ElementAt(i); if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level - offset].Trim()) && bom_node.Level <= search_depth) { if (string.IsNullOrEmpty(check_type)) { bom_node_queue.Enqueue(bom_node); if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (check_condition.CheckCondition(bom_node)) { collect_gather_node.Add(bom_node); } } } else { int check_level = toDepth(trave_path, check_type); if (bom_node.Level == check_level && bom_node.Part.BOMNodeType.Trim().Equals(check_type)) { if (check_condition.CheckCondition(bom_node)) { bom_node_queue.Enqueue(bom_node); } } else { bom_node_queue.Enqueue(bom_node); } if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (bom_node.Level == 1) { if(bom_node.Part.BOMNodeType.Trim().Equals(check_type)) { if (check_condition.CheckCondition(bom_node)) { collect_gather_node.Add(bom_node); } } } else { collect_gather_node.Add(bom_node); } } } } //else //{ // if (contains(collect_gather_node,queue_node)) //不满足路径要求的,当阶删除。 // { // remove(collect_gather_node,queue_node); // } // else // { // if (queue_node.Level > 0 && queue_node.Parent != null) //不满足路径要求的,父阶删除。 // { // IBOMNode parent_node = queue_node.Parent; // while(parent_node != null) // { // if (contains(collect_gather_node,parent_node)) // { // remove( collect_gather_node,parent_node); // } // parent_node = parent_node.Parent; // } // } // } //} } } else { if (queue_node.Level == search_depth) { int check_level = toDepth(trave_path, check_type); if (queue_node.Part != null && queue_node.Level == check_level && queue_node.Part.BOMNodeType.Trim().Equals(check_type)) { if (check_condition.CheckCondition(queue_node)) { if (queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (!collect_gather_node.Contains(queue_node)) { collect_gather_node.Add(queue_node); } } } } else { if (queue_node.Part != null && queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (!collect_gather_node.Contains(queue_node)) { collect_gather_node.Add(queue_node); } } } } if (queue_node.Level < search_depth) { IBOMNode parent_node = queue_node; while(parent_node != null) { if (contains(collect_gather_node, parent_node)) { remove(collect_gather_node, parent_node); } parent_node = parent_node.Parent; } } } //} //remove the first node from queue //queue_node = //bom_node_queue.Dequeue(); //if (queue_node.Part != null && queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) //{ // if (check_condition.CheckCondition(queue_node)) // { // collect_gather_node.Add(queue_node); // } //} } //if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) //{ //List<IBOMNode> collect_gather_node_temp = new List<IBOMNode>(); //foreach (IBOMNode collect_node in collect_gather_node) //{ // if (!collect_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim()) || !check_condition.CheckCondition(collect_node)) // { // //collect_gather_node.Add(bom_node); // collect_gather_node_temp.Add(collect_node); // } //} //foreach (IBOMNode bom_node_temp in collect_gather_node_temp) //{ // collect_gather_node.Remove(bom_node_temp); //} //} for (int j = 0; j < collect_gather_node.Count(); j++) { bom_node = collect_gather_node.ElementAt(j); //Part part = new Part(bom_node.Part.PN,bom_node.Part.BOMNodeType,bom_node.Part.Type,bom_node.Part.CustPn,bom_node.Part.Descr, // bom_node.Part.Remark,bom_node.Part.AutoDL,bom_node.Part.Editor,bom_node.Part.Cdt,bom_node.Part.Udt,bom_node.Part.Descr2); //foreach (PartInfo info in bom_node.Part.Attributes) //{ // part.AddAttribute(info); //} bom_node_queue.Enqueue(bom_node); BOMNode tmp = (BOMNode)bom_node; int qty = 0; if (bom_node.Part.BOMNodeType.Trim().Equals(search_node_type)) { qty = bom_node.Qty; } do { if (tmp.Parent != null) { int search_node_level = toDepth(trave_path, search_node_type); tmp = (BOMNode)tmp.Parent; if (tmp.Part.BOMNodeType.Trim().Equals(search_node_type)) { qty = tmp.Qty; } else { if (tmp.Level < search_node_level ) { qty *= tmp.Qty; } } } } while (tmp.Level != 1); //if (bom_node.Children.Count > 0) //{ // qty *= ((BOMNode)bom_node.Children.ElementAt(0)).Qty; //} //while (bom_node_queue.Count > 0) //{ // queue_node = bom_node_queue.Peek(); // for (int i = 0; i < queue_node.Children.Count; i++) // { // bom_node = queue_node.Children.ElementAt(i); // if (((BOMNode)node).Part == null) // { // if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level - 1].Trim())) // { // bom_node_queue.Enqueue(bom_node); // } // } // else // { // if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level].Trim())) // { // bom_node_queue.Enqueue(bom_node); // } // } // } // queue_node = bom_node_queue.Dequeue(); // if (queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) // { // if (check_condition.CheckCondition(queue_node)) // { // foreach (PartInfo attr in queue_node.Part.Attributes) // part.AddAttribute(attr); // } // } ////} List<IPart> parts = new List<IPart>(); parts.Add(bom_node.Part); QtyParts bom_item = new QtyParts(qty, parts); ret.Add(bom_item); } } } else { string[] param = { "IMES.CheckItemModule.Utility.BreadthFirstTraversal", "search_node" }; throw new FisException("CHK156", param); } } } catch (Exception e) { throw; } if (collect_gather_node.Count > 0) return ret; else return null; }
//FA代码已经稳定,所以加此函数供PAK使用。等PAK稳定后,再考虑代码合并。 public IList<QtyParts> BreadthFirstTraversal(String part_no_filter_str,IBOMNode node, string search_path, string search_node_type, ITreeTraversal check_condition,string check_type) { List<IBOMNode> collect_gather_node = new List<IBOMNode>(); List<QtyParts> ret = new List<QtyParts>(); Queue<IBOMNode> bom_node_queue = new Queue<IBOMNode>(30); try { if (string.IsNullOrEmpty(search_path)) { throw new FisException("CHK169", new string[] { "IMES.CheckItemModule.Utility.TreeTraversal.BreadthFirstTraversal" }); } else { if (!string.IsNullOrEmpty(search_node_type.Trim()) && search_path.Contains(search_node_type.Trim())) { IBOMNode bom_node = node; string[] trave_path = parse_paths(search_path); if (bom_node != null) { bom_node_queue.Enqueue(node); IBOMNode queue_node; int search_depth = trave_path.Length; while (bom_node_queue.Count > 0) { queue_node = bom_node_queue.Dequeue(); if (queue_node.Children != null && queue_node.Children.Count > 0) { int offset = 1; for (int i = 0; i < queue_node.Children.Count; i++) { bom_node = queue_node.Children.ElementAt(i); if (bom_node.Part.BOMNodeType.Trim().Equals(trave_path[bom_node.Level - offset].Trim()) && bom_node.Level <= search_depth) { if (string.IsNullOrEmpty(check_type)) { bom_node_queue.Enqueue(bom_node); if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (!string.IsNullOrEmpty(part_no_filter_str)) { if (!bom_node.Part.PN.Trim().Substring(0, 3).Equals(part_no_filter_str.Trim())) { if (check_condition.CheckCondition(bom_node)) { collect_gather_node.Add(bom_node); } } } else //使用不需要PartNo过滤的情况 { if (check_condition.CheckCondition(bom_node)) { collect_gather_node.Add(bom_node); } } } } else { int check_level = toDepth(trave_path, check_type); if (bom_node.Level == check_level && bom_node.Part.BOMNodeType.Trim().Equals(check_type)) { if (!string.IsNullOrEmpty(part_no_filter_str)) { if (!bom_node.Part.PN.Trim().Substring(0, 3).Equals(part_no_filter_str.Trim())) { if (check_condition.CheckCondition(bom_node)) { bom_node_queue.Enqueue(bom_node); } } } else //使用不需要PartNo过滤的情况 { if (check_condition.CheckCondition(bom_node)) { bom_node_queue.Enqueue(bom_node); } } } else { bom_node_queue.Enqueue(bom_node); } if (bom_node.Part != null && bom_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { collect_gather_node.Add(bom_node); } } } } } else { if (queue_node.Level == search_depth) { String check_type_str = ""; if (string.IsNullOrEmpty(check_type)) { check_type_str =search_node_type.Trim(); } else { check_type_str = check_type; } int check_level = toDepth(trave_path, check_type_str); if (queue_node.Part != null && queue_node.Level == check_level && queue_node.Part.BOMNodeType.Trim().Equals(check_type_str)) { if (check_condition.CheckCondition(queue_node)) { if (queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (!string.IsNullOrEmpty(part_no_filter_str)) { if (!queue_node.Part.PN.Trim().Substring(0, 3).Equals(part_no_filter_str.Trim())) { if (!collect_gather_node.Contains(queue_node)) { collect_gather_node.Add(queue_node); } } } } } } else { if (queue_node.Part != null && queue_node.Part.BOMNodeType.Trim().Equals(search_node_type.Trim())) { if (!string.IsNullOrEmpty(part_no_filter_str)) { if (!queue_node.Part.PN.Trim().Substring(0, 3).Equals(part_no_filter_str.Trim())) { if (!collect_gather_node.Contains(queue_node)) { collect_gather_node.Add(queue_node); } } } } } } if (queue_node.Level < search_depth) { IBOMNode parent_node = queue_node; while (parent_node != null) { if (contains(collect_gather_node, parent_node)) { remove(collect_gather_node, parent_node); } parent_node = parent_node.Parent; } } } } for (int j = 0; j < collect_gather_node.Count(); j++) { bom_node = collect_gather_node.ElementAt(j); bom_node_queue.Enqueue(bom_node); BOMNode tmp = (BOMNode)bom_node; int qty = bom_node.Qty; do { if (tmp.Parent != null) { tmp = (BOMNode)tmp.Parent; qty *= tmp.Qty; } } while (tmp.Level != node.Level); //Packing Pizza 特例 if (bom_node.Children != null && bom_node.Children.Count > 0) { qty *= ((BOMNode)bom_node.Children.ElementAt(0)).Qty; } // int qty = 0; // if (bom_node.Part.BOMNodeType.Trim().Equals(search_node_type)) // { // qty = bom_node.Qty; // } // tmp = (BOMNode)bom_node; // do // { // if (tmp.Parent != null) // { // int search_node_level = toDepth(trave_path, search_node_type); // // tmp = (BOMNode)tmp.Parent; // if (tmp.Part.BOMNodeType.Trim().Equals(search_node_type)) // { // qty = tmp.Qty; // } // else // { // if (tmp.Level < search_node_level) // { // qty *= tmp.Qty; // } // } // // } // } while (tmp.Level != 1); List<IPart> parts = new List<IPart>(); parts.Add(bom_node.Part); QtyParts bom_item = new QtyParts(qty, parts); ret.Add(bom_item); } } } else { string[] param = { "IMES.CheckItemModule.Utility.BreadthFirstTraversal", "search_node" }; throw new FisException("CHK156", param); } } } catch (Exception e) { throw; } if (collect_gather_node.Count > 0) return ret; else return null; }
public object FilterBOM(object hierarchical_bom, string station, object main_object) { IFlatBOM ret = null; IList<IFlatBOMItem> flat_bom_items = new List<IFlatBOMItem>(); if (hierarchical_bom == null) { throw new ArgumentNullException(); } HierarchicalBOM bom = (HierarchicalBOM)hierarchical_bom; Hashtable share_parts_set = new Hashtable(); Hashtable share_part_no_set = new Hashtable(); Hashtable part_no_set = new Hashtable(); Hashtable qty_set = new Hashtable(); Hashtable check_typ_set = new Hashtable(); Hashtable descr_parts_set = new Hashtable(); TreeTraversal tree_traversal = new TreeTraversal(); IList<KPVendorCode> kpVCList = new List<KPVendorCode>(); try { /* IList<QtyParts> check_conditon_nodes_case_one = tree_traversal.BreadthFirstTraversal(bom.Root, "VK->P1->KP", "P1", this,"VK"); //if (check_conditon_nodes_case_one != null && check_conditon_nodes_case_one.Count > 0) //{ // foreach (QtyParts check_conditon_node in check_conditon_nodes_case_one) // { // //替代料: // //对于P1 Part 来说,Part.Descr 相同的记录是替代料,替代料的料号以逗号分隔,显示在Part No / Item Name列(包括主料);取替代料中Qty 最大的P1 Part 为主料 // //Qty: // //对于Model-> VK-> P1-> KP 这种结构,P1 Part 的数量是VK Part 在ModelBOM 定义的数量乘以P1 Part在ModelBOM 定义的数量 // //对于Model -> VK -> KP 这种结构,P1 Part 的数量是VK Part 在ModelBOM 定义的数量乘以KP Part在ModelBOM 定义的数量 // FlatBOMItem item = new FlatBOMItem(check_conditon_node.Qty, part_check_type, check_conditon_node.Parts); // flat_bom_items.Add(item); // } //} if (check_conditon_nodes_case_one != null && check_conditon_nodes_case_one.Count > 0) { foreach (QtyParts bm_check_conditon_node in check_conditon_nodes_case_one) { if (bom.FirstLevelNodes != null) { IList<IBOMNode> bom_nodes = bom.FirstLevelNodes; foreach (IBOMNode bom_node in bom_nodes) { if (bom_node.Part != null && bom_node.Part.BOMNodeType.Equals("VK")) { IList<IBOMNode> vk_child_nodes = bom_node.Children; if (vk_child_nodes != null) { foreach (IBOMNode vk_child_node in vk_child_nodes) { if (vk_child_node.Part != null && vk_child_node.Part.BOMNodeType.Equals("P1")) { if (PartCompare(bm_check_conditon_node.Parts, vk_child_node.Part)) { String share_material_key = vk_child_node.Part.PN; if (!string.IsNullOrEmpty(share_material_key)) { if (!check_typ_set.ContainsKey(share_material_key)) { check_typ_set.Add(share_material_key,"P1"); } IList<IBOMNode> p1_child_nodes = vk_child_node.Children; if (p1_child_nodes != null) { foreach (IBOMNode p1_child_node in p1_child_nodes) { if (p1_child_node.Part != null && p1_child_node.Part.BOMNodeType.Equals("KP")) { IList<PartInfo> part_infos =p1_child_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { vk_child_node.Part.AddAttribute(part_info); } } } } } } if (share_parts_set.ContainsKey(share_material_key)) { part_no_set[share_material_key] += "," + vk_child_node.Part.PN; ((IList<IPart>) share_parts_set[share_material_key]).Add(vk_child_node.Part); int qty = getMaxQty(check_conditon_nodes_case_one,vk_child_node.Part); if ((int) qty_set[share_material_key] < qty) { qty_set[share_material_key] = qty; } } else { part_no_set.Add(share_material_key, vk_child_node.Part.PN); IList<IPart> parts = new List<IPart>(); parts.Add(vk_child_node.Part); share_parts_set.Add(share_material_key, parts); int qty = getMaxQty(check_conditon_nodes_case_one,vk_child_node.Part); qty_set.Add(share_material_key, qty); } } } } } } } } } } } IList<QtyParts> check_conditon_nodes_case_two = tree_traversal.BreadthFirstTraversal(bom.Root, "VK->KP", "KP", this,"VK"); IBOMRepository bom_repository = RepositoryFactory.GetInstance().GetRepository<IBOMRepository>(); if (check_conditon_nodes_case_two != null) { foreach (QtyParts qty_part in check_conditon_nodes_case_two) { IList<IPart> parts = qty_part.Parts; if (parts != null) { foreach (IPart part in parts) { IList<IBOMNode> parent_boms = bom_repository.GetParentBomNode(part.PN); if (parent_boms != null) { foreach (IBOMNode flat_bom_item in parent_boms) { IPart parent_part = flat_bom_item.Part; if (parent_part != null && parent_part.BOMNodeType.Trim().Equals("P1")) { //IList<IPart> p1_parts = new List<IPart>(); //p1_parts.Add(part); //var item = new FlatBOMItem(qty_part.Qty, part_check_type, p1_parts); //item.PartNoItem = part.PN; //item.Descr = part.Descr; //flat_bom_items.Add(item); IList<PartInfo> part_infos = part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { parent_part.AddAttribute(part_info); } } } String share_material_key = parent_part.PN; if (!string.IsNullOrEmpty(share_material_key)) { if (!check_typ_set.ContainsKey(share_material_key)) { check_typ_set.Add(share_material_key, "P1"); } if (share_parts_set.ContainsKey(share_material_key)) { part_no_set[share_material_key] += "," + parent_part.PN; ((IList<IPart>) share_parts_set[share_material_key]).Add(parent_part); int qty = getMaxQty(check_conditon_nodes_case_two, parent_part); if ((int) qty_set[share_material_key] < qty) { qty_set[share_material_key] = qty; } } else { part_no_set.Add(share_material_key, parent_part.PN); IList<IPart> sparts = new List<IPart>(); sparts.Add(parent_part); share_parts_set.Add(share_material_key, sparts); int qty = getMaxQty(check_conditon_nodes_case_two, parent_part); qty_set.Add(share_material_key, qty); } } } } } } } } } */ List<QtyParts> c2_check_conditon_nodes = new List<QtyParts>(); if (bom.FirstLevelNodes != null) { for (int i = 0; i < bom.FirstLevelNodes.Count; i++) { if (bom.FirstLevelNodes.ElementAt(i).Part != null) { if (bom.FirstLevelNodes.ElementAt(i).Part.BOMNodeType.Equals("C2")) { IList<PartInfo> part_infos = bom.FirstLevelNodes.ElementAt(i).Part.Attributes; Boolean have_vendor_code = false; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { have_vendor_code = true; break; } } } Hashtable dib_share_part_infos = new Hashtable(); IPartRepository repository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); if (!have_vendor_code) { if (bom.FirstLevelNodes.ElementAt(i).Part.PN.Length>=3 && bom.FirstLevelNodes.ElementAt(i).Part.PN.Trim().Substring(0, 3).Equals("DIB")) { string part_pn = bom.FirstLevelNodes.ElementAt(i).Part.PN.Trim(); // IPartRepository repository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); IPart dib_part = repository.GetPartByPartNo(part_pn.Substring(3, part_pn.Length-3)); if (dib_part != null) { IList<PartInfo> dib_part_infos = dib_part.Attributes; if (dib_part_infos != null && dib_part_infos.Count > 0) { foreach (PartInfo dib_part_info in dib_part_infos) { if (dib_part_info.InfoType.Equals("VendorCode")) { have_vendor_code = true; //bom.FirstLevelNodes.ElementAt(i).Part.AddAttribute(dib_part_info); kpVCList.Add(new KPVendorCode { PartNo = bom.FirstLevelNodes.ElementAt(i).Part.PN, VendorCode = dib_part_info.InfoValue }); break; } } } } //IPart part = bom.FirstLevelNodes.ElementAt(i).Part; // IList<PartInfo> sub_part_infos = bom.FirstLevelNodes.ElementAt(i).Part.Attributes; // if (sub_part_infos != null && sub_part_infos.Count > 0) // { // PartInfo need_vendor_code = null; // foreach (PartInfo sub_part_info in sub_part_infos) // { // if (sub_part_info.InfoType.Equals("SUB")) // { // string[] part_pns = sub_part_info.InfoValue.Trim().Split(';'); // for (int j = 0; j < part_pns.Length;j++ ) // { // if (part_pns[j].Length > 3 && part_pns[j].Substring(0, 3).Equals("DIB")) // { // IPart sub_dib_part = repository.GetPartByPartNo(part_pns[j].Substring(3, part_pns[j].Length - 3)); // if (sub_dib_part != null) // { // IList<PartInfo> sub2_part_infos = sub_dib_part.Attributes; // if (sub2_part_infos != null && sub2_part_infos.Count > 0) // { // foreach (PartInfo sub2_part_info in sub2_part_infos) // { // if (sub2_part_info.InfoType.Equals("VendorCode")) // { // have_vendor_code = true; // need_vendor_code = sub2_part_info; //// if (dib_share_part_infos.ContainsKey(part_pns[j])) //// { //// ((IList<PartInfo>)dib_share_part_infos[part_pns[j]]).Add(sub2_part_info); //// } //// else //// { //// IList<PartInfo> dib_tmp_part_infos = new List<PartInfo>(); //// dib_tmp_part_infos.Add(sub2_part_info); //// dib_share_part_infos.Add(part_pns[j], dib_tmp_part_infos); //// } // break; // } // } // } // } // } // else // { // IPart sub_dib_part = repository.GetPartByPartNo(part_pns[j]); // if (sub_dib_part != null) // { // IList<PartInfo> sub2_part_infos = sub_dib_part.Attributes; // if (sub2_part_infos != null && sub2_part_infos.Count > 0) // { // foreach (PartInfo sub2_part_info in sub2_part_infos) // { // if (sub2_part_info.InfoType.Equals("VendorCode")) // { // have_vendor_code = true; // need_vendor_code = sub2_part_info; //// if (dib_share_part_infos.ContainsKey(part_pns[j])) //// { //// ((IList<PartInfo>)dib_share_part_infos[part_pns[j]]).Add(sub2_part_info); //// } //// else //// { //// dib_share_part_infos.Add(part_pns[j], sub2_part_info); //// } // break; // } // } // } // } // } // } // } // } // if (need_vendor_code != null) // { // bom.FirstLevelNodes.ElementAt(i).Part.AddAttribute(need_vendor_code); // } // } } } if (have_vendor_code) { List<IPart> parts = new List<IPart>(); parts.Add(bom.FirstLevelNodes.ElementAt(i).Part); // if (dib_share_part_infos.Count > 0) // { // foreach (DictionaryEntry de in dib_share_part_infos) // { // IPart dib_part = repository.GetPartByPartNo((string)de.Key); // if (dib_part != null) // { // IList<PartInfo> dib_share_part_set = (IList<PartInfo>) dib_share_part_infos[de.Key]; // foreach (PartInfo dib_share_part_info in dib_share_part_set) // { // dib_part.AddAttribute(dib_share_part_info); // } // parts.Add(dib_part); // } // } // } QtyParts bom_item = new QtyParts(bom.FirstLevelNodes.ElementAt(i).Qty, parts); c2_check_conditon_nodes.Add(bom_item); } } } } } if (c2_check_conditon_nodes.Count > 0) { foreach (QtyParts c2_check_conditon_node in c2_check_conditon_nodes) { if (bom.FirstLevelNodes != null) { IList<IBOMNode> bom_nodes = bom.FirstLevelNodes; foreach (IBOMNode bom_node in bom_nodes) { if (bom_node.Part != null && bom_node.Part.BOMNodeType.Equals("C2")) { String share_material_key = bom_node.Part.PN; if (!check_typ_set.ContainsKey(share_material_key)) { check_typ_set.Add(share_material_key, "C2"); } if (PartCompare(c2_check_conditon_node.Parts, bom_node.Part)) { Boolean exist_share_part = false; //parts.Add(part); IList<PartInfo> part_infos = bom_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("SUB")) { // exist_share_part = true; String[] share_parts = part_info.InfoValue.Trim().Split(';'); if (share_parts.Length > 0) { string share_part_no = part_info.InfoValue.Trim(); share_part_no = share_part_no.Replace("DIB", ""); if (share_part_no_set.ContainsKey(bom_node.Part.PN)) { share_part_no_set[bom_node.Part.PN] += "," + share_part_no.Replace(';',','); } else { share_part_no_set.Add(bom_node.Part.PN, share_part_no.Replace(';', ',')); } IPartRepository repository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); IList<IPart> parts = new List<IPart>(); // parts.Add(bom_node.Part); for (int j = 0; j < share_parts.Length; j++) { IPart share_part = null; if (share_parts[j].Length >=3 && share_parts[j].Substring(0,3).Equals("DIB")) { share_part = repository.GetPartByPartNo(share_parts[j]); IPart real_part = repository.GetPartByPartNo(share_parts[j].Substring(3, share_parts[j].Length - 3)); if (share_part != null && real_part != null) { IList<PartInfo> sub2_part_infos = real_part.Attributes; if (sub2_part_infos != null && sub2_part_infos.Count > 0) { foreach (PartInfo sub2_part_info in sub2_part_infos) { if (sub2_part_info.InfoType.Equals("VendorCode")) { //share_part.AddAttribute(sub2_part_info); kpVCList.Add(new KPVendorCode { PartNo = share_part.PN, VendorCode = sub2_part_info.InfoValue } ); break; } } } } } else { share_part = repository.GetPartByPartNo(share_parts[j]); } if (share_part != null) { parts.Add(share_part); } } String share_parts_code = bom_node.Part.PN; if (!share_parts_set.ContainsKey(share_parts_code)) { share_parts_set.Add(share_parts_code, parts); qty_set.Add(share_parts_code, bom_node.Qty); descr_parts_set.Add(share_parts_code, bom_node.Part.Descr); } else { // ((IList<IPart>)share_parts_set[share_parts_code]).Add(bom_node.Part); if (parts.Count > 0) { foreach (IPart part in parts) { ((IList<IPart>)share_parts_set[share_parts_code]).Add(part); } } if (!((String)descr_parts_set[share_parts_code]).Contains(bom_node.Part.Descr)) { descr_parts_set[share_parts_code] += "," + bom_node.Part.Descr; } } } } } } // if (!exist_share_part) // { if (!share_parts_set.ContainsKey(bom_node.Part.PN)) { IList<IPart> parts = new List<IPart>(); // if (bom_node.Part.PN.Substring(0,3).Equals("DIB")) // { // IPartRepository repository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); // IPart part = repository.GetPartByPartNo(bom_node.Part.PN.Substring(3, bom_node.Part.PN.Length - 3)); // parts.Add(part); // } // else // { parts.Add(bom_node.Part); // } share_parts_set.Add(bom_node.Part.PN, parts); qty_set.Add(bom_node.Part.PN, bom_node.Qty); descr_parts_set.Add(bom_node.Part.PN, bom_node.Part.Descr); } else { // if (bom_node.Part.PN.Substring(0, 3).Equals("DIB")) // { // IPartRepository repository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); // IPart part = repository.GetPartByPartNo(bom_node.Part.PN.Substring(3, bom_node.Part.PN.Length - 3)); // ((IList<IPart>)share_parts_set[bom_node.Part.PN]).Add(part); // } // else // { ((IList<IPart>)share_parts_set[bom_node.Part.PN]).Insert(0, bom_node.Part); // } if (!((String)descr_parts_set[bom_node.Part.PN]).Contains(bom_node.Part.Descr)) { descr_parts_set[bom_node.Part.PN] += "," + bom_node.Part.Descr; } } // } // else // { // //开头不是DIB的Part,要将自身加入到share_parts_set中。 // if (!bom_node.Part.PN.Substring(0, 3).Equals("DIB")) // { // ((IList<IPart>)share_parts_set[bom_node.Part.PN]).Add(bom_node.Part); // if (!((String)descr_parts_set[bom_node.Part.PN]).Contains(bom_node.Part.Descr)) // { // descr_parts_set[bom_node.Part.PN] += "," + bom_node.Part.Descr; // } // } // } } } } } } } if (share_parts_set.Count > 0) { foreach (DictionaryEntry de in share_parts_set) { var flat_bom_item = new FlatBOMItem((int)qty_set[de.Key],part_check_type , (IList<IPart>)de.Value); flat_bom_item.Tag = kpVCList; if (share_part_no_set.ContainsKey(de.Key)) { // if (((String)de.Key).Substring(0,3).Equals("DIB")) // { // flat_bom_item.PartNoItem = ((string)share_part_no_set[de.Key]).Replace("DIB",""); // } // else // { flat_bom_item.PartNoItem = (String)de.Key + "," + (string)share_part_no_set[de.Key]; flat_bom_item.PartNoItem = flat_bom_item.PartNoItem.Replace("DIB", ""); // } } else { if (part_no_set.ContainsKey(de.Key)) { flat_bom_item.PartNoItem = ((String)part_no_set[de.Key]).Replace("DIB", ""); } else { flat_bom_item.PartNoItem = ((string)de.Key).Replace("DIB", ""); } } flat_bom_item.Tp = (string) check_typ_set[de.Key]; if (descr_parts_set.ContainsKey(de.Key)) { flat_bom_item.Descr = (string)descr_parts_set[de.Key]; } else { flat_bom_item.Descr = (String)de.Key; } flat_bom_items.Add(flat_bom_item); } } if (flat_bom_items.Count > 0) { ret = new FlatBOM(flat_bom_items); } } catch (Exception e) { throw; } return ret; }
public object FilterBOM(object hierarchical_bom, string station, object main_object) { //描述同上,不同的是(Descr like 'CD%' or Descr like 'DVD%'or Descr like 'ODD%' or Descr like 'COMBO%'or Descr like 'VCD%') IFlatBOM ret = null; IList<IFlatBOMItem> flat_bom_items = new List<IFlatBOMItem>(); if (hierarchical_bom == null) { throw new ArgumentNullException(); } var bom = (HierarchicalBOM)hierarchical_bom; Hashtable share_parts_set = new Hashtable(); Hashtable descr_kp_part_set = new Hashtable(); Hashtable info_value_string_set = new Hashtable(); var tree_traversal = new TreeTraversal(); try { //处理BM->KP情况 IList<QtyParts> bm_check_conditon_nodes = tree_traversal.BreadthFirstTraversal(bom.Root, "BM->KP", "KP", this,"BM"); IList<ShareMaterialType> material_type = FilterShareMaterialType(bm_check_conditon_nodes); if (bm_check_conditon_nodes != null && bm_check_conditon_nodes.Count > 0) { foreach (QtyParts bm_check_conditon_node in bm_check_conditon_nodes) { if (bom.FirstLevelNodes != null) //当bom.Root.Part不为空时,Root是首阶 { IList<IBOMNode> bom_nodes = bom.FirstLevelNodes; foreach (IBOMNode bom_node in bom_nodes) { if (bom_node.Part.BOMNodeType.Equals("BM")) { IList<IBOMNode> child_nodes = bom_node.Children; if (child_nodes != null) { foreach (IBOMNode child_node in child_nodes) { if (child_node.Part != null && child_node.Part.BOMNodeType.Equals("KP") && child_node.Part.Attributes != null) { if (PartCompare(bm_check_conditon_node.Parts, child_node.Part)) { if (material_type.Count > 0) { foreach (ShareMaterialType type in material_type) { if (child_node.Part.Descr.Equals(type.Descr) && bm_check_conditon_node.Qty == type.Qty) { String share_material_key = type.Qty.ToString() + type.Descr; if (!descr_kp_part_set.ContainsKey(share_material_key)) { descr_kp_part_set.Add(share_material_key, child_node.Part.Descr); } else { if (!((String)descr_kp_part_set[share_material_key]).Contains(child_node.Part.Descr)) { descr_kp_part_set[share_material_key] += "," + child_node.Part.Descr; } } IList<PartInfo> part_infos = child_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { if (!info_value_string_set.ContainsKey(share_material_key)) { info_value_string_set.Add(share_material_key, part_info.InfoValue); } else { if (!((String)info_value_string_set[share_material_key]).Contains(part_info.InfoValue)) { info_value_string_set[share_material_key] += "," + part_info.InfoValue; } } if (!share_parts_set.ContainsKey(share_material_key)) { IList<IPart> share_parts = new List<IPart>(); share_parts.Add(child_node.Part); share_parts_set.Add(share_material_key, share_parts); } else { ((IList<IPart>)share_parts_set[share_material_key]).Add(child_node.Part); } } } } } } } } } } } } } } } //if (material_type.Count > 0) //{ // foreach (ShareMaterialType type in material_type) // { // String share_material_key = type.Qty.ToString() + type.Descr; // var bm_flat_bom_item = new FlatBOMItem(type.Qty, part_check_type, (IList<IPart>)share_parts_set[share_material_key]); // bm_flat_bom_item.PartNoItem = (String)info_value_string_set[share_material_key]; // bm_flat_bom_item.Descr = (String)descr_kp_part_set[share_material_key]; // flat_bom_items.Add(bm_flat_bom_item); // } //} } //处理P1->KP情况 //descr_kp_part_set.Clear(); //info_value_string_set.Clear(); //share_parts_set.Clear(); IList<QtyParts> p1_check_conditon_nodes = tree_traversal.BreadthFirstTraversal(bom.Root, "P1->KP", "KP", this,"P1"); IList<ShareMaterialType> p1_material_type = FilterShareMaterialType(p1_check_conditon_nodes); foreach (ShareMaterialType type in p1_material_type) { Boolean is_add = true; foreach (ShareMaterialType mtype in material_type) { if (mtype.Descr.Trim().Equals(type.Descr.Trim()) && mtype.Qty == type.Qty) { is_add = false; break; } } if (is_add) { material_type.Add(type); } } if (p1_check_conditon_nodes != null && p1_check_conditon_nodes.Count > 0) { foreach (QtyParts bm_check_conditon_node in p1_check_conditon_nodes) { if (bom.FirstLevelNodes != null) { IList<IBOMNode> bom_nodes = bom.FirstLevelNodes; foreach (IBOMNode bom_node in bom_nodes) { if (bom_node.Part.BOMNodeType.Equals("P1")) { IList<IBOMNode> child_nodes = bom_node.Children; if (child_nodes != null) { foreach (IBOMNode child_node in child_nodes) { if (child_node.Part != null && child_node.Part.BOMNodeType.Equals("KP") && child_node.Part.Attributes != null) { if (PartCompare(bm_check_conditon_node.Parts, child_node.Part)) { if (material_type.Count > 0) { foreach (ShareMaterialType type in material_type) { if (child_node.Part.Descr.Equals(type.Descr) && bm_check_conditon_node.Qty == type.Qty) { String share_material_key = type.Qty.ToString() + type.Descr; //if (!share_parts_set.ContainsKey(share_material_key)) //{ // IList<IPart> share_parts = new List<IPart>(); // share_parts.Add(child_node.Part); // share_parts_set.Add(share_material_key, share_parts); //} //else //{ // ((IList<IPart>)share_parts_set[share_material_key]).Add(child_node.Part); //} if (!descr_kp_part_set.ContainsKey(share_material_key)) { descr_kp_part_set.Add(share_material_key, child_node.Part.Descr); } else { if (!((String)descr_kp_part_set[share_material_key]).Contains(child_node.Part.Descr)) { descr_kp_part_set[share_material_key] += "," + child_node.Part.Descr; } } IList<PartInfo> part_infos = child_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { if (!info_value_string_set.ContainsKey(share_material_key)) { info_value_string_set.Add(share_material_key, part_info.InfoValue); } else { if (!((String)info_value_string_set[share_material_key]).Contains(part_info.InfoValue)) { info_value_string_set[share_material_key] += "," + part_info.InfoValue; } } if (!share_parts_set.ContainsKey(share_material_key)) { IList<IPart> share_parts = new List<IPart>(); share_parts.Add(child_node.Part); share_parts_set.Add(share_material_key, share_parts); } else { ((IList<IPart>)share_parts_set[share_material_key]).Add(child_node.Part); } } } } } } } } } } } } } } } //if (material_type.Count > 0) //{ // foreach (ShareMaterialType type in material_type) // { // String share_material_key = type.Qty.ToString() + type.Descr; // if (share_parts_set.ContainsKey(share_material_key)) // { // var p1_flat_bom_item = new FlatBOMItem(type.Qty, part_check_type, (IList<IPart>)share_parts_set[share_material_key]); // p1_flat_bom_item.PartNoItem = (String)info_value_string_set[share_material_key]; // p1_flat_bom_item.Descr = (String)descr_kp_part_set[share_material_key]; // flat_bom_items.Add(p1_flat_bom_item); // } // } //} } //处理首阶为KP情况 //descr_kp_part_set.Clear(); //info_value_string_set.Clear(); //share_parts_set.Clear(); List<IBOMNode> collect_gather_node = new List<IBOMNode>(); List<QtyParts> kp_check_conditon_nodes = new List<QtyParts>(); // IList<QtyParts> kp_check_conditon_nodes = tree_traversal.BreadthFirstTraversal(bom.Root, "KP", "KP", this,"KP"); if (bom.FirstLevelNodes != null) { for (int i = 0; i < bom.FirstLevelNodes.Count; i++) { if (bom.FirstLevelNodes.ElementAt(i).Part != null) { if (bom.FirstLevelNodes.ElementAt(i).Part.BOMNodeType.Equals("KP")) { if (CheckCondition(bom.FirstLevelNodes.ElementAt(i))) { collect_gather_node.Add(bom.FirstLevelNodes.ElementAt(i)); List<IPart> parts = new List<IPart>(); parts.Add(bom.FirstLevelNodes.ElementAt(i).Part); QtyParts bom_item = new QtyParts(bom.FirstLevelNodes.ElementAt(i).Qty, parts); kp_check_conditon_nodes.Add(bom_item); } } } } } IList<ShareMaterialType> kp_material_type = FilterShareMaterialType(kp_check_conditon_nodes); foreach (ShareMaterialType type in kp_material_type) { Boolean is_add = true; foreach (ShareMaterialType mtype in material_type) { if (mtype.Descr.Trim().Equals(type.Descr.Trim()) && mtype.Qty == type.Qty) { is_add = false; break; } } if (is_add) { material_type.Add(type); } } if ( kp_check_conditon_nodes.Count > 0) { foreach (QtyParts bm_check_conditon_node in kp_check_conditon_nodes) { if (bom.FirstLevelNodes != null) { for (int i = 0; i < bom.FirstLevelNodes.Count; i++) { if (bom.FirstLevelNodes.ElementAt(i).Part != null) { if (bom.FirstLevelNodes.ElementAt(i).Part.BOMNodeType.Equals("KP") && bom.FirstLevelNodes.ElementAt(i).Part.Attributes != null) { IBOMNode kp_node = bom.FirstLevelNodes.ElementAt(i); //if (CheckCondition(bom.FirstLevelNodes.ElementAt(i))) if (PartCompare(bm_check_conditon_node.Parts, kp_node.Part)) { if (material_type.Count > 0) { foreach (ShareMaterialType type in material_type) { if (kp_node.Part.Descr.Equals(type.Descr) && bm_check_conditon_node.Qty == type.Qty) { String share_material_key = type.Qty.ToString() + type.Descr; if (!descr_kp_part_set.ContainsKey(share_material_key)) { descr_kp_part_set.Add(share_material_key, kp_node.Part.Descr); } else { if (!((String)descr_kp_part_set[share_material_key]).Contains(kp_node.Part.Descr)) { descr_kp_part_set[share_material_key] += "," + kp_node.Part.Descr; } } IList<PartInfo> part_infos = kp_node.Part.Attributes; if (part_infos != null && part_infos.Count > 0) { foreach (PartInfo part_info in part_infos) { if (part_info.InfoType.Equals("VendorCode")) { if (!info_value_string_set.ContainsKey(share_material_key)) { info_value_string_set.Add(share_material_key, part_info.InfoValue); } else { if (!((String)info_value_string_set[share_material_key]).Contains(part_info.InfoValue)) { info_value_string_set[share_material_key] += "," + part_info.InfoValue; } } if (!share_parts_set.ContainsKey(share_material_key)) { IList<IPart> share_parts = new List<IPart>(); share_parts.Add(kp_node.Part); share_parts_set.Add(share_material_key, share_parts); } else { ((IList<IPart>)share_parts_set[share_material_key]).Add(kp_node.Part); } } } } } } } } } } } } } //if (material_type.Count > 0) //{ // foreach (ShareMaterialType type in material_type) // { // String share_material_key = type.Qty.ToString() + type.Descr; // if (share_parts_set.ContainsKey(share_material_key)) // { // var kp_flat_bom_item = new FlatBOMItem(type.Qty, part_check_type, (IList<IPart>)share_parts_set[share_material_key]); // kp_flat_bom_item.PartNoItem = (String)info_value_string_set[share_material_key]; // kp_flat_bom_item.Descr = (String)descr_kp_part_set[share_material_key]; // flat_bom_items.Add(kp_flat_bom_item); // } // } //} } if (material_type.Count > 0) { foreach (ShareMaterialType type in material_type) { String share_material_key = type.Qty.ToString() + type.Descr; if (share_parts_set.ContainsKey(share_material_key)) { var kp_flat_bom_item = new FlatBOMItem(type.Qty, part_check_type, (IList<IPart>)share_parts_set[share_material_key]); kp_flat_bom_item.PartNoItem = (String)info_value_string_set[share_material_key]; kp_flat_bom_item.Descr = (String)descr_kp_part_set[share_material_key]; flat_bom_items.Add(kp_flat_bom_item); } } } if (flat_bom_items.Count > 0) { ret = new FlatBOM(flat_bom_items); } } catch (Exception e) { throw; } return ret; }