Esempio n. 1
0
        public ActionResult SaveCalculation(SheetDetailsCalculation sheetDetailsCalculation, SheetDetailViewModels sheetDetailViewModels /*, int? detId*/)
        {
            SheetDetail[] details = new SheetDetail[sheetDetailViewModels.DetailNumber.Length];
            for (int j = 0; j < details.Length; j++)
            {
                if (sheetDetailViewModels.DetailId[j] == -1)
                {
                    details[j] = new SheetDetail();
                    details[j].DetailLength    = sheetDetailViewModels.DetailLength[j];
                    details[j].DetailName      = sheetDetailViewModels.DetailName[j];
                    details[j].DetailNumber    = sheetDetailViewModels.DetailNumber[j];
                    details[j].DetailWidth     = sheetDetailViewModels.DetailWidth[j];
                    details[j].DetailThickness = sheetDetailsCalculation.SheetThickness;
                    db.SheetDetails.Add(details[j]);
                }
                else
                {
                    details[j] = db.SheetDetails.Find(sheetDetailViewModels.DetailId[j]);
                }

                DetailCalculation detailCalculation = new DetailCalculation();
                detailCalculation.Calculation   = sheetDetailsCalculation;
                detailCalculation.Detail        = details[j];
                detailCalculation.Amount        = sheetDetailViewModels.DetailAmount[j];
                detailCalculation.DetailsSquare = detailCalculation.Amount * details[j].DetailLength * details[j].DetailWidth;
                detailCalculation.DetailPrice   = sheetDetailViewModels.DetailPrice[j];

                db.DetailsCalculations.Add(detailCalculation);
            }

            db.SheetDetailsCalculations.Add(sheetDetailsCalculation);
            db.SaveChanges();

            return(RedirectToAction("GetAllCalculations", db.SheetDetailsCalculations.ToList()));
        }
Esempio n. 2
0
        public JsonResult Calculation(SheetDetailsCalculation sheetDetailsCalculation, SheetDetailViewModels sheetDetailViewModels)
        {
            DetailCalculation[] Details = Calculate(sheetDetailsCalculation, sheetDetailViewModels);

            //sheetDetailsCalculation.DetailsCalculation.details = details;
            DetailsPricesAndWasteCoef detailsPricesAndWasteCoef = new DetailsPricesAndWasteCoef();

            detailsPricesAndWasteCoef.DetailsPrices = Details.Select(i => i.DetailPrice).ToArray();
            detailsPricesAndWasteCoef.WasteCoef     = sheetDetailsCalculation.WasteCoeficcient;

            //return Json(res);
            return(Json(detailsPricesAndWasteCoef));
        }
Esempio n. 3
0
        private static DetailCalculation[] Calculate(SheetDetailsCalculation sheetDetailsCalculation, SheetDetailViewModels sheetDetailViewModels)
        {
            DetailCalculation[] Details = new DetailCalculation[sheetDetailViewModels.DetailNumber.Length];

            sheetDetailsCalculation.DetailsSquares = new double[sheetDetailViewModels.DetailNumber.Length];
            for (int i = 0; i < sheetDetailViewModels.DetailNumber.Length; i++)
            {
                sheetDetailsCalculation.DetailsSquares[i] = (sheetDetailViewModels.DetailAmount[i] * sheetDetailViewModels.DetailLength[i] * sheetDetailViewModels.DetailWidth[i]) / 1000000;
            }
            // Рассчитываем коэф.отхода по всему заказу
            sheetDetailsCalculation.WasteCoeficcient = sheetDetailsCalculation.Area / sheetDetailsCalculation.DetailsSquares.Sum();

            // доля каждой детали от площади листа в %
            //decimal[] ItemsPercentages = new decimal[sheetDetailViewModels.DetailNumber.Length];
            sheetDetailsCalculation.ItemsPercentages = new double[sheetDetailViewModels.DetailNumber.Length];

            for (int i = 0; i < sheetDetailViewModels.DetailNumber.Length; i++)
            {
                sheetDetailsCalculation.ItemsPercentages[i] = (sheetDetailsCalculation.DetailsSquares[i] * sheetDetailsCalculation.WasteCoeficcient) / sheetDetailsCalculation.Area;
                // считаем стоимость за материалл для каждой детали

                Details[i] = new DetailCalculation();
                Details[i].MaterialPrice = sheetDetailsCalculation.MaterialPrice * sheetDetailsCalculation.ItemsPercentages[i];
                // считаем стоимость работы для каждой детали
                Details[i].WorkPrice = sheetDetailsCalculation.CuttingPrice * sheetDetailsCalculation.ItemsPercentages[i];
                // считаем стоимость каждой детали
                Details[i].DetailPrice = (Details[i].MaterialPrice + Details[i].WorkPrice) / sheetDetailViewModels.DetailAmount[i];
            }

            return(Details);
        }
Esempio n. 4
0
        public async System.Threading.Tasks.Task <ActionResult> EditCalculation(SheetDetailsCalculation Calculation, SheetDetailViewModels sheetDetailViewModels /*int[] DetailId*/)
        {
            if (ModelState.IsValid)
            {
                SheetDetailsCalculation currentCalculation = await db.SheetDetailsCalculations.FindAsync(Calculation.Id);

                currentCalculation.Area             = Calculation.Area;
                currentCalculation.CalculationDate  = Calculation.CalculationDate;
                currentCalculation.CuttingPrice     = Calculation.CuttingPrice;
                currentCalculation.DetailsSquares   = Calculation.DetailsSquares;
                currentCalculation.InvoiceDate      = Calculation.InvoiceDate;
                currentCalculation.InvoiceNumber    = Calculation.InvoiceNumber;
                currentCalculation.ItemsPercentages = Calculation.ItemsPercentages;
                currentCalculation.MaterialPrice    = Calculation.MaterialPrice;
                currentCalculation.SheetThickness   = Calculation.SheetThickness;
                currentCalculation.WasteCoeficcient = Calculation.WasteCoeficcient;

                currentCalculation.DetailsCalculation.Clear();

                for (var i = 0; i < sheetDetailViewModels.DetailId.Length; i++)
                {
                    DetailCalculation detailCalculation = new DetailCalculation();
                    currentCalculation.DetailsCalculation.Add(detailCalculation);
                    if (sheetDetailViewModels.DetailId[i] != -1)
                    {
                        detailCalculation.Detail = db.SheetDetails.Find(sheetDetailViewModels.DetailId[i]);
                    }
                    else
                    {
                        SheetDetail newDetail = new SheetDetail();
                        newDetail.DetailLength    = sheetDetailViewModels.DetailLength[i];
                        newDetail.DetailName      = sheetDetailViewModels.DetailName[i];
                        newDetail.DetailNumber    = sheetDetailViewModels.DetailNumber[i];
                        newDetail.DetailThickness = currentCalculation.SheetThickness;
                        newDetail.DetailWidth     = sheetDetailViewModels.DetailWidth[i];
                        db.SheetDetails.Add(newDetail);
                        detailCalculation.Detail = newDetail;
                    }
                    detailCalculation.Amount        = sheetDetailViewModels.DetailAmount[i];;
                    detailCalculation.DetailsSquare = (sheetDetailViewModels.DetailAmount[i] * sheetDetailViewModels.DetailLength[i] * sheetDetailViewModels.DetailWidth[i]) / 1000000;
                    detailCalculation.DetailPrice   = sheetDetailViewModels.DetailPrice[i];
                }


                await db.SaveChangesAsync();
            }
            return(RedirectToAction("GetAllCalculations"));
        }