Exemple #1
0
        private static void ReportBuilderRetainRedeems(int cropYear, string paymentDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilderRetainRedeems: ";

            string  SHID               = "";
            string  equityCropYear     = "";
            string  lastSHID           = "";
            string  lastEquityCropYear = "";
            decimal totalCheckAmount   = 0;
            string  rptTitle           = "";
            string  statementDate      = Convert.ToDateTime(paymentDate).ToString(HEADER_DATE_FORMAT);

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

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

            try {
                List <ListStatementPatRetainItem> stateList = WSCReportsExec.RptStatementRetainRedeem(cropYear, shid, fromShid, toShid, paymentDate);

                for (int i = 0; i < stateList.Count; i++)
                {
                    ListStatementPatRetainItem state = stateList[i];

                    if (rptTitle.Length == 0)
                    {
                        rptTitle = "Unit Retain -- " + state.Qualified + " -- " + statementDate;
                    }

                    SHID           = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null)
                    {
                        // Create the detail table
                        detailTable = PdfReports.CreateTable(_primaryTableLayout, 0);
                        AddRetainRedeemDetailHeader(detailTable);

                        lastSHID         = state.SHID;
                        totalCheckAmount = CalcRedeemCheck(stateList, i);

                        // 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, 77, 45, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new StatementPatronageRetainEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, totalCheckAmount, 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();
                    }
                    else
                    {
                        if (lastSHID != SHID)
                        {
                            //-------------------------------------------------------------------------------------
                            // When you change members, kick out the page and move on to the next member,
                            // and reset flags.
                            //-------------------------------------------------------------------------------------

                            lastSHID           = SHID;
                            lastEquityCropYear = "";

                            // Add Grand Total Line
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                            PdfReports.AddText2Table(detailTable, "Total Amount", _labelFont, "center");
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, 2);
                            PdfReports.AddText2Table(detailTable, totalCheckAmount.ToString("$#,##0.00"), _normalFont, "right");

                            // Add this members detail lines to the document
                            PdfReports.AddTableNoSplit(document, pgEvent, detailTable);

                            // Calc the total for the new SHID
                            totalCheckAmount = CalcRedeemCheck(stateList, i);

                            pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, totalCheckAmount, 0, rptTitle, imgLogo);
                            document.NewPage();

                            // Refresh the detail table
                            detailTable = PdfReports.CreateTable(_primaryTableLayout, 0);
                            AddRetainRedeemDetailHeader(detailTable);
                        }
                    }

                    // =======================================================
                    // Build Report
                    // =======================================================
                    if (state.EquityCropYear != lastEquityCropYear)
                    {
                        // Before resetting the lastEquityCropYear, a non-blank crop year means this is a subsequent
                        // crop year for the same shid. Add a blank
                        if (lastEquityCropYear.Length > 0)
                        {
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                        }

                        lastEquityCropYear = state.EquityCropYear;

                        // Show Equity Data for Crop Year
                        PdfReports.AddText2Table(detailTable, state.EquityCropYear, _normalFont, "center");
                        PdfReports.AddText2Table(detailTable, state.EquityTons, _normalFont, "right");
                        PdfReports.AddText2Table(detailTable, state.RatePerTon, _normalFont, "right");
                        PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.RedeemAmt).ToString("$#,##0.00"), _normalFont, "right");

                        if (state.DeductionDesc.Length > 0)
                        {
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);

                            PdfReports.AddText2Table(detailTable, " ", _normalFont);
                            PdfReports.AddText2Table(detailTable, "Less Deductions: ", _normalItalicFont, "left", 3);

                            PdfReports.AddText2Table(detailTable, " ", _normalFont);
                            PdfReports.AddText2Table(detailTable, state.DeductionDesc, _normalFont, "left", 2);
                            PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.DeductionAmt).ToString("$#,##0.00"), _normalFont, "right");
                        }
                    }
                    else
                    {
                        //----------------------------------------------------------
                        // This is a deduction only line, a subsequent deduction.
                        //----------------------------------------------------------
                        PdfReports.AddText2Table(detailTable, " ", _normalFont);
                        PdfReports.AddText2Table(detailTable, state.DeductionDesc, _normalFont, "left", 2);
                        PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.DeductionAmt).ToString("$#,##0.00"), _normalFont, "right");
                    }
                }

                if (detailTable != null)
                {
                    // Add Grand Total Line
                    PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                    PdfReports.AddText2Table(detailTable, "Total Amount", _labelFont, "center");
                    PdfReports.AddText2Table(detailTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(detailTable, totalCheckAmount.ToString("$#,##0.00"), _normalFont, "right");

                    // Add this members detail lines to the document
                    PdfReports.AddTableNoSplit(document, pgEvent, detailTable);
                }

                // ======================================================
                // 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();
                }
            }
        }
        private static void ReportBuilderRetainRedeems(int cropYear, string paymentDate, string shid, string fromShid, string toShid, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilderRetainRedeems: ";

            string SHID = "";
            string equityCropYear = "";
            string lastSHID = "";
            string lastEquityCropYear = "";
            decimal totalCheckAmount = 0;
            string rptTitle = "";
            string statementDate = Convert.ToDateTime(paymentDate).ToString(HEADER_DATE_FORMAT);

            Document document = null;
            PdfWriter writer = null;
            PdfPTable detailTable = null;
            iTextSharp.text.Image imgLogo = null;
            StatementPatronageRetainEvent pgEvent = null;

            try {

                List<ListStatementPatRetainItem> stateList = WSCReportsExec.RptStatementRetainRedeem(cropYear, shid, fromShid, toShid, paymentDate);

                for (int i = 0; i < stateList.Count; i++) {

                    ListStatementPatRetainItem state = stateList[i];

                    if (rptTitle.Length == 0) {
                        rptTitle = "Unit Retain -- " + state.Qualified + " -- " + statementDate;
                    }

                    SHID = state.SHID;
                    equityCropYear = state.EquityCropYear;

                    if (document == null) {

                        // Create the detail table
                        detailTable = PdfReports.CreateTable(_primaryTableLayout, 0);
                        AddRetainRedeemDetailHeader(detailTable);

                        lastSHID = state.SHID;
                        totalCheckAmount = CalcRedeemCheck(stateList, i);

                        // 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, 77, 45, iTextSharp.text.Element.ALIGN_CENTER);

                        // Attach my override event handler(s)
                        pgEvent = new StatementPatronageRetainEvent();
                        pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, totalCheckAmount, 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                    } else {

                        if (lastSHID != SHID) {

                            //-------------------------------------------------------------------------------------
                            // When you change members, kick out the page and move on to the next member,
                            // and reset flags.
                            //-------------------------------------------------------------------------------------

                            lastSHID = SHID;
                            lastEquityCropYear = "";

                            // Add Grand Total Line
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                            PdfReports.AddText2Table(detailTable, "Total Amount", _labelFont, "center");
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, 2);
                            PdfReports.AddText2Table(detailTable, totalCheckAmount.ToString("$#,##0.00"), _normalFont, "right");

                            // Add this members detail lines to the document
                            PdfReports.AddTableNoSplit(document, pgEvent, detailTable);

                            // Calc the total for the new SHID
                            totalCheckAmount = CalcRedeemCheck(stateList, i);

                            pgEvent.FillEvent(state.SHID, state.BusName, state.Addr1, state.Addr2, state.CSZ, totalCheckAmount, 0, rptTitle, imgLogo);
                            document.NewPage();

                            // Refresh the detail table
                            detailTable = PdfReports.CreateTable(_primaryTableLayout, 0);
                            AddRetainRedeemDetailHeader(detailTable);
                        }
                    }

                    // =======================================================
                    // Build Report
                    // =======================================================
                    if (state.EquityCropYear != lastEquityCropYear) {

                        // Before resetting the lastEquityCropYear, a non-blank crop year means this is a subsequent
                        // crop year for the same shid. Add a blank
                        if (lastEquityCropYear.Length > 0) {
                            PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                        }

                        lastEquityCropYear = state.EquityCropYear;

                        // Show Equity Data for Crop Year
                        PdfReports.AddText2Table(detailTable, state.EquityCropYear, _normalFont, "center");
                        PdfReports.AddText2Table(detailTable, state.EquityTons, _normalFont, "right");
                        PdfReports.AddText2Table(detailTable, state.RatePerTon, _normalFont, "right");
                        PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.RedeemAmt).ToString("$#,##0.00"), _normalFont, "right");

                        if (state.DeductionDesc.Length > 0) {

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

                            PdfReports.AddText2Table(detailTable, " ", _normalFont);
                            PdfReports.AddText2Table(detailTable, "Less Deductions: ", _normalItalicFont, "left", 3);

                            PdfReports.AddText2Table(detailTable, " ", _normalFont);
                            PdfReports.AddText2Table(detailTable, state.DeductionDesc, _normalFont, "left", 2);
                            PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.DeductionAmt).ToString("$#,##0.00"), _normalFont, "right");
                        }

                    } else {

                        //----------------------------------------------------------
                        // This is a deduction only line, a subsequent deduction.
                        //----------------------------------------------------------
                        PdfReports.AddText2Table(detailTable, " ", _normalFont);
                        PdfReports.AddText2Table(detailTable, state.DeductionDesc, _normalFont, "left", 2);
                        PdfReports.AddText2Table(detailTable, Convert.ToDecimal(state.DeductionAmt).ToString("$#,##0.00"), _normalFont, "right");
                    }
                }

                if (detailTable != null) {

                    // Add Grand Total Line
                    PdfReports.AddText2Table(detailTable, " ", _normalFont, _primaryTableLayout.Length);
                    PdfReports.AddText2Table(detailTable, "Total Amount", _labelFont, "center");
                    PdfReports.AddText2Table(detailTable, " ", _normalFont, 2);
                    PdfReports.AddText2Table(detailTable, totalCheckAmount.ToString("$#,##0.00"), _normalFont, "right");

                    // Add this members detail lines to the document
                    PdfReports.AddTableNoSplit(document, pgEvent, detailTable);
                }

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