示例#1
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());
        }
示例#2
0
        private static Dictionary <int, Tuple <DateTime, int> > GetEmployeeIdentifiableByLot(PackScheduleDTO packSchedule)
        {
            if (packSchedule == null || string.IsNullOrWhiteSpace(packSchedule.Serialized))
            {
                return(new Dictionary <int, Tuple <DateTime, int> >());
            }

            try
            {
                var lotKeyParser = new LotKey();
                var employeeKey  = new EmployeeKey();
                return(SerializablePackSchedule.Deserialize(packSchedule.Serialized).Batches.ToDictionary(b =>
                {
                    var lotKey = lotKeyParser.Parse(b.LotKey);
                    return LotNumberBuilder.BuildLotNumber(lotKey).LotNumber;
                }, b => new Tuple <DateTime, int>(b.TimeStamp, employeeKey.Parse(b.EmployeeKey).EmployeeKey_Id)));
            }
            catch (Exception ex)
            {
                throw new Exception("Error parsing PackSchedule deserialized data.", ex);
            }
        }
        public static bool DeserializeIntoPackSchedule(PackSchedule packSchedule, string serializedPackSchedule, out int?pkgID)
        {
            pkgID = null;
            var deserialized = Deserialize(serializedPackSchedule);

            if (deserialized == null)
            {
                return(false);
            }

            var employeeKeyParser = new EmployeeKey();
            var lotKeyParser      = new LotKey();

            pkgID = deserialized.PkgID;

            IEmployeeKey employeeKey;

            if (employeeKeyParser.TryParse(deserialized.EmployeeKey, out employeeKey))
            {
                packSchedule.EmployeeId = employeeKey.EmployeeKey_Id;
            }
            packSchedule.TimeStamp = deserialized.TimeStamp;

            packSchedule.DefaultBatchTargetParameters = new ProductionBatchTargetParameters(deserialized.TargetParameters);
            packSchedule.ProductionBatches            = deserialized.Batches.Select(b =>
            {
                var lotKey            = lotKeyParser.Parse(b.LotKey);
                var batchEmployeeKey  = employeeKeyParser.Parse(b.EmployeeKey);
                var pickedEmployeeKey = employeeKeyParser.Parse(b.PickedInventory.EmployeeKey);

                var productionBatch = new ProductionBatch
                {
                    EmployeeId = batchEmployeeKey.EmployeeKey_Id,
                    TimeStamp  = b.TimeStamp,

                    LotDateCreated  = lotKey.LotKey_DateCreated,
                    LotDateSequence = lotKey.LotKey_DateSequence,
                    LotTypeId       = lotKey.LotKey_LotTypeId,

                    PackScheduleDateCreated = packSchedule.DateCreated,
                    PackScheduleSequence    = packSchedule.SequentialNumber,

                    ProductionHasBeenCompleted = false,
                    TargetParameters           = new ProductionBatchTargetParameters(b.TargetParameters),

                    Production = new ChileLotProduction
                    {
                        EmployeeId = batchEmployeeKey.EmployeeKey_Id,
                        TimeStamp  = b.TimeStamp,

                        LotDateCreated  = lotKey.LotKey_DateCreated,
                        LotDateSequence = lotKey.LotKey_DateSequence,
                        LotTypeId       = lotKey.LotKey_LotTypeId,

                        ProductionType = ProductionType.ProductionBatch,

                        PickedInventory = new Models.PickedInventory
                        {
                            EmployeeId   = pickedEmployeeKey.EmployeeKey_Id,
                            TimeStamp    = b.PickedInventory.TimeStamp,
                            PickedReason = PickedReason.Production,
                            Archived     = false,
                            Items        = new List <PickedInventoryItem>()
                        }
                    }
                };
                return(productionBatch);
            }).ToList();

            return(true);
        }
示例#4
0
        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);
        }