Exemple #1
0
        /// <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;
        }
Exemple #2
0
        /// <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阶,得到第一阶是V2的part其下下阶(注意Qty需要相乘) [ V2一定会有VC下阶: V2->P1->KP->VC]
            //界面上显示Part No和Description是P1对应的Part;不同的P1作为多条记录显示在界面上,即相同的P1只显示一条,
            //其VC合并,相同的P1对应的数量认为是一样的,数量只取第一条记录的Qty即可
            //删掉PN前3位是MMI的Part ((GYJ)前三位只是代号,可能有DIB,MMI等)
            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;
            TreeTraversal tree_traversal = new TreeTraversal();
            Hashtable part_group_set = new Hashtable();
            Hashtable descr_part_set = new Hashtable();
            IList<KPVendorCode> kpVCList = new List<KPVendorCode>();
            //Hashtable info_value_string_set = new Hashtable();
            try
            {
                IList<QtyParts> check_conditon_nodes = tree_traversal.BreadthFirstTraversal("MMI",bom.Root, "V2->P1->KP","P1",this);
                IList<PartGroupType> part_group_type = FilterPartGroupType(check_conditon_nodes);
                if (check_conditon_nodes != null && check_conditon_nodes.Count > 0)
                {
                     List<IFlatBOMItem> items = new List<IFlatBOMItem>();
                    foreach (QtyParts check_conditon_node in check_conditon_nodes)
                    {
                        //FlatBOMItem item = new FlatBOMItem(check_conditon_node.Qty,part_check_type,check_conditon_node.Parts);
                        //items.Add(item);
                        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("V2"))
                                {
                                    IList<IBOMNode> p1_child_nodes = bom_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("P1"))
                                            {
                                                if (PartCompare(check_conditon_node.Parts, p1_child_node.Part))
                                                {
                                                    if (part_group_type.Count > 0)
                                                    {
                                                        foreach (PartGroupType type in part_group_type)
                                                        {
                                                            if (p1_child_node.Part.PN.Equals(type.PN))
                                                            {
                                                                String part_group_key = type.PN;

                                                                if (!descr_part_set.ContainsKey(part_group_key))
                                                                {
                                                                    descr_part_set.Add(part_group_key, p1_child_node.Part.Descr);
                                                                }
                                                                else
                                                                {
                                                                    if (!((String)descr_part_set[part_group_key]).Contains(p1_child_node.Part.Descr))
                                                                    {
                                                                        descr_part_set[part_group_key] += "," + p1_child_node.Part.Descr;
                                                                    }
                                                                }
                                                                IList<IBOMNode> kp_child_nodes = p1_child_node.Children;
                                                                //String info_value_string = "";
                                                                if (kp_child_nodes != null)
                                                                {
                                                                    foreach (IBOMNode kp_child_node in kp_child_nodes)
                                                                    {
                                                                        if (kp_child_node.Part != null && kp_child_node.Part.BOMNodeType.Equals("KP"))
                                                                        {
                                                                            IList<PartInfo> part_infos = kp_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"))
                                                                                    {
                                                                                        //p1_child_node.Part.AddAttribute(part_info);
                                                                                        kpVCList.Add(new KPVendorCode
                                                                                        {
                                                                                            PartNo = p1_child_node.Part.PN,
                                                                                            VendorCode = part_info.InfoValue
                                                                                        }
                                                                                            );
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                if (!part_group_set.ContainsKey(part_group_key))
                                                                {
                                                                    IList<IPart> share_parts = new List<IPart>();
                                                                    share_parts.Add(p1_child_node.Part);
                                                                    part_group_set.Add(part_group_key, share_parts);
                                                                }
                                                                else
                                                                {
//                                                                    ((IList<IPart>)part_group_set[part_group_key]).Add(p1_child_node.Part);
                                                                    IList<IBOMNode> identical_p1_child_nodes = p1_child_node.Children;
                                                                    //String info_value_string = "";
                                                                    if (kp_child_nodes != null)
                                                                    {
                                                                        foreach (IBOMNode identical_p1_child_node in identical_p1_child_nodes)
                                                                        {
                                                                            if (identical_p1_child_node.Part != null && identical_p1_child_node.Part.BOMNodeType.Equals("KP"))
                                                                            {
                                                                                IList<PartInfo> part_infos = identical_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"))
                                                                                        {
//                                                                                            p1_child_node.Part.AddAttribute(part_info);
                                                                                            // ((IList<IPart>)part_group_set[part_group_key]).ElementAt(0).AddAttribute(part_info);

                                                                                           kpVCList.Add(new KPVendorCode
                                                                                            {
                                                                                                PartNo = ((IList<IPart>)part_group_set[part_group_key]).ElementAt(0).PN,
                                                                                                VendorCode = part_info.InfoValue
                                                                                            });
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (part_group_type.Count > 0)
                    {
                        foreach (PartGroupType type in part_group_type)
                        {
                            String share_material_key = type.PN;
                            var bm_flat_bom_item = new FlatBOMItem(type.Qty, part_check_type, (IList<IPart>)part_group_set[share_material_key]);
                            bm_flat_bom_item.PartNoItem = type.PN;
                            bm_flat_bom_item.Descr = (String)descr_part_set[share_material_key];
                            flat_bom_items.Add(bm_flat_bom_item);
                        }
                    }
                }
 
                if (flat_bom_items.Count > 0)
                {
                    ret = new FlatBOM(flat_bom_items);
                }
            }
            catch (Exception e)
            {
                throw;
            }

            return ret;
        }
Exemple #3
0
        /// <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,
            IFlatBOM ret = null;
            List<IFlatBOMItem> items = new List<IFlatBOMItem>();
            var parts = new List<IPart>();
            int qty = 0;
            if (hierarchical_bom == null)
            {
                throw new ArgumentNullException();
            }
            var bom = (HierarchicalBOM)hierarchical_bom;

            // mantis 324
             if(Uti.CheckCPUOnBoard(bom))
             {  return ret;}
           var tree_traversal = new TreeTraversal();
            try
            {
                IList<QtyParts> bm_check_conditon_nodes = tree_traversal.BreadthFirstTraversal(bom.Root, "BM->P1->KP", "P1", this,"BM");
                String descr = "";
                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)
                        {
                            IList<IBOMNode> bom_nodes = bom.FirstLevelNodes;
                            foreach (IBOMNode bom_node in bom_nodes)
                            {
                                if (bom_node.Part.BOMNodeType.Equals("BM"))
                                {
                                    if (bom_node.Children != null)
                                    {
                                        IList<IBOMNode> p1_child_nodes = bom_node.Children;
                                        foreach (var p1_child_node in p1_child_nodes)
                                        {
                                            if (p1_child_node.Part != null && p1_child_node.Part.BOMNodeType.Equals("P1"))
                                            {
                                                if (!descr.Contains(p1_child_node.Part.Descr))
                                                {
                                                    if (descr.Length == 0)
                                                    {
                                                        descr = p1_child_node.Part.Descr;
                                                    }
                                                    else
                                                    {
                                                        if (!descr.Contains(p1_child_node.Part.Descr))
                                                        {
                                                            descr += "," + p1_child_node.Part.Descr;
                                                        }
                                                        
                                                    }
                                                    
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        //var item = new FlatBOMItem(bm_check_conditon_node.Qty, part_check_type, bm_check_conditon_node.Parts);
                        //items.Add(item);
                        if(bm_check_conditon_node.Parts != null)
                        {
                            foreach (IPart cpu_part in bm_check_conditon_node.Parts)
                            {
                                parts.Add(cpu_part);
                            }
                        }
                    }
                    var item = new FlatBOMItem(bm_check_conditon_nodes.ElementAt(0).Qty, part_check_type, parts);
                    item.PartNoItem = bm_check_conditon_nodes.ElementAt(0).Parts.ElementAt(0).PN;
                    item.Descr = descr;
                    items.Add(item);
                }
 
                if (items.Count > 0)
                {
                    ret = new FlatBOM(items);
                }
            }
            catch (Exception e)
            {
                throw;
            }

            return ret;
Exemple #4
0
        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;
        }
Exemple #5
0
        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"))
                                            //Flter out Battery ....
                                            if (vk_child_node.Part != null && vk_child_node.Part.BOMNodeType.Equals("P1") && !vk_child_node.Part.Descr.ToUpper().Contains("BATT"))
                                            {
                                              
                                                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);
                                                                                kpVCList.Add(new KPVendorCode
                                                                                {
                                                                                    PartNo = vk_child_node.Part.PN,
                                                                                    VendorCode = part_info.InfoValue
                                                                                });
                                                                           
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }

                                                        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);
                                                        kpVCList.Add(new KPVendorCode
                                                        {
                                                            PartNo = parent_part.PN,
                                                            VendorCode = part_info.InfoValue
                                                        });
                                                    }
                                                }
                                            }
                                            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);
                                                    int qty = qty_part.Qty;
                                                    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);
                                                    int qty = qty_part.Qty;
                                                    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;
                                          dib_part  = repository.GetPartByPartNo(part_pn.Substring(3, part_pn.Length-3));
                                          //For ICC: If part no format:DIBxxxxxx-yyyy,Remove the last character
                                          //              e.g. Change DIB709986-0011 to 709986-001
                                          if (dib_part == null)
                                          {
                                              if (part_pn.Split('-').Length == 2 && part_pn.Split('-')[1].Length == 4)
                                              {
                                                 dib_part = repository.GetPartByPartNo(part_pn.Substring(3, part_pn.Length - 4));
                                              }
                                           }
                                         //For ICC

                                        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));
                                                               //For ICC
                                                                if (real_part == null)
                                                                {
                                                                    if (share_parts[j].Split('-').Length == 2 && share_parts[j].Split('-')[1].Length == 4)
                                                                    {
                                                                        real_part = repository.GetPartByPartNo(share_parts[j].Substring(3, share_parts[j].Length - 4));
                                                                    }
                                                                }
                                                                //For ICC

                                                                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;
        }