예제 #1
0
        public void GetPrice()
        {
            var secondaryProduction = new List <SecondaryProduction>
            {
                new SecondaryProduction("Заготовка-AL5", new Size(50, 50, 12, 5),
                                        new PrimaryProduction(TypeMaterial.Aluminum, TypeProduction.Plate, "Лист AL-4",
                                                              new Size(50, 70, 5, 3), 1000,
                                                              250m)),
                new SecondaryProduction("Заготовка-ТТ3", new Size(150, 7, 7, 40),
                                        new PrimaryProduction(TypeMaterial.Steel, TypeProduction.Rod, "Прут ST-5",
                                                              new Size(0.5, 0.5, 5, 7), 500,
                                                              1500m))
            };

            FinalProduction production = new FinalProduction("Станок измерительный", new Size(100, 200, 160, 15),
                                                             1100, secondaryProduction);


            Assert.AreEqual(3937.50m, production.PriceProduction);
        }
        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()} ";
        }