public static void ReportBuilder(SqlDataReader dr, int cropYear, DateTime letterDate, DateTime deadlineDate, string logoUrl, System.IO.FileStream fs) { const string METHOD_NAME = "ReportBuilder"; const float primaryLeading = 13.5F; const float primaryLeftIndent = 20F; string strLetterDate = letterDate.ToString("MMMM dd, yyyy"); string strDeadlineDate = deadlineDate.ToString("MMMM dd, yyyy"); string LdoBusinessName = ""; string tmpStr = ""; string tmpStr2 = ""; Document document = null; PdfWriter writer = null; LandownerLetterEvent pgEvent = null; ColumnText ct = null; iTextSharp.text.Image imgLogo = null; try { while (dr.Read()) { LdoBusinessName = dr["LdoBusinessName"].ToString(); string LdoAddressLine1 = dr["LdoAddressLine1"].ToString(); string LdoAddressLine2 = dr["LdoAddressLine2"].ToString(); string LdoCityStateZip = dr["LdoCityStateZip"].ToString(); if (document == null) { // 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); imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER); // we create a writer that listens to the document // and directs a PDF-stream to a file writer = PdfWriter.GetInstance(document, fs); // Attach my override event handler(s) pgEvent = new LandownerLetterEvent(); pgEvent.FillEvent(imgLogo, strLetterDate, LdoBusinessName, LdoAddressLine1, LdoAddressLine2, LdoCityStateZip); writer.PageEvent = pgEvent; // Open the document document.Open(); } else { pgEvent.FillEvent(imgLogo, strLetterDate, LdoBusinessName, LdoAddressLine1, LdoAddressLine2, LdoCityStateZip); document.NewPage(); } ct = pgEvent.GetColumnObject(); Paragraph p = new Paragraph(primaryLeading, "Your tenant, " + dr["GroBusinessName"].ToString() + ", has indicated that the proceeds for sugar beets grown on your land in\n" + cropYear.ToString() + " are to be split and you will be receiving " + dr.GetDecimal(dr.GetOrdinal("LdoSplitPercent")).ToString("##.0##") + "% of the proceeds. Since Western Sugar Cooperative no\n" + "longer requires signatures for the second payees, this letter has been sent for your verification.\n\n", _normalFont); ct.AddElement(p); p = new Paragraph(new Phrase(primaryLeading, "Your check will be made payable as follows:", _normalFont)); ct.AddElement(p); p = new Paragraph(primaryLeading, dr["ldoPayeeDescription"].ToString(), _normalFont); p.IndentationLeft = primaryLeftIndent; ct.AddElement(p); p = new Paragraph(primaryLeading, "If you have a lien on the beets, the lien holder’s name should be included above.\n\n" + "In addition, the following options were selected by your tenant.", _normalFont); ct.AddElement(p); decimal ldoChemPct = dr.GetDecimal(dr.GetOrdinal("LdoChemicalSplitPct")); if (dr.GetBoolean(dr.GetOrdinal("IsSplitChemical")) && ldoChemPct != 0) { tmpStr = ldoChemPct.ToString("##.0##") + "%"; } else { tmpStr = "No"; } decimal ldoRetainPct = dr.GetDecimal(dr.GetOrdinal("LdoSplitPercent")); if (dr.GetBoolean(dr.GetOrdinal("IsSplitRetain")) && ldoRetainPct != 0) { tmpStr2 = ldoRetainPct.ToString("##.0##") + "% of the"; } else { tmpStr2 = "No"; } p = new Paragraph(primaryLeading, tmpStr2 + " Unit Retains on this contract will be deducted from your proceeds.\n" + tmpStr + " seed & chemical receivables charged to this contract will be deducted from your proceeds.", _normalFont); p.IndentationLeft = primaryLeftIndent; ct.AddElement(p); p = new Paragraph(primaryLeading, "If the above information is correct, no response is needed.\n\n", _normalFont); ct.AddElement(p); p = new Paragraph(primaryLeading, "If any of the above information is not correct, please contact your tenant’s agriculturist, " + dr["AgriculturistName"].ToString() + " at\n" + WSCIEMP.Common.CodeLib.FormatPhoneNumber2Display(dr["AgriculturistPhone"].ToString()) + " by " + strDeadlineDate + ", or mail the corrections to:\n\n", _normalFont); ct.AddElement(p); p = new Paragraph(12F, "Western Sugar Cooperative\n" + "Attn: Marty Smith\n" + "1221 8th Avenue Unit E\n" + "Greeley, CO 80631\n\n", _normalFont); p.IndentationLeft = primaryLeftIndent; ct.AddElement(p); p = new Paragraph(primaryLeading, "Sincerely,\n\n" + "Marty Smith\n" + "Beet Accounting Manager\n\n" + "Ref: " + dr["ContractNo"].ToString(), _normalFont); ct.AddElement(p); ct.Go(false); } // ====================================================== // Close document // ====================================================== if (document != null) { pgEvent.IsDocumentClosing = true; document.Close(); document = null; } if (writer == null || String.IsNullOrEmpty(LdoBusinessName)) { // 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(MOD_NAME + METHOD_NAME + errMsg, ex); throw (wscex); } finally { if (document != null) { pgEvent.IsDocumentClosing = true; document.Close(); } if (writer != null) { writer.Close(); } } }
public static void ReportBuilder(SqlDataReader dr, int cropYear, DateTime letterDate, DateTime deadlineDate, string logoUrl, System.IO.FileStream fs) { const string METHOD_NAME = "ReportBuilder"; const float primaryLeading = 13.5F; const float primaryLeftIndent = 20F; string strLetterDate = letterDate.ToString("MMMM dd, yyyy"); string strDeadlineDate = deadlineDate.ToString("MMMM dd, yyyy"); string LdoBusinessName = ""; string tmpStr = ""; string tmpStr2 = ""; Document document = null; PdfWriter writer = null; LandownerLetterEvent pgEvent = null; ColumnText ct = null; iTextSharp.text.Image imgLogo = null; try { while (dr.Read()) { LdoBusinessName = dr["LdoBusinessName"].ToString(); string LdoAddressLine1 = dr["LdoAddressLine1"].ToString(); string LdoAddressLine2 = dr["LdoAddressLine2"].ToString(); string LdoCityStateZip = dr["LdoCityStateZip"].ToString(); if (document == null) { // 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); imgLogo = PdfReports.GetImage(logoUrl, 127, 50, iTextSharp.text.Element.ALIGN_CENTER); // we create a writer that listens to the document // and directs a PDF-stream to a file writer = PdfWriter.GetInstance(document, fs); // Attach my override event handler(s) pgEvent = new LandownerLetterEvent(); pgEvent.FillEvent(imgLogo, strLetterDate, LdoBusinessName, LdoAddressLine1, LdoAddressLine2, LdoCityStateZip); writer.PageEvent = pgEvent; // Open the document document.Open(); } else { pgEvent.FillEvent(imgLogo, strLetterDate, LdoBusinessName, LdoAddressLine1, LdoAddressLine2, LdoCityStateZip); document.NewPage(); } ct = pgEvent.GetColumnObject(); Paragraph p = new Paragraph(primaryLeading, "Your tenant, " + dr["GroBusinessName"].ToString() + ", has indicated that the proceeds for sugar beets grown on your land in\n" + cropYear.ToString() + " are to be split and you will be receiving " + dr.GetDecimal(dr.GetOrdinal("LdoSplitPercent")).ToString("##.0##") + "% of the proceeds. Since Western Sugar Cooperative no\n" + "longer requires signatures for the second payees, this letter has been sent for your verification.\n\n", _normalFont); ct.AddElement(p); p = new Paragraph(new Phrase(primaryLeading, "Your check will be made payable as follows:", _normalFont)); ct.AddElement(p); p = new Paragraph(primaryLeading, dr["ldoPayeeDescription"].ToString(), _normalFont); p.IndentationLeft = primaryLeftIndent; ct.AddElement(p); p = new Paragraph(primaryLeading, "If you have a lien on the beets, the lien holder’s name should be included above.\n\n" + "In addition, the following options were selected by your tenant.", _normalFont); ct.AddElement(p); decimal ldoChemPct = dr.GetDecimal(dr.GetOrdinal("LdoChemicalSplitPct")); if (dr.GetBoolean(dr.GetOrdinal("IsSplitChemical")) && ldoChemPct != 0) { tmpStr = ldoChemPct.ToString("##.0##") + "%"; } else { tmpStr = "No"; } decimal ldoRetainPct = dr.GetDecimal(dr.GetOrdinal("LdoSplitPercent")); if (dr.GetBoolean(dr.GetOrdinal("IsSplitRetain")) && ldoRetainPct != 0) { tmpStr2 = ldoRetainPct.ToString("##.0##") + "% of the"; } else { tmpStr2 = "No"; } p = new Paragraph(primaryLeading, tmpStr2 + " Unit Retains on this contract will be deducted from your proceeds.\n" + tmpStr + " seed & chemical receivables charged to this contract will be deducted from your proceeds.", _normalFont); p.IndentationLeft = primaryLeftIndent; ct.AddElement(p); p = new Paragraph(primaryLeading, "If the above information is correct, no response is needed.\n\n", _normalFont); ct.AddElement(p); p = new Paragraph(primaryLeading, "If any of the above information is not correct, please contact your tenant’s agriculturist, " + dr["AgriculturistName"].ToString() + " at\n" + WSCIEMP.Common.CodeLib.FormatPhoneNumber2Display(dr["AgriculturistPhone"].ToString()) + " by " + strDeadlineDate + ", or mail the corrections to:\n\n", _normalFont); ct.AddElement(p); p = new Paragraph(12F, "Western Sugar Cooperative\n" + "Attn: Marty Smith\n" + "1221 8th Avenue Unit E\n" + "Greeley, CO 80631\n\n", _normalFont); p.IndentationLeft = primaryLeftIndent; ct.AddElement(p); p = new Paragraph(primaryLeading, "Sincerely,\n\n" + "Marty Smith\n" + "Beet Accounting Manager\n\n" + "Ref: " + dr["ContractNo"].ToString(), _normalFont); ct.AddElement(p); ct.Go(false); } // ====================================================== // Close document // ====================================================== if (document != null) { pgEvent.IsDocumentClosing = true; document.Close(); document = null; } if (writer == null || String.IsNullOrEmpty(LdoBusinessName)) { // 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(MOD_NAME + METHOD_NAME + errMsg, ex); throw (wscex); } finally { if (document != null) { pgEvent.IsDocumentClosing = true; document.Close(); } if (writer != null) { writer.Close(); } } }