예제 #1
0
파일: Filter.cs 프로젝트: wra222/testgit
        void cacheTagDataValue(CheckItemTypeRuleDef chkRule, TagData tagData)
        {
            foreach (KeyValuePair<string, bool> keyValue in chkRule.MatchRuleGroupNames)
            {

                if (keyValue.Value)
                {
                    if (!tagData.GroupValueList.ContainsKey(keyValue.Key))
                    {
                        tagData.GroupValueList.Add(keyValue.Key,
                                                                   ResolveValue.GetValueWithoutError(tagData.Product, tagData.PCB, tagData.DN, null, 
                                                                                                                          keyValue.Key, GlobalConstName.UnderScoreChar));
                    }
                }
            }
            #region disable code
            //if (!string.IsNullOrEmpty(chkRule.Descr))
            //{
            //    string[] nameList = chkRule.Descr.Split(',');
            //    foreach (string name in nameList)
            //    {
            //        if (name.Contains("."))
            //        {
            //            string groupName= name.Replace(".", "_");
            //            chkRule.MatchRule = chkRule.MatchRule.Replace(name, groupName);
            //            if (!tagData.GroupValueList.ContainsKey(groupName))
            //            {
            //                tagData.GroupValueList.Add(groupName, 
            //                                                           ResolveValue.GetValueWithoutError(tagData.Product, tagData.PCB, tagData.DN, null, name, '.'));
            //            }
            //        }
            //        else  //no object format type
            //        {
            //            //throw new Exception(string.Format(wrongDescrError, chkRule.CheckItemType));
            //        }
            //    }

            //    chkRule.Descr=chkRule.Descr.Replace(".", "_");
            //}

            #endregion
        }
예제 #2
0
파일: Filter.cs 프로젝트: wra222/testgit
        public object FilterBOMEx(object hierarchical_bom, string station, string checkItemType, object main_object)
        {
            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;

            UtilityCommonImpl utl = UtilityCommonImpl.GetInstance();
            var filterMatchRule = utl.FilterMatchRule;
            IList<CheckItemTypeRuleDef> filteredChkItemRules = new List<CheckItemTypeRuleDef>();
            IList<CheckItemTypeRuleDef> lstChkItemRule = utl.GetCheckItemTypeRule(main_object, checkItemType, station);
            if (null == lstChkItemRule || lstChkItemRule.Count == 0)
            {
                // 未維護CheckItemTypeRule,請先維護!
                throw new FisException("CHK1151", new string[] { checkItemType });
                //return ret;
            }

            //order by BomNodeType,PartDescr,PartType, ID
            if (lstChkItemRule.Count > 1)
            {
                lstChkItemRule = lstChkItemRule.OrderBy(x => x.BomNodeType + GlobalConstName.UnderScoreStr + x.PartDescr + GlobalConstName.UnderScoreStr + x.PartType + GlobalConstName.UnderScoreStr + x.ID.ToString(Digit11)).ToList();
            }

            IList<IBOMNode> bom_nodes = bom.FirstLevelNodes;
           
            Session session = null;
            Delivery dn = null;
            Part mbPart = null;
            IProduct product = GetProduct(main_object, out session);
            
            IMB mb = GetPCB(main_object, out session);
            if (product == null && mb == null)
            {
                throw new FisException("Can not get Product and PCB object in " + checkItemType + " module");
            }

            if (product != null && 
                !string.IsNullOrEmpty(product.PCBID) &&
                mb == null)
            {
                //IMBRepository mbRep = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>();
                mb = mbRep.Find(product.PCBID);
            }

            if (mb != null && mb.ModelObj != null)
            {
                mbPart = (Part)mb.ModelObj.PartObj;
            }

            if (product != null && 
                !string.IsNullOrEmpty(product.DeliveryNo))
            {
                //IDeliveryRepository dnRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>();
                dn = dnRep.Find(product.DeliveryNo);
            }

            TagData tagdata = new TagData
            {
                Product = product,
                PCB = mb,
                MBPart = mbPart,
                DN = dn
            };
            string prevBomKey = null;
            string curBomKey = null;
            IFlatBOMItem prevFlatBomItem = null;
            foreach (CheckItemTypeRuleDef chkRule in lstChkItemRule)
            {
                if (string.IsNullOrEmpty(chkRule.MatchRule))
                {
                    throw new Exception(string.Format(emptyMatchRuleError, chkRule.CheckItemType));
                }

                if (string.IsNullOrEmpty(chkRule.BomNodeType))
                {
                    throw new Exception(string.Format(emptyBomNodeTypeError, chkRule.CheckItemType));
                }

                filterMatchRule.ParseCheckItemTypeRuleGroupName(chkRule);
                
                IFlatBOMItem kp_flat_bom_item = null;
                curBomKey = chkRule.BomNodeType + GlobalConstName.UnderScoreStr + chkRule.PartDescr + GlobalConstName.UnderScoreStr + chkRule.PartType;
                if (prevBomKey == curBomKey) 
                {
                    if (prevFlatBomItem != null) //上下FlatBomItem 有關連
                    {
                        kp_flat_bom_item = new FlatBOMItem(prevFlatBomItem.Qty, checkItemType, prevFlatBomItem.AlterParts);
                        cacheTagDataValue(chkRule, tagdata);
                        kp_flat_bom_item.PartNoItem = prevFlatBomItem.PartNoItem;
                        kp_flat_bom_item.Descr = prevFlatBomItem.AlterParts[0].Descr + (string.IsNullOrEmpty(chkRule.Descr) ? string.Empty : GlobalConstName.SlashStr + chkRule.Descr);
                        kp_flat_bom_item.CheckItemTypeRuleList = new List<CheckItemTypeRuleDef> { chkRule };
                        kp_flat_bom_item.RelationBomItem = prevFlatBomItem;
                    }
                    else
                    {
                        kp_flat_bom_item = null;
                    }
                }
                else
                {
                    kp_flat_bom_item = getNextBom(checkItemType,
                                                                       chkRule.BomNodeType,
                                                                        bom_nodes, 
                                                                        utl, 
                                                                        chkRule,
                                                                        tagdata,
                                                                        product);
                }

                if (kp_flat_bom_item != null)
                {
                    kp_flat_bom_item.Tag = tagdata;
                    flat_bom_items.Add(kp_flat_bom_item);
                    prevFlatBomItem = kp_flat_bom_item;                    
                }
                else
                {
                    prevFlatBomItem = null;                   
                }

                prevBomKey = curBomKey;                
            }

            if (flat_bom_items.Count > 0)
            {
                ret = new FlatBOM(flat_bom_items);
            }          

            return ret;
        }
예제 #3
0
파일: Filter.cs 프로젝트: wra222/testgit
        private FlatBOMItem getNextBom(string checkItemType,
                                             string bomNodeTypeLink,
                                              IList<IBOMNode> bomNodes,
                                              UtilityCommonImpl utl,
                                              CheckItemTypeRuleDef chkRule,
                                              TagData tagdata,                                                
                                              IProduct product)
        {
            int index = bomNodeTypeLink.IndexOf(GlobalConstName.ArrowStr);
            string bomNodeType = index < 0 ? bomNodeTypeLink : bomNodeTypeLink.Substring(0, index);
            string nextBomNodeType = index <= 0 ?null : bomNodeTypeLink.Substring(index + 2);
            var filterMatchRule = utl.FilterMatchRule;
            if (string.IsNullOrEmpty(nextBomNodeType))
            {
                var matchBomNodeList = bomNodes.Where(x => filterMatchRule.MatchCheckItemTypeRule(product, x.Part, chkRule, bomNodeType.Trim())).ToList();
                if (matchBomNodeList.Count > 0)
                {
                    if (string.IsNullOrEmpty(chkRule.MatchRule))
                    {
                        throw new Exception(string.Format(emptyMatchRuleError, chkRule.CheckItemType));
                    }

                     var partList = matchBomNodeList.Select(x => x.Part).ToList();

                    //Qty 不一致報錯
                    int qty = matchBomNodeList[0].Qty;
                    if (matchBomNodeList.Count > 1)
                    {
                        if (matchBomNodeList.Any(x => x.Qty != qty))
                        {
                            throw new Exception(string.Format(differentQtyError, string.Join(GlobalConstName.CommaStr,partList.Select(x=>x.PN).ToArray())));
                        }
                    }

                    //replace matchRule  '.'  to    '_'
                    cacheTagDataValue(chkRule, tagdata);

                   
                    var kp_flat_bom_item = new FlatBOMItem(qty, checkItemType, partList);
                    kp_flat_bom_item.PartNoItem = string.Join(GlobalConstName.CommaStr, partList.Select(x => x.PN).ToArray());
                    kp_flat_bom_item.Descr = partList[0].Descr + (string.IsNullOrEmpty(chkRule.Descr)?string.Empty: GlobalConstName.SlashStr + chkRule.Descr);
                    kp_flat_bom_item.CheckItemTypeRuleList = new List<CheckItemTypeRuleDef> { chkRule };
                    return kp_flat_bom_item;
                }

                return null;
            }
            else  // have next bomNode
            {
                foreach( IBOMNode node in  bomNodes)
                {
                    if (filterMatchRule.CheckBomNodeType(node.Part.BOMNodeType, bomNodeType))
                    {
                        FlatBOMItem bomItem= getNextBom(checkItemType,nextBomNodeType,node.Children,utl,chkRule,tagdata,product);
                        if (bomItem != null)
                        {
                            return bomItem;
                        }
                    }
                }
                return null;
            }
        }