private static void BuildReportFromDataTable(DataTable dataTable, Page page, Report report) { //// Convert data table //// Initializes a new instance of the Table var table = new Table { ColumnWidths = "60 50 60 70 40 60 40 40 90", ColumnAdjustment = ColumnAdjustment.Customized, RepeatingRowsCount = 4, Border = new BorderInfo(BorderSide.Top, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)), DefaultCellBorder = new BorderInfo(BorderSide.None, 0.0f), DefaultCellPadding = new MarginInfo(1, 3, 0, 0), Alignment = HorizontalAlignment.Left, Margin = new MarginInfo(0, 3, 0, 3) }; if (dataTable != null) { const int firstFilledRow = 3; ////start at row 4 to leave room for header. const bool isColumnNamesShown = true; const byte firstFilledColumn = 0; table.ImportDataTable(dataTable, isColumnNamesShown, firstFilledRow, firstFilledColumn); table.DefaultCellTextState.FontSize = 8; table.DefaultCellTextState.FontStyle = FontStyles.Regular; table.Alignment = HorizontalAlignment.Left; table.Margin = new MarginInfo(6, 3, 5, 3); ////A line under the header var firstFilledRowObject = table.Rows[firstFilledRow]; firstFilledRowObject.Border = new BorderInfo(BorderSide.Bottom, 1f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); var rowCount = table.Rows.Count; var colCount = dataTable.Columns.Count; //// Align last column RIGHT for (var i = 0 + firstFilledRow; i < rowCount; i++) { var rowCellsLastColumn = table.Rows[i].Cells[colCount - 1]; rowCellsLastColumn.Alignment = HorizontalAlignment.Right; } var reportHeadingText = "Transaction Input Report for NAB"; var businessDateText = string.Format("Business Date: {0}", report.HeaderInfo.BusinessDate); var reportDateText = string.Format("Report Date: {0}", report.HeaderInfo.ReportOn); table.Rows[0] = CreateTableRow(reportHeadingText, HorizontalAlignment.Center, new BorderInfo(BorderSide.None)); table.Rows[1] = CreateTableRow(businessDateText, HorizontalAlignment.Right, new BorderInfo(BorderSide.None)); table.Rows[2] = CreateTableRow(reportDateText, HorizontalAlignment.Right, new BorderInfo(BorderSide.None)); table.Rows[2].Border = new BorderInfo(BorderSide.Bottom, 1f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); table.Rows[table.Rows.Count - 1].Border = new BorderInfo(BorderSide.Bottom, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); page.Paragraphs.Add(table); ////Add footer as table, was having formatting issues when adding as rows to above table. var footer = new Table { ColumnWidths = "510", ColumnAdjustment = ColumnAdjustment.Customized, Border = new BorderInfo(BorderSide.None, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)), DefaultCellBorder = new BorderInfo(BorderSide.None, 0.0f), DefaultCellPadding = new MarginInfo(1, 3, 0, 0), Alignment = HorizontalAlignment.Left, Margin = new MarginInfo(6, 3, 5, 3), DefaultCellTextState = { FontSize = 8, FontStyle = FontStyles.Regular } }; var totalAmountText = string.Format("Total Credit Amount: {0} Total Debit Amount: {1}", FormatAmount(report.FooterInfo.TotalCreditAmount, "Currency"), FormatAmount(report.FooterInfo.TotalDebitAmount, "Currency")); var totalCountText = string.Format("Credit Count: {0} Debit Count: {1} Total Item Count: {2}", report.FooterInfo.CreditCount, report.FooterInfo.DebitCount, report.VoucherRows.Count); var totalAmountRow = new Row(); totalAmountRow.Cells.Add(totalAmountText); footer.Rows.Add(totalAmountRow); var totalCountRow = new Row(); totalCountRow.Cells.Add(totalCountText); totalCountRow.Border = new BorderInfo(BorderSide.Bottom, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); footer.Rows.Add(totalCountRow); page.Paragraphs.Add(footer); } }
private static void BuildReportFromDataTable(DataTable dataTable, Page page, Report report) { //// Convert data table //// Initializes a new instance of the Table var table = new Table { ColumnWidths = "60 50 60 70 40 60 40 40 90", ColumnAdjustment = ColumnAdjustment.Customized, RepeatingRowsCount = 4, Border = new BorderInfo(BorderSide.Top, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)), DefaultCellBorder = new BorderInfo(BorderSide.None, 0.0f), DefaultCellPadding = new MarginInfo(1, 3, 0, 0), Alignment = HorizontalAlignment.Left, Margin = new MarginInfo(0, 3, 0, 3) }; if (dataTable != null) { const int firstFilledRow = 3; ////start at row 4 to leave room for header. const bool isColumnNamesShown = true; const byte firstFilledColumn = 0; table.ImportDataTable(dataTable, isColumnNamesShown, firstFilledRow, firstFilledColumn); table.DefaultCellTextState.FontSize = 8; table.DefaultCellTextState.FontStyle = FontStyles.Regular; table.Alignment = HorizontalAlignment.Left; table.Margin = new MarginInfo(6, 3, 5, 3); ////A line under the header var firstFilledRowObject = table.Rows[firstFilledRow]; firstFilledRowObject.Border = new BorderInfo(BorderSide.Bottom, 1f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); var rowCount = table.Rows.Count; var colCount = dataTable.Columns.Count; //// Align last column RIGHT for (var i = 0 + firstFilledRow; i < rowCount; i++) { var rowCellsLastColumn = table.Rows[i].Cells[colCount - 1]; rowCellsLastColumn.Alignment = HorizontalAlignment.Right; } var reportHeadingText = "Transaction Input Report for NAB"; var businessDateText = string.Format("Business Date: {0}", report.HeaderInfo.BusinessDate); var reportDateText = string.Format("Report Date: {0}", report.HeaderInfo.ReportOn); table.Rows[0] = CreateTableRow(reportHeadingText, HorizontalAlignment.Center, new BorderInfo(BorderSide.None)); table.Rows[1] = CreateTableRow(businessDateText, HorizontalAlignment.Right, new BorderInfo(BorderSide.None)); table.Rows[2] = CreateTableRow(reportDateText, HorizontalAlignment.Right, new BorderInfo(BorderSide.None)); table.Rows[2].Border = new BorderInfo(BorderSide.Bottom, 1f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); table.Rows[table.Rows.Count - 1].Border = new BorderInfo(BorderSide.Bottom, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); page.Paragraphs.Add(table); ////Add footer as table, was having formatting issues when adding as rows to above table. var footer = new Table { ColumnWidths = "510", ColumnAdjustment = ColumnAdjustment.Customized, Border = new BorderInfo(BorderSide.None, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)), DefaultCellBorder = new BorderInfo(BorderSide.None, 0.0f), DefaultCellPadding = new MarginInfo(1, 3, 0, 0), Alignment = HorizontalAlignment.Left, Margin = new MarginInfo(6, 3, 5, 3), DefaultCellTextState = { FontSize = 8, FontStyle = FontStyles.Regular } }; var totalAmountText = string.Format("Total Credit Amount: {0} Total Debit Amount: {1}", FormatAmount(report.FooterInfo.TotalCreditAmount, "Currency"), FormatAmount(report.FooterInfo.TotalDebitAmount, "Currency")); var totalCountText = string.Format("Credit Count: {0} Debit Count: {1} Total Item Count: {2}", report.FooterInfo.CreditCount, report.FooterInfo.DebitCount, report.VoucherRows.Count); var totalAmountRow = new Row(); totalAmountRow.Cells.Add(totalAmountText); footer.Rows.Add(totalAmountRow); var totalCountRow = new Row(); totalCountRow.Cells.Add(totalCountText); totalCountRow.Border = new BorderInfo(BorderSide.Bottom, .5f, Aspose.Pdf.Color.FromRgb(Color.LightGray)); footer.Rows.Add(totalCountRow); page.Paragraphs.Add(footer); } }
public Report MapVoucherToReport(AdjustmentLetter letter) { var voucher = letter.AdjustedVoucher; var headerRow = new HeaderRow { BusinessDate = voucher.voucher.processingDate.ToShortDateString(), ReportOn = DateTime.Today.ToShortDateString(), Page = "1" }; var voucherList = letter.Vouchers.Select(vouch => new TableRow { AccountNo = vouch.voucher.accountNumber.ToString(), Ad = vouch.voucher.auxDom, Amount = FormatAmount(vouch.voucher.amount, "Decimal"), Bsb = vouch.voucher.bsbNumber, Bch = vouch.voucherBatch.scannedBatchNumber, NegBsb = vouch.voucherBatch.collectingBank, Drcr = vouch.voucher.documentType.ToString(), TransCode = vouch.voucher.transactionCode, Ean = vouch.voucher.extraAuxDom, Din = vouch.voucher.documentReferenceNumber }).ToList(); var totalCredAmount = letter.Vouchers.Where(x => x.voucher.documentType.ToString().ToUpper() == "CR").Sum(x => Convert.ToDecimal(x.voucher.amount)); var totalDebAmount = letter.Vouchers.Where(x => x.voucher.documentType.ToString().ToUpper() == "DR").Sum(x => Convert.ToDecimal(x.voucher.amount)); var footerRow = new FooterRow { TotalCreditAmount = totalCredAmount.ToString(CultureInfo.InvariantCulture), TotalDebitAmount = totalDebAmount.ToString(CultureInfo.InvariantCulture), CreditCount = letter.Vouchers.Count(x => x.voucher.documentType.ToString().ToUpper() == "CR").ToString(), DebitCount = letter.Vouchers.Count(x => x.voucher.documentType.ToString().ToUpper() == "DR").ToString() }; var report = new Report { HeaderInfo = headerRow, VoucherRows = voucherList, FooterInfo = footerRow }; return report; }
private static DataTable CreateTransactionLines(Report report) { var dataTable = new DataTable(); dataTable.Columns.Add("DIN"); dataTable.Columns.Add("NEGBSB"); dataTable.Columns.Add("EAD"); dataTable.Columns.Add("AD"); dataTable.Columns.Add("BSB"); dataTable.Columns.Add("ACCOUNT NO"); dataTable.Columns.Add("TC"); dataTable.Columns.Add("DR/CR"); dataTable.Columns.Add("AMOUNT"); //// Add the rows to the table foreach (var transactionLine in report.VoucherRows) { dataTable.Rows.Add(transactionLine.Din, transactionLine.NegBsb, transactionLine.Ean, transactionLine.Ad, transactionLine.Bsb, transactionLine.AccountNo, transactionLine.TransCode, transactionLine.Drcr, transactionLine.Amount); } return dataTable; }