Beispiel #1
0
        public static void GetAccessors(this ILotAttributes lotAttributes, IAttributeNameKey attribute, out Func <decimal?> get, out Func <decimal?, decimal?> set)
        {
            var attributeNameKey = new AttributeNameKey(attribute);

            get = () => AttributeGetters[attributeNameKey](lotAttributes);
            set = v => AttributeSetters[attributeNameKey](lotAttributes, v);
        }
            private void ReconcileLotAttributesAndDefects(LotDTO oldLot, Lot newLot, ChileProduct chileProduct, AttributeCommonData attributeData, ref List <LotAttributeDefect> lotAttributeDefects)
            {
                foreach (var name in StaticAttributeNames.AttributeNames)
                {
                    var getValue = oldLot.AttributeGet(name);
                    if (getValue == null)
                    {
                        continue;
                    }
                    var oldContextValue = getValue();

                    var nameKey = new AttributeNameKey(name);
                    var productAttributeRange = chileProduct.ProductAttributeRanges.FirstOrDefault(r => nameKey.Equals(r));
                    var newContextAttribute   = newLot.Attributes.FirstOrDefault(a => nameKey.Equals(a));

                    if (newContextAttribute == null)
                    {
                        if (oldContextValue != null)
                        {
                            AddNewLotAttribute(oldLot, newLot, productAttributeRange, name, attributeData, (double)oldContextValue, ref lotAttributeDefects);
                        }
                    }
                    else
                    {
                        if (oldContextValue != null)
                        {
                            UpdateExistingLotAttribute(newContextAttribute, name, attributeData, productAttributeRange, (double)oldContextValue, ref lotAttributeDefects);
                        }
                        else
                        {
                            RemoveExistingLotAttribute(newContextAttribute, ref lotAttributeDefects);
                        }
                    }
                }
            }
Beispiel #3
0
        private IResult UpdateOrCreateLotAttribute(ILotKey chileLotKey, AttributeNameKey attributeNameKey, IAttributeValueParameters newAttribute, ref List <LotAttribute> unaccountedAttributes)
        {
            var existingAttribute = false;
            var lotAttribute      = unaccountedAttributes.FirstOrDefault(a => a.AttributeName != null && attributeNameKey.FindByPredicate.Invoke(a.AttributeName));

            if (lotAttribute != null)
            {
                existingAttribute = true;
                unaccountedAttributes.Remove(lotAttribute);
            }
            else
            {
                var attributeName = _parameters.AttributeNames.FirstOrDefault(a => attributeNameKey.FindByPredicate.Invoke(a));
                if (attributeName == null)
                {
                    return(new InvalidResult(string.Format(UserMessages.AttributeNameNotFound, attributeNameKey.KeyValue)));
                }

                lotAttribute = _lotUnitOfWork.LotAttributeRepository.Add(new LotAttribute
                {
                    LotDateCreated  = chileLotKey.LotKey_DateCreated,
                    LotDateSequence = chileLotKey.LotKey_DateSequence,
                    LotTypeId       = chileLotKey.LotKey_LotTypeId,

                    AttributeShortName = attributeNameKey.AttributeNameKey_ShortName,
                    AttributeName      = attributeName
                });
            }

            var newValueInSpec = false;

            if (!existingAttribute ||
                (Math.Abs(lotAttribute.AttributeValue - newAttribute.AttributeInfo.Value) > EPSILON) ||
                lotAttribute.AttributeDate != newAttribute.AttributeInfo.Date)
            {
                var updateResult = UpdateLotAttribute(lotAttribute, newAttribute, out newValueInSpec);
                if (!updateResult.Success)
                {
                    return(updateResult);
                }
            }

            if (newValueInSpec || newAttribute.Resolution != null)
            {
                var resolveOpenDefectsResult = ResolveOpenDefectsForAttribute(lotAttribute, newAttribute);
                if (!resolveOpenDefectsResult.Success)
                {
                    return(resolveOpenDefectsResult);
                }
            }

            return(new SuccessResult());
        }
Beispiel #4
0
            public LotAttributeWrapper(ILotAttributes lot, ILotAttributes untestedHistory, AttributeName attributeName)
            {
                ActualValueRequired = attributeName.ActualValueRequired;
                AttributeNameKey    = new AttributeNameKey(attributeName);
                lot.GetAccessors(attributeName, out _get, out _set);

                Computed = lot.TestDate == null;
                if (untestedHistory != null)
                {
                    Computed = Value == untestedHistory.AttributeGet(attributeName)();
                }
            }
Beispiel #5
0
        private IResult RemoveLotAttributeIfExists(AttributeNameKey attributeNameKey, IAttributeValueParameters attributeValue, ref List <LotAttribute> unaccountedAttributes)
        {
            var lotAttribute = unaccountedAttributes.FirstOrDefault(a => a.AttributeName != null && attributeNameKey.FindByPredicate.Invoke(a.AttributeName));

            if (lotAttribute != null)
            {
                var resolveOpenDefectsResult = ResolveOpenDefectsForAttribute(lotAttribute, attributeValue);
                if (!resolveOpenDefectsResult.Success)
                {
                    return(resolveOpenDefectsResult);
                }

                unaccountedAttributes.Remove(lotAttribute);
                _lotUnitOfWork.LotAttributeRepository.Remove(lotAttribute);
            }

            return(new SuccessResult());
        }
Beispiel #6
0
        public List <CustomerProductAttributeRange> ToDataModels(IChileProductKey chileProduct, ICompanyKey customer)
        {
            var employeeKeyParser      = new EmployeeKey();
            var attributeNameKeyParser = new AttributeNameKey();

            return(AttributeRanges.Select(r => new CustomerProductAttributeRange
            {
                EmployeeId = employeeKeyParser.Parse(r.EmployeeKey).EmployeeKey_Id,
                TimeStamp = r.TimeStamp,

                CustomerId = customer.CompanyKey_Id,
                ChileProductId = chileProduct.ChileProductKey_ProductId,
                AttributeShortName = attributeNameKeyParser.Parse(r.AttributeNameKey).AttributeNameKey_ShortName,

                Active = r.Active,
                RangeMin = r.RangeMin,
                RangeMax = r.RangeMax
            }).ToList());
        }
        public static bool UpdateLot(Lot newLot, SerializableLot deserialized, bool tested, out List <LotAttributeDefect> attributeDefects)
        {
            if (deserialized == null)
            {
                newLot.Attributes = new List <LotAttribute>();
                newLot.LotDefects = new List <LotDefect>();
                attributeDefects  = new List <LotAttributeDefect>();
                return(false);
            }

            if (deserialized.LotIdentifiable != null)
            {
                newLot.EmployeeId = deserialized.LotIdentifiable.EmployeeKey.EmployeeKeyId;
                newLot.TimeStamp  = deserialized.LotIdentifiable.TimeStamp;
            }

            var newAttributeDefects    = new List <LotAttributeDefect>();
            var attributeNameKeyParser = new AttributeNameKey();
            var employeeKeyParser      = new EmployeeKey();

            newLot.Hold            = deserialized.HoldType;
            newLot.HoldDescription = deserialized.HoldDescription;
            newLot.Attributes      = deserialized.Attributes.Select(a =>
            {
                var nameKey     = attributeNameKeyParser.Parse(a.NameKey);
                var employeeKey = employeeKeyParser.Parse(a.EmployeeKey);

                return(new LotAttribute
                {
                    Lot = newLot,
                    TimeStamp = a.TimeStamp,
                    EmployeeId = employeeKey.EmployeeKey_Id,
                    LotDateCreated = newLot.LotDateCreated,
                    LotDateSequence = newLot.LotDateSequence,
                    LotTypeId = newLot.LotTypeId,
                    AttributeShortName = nameKey.AttributeNameKey_ShortName,

                    AttributeValue = a.Value,
                    AttributeDate = a.DateTested.Date,
                    Computed = a.Computed ?? !tested
                });
            }).ToList();

            var defectId = 0;

            newLot.LotDefects = deserialized.Defects.Select(d =>
            {
                DefectTypeEnum defectType;
                if (!DefectTypeEnum.TryParse(d.DefectType, out defectType))
                {
                    throw new Exception(string.Format("Could not parse DefectTypeEnum[{0}]", d.DefectType));
                }

                var resolutionType = default(ResolutionTypeEnum);
                if (d.DefectResolution != null)
                {
                    if (!ResolutionTypeEnum.TryParse(d.DefectResolution.ResolutionType, out resolutionType))
                    {
                        throw new Exception(string.Format("Could not parse ResolutionTypeEnum[{0}]", d.DefectResolution.ResolutionType));
                    }
                }

                defectId  += 1;
                var defect = new LotDefect
                {
                    LotDateCreated  = newLot.LotDateCreated,
                    LotDateSequence = newLot.LotDateSequence,
                    LotTypeId       = newLot.LotTypeId,
                    DefectId        = defectId,

                    DefectType  = defectType,
                    Description = d.Description,
                    Resolution  = d.DefectResolution == null ? null : new LotDefectResolution
                    {
                        EmployeeId = employeeKeyParser.Parse(d.DefectResolution.EmployeeKey).EmployeeKey_Id,
                        TimeStamp  = d.DefectResolution.TimeStamp,

                        LotDateCreated  = newLot.LotDateCreated,
                        LotDateSequence = newLot.LotDateSequence,
                        LotTypeId       = newLot.LotTypeId,
                        DefectId        = defectId,

                        ResolutionType = resolutionType,
                        Description    = d.DefectResolution.Description,
                    }
                };

                if (d.AttributeDefect != null)
                {
                    var nameKey = attributeNameKeyParser.Parse(d.AttributeDefect.NameKey);

                    newAttributeDefects.Add(new LotAttributeDefect
                    {
                        LotDateCreated     = newLot.LotDateCreated,
                        LotDateSequence    = newLot.LotDateSequence,
                        LotTypeId          = newLot.LotTypeId,
                        DefectId           = defectId,
                        AttributeShortName = nameKey.AttributeNameKey_ShortName,

                        OriginalAttributeValue    = d.AttributeDefect.Value,
                        OriginalAttributeMinLimit = d.AttributeDefect.Min,
                        OriginalAttributeMaxLimit = d.AttributeDefect.Max,

                        LotDefect = defect
                    });
                }

                return(defect);
            }).ToList();

            attributeDefects = newAttributeDefects;
            return(true);
        }