コード例 #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);
        }
コード例 #2
0
        public void UpdateAllBySectionIds(int markId, List <int> sectionIds)
        {
            if (sectionIds == null)
            {
                throw new ArgumentNullException(nameof(sectionIds));
            }
            var foundMark = _markRepo.GetById(markId);

            if (foundMark == null)
            {
                throw new ArgumentNullException(nameof(foundMark));
            }

            foreach (var id in sectionIds)
            {
                var section = _generalDataSectionRepo.GetById(id);
                if (section == null)
                {
                    throw new ArgumentNullException(nameof(section));
                }
            }

            var points          = _repository.GetAllByMarkId(markId);
            var currentPointIds = new List <int> {
            };

            foreach (var p in points)
            {
                if (!sectionIds.Contains(p.Section.Id))
                {
                    _repository.Delete(p);
                }
                currentPointIds.Add(p.Section.Id);
            }

            foundMark.EditedDate = DateTime.Now;
            _markRepo.Update(foundMark);
        }
コード例 #3
0
        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);
            }
        }