Exemplo n.º 1
0
        public static void ReportBuilder(SqlDataReader dr, int cropYear,
                                         int shid, string busName, string deliveryDate, 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;
            DeliveryByDayEvent    pgEvent = null;

            const int RowBlockSize = 4;
            int       rowCount     = 1;
            int       resetFlag    = 0;

            string rptTitle = "Delivery By Day - Summary";

            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 DeliveryByDayEvent();
                        pgEvent.FillEvent(busName, shid, deliveryDate, resetFlag, rptTitle, imgLogo, _detailTableNames, _primaryTableLayout);

                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }

                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    // =======================================================
                    // Add Delivery information
                    // =======================================================
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractFactory")),
                                             _normalFont, "left");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("DeliveryStation")),
                                             _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("SLMPct")).ToString("##0.0000"),
                                             _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetInt32(dr.GetOrdinal("ExtractableSugarPerTon")).ToString("#,##0"),
                                             _normalFont, "center");

                    // add a blank after every row-block-size for visual breaks.
                    if (rowCount % RowBlockSize == 0)
                    {
                        PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);
                        rowCount = 1;
                    }
                    else
                    {
                        rowCount++;
                    }

                    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();
                }
            }
        }
Exemplo n.º 2
0
        public static void ReportBuilder(SqlDataReader dr, int cropYear,
            int shid, string busName, string deliveryDate, 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;
            DeliveryByDayEvent pgEvent = null;

            const int RowBlockSize = 4;
            int rowCount = 1;
            int resetFlag = 0;

            string rptTitle = "Delivery By Day - Summary";

            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 DeliveryByDayEvent();
                        pgEvent.FillEvent(busName, shid, deliveryDate, resetFlag, rptTitle, imgLogo, _detailTableNames, _primaryTableLayout);

                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                    }

                    table = PdfReports.CreateTable(_primaryTableLayout, 1);

                    // =======================================================
                    // Add Delivery information
                    // =======================================================
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("ContractFactory")),
                        _normalFont, "left");
                    PdfReports.AddText2Table(table, dr.GetString(dr.GetOrdinal("DeliveryStation")),
                        _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("SLMPct")).ToString("##0.0000"),
                        _normalFont, "center");
                    PdfReports.AddText2Table(table, dr.GetInt32(dr.GetOrdinal("ExtractableSugarPerTon")).ToString("#,##0"),
                        _normalFont, "center");

                    // add a blank after every row-block-size for visual breaks.
                    if (rowCount % RowBlockSize == 0) {
                        PdfReports.AddText2Table(table, " ", _normalFont, _primaryTableLayout.Length);
                        rowCount = 1;
                    } else {
                        rowCount++;
                    }

                    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();
                }
            }
        }