private void ReportBuilder(SqlDataReader dr, int cropYear, DateTime reportDate, string logoUrl, System.IO.FileStream fs) { const string METHOD_NAME = "rptEquityStatement.ReportBuilder: "; const int resetFlag = 0; Document document = null; PdfWriter writer = null; PdfPTable table = null; iTextSharp.text.Image imgLogo = null; EQStmtEvent pgEvent = null; _cropYear = cropYear; _reportDate = reportDate; int shid = 0; int lastShid = 0; int entityTypeID = 0; int lastEntityTypeID = 0; string rptTitle = "Shareholder Equity Statement"; try { while (dr.Read()) { entityTypeID = dr.GetInt32(dr.GetOrdinal("EntityTypeID")); if (entityTypeID == _entTypeIDAddress) { shid = dr.GetInt32(dr.GetOrdinal("MemberNumber")); } // when you switch entities, close out the last entity when appropriate if (entityTypeID != lastEntityTypeID || entityTypeID == _entTypeIDAddress) { FinishEntityBlock(writer, document, ref table, entityTypeID, lastEntityTypeID, pgEvent); } if (document == null) { lastShid = shid; // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!! // *** US LETTER: 612 X 792 *** document = new Document(PortraitPageSize.PgPageSize, PortraitPageSize.PgLeftMargin, PortraitPageSize.PgRightMargin, PortraitPageSize.PgTopMargin, PortraitPageSize.PgBottomMargin); // we create a writer that listens to the document // and directs a PDF-stream to a file writer = PdfWriter.GetInstance(document, fs); imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER); // Attach my override event handler(s) pgEvent = new EQStmtEvent(); pgEvent.FillEvent(reportDate, shid, " ", dr.GetString(dr.GetOrdinal("BusinessName")), dr.GetString(dr.GetOrdinal("Addr1")), dr.GetString(dr.GetOrdinal("Addr2")), dr.GetString(dr.GetOrdinal("CityStateZip")), resetFlag, rptTitle, imgLogo); writer.PageEvent = pgEvent; // Open the document document.Open(); } else { if (lastShid != shid) { lastShid = shid; lastEntityTypeID = entityTypeID; _financingBalance = 0; pgEvent.FillEvent(reportDate, shid, " ", dr.GetString(dr.GetOrdinal("BusinessName")), dr.GetString(dr.GetOrdinal("Addr1")), dr.GetString(dr.GetOrdinal("Addr2")), dr.GetString(dr.GetOrdinal("CityStateZip")), resetFlag, rptTitle, imgLogo); document.NewPage(); } } //========================================================= // Add Common Stock //========================================================= if (entityTypeID == _entTypeIDCommonStock) { if (lastEntityTypeID != _entTypeIDCommonStock) { lastEntityTypeID = _entTypeIDCommonStock; AddCommonHeader(ref table); } AddCommonData(dr, table); } //========================================================= // Patron Stock //========================================================= if ((entityTypeID == _entTypeIDPatronStock || entityTypeID == _entTypeIDPatronPermTransfer) && ((lastEntityTypeID != _entTypeIDPatronStock && lastEntityTypeID != _entTypeIDPatronPermTransfer))) { AddPatronStockHeader(ref table); } if (entityTypeID == _entTypeIDPatronStock) { if (lastEntityTypeID != _entTypeIDPatronStock) { lastEntityTypeID = _entTypeIDPatronStock; AddPatronStockPurchaseHeader(ref table); } AddPatronStockPurchaseData(dr, table); } if (entityTypeID == _entTypeIDPatronPermTransfer) { if (lastEntityTypeID != _entTypeIDPatronPermTransfer) { lastEntityTypeID = _entTypeIDPatronPermTransfer; AddPatronStockTransferHeader(ref table); } AddPatronStockTransferData(dr, table); } //========================================================= // Add Unit Retains //========================================================= if (entityTypeID == _entTypeIDUnitRetain) { if (lastEntityTypeID != _entTypeIDUnitRetain) { lastEntityTypeID = _entTypeIDUnitRetain; AddUnitRetainHeader(ref table); } AddUnitRetainData(dr, table); } //========================================================= // Add Patronage Refunds //========================================================= if (entityTypeID == _entTypeIDPatronageRefundCert) { if (lastEntityTypeID != _entTypeIDPatronageRefundCert) { lastEntityTypeID = _entTypeIDPatronageRefundCert; AddPatronageRefundHeader(ref table); } AddPatronageRefundData(dr, table); } //========================================================= // Add Equity Financing //========================================================= if (entityTypeID == _entTypeIDEquityFinancing || entityTypeID == _entTypeIDEquityFinancingPayment) { if (lastEntityTypeID != _entTypeIDEquityFinancing && lastEntityTypeID != _entTypeIDEquityFinancingPayment) { AddFinancingHeader(ref table); } lastEntityTypeID = entityTypeID; if (entityTypeID == _entTypeIDEquityFinancing) { AddFinancingLoanData(dr, table); } if (entityTypeID == _entTypeIDEquityFinancingPayment) { AddFinancingLoanPaymentData(dr, table); } } /* */ } entityTypeID = 0; FinishEntityBlock(writer, document, ref table, entityTypeID, lastEntityTypeID, pgEvent); // ====================================================== // Close document // ====================================================== if (document != null) { pgEvent.IsDocumentClosing = true; document.Close(); document = null; } if (writer == null) { // Warn that we have no data. WSCIEMP.Common.CWarning warn = new WSCIEMP.Common.CWarning("No records matched your report criteria."); throw (warn); } } catch (Exception ex) { string errMsg = "document is null: " + (document == null).ToString() + "; " + "writer is null: " + (writer == null).ToString(); WSCIEMP.Common.CException wscex = new WSCIEMP.Common.CException(METHOD_NAME + errMsg, ex); throw (wscex); } finally { if (dr != null) { if (!dr.IsClosed) { dr.Close(); } } if (document != null) { pgEvent.IsDocumentClosing = true; document.Close(); } if (writer != null) { writer.Close(); } } }
private void FinishPatronStockData(PdfWriter writer, Document document, ref PdfPTable table, EQStmtEvent pgEvent) { PdfReports.AddText2Table(table, " ", _normalFont, _patronStockLayout.Length); iTextSharp.text.pdf.PdfPCell cell = PdfReports.AddText2Cell("Total Shares Owned", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell(_patronStockShares.ToString("#,##0"), _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); PdfReports.AddText2Table(table, " ", _normalFont, _patronStockLayout.Length - 2); PdfReports.AddText2Table(table, " ", _normalFont, _patronStockLayout.Length); PdfReports.AddTableNoSplit(document, pgEvent, table); table = null; }
private void FinishUnitRetainData(PdfWriter writer, Document document, ref PdfPTable table, EQStmtEvent pgEvent) { PdfReports.AddText2Table(table, " ", _normalFont, _unitRetainsLayout.Length); iTextSharp.text.pdf.PdfPCell cell = PdfReports.AddText2Cell("Total", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Date cell = PdfReports.AddText2Cell(" ", _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell(_unitRetainTons.ToString("#,##0.0000"), _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell(" ", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell("$" + _unitRetainAmount.ToString("#,##0.00"), _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell("$" + _unitRetainPaid.ToString("#,##0.00"), _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell("$" + _unitRetainBalance.ToString("#,##0.00"), _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell(" ", _labelFont, "right"); table.AddCell(cell); PdfReports.AddText2Table(table, " ", _normalFont, _unitRetainsLayout.Length); PdfReports.AddTableNoSplit(document, pgEvent, table); table = null; }
private void FinishFinancingData(PdfWriter writer, Document document, ref PdfPTable table, EQStmtEvent pgEvent) { PdfReports.AddText2Table(table, " ", _normalFont, _equityFinancingLayout.Length); iTextSharp.text.pdf.PdfPCell cell = PdfReports.AddText2Cell("Total", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); cell = PdfReports.AddText2Cell(" ", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); if (_financingPaid < 0) { cell = PdfReports.AddText2Cell("($" + Math.Abs(_financingPaid).ToString("#,##0.00") + ")", _labelFont, "right"); } else { cell = PdfReports.AddText2Cell("$" + _financingPaid.ToString("#,##0.00"), _labelFont, "right"); } cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); if (_financingInterest < 0) { cell = PdfReports.AddText2Cell("($" + Math.Abs(_financingInterest).ToString("#,##0.00") + ")", _labelFont, "right"); } else { cell = PdfReports.AddText2Cell("$" + _financingInterest.ToString("#,##0.00"), _labelFont, "right"); } cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); if (_financingBalance < 0) { cell = PdfReports.AddText2Cell("($" + Math.Abs(_financingBalance).ToString("#,##0.00") + ")", _labelFont, "right"); } else { cell = PdfReports.AddText2Cell("$" + _financingBalance.ToString("#,##0.00"), _labelFont, "right"); } cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); PdfReports.AddText2Table(table, " ", _normalFont, 2); PdfReports.AddText2Table(table, " ", _normalFont, _equityFinancingLayout.Length); PdfReports.AddTableNoSplit(document, pgEvent, table); table = null; }
private void FinishPatronageRefundData(PdfWriter writer, Document document, ref PdfPTable table, EQStmtEvent pgEvent) { PdfReports.AddText2Table(table, " ", _normalFont, _patronageRefundLayout.Length); // Crop Year iTextSharp.text.pdf.PdfPCell cell = PdfReports.AddText2Cell("Total", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Date cell = PdfReports.AddText2Cell(" ", _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Tons cell = PdfReports.AddText2Cell(_patronageRefundTons.ToString("#,##0.0000"), _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Rate cell = PdfReports.AddText2Cell(" ", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Amount if (_patronageRefundAmount < 0) { cell = PdfReports.AddText2Cell("($" + Math.Abs(_patronageRefundAmount).ToString("#,##0.00") + ")", _labelFont, "right"); } else { cell = PdfReports.AddText2Cell("$" + _patronageRefundAmount.ToString("#,##0.00"), _labelFont, "right"); } cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Initial Paid cell = PdfReports.AddText2Cell("$" + _patronageRefundInitialPaid.ToString("#,##0.00"), _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Loss Alloc cell = PdfReports.AddText2Cell(" ", _labelFont, "center"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // Certificate Paid cell = PdfReports.AddText2Cell("$" + _patronageCertificatePaid.ToString("#,##0.00"), _labelFont, "right"); cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); // New Balance if (_patronageRefundNewBalance < 0) { cell = PdfReports.AddText2Cell("($" + Math.Abs(_patronageRefundNewBalance).ToString("#,##0.00") + ")", _labelFont, "right"); } else { cell = PdfReports.AddText2Cell("$" + _patronageRefundNewBalance.ToString("#,##0.00"), _labelFont, "right"); } cell.BackgroundColor = cell.BackgroundColor = Color_Highlight; table.AddCell(cell); PdfReports.AddText2Table(table, " ", _normalFont, _patronageRefundLayout.Length); PdfReports.AddTableNoSplit(document, pgEvent, table); table = null; }
private void FinishCommonData(PdfWriter writer, Document document, ref PdfPTable table, EQStmtEvent pgEvent) { PdfReports.AddText2Table(table, " ", _normalFont, _commonStockLayout.Length); PdfReports.AddTableNoSplit(document, pgEvent, table); table = null; }
private void FinishEntityBlock(PdfWriter writer, Document document, ref PdfPTable table, int entityTypeID, int lastEntityTypeID, EQStmtEvent pgEvent) { if (table != null) { // Finish Common Stock if (lastEntityTypeID == _entTypeIDCommonStock) { FinishCommonData(writer, document, ref table, pgEvent); } // Finish Patron Stock if ((entityTypeID != _entTypeIDPatronStock && entityTypeID != _entTypeIDPatronPermTransfer) && (lastEntityTypeID == _entTypeIDPatronPermTransfer || lastEntityTypeID == _entTypeIDPatronStock)) { FinishPatronStockData(writer, document, ref table, pgEvent); _patronStockShares = 0; } // Finish Unit Retains if (lastEntityTypeID == _entTypeIDUnitRetain) { FinishUnitRetainData(writer, document, ref table, pgEvent); _unitRetainTons = 0; _unitRetainAmount = 0; _unitRetainPaid = 0; _unitRetainBalance = 0; } // Finish Patronage Refund if (lastEntityTypeID == _entTypeIDPatronageRefundCert) { FinishPatronageRefundData(writer, document, ref table, pgEvent); _patronageRefundTons = 0; _patronageRefundAmount = 0; _patronageRefundInitialPaid = 0; _patronageCertificatePaid = 0; _patronageRefundNewBalance = 0; _patronageRefundLossAlloc = 0; } // Finish Loan Financing if ((entityTypeID != _entTypeIDEquityFinancing && entityTypeID != _entTypeIDEquityFinancingPayment) && (lastEntityTypeID == _entTypeIDEquityFinancing || lastEntityTypeID == _entTypeIDEquityFinancingPayment)) { FinishFinancingData(writer, document, ref table, pgEvent); _financingPaid = 0; _financingInterest = 0; _financingBalance = 0; } } }