/// <summary> /// Печать технических деталей ТКП /// </summary> /// <param name="docWriter"></param> /// <param name="offerUnitsGroupsByFacilities"></param> private void PrintTechnicalDetails(WordDocumentWriter docWriter, List <IGrouping <Facility, OfferUnitsGroup> > offerUnitsGroupsByFacilities) { var paragraphProperties = docWriter.CreateParagraphProperties(); paragraphProperties.PageBreakBefore = true; Font fontHeader = docWriter.CreateFont(); fontHeader.Bold = true; docWriter.PrintParagraph("Технические характеристики оборудования(в соответствии с позициями таблицы):", paragraphProperties, fontHeader); int positionNumber = 1; foreach (var offerUnitsGroupsByFacility in offerUnitsGroupsByFacilities) { foreach (var offerUnitsGroup in offerUnitsGroupsByFacility) { docWriter.PrintParagraph($"{positionNumber++}. {offerUnitsGroup.Product} = {offerUnitsGroupsByFacility.Count()} шт.:"); _printProductService.Print(docWriter, offerUnitsGroup.Product.Model); // включенное в состав оборудование if (offerUnitsGroup.ProductsIncluded.Any()) { docWriter.PrintParagraph("Дополнительное оборудование, включенное в состав:"); foreach (var productIncluded in offerUnitsGroup.ProductsIncluded) { docWriter.PrintParagraph($"{productIncluded.Model.Product} {productIncluded.Model.Amount} шт.:"); _printProductService.Print(docWriter, productIncluded.Model.Product); } } docWriter.PrintParagraph(Environment.NewLine); } } }
public void Print(WordDocumentWriter docWriter, Product product, int?amount = null, ProductBlock block = null) { var tableProperties = docWriter.CreateTableProperties(); tableProperties.Alignment = ParagraphAlignment.Left; tableProperties.PreferredWidthAsPercentage = 100; //выделяем необходимый блок if (block != null && product.ProductBlock.Id == block.Id) { tableProperties.BorderProperties.Color = Colors.Red; tableProperties.BorderProperties.Width = 3; } docWriter.StartTable(2, tableProperties); //Заголовок docWriter.StartTableRow(); Font fontBold = docWriter.CreateFont(); fontBold.Bold = true; var header = amount == null ? $"{product}" : $"{product} x {amount} шт."; docWriter.PrintTableCell(header, docWriter.CellProps(2, null, Colors.AliceBlue), null, fontBold); docWriter.EndTableRow(); //строки параметров foreach (var parameter in product.ProductBlock.GetOrderedParameters()) { docWriter.StartTableRow(); docWriter.PrintTableCell($"{parameter.ParameterGroup}"); docWriter.PrintTableCell($"{parameter}"); docWriter.EndTableRow(); } //печать зависимого оборудования foreach (var dependent in product.DependentProducts) { docWriter.StartTableRow(); docWriter.StartTableCell(docWriter.CellProps(2, Padding.PadAll(0.25f))); Print(docWriter, dependent.Product, dependent.Amount, block); docWriter.EndTableCell(); docWriter.EndTableRow(); } docWriter.EndTable(); }
private static MemoryStream CreateWord() { // private static MemoryStream CreateExcel(METTLib.Questionnaire.QuestionnaireAnswerExportSetList QuestionnaireAnswerExportSetList) //public void CreateWord() //{ // //Create a new instance of the WordDocumentWriter class MemoryStream m = new MemoryStream(); WordDocumentWriter docWriter = WordDocumentWriter.Create(m); docWriter.Unit = UnitOfMeasurement.Point; docWriter.DocumentProperties.Title = "METT - Intervention Report"; docWriter.DocumentProperties.Author = string.Format("Singular Systems", ""); docWriter.StartDocument(); Infragistics.Documents.Word.Font fontHeading = docWriter.CreateFont(); fontHeading.Name = "Arial"; fontHeading.Size = 22; fontHeading.Bold = true; Infragistics.Documents.Word.Font fontSubHeading = docWriter.CreateFont(); fontSubHeading.Name = "Arial"; fontSubHeading.Size = 16; fontSubHeading.Bold = true; Infragistics.Documents.Word.Font fontNormal = docWriter.CreateFont(); fontNormal.Name = "Arial"; fontNormal.Size = 9; fontNormal.Bold = false; Infragistics.Documents.Word.Font fontBold = docWriter.CreateFont(); fontBold.Name = "Arial"; fontBold.Size = 9; fontBold.Bold = true; Infragistics.Documents.Word.Font fontBoldLarge = docWriter.CreateFont(); fontBoldLarge.Name = "Arial"; fontBoldLarge.Size = 11; fontBoldLarge.Bold = true; Infragistics.Documents.Word.Font fontSmall = docWriter.CreateFont(); fontSmall.Name = "Arial"; fontSmall.Size = 8; fontSmall.Bold = false; docWriter.StartParagraph(); docWriter.AddTextRun("Intervention Report", fontHeading); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun("", fontHeading); docWriter.EndParagraph(); //Specify the default parts for header and footer SectionHeaderFooterParts parts = SectionHeaderFooterParts.HeaderAllPages | SectionHeaderFooterParts.FooterAllPages; SectionHeaderFooterWriterSet writerSet = docWriter.AddSectionHeaderFooter(parts); //Set text for Header writerSet.HeaderWriterAllPages.Open(); writerSet.HeaderWriterAllPages.StartParagraph(); writerSet.HeaderWriterAllPages.AddTextRun("Management Effectiveness Tracking Tool-South Africa (METT) - Intervention Report [Protected Area]", fontSmall); writerSet.HeaderWriterAllPages.EndParagraph(); writerSet.HeaderWriterAllPages.Close(); // Set text for Footer writerSet.FooterWriterAllPages.Open(); writerSet.FooterWriterAllPages.StartParagraph(); writerSet.FooterWriterAllPages.AddTextRun("[This report was generated on " + DateTime.Now.ToString("dd/MM/yyyy") + "]", fontSmall); writerSet.FooterWriterAllPages.EndParagraph(); writerSet.FooterWriterAllPages.Close(); // MANAGEMENT SPHERES SUMMARY SECTION // ********************************** docWriter.StartParagraph(); docWriter.AddTextRun("Management Sphere Summary", fontSubHeading); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun("", fontHeading); docWriter.EndParagraph(); TableBorderProperties borderProps = docWriter.CreateTableBorderProperties(); borderProps.Color = Color.Black; borderProps.Style = TableBorderStyle.Double; TableProperties tableProps = docWriter.CreateTableProperties(); tableProps.Layout = TableLayout.Fixed; tableProps.PreferredWidthAsPercentage = 100; tableProps.Alignment = ParagraphAlignment.Center; tableProps.BorderProperties.Color = borderProps.Color; tableProps.BorderProperties.Style = borderProps.Style; TableRowProperties rowProps = docWriter.CreateTableRowProperties(); rowProps.IsHeaderRow = true; TableCellProperties cellProps = docWriter.CreateTableCellProperties(); var ROManagementSphereList = METTLib.Reports.ROManagementSphereList.GetROManagementSphereList(); foreach (var sphereitem in ROManagementSphereList) { cellProps.BackColor = Color.DarkGray; cellProps.TextDirection = TableCellTextDirection.LeftToRightTopToBottom; docWriter.StartTable(1, tableProps); docWriter.StartTableRow(rowProps); docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun(""); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun(sphereitem.ManagementSphereID + ". " + sphereitem.ManagementSphere, fontBoldLarge); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun(sphereitem.ManagementSphereContent, fontNormal); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun(""); docWriter.EndParagraph(); docWriter.EndTableCell(); docWriter.EndTableRow(); docWriter.EndTable(); docWriter.StartParagraph(); docWriter.AddTextRun(""); docWriter.EndParagraph(); docWriter.StartTable(3, tableProps); docWriter.StartTableRow(rowProps); cellProps.PreferredWidthAsPercentage = 70; docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun("Indicators"); docWriter.EndParagraph(); docWriter.EndTableCell(); cellProps.PreferredWidthAsPercentage = 15; docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun("Value"); docWriter.EndParagraph(); docWriter.EndTableCell(); cellProps.PreferredWidthAsPercentage = 15; docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun("Rating (as %)"); docWriter.EndParagraph(); docWriter.EndTableCell(); docWriter.EndTableRow(); cellProps.Reset(); cellProps.BackColor = Color.White; docWriter.EndTable(); docWriter.StartTable(3, tableProps); int dTotalValue = 0; int dTotalRating = 0; decimal dTotalPerc = 0; var ReportInterventionManagementSphereList = METTLib.Reports.ReportInterventionManagementSphereList.GetReportInterventionManagementSphereList(284, sphereitem.ManagementSphereID); foreach (var item in ReportInterventionManagementSphereList) { dTotalValue = dTotalValue + item.MaxValue; dTotalRating = dTotalRating + item.AnswerRating; docWriter.StartTableRow(); docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun(item.IndicatorDetailName, fontNormal); docWriter.EndParagraph(); docWriter.EndTableCell(); docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun(Convert.ToString(item.MaxValue), fontNormal); docWriter.EndParagraph(); docWriter.EndTableCell(); if (item.AnswerRating == 0) { cellProps.BackColor = Color.Red; } if (item.AnswerRating == 1) { cellProps.BackColor = Color.Yellow; } if (item.AnswerRating == 2) { cellProps.BackColor = Color.Yellow; } if (item.AnswerRating == 3) { cellProps.BackColor = Color.LightGreen; } docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun(Convert.ToString(item.AnswerRating), fontNormal); docWriter.EndParagraph(); docWriter.EndTableCell(); cellProps.Reset(); cellProps.BackColor = Color.White; docWriter.EndTableRow(); } docWriter.StartTableRow(); docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun("Total", fontBold); docWriter.EndParagraph(); docWriter.EndTableCell(); docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun(Convert.ToString(dTotalValue), fontBold); docWriter.EndParagraph(); docWriter.EndTableCell(); if (dTotalRating > 0) { if (dTotalValue > 0) { dTotalPerc = Math.Round((Convert.ToDecimal(dTotalRating) / Convert.ToDecimal(dTotalValue)) * 100, 2); } else { dTotalPerc = 0; } } else { dTotalPerc = 0; } docWriter.StartTableCell(cellProps); docWriter.StartParagraph(); docWriter.AddTextRun(Convert.ToString(dTotalPerc), fontBold); docWriter.EndParagraph(); docWriter.EndTableCell(); docWriter.EndTableRow(); docWriter.EndTable(); docWriter.StartParagraph(); docWriter.AddTextRun("", fontHeading); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun("", fontHeading); docWriter.EndParagraph(); } docWriter.StartParagraph(); docWriter.AddTextRun("", fontHeading); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun(""); docWriter.EndParagraph(); // NEXT STEPS REPORT SECTION // ************************* docWriter.StartParagraph(); docWriter.AddTextRun("Next Steps Summary", fontSubHeading); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun("", fontHeading); docWriter.EndParagraph(); TableBorderProperties NextStepsborderProps = docWriter.CreateTableBorderProperties(); NextStepsborderProps.Color = Color.Black; NextStepsborderProps.Style = TableBorderStyle.Double; TableProperties NextStepstableProps = docWriter.CreateTableProperties(); NextStepstableProps.Layout = TableLayout.Fixed; NextStepstableProps.PreferredWidthAsPercentage = 100; NextStepstableProps.Alignment = ParagraphAlignment.Left; NextStepstableProps.BorderProperties.Color = borderProps.Color; NextStepstableProps.BorderProperties.Style = borderProps.Style; TableRowProperties NextStepsrowProps = docWriter.CreateTableRowProperties(); rowProps.IsHeaderRow = true; TableCellProperties NextStepscellProps = docWriter.CreateTableCellProperties(); NextStepscellProps.BackColor = Color.DarkGray; NextStepscellProps.TextDirection = TableCellTextDirection.LeftToRightTopToBottom; var ReportInterventionNextStepsGroupList = METTLib.Questionnaire.ROQuestionnaireGroupList.GetROQuestionnaireGroupList(); foreach (var groupItem in ReportInterventionNextStepsGroupList) { docWriter.StartParagraph(); docWriter.AddTextRun(groupItem.QuestionnaireGroup, fontBoldLarge); docWriter.EndParagraph(); docWriter.StartParagraph(); docWriter.AddTextRun(""); docWriter.EndParagraph(); docWriter.StartTable(3, NextStepstableProps); //HEADER ROW NextStepscellProps.BackColor = Color.DarkGray; docWriter.StartTableRow(NextStepsrowProps); NextStepscellProps.PreferredWidthAsPercentage = 15; docWriter.StartTableCell(NextStepscellProps); docWriter.StartParagraph(); docWriter.AddTextRun("Indicator #"); docWriter.EndParagraph(); docWriter.EndTableCell(); NextStepscellProps.PreferredWidthAsPercentage = 40; docWriter.StartTableCell(NextStepscellProps); docWriter.StartParagraph(); docWriter.AddTextRun("Indicator"); docWriter.EndParagraph(); docWriter.EndTableCell(); NextStepscellProps.PreferredWidthAsPercentage = 45; docWriter.StartTableCell(NextStepscellProps); docWriter.StartParagraph(); docWriter.AddTextRun("Next Steps"); docWriter.EndParagraph(); docWriter.EndTableCell(); docWriter.EndTableRow(); NextStepscellProps.BackColor = Color.White; var iNo = 1; var ReportInterventionNextStepsList = METTLib.Reports.ReportInterventionNextStepList.GetReportInterventionNextStepList(284, groupItem.QuestionnaireGroupID); foreach (var item in ReportInterventionNextStepsList) { docWriter.StartTableRow(); NextStepscellProps.PreferredWidthAsPercentage = 15; docWriter.StartTableCell(NextStepscellProps); docWriter.StartParagraph(); docWriter.AddTextRun(Convert.ToString(iNo), fontNormal); docWriter.EndParagraph(); docWriter.EndTableCell(); NextStepscellProps.PreferredWidthAsPercentage = 40; docWriter.StartTableCell(NextStepscellProps); docWriter.StartParagraph(); docWriter.AddTextRun(item.IndicatorDetailName, fontNormal); docWriter.EndParagraph(); docWriter.EndTableCell(); NextStepscellProps.PreferredWidthAsPercentage = 45; docWriter.StartTableCell(NextStepscellProps); docWriter.StartParagraph(); docWriter.AddTextRun(item.NextSteps, fontNormal); docWriter.EndParagraph(); docWriter.EndTableCell(); docWriter.EndTableRow(); iNo++; } docWriter.EndTable(); docWriter.StartParagraph(); docWriter.AddTextRun(""); docWriter.EndParagraph(); } docWriter.StartParagraph(); docWriter.AddTextRun(""); docWriter.EndParagraph(); docWriter.EndDocument(); docWriter.Close(); m.Position = 0; //Document doc = new Document(); //m.Position = 0; //doc.Save(m); return(m); }