コード例 #1
0
        public static void ReportBuilder(SqlDataReader dr, int cropYear, int shid, string busName, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder";
            Document     document    = null;
            PdfWriter    writer      = null;
            PdfPTable    table       = null;

            iTextSharp.text.Image imgLogo = null;
            ContractSummaryEvent  pgEvent = null;

            int resetFlag = 0;

            string rptTitle = "Contract Summary\nCrop Year " + cropYear.ToString();

            Font headerFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font normalFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font labelFont  = FontFactory.GetFont("HELVETICA", 8F, Font.BOLD);

            try {
                while (dr.Read())
                {
                    if (document == null)
                    {
                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                        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 ContractSummaryEvent();
                        pgEvent.FillEvent(busName, shid, resetFlag, rptTitle, imgLogo, _primaryTableLayout);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        //table = PdfReports.CreateTable(_primaryTableLayout, 1);
                        //AddDetailSectionHdr(ref table, labelFont, normalFont);
                    }

                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    // =======================================================
                    // Add Delivery information
                    // =======================================================
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractFactory")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractStation")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractNo")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("LandownerName")),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("FinalNetTons")).ToString("#,##0.0000"),
                                             normalFont, "right");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SugarPct")).ToString("##0.00"),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("TarePct")).ToString("##0.00"),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("TonsPerAcre")).ToString("#,##0.00"),
                                             normalFont, "right");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SLMPct")).ToString("##0.0000"),
                                             normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetInt32(dr.GetOrdinal("ExtSugarTon")).ToString("#,##0"),
                                             normalFont, "center");

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

                // ======================================================
                // Close document
                // ======================================================
                if (document != null)
                {
                    pgEvent.IsDocumentClosing = true;
                    document.Close();
                    document = null;
                }
                if (table == 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
        public static void ReportBuilder(SqlDataReader dr, int cropYear, int shid, string busName, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder";
            Document document = null;
            PdfWriter writer = null;
            PdfPTable table = null;
            iTextSharp.text.Image imgLogo = null;
            ContractSummaryEvent pgEvent = null;

            int resetFlag = 0;

            string rptTitle = "Contract Summary\nCrop Year " + cropYear.ToString();

            Font headerFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font normalFont = FontFactory.GetFont("HELVETICA", 8F, Font.NORMAL);
            Font labelFont = FontFactory.GetFont("HELVETICA", 8F, Font.BOLD);

            try {

                while (dr.Read()) {

                    if (document == null) {

                        // IF YOU CHANGE MARGINS, CHANGE YOUR TABLE LAYOUTS !!!
                        //  ***  US LETTER: 612 X 792  ***
                        //document = new Document(iTextSharp.text.PageSize.LETTER, 36, 36, 54, 72);
                        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 ContractSummaryEvent();
                        pgEvent.FillEvent(busName, shid, resetFlag, rptTitle, imgLogo, _primaryTableLayout);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        //table = PdfReports.CreateTable(_primaryTableLayout, 1);
                        //AddDetailSectionHdr(ref table, labelFont, normalFont);
                    }

                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    // =======================================================
                    // Add Delivery information
                    // =======================================================
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractFactory")),
                        normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractStation")),
                        normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractNo")),
                        normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("LandownerName")),
                        normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("FinalNetTons")).ToString("#,##0.0000"),
                        normalFont, "right");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SugarPct")).ToString("##0.00"),
                        normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("TarePct")).ToString("##0.00"),
                        normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("TonsPerAcre")).ToString("#,##0.00"),
                        normalFont, "right");
                    PdfReports.AddText2Table(table, dr.GetDecimal(dr.GetOrdinal("SLMPct")).ToString("##0.0000"),
                        normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetInt32(dr.GetOrdinal("ExtSugarTon")).ToString("#,##0"),
                        normalFont, "center");

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

                // ======================================================
                // Close document
                // ======================================================
                if (document != null) {

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