Exemplo n.º 1
0
        public MemoryStream GetGeneralDataDocument(int markId)
        {
            var mark = _markRepo.GetById(markId);

            if (mark == null)
            {
                throw new ArgumentNullException(nameof(mark));
            }
            var markApprovals         = _markApprovalRepo.GetAllByMarkId(markId);
            var subnode               = mark.Subnode;
            var node                  = subnode.Node;
            var project               = node.Project;
            var markGeneralDataPoints = _markGeneralDataPointRepo.GetAllByMarkId(
                markId).OrderByDescending(
                v => v.Section.OrderNum).ThenByDescending(v => v.OrderNum);
            var sheets = _docRepo.GetAllByMarkIdAndDocType(markId, _sheetDocTypeId);

            var path = "D:\\Dev\\Gipromez\\word\\template.docx";

            var    g          = Guid.NewGuid();
            string guidString = Convert.ToBase64String(g.ToByteArray());

            guidString = guidString.Replace("=", "");
            guidString = guidString.Replace("+", "");
            var outputPath = $"D:\\Dev\\Gipromez\\word\\{guidString}.docx";

            var memory = GetStreamFromTemplate(path);

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

                GeneralDataDocument.AppendToSheetTable(wordDoc, sheets.ToList());
                GeneralDataDocument.AppendToLinkedAndAttachedDocsTable(
                    wordDoc,
                    _markLinkedDocRepo.GetAllByMarkId(markId).ToList(),
                    _attachedDocRepo.GetAllByMarkId(markId).ToList());
                AppendToBigFooterTable(
                    wordDoc,
                    markName,
                    complexName,
                    objectName,
                    sheets.Count(),
                    mark,
                    markApprovals.ToList());
                AppendToSmallFooterTable(wordDoc, markName);
            }
            memory.Seek(0, SeekOrigin.Begin);
            return(memory);
        }
        public void PopulateDocument(int markId, MemoryStream memory)
        {
            var mark = _markRepo.GetById(markId);

            if (mark == null)
            {
                throw new ArgumentNullException(nameof(mark));
            }
            var markApprovals = _markApprovalRepo.GetAllByMarkId(markId);
            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 opCond = _markOperatingConditionsRepo.GetByMarkId(markId);

            if (opCond == null)
            {
                throw new ArgumentNullException(nameof(opCond));
            }
            var markGeneralDataPoints = _markGeneralDataPointRepo.GetAllByMarkId(
                markId).OrderByDescending(
                v => v.Section.OrderNum).ThenByDescending(v => v.OrderNum);
            var sheets = _docRepo.GetAllByMarkIdAndDocType(markId, _sheetDocTypeId);

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

                AppendList(wordDoc, markGeneralDataPoints, opCond);
                AppendToSheetTable(wordDoc, sheets.ToList());
                AppendToLinkedAndAttachedDocsTable(
                    wordDoc,
                    _markLinkedDocRepo.GetAllByMarkId(markId).ToList(),
                    _attachedDocRepo.GetAllByMarkId(markId).ToList());
                Word.AppendToBigFooterTable(
                    wordDoc,
                    markName,
                    complexName,
                    objectName,
                    sheets.Count(),
                    mark,
                    markApprovals.ToList(),
                    departmentHead);
                Word.AppendToSmallFooterTable(wordDoc, markName);
            }
        }
Exemplo n.º 3
0
 public IEnumerable <Doc> GetAllSheetsByMarkId(int markId)
 {
     return(_repository.GetAllByMarkIdAndDocType(
                markId, _sheetDocTypeId));
 }