Пример #1
0
        private void ReportBuilder(SqlDataReader dr, int cropYear, DateTime reportDate, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder: ";

            int contractNumber = 0;
            int groSHID        = 0;
            int lastGroSHID    = 0;

            Document  document = null;
            PdfWriter writer   = null;
            PdfPTable table    = null;

            iTextSharp.text.Image imgLogo = null;

            ContractPayeeSummaryEvent pgEvent = null;
            string rptTitle = "Western Sugar Cooperative\n" +
                              "Contract Payee Summary\n" +
                              "Crop Year " + cropYear;

            try {
                while (dr.Read())
                {
                    contractNumber = Convert.ToInt32(dr.GetString(dr.GetOrdinal("ContractNumber")));
                    groSHID        = Convert.ToInt32(dr.GetString(dr.GetOrdinal("GroAdrNumber")));
                    if (document == null)
                    {
                        lastGroSHID = groSHID;

                        // 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 ContractPayeeSummaryEvent();
                        pgEvent.FillEvent(dr, reportDate.ToShortDateString(), 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }
                    else
                    {
                        if (lastGroSHID != groSHID)
                        {
                            lastGroSHID = groSHID;
                            pgEvent.FillEvent(dr, reportDate.ToShortDateString(), 0, rptTitle, imgLogo);

                            document.NewPage();
                        }
                    }

                    // =======================================================
                    // Build Report
                    // =======================================================
                    table = PdfReports.CreateTable(_primaryTableLayout, 0);

                    Phrase    phrase = new Phrase("Contract: ", _labelFont);
                    Paragraph p      = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("ContractNumber")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p);

                    phrase = new Phrase("Grower #: ", _labelFont);
                    p      = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("GroAdrNumber")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p);

                    phrase = new Phrase("Landowner #: ", _labelFont);
                    p      = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("LdoAdrNumber")) + " - " + dr.GetString(dr.GetOrdinal("LandownerName")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p, 3);

                    PdfReports.AddText2Table(table, "Factory", _labelFont);
                    PdfReports.AddText2Table(table, "Station", _labelFont);
                    PdfReports.AddText2Table(table, "Assoc Member", _labelFont);
                    PdfReports.AddText2Table(table, "LO Name on Check", _labelFont);
                    PdfReports.AddText2Table(table, "Pac Dues", _labelFont);

                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("FactoryName")), _normalFont);
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("StationName")), _normalFont);
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("AssocMember")), _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("CashRent")), _normalFont, "center");
                    PdfReports.AddText2Table(table, "$" + dr.GetDecimal(dr.GetOrdinal("PacDues")).ToString("0.00"), _normalFont);

                    // Add Payee information
                    ShowPayeeInformation(table, contractNumber, cropYear, dr.GetBoolean(dr.GetOrdinal("SplitRetain")), dr.GetBoolean(dr.GetOrdinal("SplitChemical")));

                    ShowAcreage(table, dr.GetInt16(dr.GetOrdinal("ContractAcres")), dr.GetInt16(dr.GetOrdinal("PlantedAcres")),
                                dr.GetInt16(dr.GetOrdinal("AcresLost")), dr.GetInt16(dr.GetOrdinal("HarvestAcres")));

                    PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);
                    PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);

                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                }

                // ======================================================
                // 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 (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Пример #2
0
        private void ReportBuilder(SqlDataReader dr, int cropYear, DateTime reportDate, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder: ";

            int contractNumber = 0;
            int groSHID = 0;
            int lastGroSHID = 0;

            Document document = null;
            PdfWriter writer = null;
            PdfPTable table = null;
            iTextSharp.text.Image imgLogo = null;

            ContractPayeeSummaryEvent pgEvent = null;
            string rptTitle = "Western Sugar Cooperative\n" +
                "Contract Payee Summary\n" +
                "Crop Year " + cropYear;

            try {

                while (dr.Read()) {

                    contractNumber = Convert.ToInt32(dr.GetString(dr.GetOrdinal("ContractNumber")));
                    groSHID = Convert.ToInt32(dr.GetString(dr.GetOrdinal("GroAdrNumber")));
                    if (document == null) {

                        lastGroSHID = groSHID;

                        // 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 ContractPayeeSummaryEvent();
                        pgEvent.FillEvent(dr, reportDate.ToShortDateString(), 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                    } else {
                        if (lastGroSHID != groSHID) {

                            lastGroSHID = groSHID;
                            pgEvent.FillEvent(dr, reportDate.ToShortDateString(), 0, rptTitle, imgLogo);

                            document.NewPage();
                        }
                    }

                    // =======================================================
                    // Build Report
                    // =======================================================
                    table = PdfReports.CreateTable(_primaryTableLayout, 0);

                    Phrase phrase = new Phrase("Contract: ", _labelFont);
                    Paragraph p = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("ContractNumber")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p);

                    phrase = new Phrase("Grower #: ", _labelFont);
                    p = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("GroAdrNumber")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p);

                    phrase = new Phrase("Landowner #: ", _labelFont);
                    p = new Paragraph("", _normalFont);
                    p.Add(phrase);
                    phrase = new Phrase(dr.GetString(dr.GetOrdinal("LdoAdrNumber")) + " - " + dr.GetString(dr.GetOrdinal("LandownerName")), _normalFont);
                    p.Add(phrase);
                    PdfReports.AddText2Table(table, p, 3);

                    PdfReports.AddText2Table(table, "Factory", _labelFont);
                    PdfReports.AddText2Table(table, "Station", _labelFont);
                    PdfReports.AddText2Table(table, "Assoc Member", _labelFont);
                    PdfReports.AddText2Table(table, "LO Name on Check", _labelFont);
                    PdfReports.AddText2Table(table, "Pac Dues", _labelFont);

                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("FactoryName")), _normalFont);
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("StationName")), _normalFont);
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("AssocMember")), _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("CashRent")), _normalFont, "center");
                    PdfReports.AddText2Table(table, "$" + dr.GetDecimal(dr.GetOrdinal("PacDues")).ToString("0.00"), _normalFont);

                    // Add Payee information
                    ShowPayeeInformation(table, contractNumber, cropYear, dr.GetBoolean(dr.GetOrdinal("SplitRetain")), dr.GetBoolean(dr.GetOrdinal("SplitChemical")));

                    ShowAcreage(table, dr.GetInt16(dr.GetOrdinal("ContractAcres")), dr.GetInt16(dr.GetOrdinal("PlantedAcres")),
                        dr.GetInt16(dr.GetOrdinal("AcresLost")), dr.GetInt16(dr.GetOrdinal("HarvestAcres")));

                    PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);
                    PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);

                    PdfReports.AddTableNoSplit(document, pgEvent, table);
                }

                // ======================================================
                // 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 (document != null) {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                }
                if (writer != null) {
                    writer.Close();
                }
            }
        }