public WeightValue SMALL_LOT(ISimEntity entity, DateTime now, ActiveObject target, WeightFactor factor, IDispatchContext ctx) { if (factor.Factor == 0) { return(new WeightValue(0)); } FabAoEquipment eqp = target as FabAoEquipment; FabLot lot = entity as FabLot; int smallSize = (int)factor.Criteria[0]; if (smallSize == 0) { return(new WeightValue(0)); } int stepCount = (int)factor.Criteria[1]; if (stepCount == 0) { return(new WeightValue(0)); } var job = InFlowMaster.GetJobState(lot); if (job == null) { return(new WeightValue(0)); } int currentUnitQty = lot.UnitQty; string shopID = lot.CurrentShopID; string productID = lot.CurrentProductID; string productVer = lot.CurrentProductVersion; bool isLastPlan = ResHelper.IsLastPlan(eqp, lot); float score = 0f; if (isLastPlan) { score = 1f; } FabStep step = lot.CurrentFabStep; string stepType = step.StepType; int cnt = 0; int runQty = 0; int waitQty = 0; int total = 0; while (cnt < stepCount) { List <FabStep> preSteps = step.GetPrevSteps(productID); List <FabLot> runWips = job.GetPrevStepWipList(step, WipType.Run, productVer); List <FabLot> waitWips = job.GetPrevStepWipList(step, WipType.Wait, productVer); if (runWips.Count <= 0 && waitWips.Count <= 0) { cnt++; continue; } int prevRunQty = runWips.Sum(x => x.UnitQty); int preWaitQty = waitWips.Sum(x => x.UnitQty); runQty += prevRunQty; waitQty += preWaitQty; total += runQty + waitQty; foreach (FabStep prevStep in preSteps) { if (prevStep.StepType == "MAIN") { step = prevStep; } if (step == null) { continue; } } cnt++; } int compareQty = currentUnitQty + total; string desc = string.Format("[SmallSize:{0}, CompareQty:{1}, IsLast:{2}]", smallSize, compareQty, isLastPlan); if (compareQty > smallSize) { score = 1f; } return(new WeightValue(score * factor.Factor, desc)); }