Example #1
0
        private double FindWeight(
            List <Construction> constructions,
            List <StandardConstruction> standardConstructions)
        {
            const double multiplier = 1.04;

            var sum = 0.0;

            for (int i = 0; i < constructions.Count(); i++)
            {
                var constructionElements = _constructionElementRepo.GetAllByConstructionId(
                    constructions[i].Id);
                sum += Math.Ceiling(constructionElements.Sum(
                                        v => v.Profile.Weight * v.Length) * multiplier) / 1000;
            }

            for (int i = 0; i < standardConstructions.Count(); i++)
            {
                sum += standardConstructions[i].Weight;
            }

            return(Math.Round(sum, 1));
        }
Example #2
0
 public IEnumerable <ConstructionElement> GetAllByConstructionId(
     int constructionId)
 {
     return(_repository.GetAllByConstructionId(constructionId));
 }
        private void AppendConstructionToTable(
            WordprocessingDocument document,
            List <Construction> constructions,
            List <StandardConstruction> standardConstructions)
        {
            const double multiplier = 1.04;

            if (constructions.Count() > 0)
            {
                var sums = new List <double> {
                };
                for (int i = 0; i < 12; i++)
                {
                    sums.Add(0.0);
                }

                Body body           = document.MainDocumentPart.Document.Body;
                var  t              = body.Descendants <Table>().FirstOrDefault();
                var  firstTr        = t.Descendants <TableRow>().ToList()[0];
                var  clonedFirstTr  = firstTr.CloneNode(true);
                var  trCells        = firstTr.Descendants <TableCell>().ToList();
                var  secondTr       = t.Descendants <TableRow>().ToList()[1];
                var  clonedSecondTr = secondTr.CloneNode(true);
                var  thirdTr        = t.Descendants <TableRow>().ToList()[2];
                var  clonedThirdTr  = thirdTr.CloneNode(true);
                t.RemoveChild(thirdTr);
                OpenXmlElement newTr = null;
                Paragraph      p     = null;

                for (int i = 0; i < constructions.Count(); i++)
                {
                    if (i > 0)
                    {
                        newTr   = clonedFirstTr.CloneNode(true);
                        trCells = newTr.Descendants <TableCell>().ToList();
                    }
                    p = trCells[0].GetFirstChild <Paragraph>();
                    p.Append(Word.GetTextElement(constructions[i].Name, 24));
                    if (i > 0)
                    {
                        t.Append(newTr);
                    }

                    var constructionElements = _constructionElementRepo.GetAllByConstructionId(
                        constructions[i].Id);
                    if (i > 0)
                    {
                        newTr   = clonedSecondTr.CloneNode(true);
                        trCells = newTr.Descendants <TableCell>().ToList();
                    }
                    else
                    {
                        trCells = secondTr.Descendants <TableCell>().ToList();
                    }

                    var weight = Math.Ceiling(constructionElements.Where(
                                                  v => v.Steel.Strength > 1).Sum(v => v.Profile.Weight * v.Length)) / 1000;
                    sums[0] += weight;
                    if (weight > 0)
                    {
                        p = trCells[0].GetFirstChild <Paragraph>();
                        p.Append(Word.GetTextElement(weight.ToStringWithComma(), 24));
                    }

                    var localSum = 0.0;
                    for (int k = 1; k < 11; k++)
                    {
                        var typeId = k;
                        if (k > 6)
                        {
                            typeId += 1;
                        }
                        if (k == 10)
                        {
                            weight = Math.Ceiling(constructionElements.Where(
                                                      v => v.Profile.Type.Id == typeId || v.Profile.Type.Id == 7).Sum(
                                                      v => v.Profile.Weight * v.Length)) / 1000;
                        }
                        else
                        {
                            weight = Math.Ceiling(constructionElements.Where(
                                                      v => v.Profile.Type.Id == typeId).Sum(
                                                      v => v.Profile.Weight * v.Length)) / 1000;
                        }
                        sums[k]  += weight;
                        localSum += weight;
                        if (weight > 0)
                        {
                            p = trCells[k].GetFirstChild <Paragraph>();
                            p.Append(Word.GetTextElement(weight.ToStringWithComma(), 24));
                        }
                    }

                    if (localSum > 0.000001)
                    {
                        p = trCells[11].GetFirstChild <Paragraph>();
                        p.Append(Word.GetTextElement(Math.Round(localSum * multiplier, 3).ToStringWithComma(), 24));
                    }

                    if (i > 0)
                    {
                        t.Append(newTr);
                    }
                }

                var standardConstWeightSum = 0.0;
                for (int i = 0; i < standardConstructions.Count(); i++)
                {
                    newTr   = clonedThirdTr.CloneNode(true);
                    trCells = newTr.Descendants <TableCell>().ToList();
                    p       = trCells[0].GetFirstChild <Paragraph>();
                    p.Append(Word.GetTextElement(standardConstructions[i].Name, 24));

                    p = trCells[1].GetFirstChild <Paragraph>();
                    p.Append(Word.GetTextElement(
                                 (Math.Ceiling(standardConstructions[i].Weight * 1000) / 1000).ToStringWithComma(), 24));
                    t.Append(newTr);

                    standardConstWeightSum += standardConstructions[i].Weight;
                }

                var lastTr = clonedFirstTr.CloneNode(true);
                trCells = lastTr.Descendants <TableCell>().ToList();
                p       = trCells[0].GetFirstChild <Paragraph>();
                p.Append(Word.GetTextElement("Итого массы", 24));
                t.Append(lastTr);

                lastTr  = clonedSecondTr.CloneNode(true);
                trCells = lastTr.Descendants <TableCell>().ToList();
                for (int k = 0; k < 11; k++)
                {
                    if (sums[k] > 0)
                    {
                        p = trCells[k].GetFirstChild <Paragraph>();
                        p.Append(Word.GetTextElement(Math.Round(sums[k], 3).ToStringWithComma(), 24));
                    }
                }

                p = trCells[11].GetFirstChild <Paragraph>();
                p.Append(Word.GetTextElement(Math.Round(sums.Skip(1).Sum() * multiplier + standardConstWeightSum, 3).ToStringWithComma(), 24));
                t.Append(lastTr);
            }
        }
        public void PopulateDocument(int markId, MemoryStream memory)
        {
            var mark = _markRepo.GetById(markId);

            if (mark == null)
            {
                throw new ArgumentNullException(nameof(mark));
            }
            var subnode = mark.Subnode;
            var node    = subnode.Node;
            var project = node.Project;

            var departmentHead = _employeeRepo.GetByDepartmentIdAndPosition(
                mark.Department.Id, _appSettings.DepartmentHeadPosId);

            if (departmentHead == null)
            {
                departmentHead = _employeeRepo.GetByDepartmentIdAndPosition(
                    mark.Department.Id, _appSettings.ActingDepartmentHeadPosId);
            }
            if (departmentHead == null)
            {
                departmentHead = _employeeRepo.GetByDepartmentIdAndPosition(
                    mark.Department.Id, _appSettings.DeputyDepartmentHeadPosId);
            }
            if (departmentHead == null)
            {
                departmentHead = _employeeRepo.GetByDepartmentIdAndPosition(
                    mark.Department.Id, _appSettings.ActingDeputyDepartmentHeadPosId);
            }
            if (departmentHead == null)
            {
                throw new ConflictException();
            }

            // Вкл в состав спецификации
            var constructions         = _constructionRepo.GetAllByMarkId(markId);
            var standardConstructions = _standardConstructionRepo.GetAllByMarkId(markId);
            var opCond = _markOperatingConditionsRepo.GetByMarkId(markId);

            if (opCond == null)
            {
                throw new ArgumentNullException(nameof(opCond));
            }
            var estTask = _estimateTaskRepo.GetByMarkId(markId);

            if (estTask == null)
            {
                throw new ArgumentNullException(nameof(estTask));
            }
            var markApprovals = new List <MarkApproval> {
            };

            if (estTask.ApprovalEmployee != null)
            {
                markApprovals.Add(new MarkApproval
                {
                    MarkId   = markId,
                    Employee = estTask.ApprovalEmployee,
                });
            }

            using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(memory, true))
            {
                var markName = MarkHelper.MakeMarkName(
                    project.BaseSeries, node.Code, subnode.Code, mark.Code);
                (var complexName, var objectName) = MarkHelper.MakeComplexAndObjectName(
                    project.Name, node.Name, subnode.Name, mark.Name);

                AppendText(wordDoc, estTask.TaskText);

                var arr = new List <ListText>
                {
                    new ListText
                    {
                        Text            = "Изготовление и монтаж конструкций",
                        LevelNum        = 0,
                        IsBold          = true,
                        WithSuperscript = false,
                    },
                    new ListText
                    {
                        Text            = "Дополнительно учитывать:",
                        LevelNum        = 4,
                        IsBold          = false,
                        WithSuperscript = false,
                    },
                    new ListText
                    {
                        Text            = $"коэффициент надежности по ответственности: {opCond.SafetyCoeff}",
                        LevelNum        = 2,
                        IsBold          = false,
                        WithSuperscript = false,
                    },
                    new ListText
                    {
                        Text            = $"среда: {opCond.EnvAggressiveness.Name}",
                        LevelNum        = 2,
                        IsBold          = false,
                        WithSuperscript = false,
                    },
                    new ListText
                    {
                        Text            = $"расчетная температура эксплуатации: {(opCond.Temperature < 0 ? ("минус " + -opCond.Temperature) : opCond.Temperature)}",
                        LevelNum        = 2,
                        IsBold          = false,
                        WithSuperscript = false,
                    },
                };
                AppendList(wordDoc, arr);

                arr = new List <ListText> {
                };
                double overallInitialWeightSum = 0.0;
                double overallAreaSum          = 0.0;
                foreach (var construction in constructions)
                {
                    arr.Add(new ListText
                    {
                        Text            = construction.Name,
                        LevelNum        = 1,
                        IsBold          = false,
                        WithSuperscript = false,
                    });
                    if (construction.Valuation != null)
                    {
                        arr.Add(new ListText
                        {
                            Text            = $"Расценка: {construction.Valuation}",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                    if (construction.StandardAlbumCode != null)
                    {
                        arr.Add(new ListText
                        {
                            Text            = $"Шифр типового альбома конструкций: {construction.StandardAlbumCode}",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                    if (construction.NumOfStandardConstructions != 0)
                    {
                        arr.Add(new ListText
                        {
                            Text            = $"Число типовых конструкций: {construction.NumOfStandardConstructions}",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                    if (construction.HasEdgeBlunting)
                    {
                        arr.Add(new ListText
                        {
                            Text            = "Притупление кромок",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                    if (construction.HasDynamicLoad)
                    {
                        arr.Add(new ListText
                        {
                            Text            = "Динамическая нагрузка",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                    if (construction.HasFlangedConnections)
                    {
                        arr.Add(new ListText
                        {
                            Text            = "Фланцевые соединения",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                    if (construction.WeldingControl.Id > 1)
                    {
                        arr.Add(new ListText
                        {
                            Text            = $"Контроль плотности сварных швов {construction.WeldingControl.Name}",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                    var constructionElements = _constructionElementRepo.GetAllByConstructionId(construction.Id);
                    if (constructionElements.Count() > 0)
                    {
                        var groupedSteel = constructionElements.Where(
                            v => v.Steel != null).GroupBy(v => v.Steel).Select(
                            v => new GroupedSteel
                        {
                            Name   = v.First().Steel.Name,
                            Length = v.Sum(v => v.Length),
                            Weight = v.Sum(v => v.Profile.Weight),
                            Area   = v.Sum(v => v.Profile.Area),
                        });
                        arr.Add(new ListText
                        {
                            Text            = "в том числе по маркам стали:",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                        double initialWeightSum = 0.0;
                        double areaSum          = 0.0;
                        foreach (var s in groupedSteel)
                        {
                            // var initialWeightValue = s.Weight * s.Length * 0.001;
                            // var initialWeightValueRounded = Math.Ceiling(initialWeightValue * 1000) / 1000;
                            var initialWeightValueRounded = Math.Ceiling(
                                s.Weight * s.Length) / 1000;
                            var finalWeightValueRounded = Math.Ceiling(
                                initialWeightValueRounded * 1040) / 1000;
                            arr.Add(new ListText
                            {
                                // Text = $"{s.Name} {initialWeightValueRounded} x 1,04 = {Math.Ceiling(initialWeightValueRounded * 1.04 * 1000) / 1000} т",
                                Text            = $"{s.Name} {initialWeightValueRounded.ToStringWithComma()} x 1,04 = {finalWeightValueRounded.ToStringWithComma()} т",
                                LevelNum        = 6,
                                IsBold          = false,
                                WithSuperscript = false,
                            });
                            // initialWeightSum += initialWeightValue;
                            initialWeightSum += initialWeightValueRounded;
                            areaSum          += s.Area * s.Length;
                        }
                        overallInitialWeightSum += initialWeightSum;
                        var initialWeightSumRounded = Math.Ceiling(
                            initialWeightSum * 1000) / 1000;
                        var finalWeightSumRounded = Math.Ceiling(
                            initialWeightSumRounded * 1040) / 1000;
                        arr.Add(new ListText
                        {
                            // Text = $"Итого масса металла: {initialWeightSumRounded} x 1,04 = {Math.Ceiling(initialWeightSumRounded * 1.04 * 1000) / 1000} т",
                            Text            = $"Итого масса металла: {initialWeightSumRounded.ToStringWithComma()} x 1,04 = {finalWeightSumRounded.ToStringWithComma()} т",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                        var areaSumRounded = Math.Round(areaSum, 3);
                        // overallAreaSum += areaSum;
                        overallAreaSum += areaSumRounded;
                        arr.Add(new ListText
                        {
                            // Text = $"Площадь поверхности для окраски: {Math.Round(areaSum, 3).ToStringWithComma()} x 100 м^2",
                            Text            = $"Площадь поверхности для окраски: {areaSumRounded.ToStringWithComma()} x 100 м^2",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = true,
                        });
                        arr.Add(new ListText
                        {
                            // Text = $"Относительная площадь окраски: {Math.Round(areaSum * 100 / (initialWeightSum * 1.04), 3).ToStringWithComma()} м^2/т",
                            Text            = $"Относительная площадь окраски: {Math.Round(areaSumRounded * 100 / (initialWeightSumRounded * 1.04), 1).ToStringWithComma()} м^2/т",
                            LevelNum        = 5,
                            IsBold          = false,
                            WithSuperscript = true,
                        });
                    }
                }

                foreach (var standardConstruction in standardConstructions)
                {
                    arr.Add(new ListText
                    {
                        Text            = $"{standardConstruction.Name}: {(Math.Ceiling(standardConstruction.Weight * 1000) / 1000).ToStringWithComma()} т",
                        LevelNum        = 1,
                        IsBold          = false,
                        WithSuperscript = false,
                    });
                }

                arr.Add(new ListText
                {
                    Text            = "Окраска конструкций",
                    LevelNum        = 0,
                    IsBold          = true,
                    WithSuperscript = false,
                });

                var overallInitialWeightSumRounded = Math.Ceiling(
                    overallInitialWeightSum * 1000) / 1000;
                var overallFinalWeightSumRounded = Math.Ceiling(
                    overallInitialWeightSumRounded * 1040) / 1000;
                arr.Add(new ListText
                {
                    // Text = $"Масса металла для окраски: {Math.Round(overallInitialWeightSum, 3)} x 1,04 = {Math.Round(Math.Round(overallInitialWeightSum, 3) * 1.04, 3)} т",
                    Text            = $"Масса металла для окраски: {overallInitialWeightSumRounded.ToStringWithComma()} x 1,04 = {overallFinalWeightSumRounded.ToStringWithComma()} т",
                    LevelNum        = 4,
                    IsBold          = false,
                    WithSuperscript = false,
                });
                arr.Add(new ListText
                {
                    Text            = $"Площадь поверхности для окраски: {Math.Round(overallAreaSum, 3).ToStringWithComma()} x 100 м^2",
                    LevelNum        = 4,
                    IsBold          = false,
                    WithSuperscript = true,
                });

                var points = _markGeneralDataPointRepo.GetAllByMarkAndSectionId(
                    markId, _paintingGeneralDataSectionId);
                for (int i = 1; i < points.Count(); i++)
                {
                    var pointText = points.ToList()[i].Text;
                    if (pointText[0] == '#' && pointText[1] == ' ')
                    {
                        pointText = pointText.Substring(2) + ".";
                    }
                    else if (pointText[0] == '-' && pointText[1] == ' ')
                    {
                        pointText = pointText.Substring(2) + ".";
                    }
                    arr.Add(new ListText
                    {
                        Text            = pointText,
                        LevelNum        = 3,
                        IsBold          = false,
                        WithSuperscript = false,
                    });
                }

                if (estTask.AdditionalText != null && estTask.AdditionalText != "")
                {
                    arr.Add(new ListText
                    {
                        Text            = "Дополнительно",
                        LevelNum        = 0,
                        IsBold          = true,
                        WithSuperscript = false,
                    });
                    var split = estTask.AdditionalText.Split("\n");
                    foreach (var splitText in split)
                    {
                        arr.Add(new ListText
                        {
                            Text            = splitText,
                            LevelNum        = 3,
                            IsBold          = false,
                            WithSuperscript = false,
                        });
                    }
                }
                AppendList(wordDoc, arr);

                Word.AppendToBigFooterTable(
                    wordDoc,
                    markName,
                    complexName,
                    objectName,
                    -1,
                    mark,
                    markApprovals.ToList(),
                    departmentHead);
                Word.AppendToSmallFooterTable(wordDoc, markName);
            }
        }
Example #5
0
        private void AppendToTable(
            WordprocessingDocument document,
            int currentSpecId)
        {
            // Вкл в спецификацию
            var constructions = _constructionRepo.GetAllBySpecificationId(
                currentSpecId).ToList();

            if (constructions.Count() > 0)
            {
                Body           body           = document.MainDocumentPart.Document.Body;
                var            t              = body.Descendants <Table>().FirstOrDefault();
                var            firstTr        = t.Descendants <TableRow>().ToList()[0];
                var            clonedFirstTr  = firstTr.CloneNode(true);
                var            trCells        = firstTr.Descendants <TableCell>().ToList();
                var            secondTr       = t.Descendants <TableRow>().ToList()[1];
                var            clonedSecondTr = secondTr.CloneNode(true);
                OpenXmlElement newTr          = null;

                var num = 1;
                List <GroupedElement> groupedConstructionElements = null;
                for (int i = 0; i < constructions.Count(); i++)
                {
                    groupedConstructionElements = _constructionElementRepo.GetAllByConstructionId(
                        constructions[i].Id).GroupBy(v => v.Profile.Type.Id).Select(
                        v => new GroupedElement
                    {
                        Name  = v.First().Profile.Class.Name,
                        Steel = v.GroupBy(v2 => v2.Steel.Id).Select(
                            v2 => new GroupedSteel
                        {
                            Name     = v2.First().Steel.Name,
                            Standard = v2.First().Steel.Standard,
                            Profiles = v2.GroupBy(v3 => v3.Profile.Id).Select(
                                v3 => new GroupedProfile
                            {
                                Name   = v3.First().Profile.Name,
                                Symbol = ((v3.First().Profile.Class.Id == 16) ||
                                          (v3.First().Profile.Class.Id == 17)) ? "s=" : v3.First().Profile.Symbol,
                                Length = Math.Round(v3.Sum(v4 => v4.Length), 3),
                                Weight = Math.Ceiling(v3.Sum(v4 => v4.Profile.Weight * v4.Length)) / 1000,
                                Area   = Math.Ceiling(v3.Sum(
                                                          v4 => v4.Profile.Area * v4.Length * constructions[i].PaintworkCoeff)) / 1000,
                            }).ToList(),
                        }).ToList(),
                    }).ToList();

                    if (groupedConstructionElements.Count() > 0)
                    {
                        if (i > 0)
                        {
                            newTr   = clonedFirstTr.CloneNode(true);
                            trCells = newTr.Descendants <TableCell>().ToList();
                        }
                        trCells[0].GetFirstChild <Paragraph>().Append(
                            Word.GetTextElement(constructions[i].Name, 24));
                        if (i > 0)
                        {
                            t.Append(newTr);
                        }

                        AppendConstruction(
                            groupedConstructionElements,
                            ref num, i, trCells, secondTr,
                            newTr, clonedSecondTr, t);
                    }
                }

                groupedConstructionElements = _constructionElementRepo.GetAllBySpecificationId(
                    currentSpecId).GroupBy(v => v.Profile.Type.Id).Select(
                    v => new GroupedElement
                {
                    Name  = v.First().Profile.Class.Name,
                    Steel = v.GroupBy(v2 => v2.Steel.Id).Select(
                        v2 => new GroupedSteel
                    {
                        Name     = v2.First().Steel.Name,
                        Standard = v2.First().Steel.Standard,
                        Profiles = v2.GroupBy(v3 => v3.Profile.Id).Select(
                            v3 => new GroupedProfile
                        {
                            Name   = v3.First().Profile.Name,
                            Symbol = ((v3.First().Profile.Class.Id == 16) ||
                                      (v3.First().Profile.Class.Id == 17)) ? "s=" : v3.First().Profile.Symbol,
                            Length = Math.Round(v3.Sum(v4 => v4.Length), 3),
                            Weight = Math.Ceiling(v3.Sum(v4 => v4.Profile.Weight * v4.Length)) / 1000,
                            Area   = Math.Ceiling(v3.Sum(
                                                      v4 => v4.Profile.Area * v4.Length * v4.Construction.PaintworkCoeff)) / 1000,
                        }).ToList(),
                    }).ToList(),
                }).ToList();

                if (groupedConstructionElements.Count() > 0)
                {
                    newTr   = clonedFirstTr.CloneNode(true);
                    trCells = newTr.Descendants <TableCell>().ToList();
                    trCells[0].GetFirstChild <Paragraph>().Append(
                        Word.GetTextElement("Общая масса", 24));
                    t.Append(newTr);

                    AppendConstruction(
                        groupedConstructionElements,
                        ref num, 99, trCells, secondTr,
                        newTr, clonedSecondTr, t);
                }
            }
        }