/// <summary> /// Adds end of record indicator to the end of the report /// </summary> private void AddEndOfRecordIndicator() { // Adds END OF RECORD statement to the end of the document Paragraph EndOfRecord = new Paragraph(); EndOfRecord.Add("*** END OF RECORD ***"); EndOfRecord.SetHorizontalAlignment(HorizontalAlignment.CENTER); EndOfRecord.SetTextAlignment(TextAlignment.CENTER); EndOfRecord.SetFont(m_FONT_CourierBold); EndOfRecord.SetFontSize(10); MainDocument.Add(EndOfRecord); }
/// <summary> /// Generates the header that will be assigned to our <see cref="MainDocument"/> /// </summary> private void HeaderGenerator() { // Adds date to header if the Report indicates that it should be done AddDateToHeader(); // Create table that will hold header Table HeaderContent = new Table(1); HeaderContent.SetWidth(UnitValue.CreatePercentValue(95)); HeaderContent.SetBorder(Border.NO_BORDER); HeaderContent.SetHorizontalAlignment(HorizontalAlignment.CENTER); HeaderContent.SetMarginBottom(20); // Create cell that will hold header paragraph Cell HeaderContentTextCell = new Cell(); HeaderContentTextCell.SetHorizontalAlignment(HorizontalAlignment.CENTER); HeaderContentTextCell.SetBorder(Border.NO_BORDER); // Create paragraph that will hold header text Paragraph HeaderContentParagraph = new Paragraph(); // Set up paragraph HeaderContentParagraph.SetBorder(Border.NO_BORDER); HeaderContentParagraph.SetTextAlignment(TextAlignment.CENTER); HeaderContentParagraph.Add(Report.HeaderText); HeaderContentParagraph.SetHorizontalAlignment(HorizontalAlignment.CENTER); HeaderContentParagraph.SetVerticalAlignment(VerticalAlignment.MIDDLE); HeaderContentParagraph.SetFont(m_FONT_Courier); HeaderContentParagraph.SetFontSize(10); // Combine elements and add to main document HeaderContentTextCell.Add(HeaderContentParagraph); HeaderContent.AddCell(HeaderContentTextCell); MainDocument.Add(HeaderContent); }
/// <summary> /// Adds all body content to the report /// </summary> private void AddBodyContent() { // Create a table to hold the body of the report // NOTE: Set column count to that of the Report DataTable Table BodyContent = new Table(Report.ReportData.Columns.Count); // Sets the table width BodyContent.SetWidth(UnitValue.CreatePercentValue(95)); // Set table positioning BodyContent.SetHorizontalAlignment(HorizontalAlignment.CENTER); // Sets the spacing after the table BodyContent.SetMarginBottom(5); // For each column in the Report Data, add a header cell with the column's name foreach (DataColumn column in Report.ReportData.Columns) { // Create cell Cell HeaderCell = new Cell(); // Set cell background and border HeaderCell.SetBackgroundColor(ColorConstants.LIGHT_GRAY); HeaderCell.SetBorder(Border.NO_BORDER); // Create a paragraph to hold the header cell text Paragraph HeaderCellText = new Paragraph(column.ColumnName); // Set up the text formatting in the header cell paragraph HeaderCellText.SetFont(m_FONT_CourierBold); HeaderCellText.SetFontSize(8); HeaderCellText.SetTextAlignment(TextAlignment.CENTER); // Add paragraph to cell HeaderCell.Add(HeaderCellText); // Add cell to Header row in Body Content BodyContent.AddHeaderCell(HeaderCell); } // Creates each row based on data in table foreach (DataRow dr in Report.ReportData.Rows) { for (int i = 0; i < Report.ReportData.Columns.Count; i++) { // Create cell and paragraph to hold text Cell CellContent = new Cell(); Paragraph CellContentText = new Paragraph(); // Set up cell for proper formatting CellContent.SetBorder(Border.NO_BORDER); CellContent.SetFontSize(8); CellContent.SetHorizontalAlignment(HorizontalAlignment.LEFT); // If particular column is indicated in the Report's ColumnsToTreatAsDateTime array // Attempt to parse column as a DateTime, if fails, take value as is // NOTE: This operation will always default to raw data if the column is not // indicated in the array if (Report.ColumnsToTreatAsDateTime.Contains(i)) { DateTime outputDateTime; if (DateTime.TryParse(dr[i].ToString(), out outputDateTime)) { CellContentText.Add(outputDateTime.ToShortDateString()); CellContent.Add(CellContentText); BodyContent.AddCell(CellContent); } else { CellContentText.Add(dr[i].ToString()); CellContent.Add(CellContentText); BodyContent.AddCell(CellContent); } } // Default if the column is not listed in the DateTime checking array else { CellContentText.Add(dr[i].ToString()); CellContent.Add(CellContentText); BodyContent.AddCell(CellContent); } } } // Adds the body content to the document MainDocument.Add(BodyContent); }