Example #1
0
        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 sheets                = _docService.GetAllSheetsByMarkId(markId).ToList();
            var docs                  = _docService.GetAllAttachedByMarkId(markId).ToList();
            var attachedDocs          = _attachedDocRepo.GetAllByMarkId(markId).ToList();
            var additionalWork        = _additionalWorkService.GetAllByMarkId(markId).ToList();
            var constructions         = _constructionRepo.GetAllByMarkId(markId).ToList();
            var standardConstructions = _standardConstructionRepo.GetAllByMarkId(markId).ToList();

            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);

                Word.ReplaceText(wordDoc, "A", markName);
                Word.ReplaceText(wordDoc, "B", complexName);
                Word.ReplaceText(wordDoc, "C", objectName);
                Word.ReplaceText(wordDoc, "D", mark.Subnode.Node.ChiefEngineer.Name);
                Word.ReplaceText(wordDoc, "E", mark.GroupLeader.Name);
                Word.ReplaceText(
                    wordDoc, "F", mark.IssueDate.GetValueOrDefault().ToString("dd.MM.yyyy"));
                Word.ReplaceText(wordDoc, "G", FindWeight(constructions, standardConstructions).ToStringWithComma());
                AppendToSheetsTable(wordDoc, sheets);
                AppendToDocsTable(wordDoc, docs);
                AppendToAttachedDocsTable(wordDoc, attachedDocs);
                AppendToAdditionalWorkTable(wordDoc, additionalWork);

                Word.AppendToMainSmallFooterTable(wordDoc, markName);
                Word.AppendToSmallFooterTable(wordDoc, markName);
            }
        }