Ejemplo n.º 1
0
 public void AddCTDetail(CuttingInstructionDetail instructionDetail)
 {
     using (var context = new ManufacturingDataContext(_connectionString))
     {
         context.CuttingInstructionDetails.InsertOnSubmit(instructionDetail);
         context.SubmitChanges();
     }
 }
        public void SubmitProduction(FinalProduction production)
        {
            var repo = new ProductionRespository(Properties.Settings.Default.ManufacturingConStr);
            var prod = new Production {
                Date = production.Date
            };

            repo.AddProduction(prod);
            if (production.CuttingInstructions.Count() > 0)
            {
                var lastLot = LotNumberIndex();
                //if (lastLot >= production.CuttingInstructions[0].LotNumber)
                //{
                //    production.CuttingInstructions = production.CuttingInstructions.Select((m, i) => { m.LotNumber = lastLot + 1 + i; return m; }).ToList();
                //}
                if (lastLot != production.CuttingInstructions[0].LotNumber)
                {
                    production.CuttingInstructions = production.CuttingInstructions.Select((m, i) => { m.LotNumber = lastLot + i; return(m); }).ToList();
                }
                repo.IncrementLotNumberCounter(production.CuttingInstructions.Count());
            }
            foreach (var cI in production.CuttingInstructions)
            {
                var cutInst = new CuttingInstruction
                {
                    ProductionId        = prod.Id,
                    LotNumber           = cI.LotNumber,
                    MarkerText          = cI.Marker.MarkerSizeText,
                    MarkerId            = MarkerId(cI.Marker),
                    PlannedProductionId = cI.Marker.PlannedProductionId
                };
                repo.AddCuttingTicket(cutInst);
                //if (!cI.Marker.AllSizes)
                //{
                //    var sizes = cI.Marker.Sizes.Select(s =>
                //    {
                //        return new CuttingInstructionSize
                //        {
                //            SizeId = s.SizeId,
                //            AmountPerLayer = s.AmountPerLayer,
                //            CuttingInstructId = cutInst.Id
                //        };
                //    });
                //    repo.AddCTSizes(sizes);
                //}
                foreach (var ctd in cI.Details)
                {
                    var newCtd = new CuttingInstructionDetail
                    {
                        FabricId             = GetFabricId(ctd.ColorMaterial.MaterialId, ctd.ColorMaterial.ColorId),
                        Layers               = ctd.ColorMaterial.Layers,
                        CuttingInstructionId = cutInst.Id
                    };
                    repo.AddCTDetail(newCtd);
                    var ctdI = ctd.Items.Select(cd =>
                    {
                        return(new CuttingInstructionItem
                        {
                            CuttingInstructionDetailsId = newCtd.Id,
                            ItemId = cd.ItemId,
                            Quantity = cd.Quantity,
                            Packaging = cd.Packaging
                        });
                    });
                    repo.AddCTItems(ctdI);
                }

                //var ctd = cI.Items.Select(cd =>
                //{
                //    return new CuttingInstructionItem
                //    {
                //        CuttingInstructionDetailsId = cutInst.Id,
                //        ItemId = cd.ItemId,
                //        Quantity = cd.Quantity,
                //        Packaging = cd.Packaging
                //    };
                //});
                //repo.AddCTDetails(ctd);
            }
            TempData["Message"] = $"You susseffully added a new production with {production.CuttingInstructions.Count()} cuttting instuctoins from lot number {production.CuttingInstructions[0].LotNumber} - {production.CuttingInstructions[production.CuttingInstructions.Count() - 1].LotNumber}." +
                                  $"<br/> {production.CuttingInstructions.Select(c => c.Details.Sum(co => co.Items.Count())).Sum()} Items. Total pieces: {production.CuttingInstructions.Select(c => c.Details.Sum(co => co.Items.Sum(i => i.Quantity))).Sum()} ";
        }