Пример #1
0
        private static void AddDetailTable(PdfPTable detailTable, List <ListDirectDeliveryStatementItem> stateList, int index,
                                           decimal subTotalFirstNetTons, decimal subTotalNinetySixPct, decimal subTotalPayAmt)
        {
            const string METHOD_NAME = "AddDetailTable";

            int    maxIndex = stateList.Count;
            string payee    = stateList[index].Payee;

            try {
                // Create the Header
                PdfReports.AddText2Table(detailTable, "Cont", _labelFont, "center");
                PdfReports.AddText2Table(detailTable, "SHID", _labelFont, "center");
                //PdfReports.AddText2Table(detailTable, "Payee", _labelFont, "center");

                PdfReports.AddText2Table(detailTable, "Pay Amt", _labelFont, "center");
                PdfReports.AddText2Table(detailTable, "1st Net Tons", _labelFont, "center");
                PdfReports.AddText2Table(detailTable, "D Station", _labelFont, "center");

                PdfReports.AddText2Table(detailTable, "C Station", _labelFont, "center");
                PdfReports.AddText2Table(detailTable, "96%", _labelFont, "center");
                PdfReports.AddText2Table(detailTable, "Rate", _labelFont, "center");

                // Add the Details
                while (index < maxIndex && stateList[index].Payee == payee)
                {
                    ListDirectDeliveryStatementItem state = stateList[index];

                    PdfReports.AddText2Table(detailTable, state.ContractNumber, _normalFont, "center");
                    PdfReports.AddText2Table(detailTable, state.Shid, _normalFont, "center");
                    //PdfReports.AddText2Table(detailTable, state.Payee, _normalFont, "left");

                    PdfReports.AddText2Table(detailTable, Math.Round(state.PaymentAmount, 2).ToString("0.00"), _normalFont, "right");
                    PdfReports.AddText2Table(detailTable, state.FirstNetTons.ToString("0.0000"), _normalFont, "right");
                    PdfReports.AddText2Table(detailTable, state.DeliveryStationName, _normalFont, "center");

                    PdfReports.AddText2Table(detailTable, state.ContractStationName, _normalFont, "center");
                    PdfReports.AddText2Table(detailTable, state.NinetySixPct.ToString("0.0000"), _normalFont, "right");
                    PdfReports.AddText2Table(detailTable, state.RatePerTon.ToString("0.0000"), _normalFont, "right");

                    index += 1;
                }

                // Add Sub Totals
                PdfReports.AddText2Table(detailTable, " ", _normalFont, "center");
                //PdfReports.AddText2Table(detailTable, " ", _normalFont, "center");
                PdfReports.AddText2Table(detailTable, "Total", _labelFont, "center");

                PdfReports.AddText2Table(detailTable, Math.Round(subTotalPayAmt, 2).ToString("0.00"), _labelFont, "right");
                PdfReports.AddText2Table(detailTable, subTotalFirstNetTons.ToString("0.0000"), _labelFont, "right");
                PdfReports.AddText2Table(detailTable, " ", _normalFont, "center");

                PdfReports.AddText2Table(detailTable, " ", _normalFont, "center");
                PdfReports.AddText2Table(detailTable, subTotalNinetySixPct.ToString("0.0000"), _labelFont, "right");
                PdfReports.AddText2Table(detailTable, " ", _normalFont, "right");
            }
            catch (Exception ex) {
                WSCIEMP.Common.CException wex = new WSCIEMP.Common.CException(MOD_NAME + METHOD_NAME, ex);
                throw (wex);
            }
        }
Пример #2
0
        private static void CalcSubTotals(List <ListDirectDeliveryStatementItem> stateList, int index, out decimal firstNetTons, out decimal ninetySixPct, out decimal payAmt)
        {
            const string METHOD_NAME = "CalcSubTotals";

            int    maxIndex = stateList.Count;
            string payee    = stateList[index].Payee;
            ListDirectDeliveryStatementItem state = null;

            firstNetTons = 0;
            ninetySixPct = 0;
            payAmt       = 0;

            try {
                while (index < maxIndex && stateList[index].Payee == payee)
                {
                    state         = stateList[index];
                    firstNetTons += state.FirstNetTons;
                    ninetySixPct += state.NinetySixPct;
                    payAmt       += state.PaymentAmount;

                    index += 1;
                }
            }
            catch (Exception ex) {
                WSCIEMP.Common.CException wex = new WSCIEMP.Common.CException(MOD_NAME + METHOD_NAME, ex);
                throw (wex);
            }
        }
Пример #3
0
        private static void ReportBuilder(int cropYear, DateTime fromDate, DateTime toDate, string shid, string filePath, string logoUrl, System.IO.FileStream fs)
        {
            const string METHOD_NAME = "ReportBuilder: ";

            string  lastPayee = "";
            decimal subTotalPayAmt;
            decimal subTotalNinetySixPct;
            decimal subTotalFirstNetTons;
            string  rptTitle = cropYear.ToString() + " Direct Deliveries";

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

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

            try {
                List <ListDirectDeliveryStatementItem> stateList = RptDirectDeliveryStatementData(cropYear, fromDate, toDate, shid);

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

                    if (document == null)
                    {
                        lastPayee = state.Payee;
                        CalcSubTotals(stateList, i, out subTotalFirstNetTons, out subTotalNinetySixPct, out subTotalPayAmt);

                        // 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 DirectDeliveryStatementEvent();
                        pgEvent.FillEvent(state.Shid, state.BusinessName, state.AddrLine1, state.AddrLine2, state.CSZ, subTotalPayAmt, 0, rptTitle, imgLogo);
                        writer.PageEvent = pgEvent;

                        // Open the document
                        document.Open();

                        bodyTable   = PdfReports.CreateTable(_bodyTableLayout, 0);
                        detailTable = PdfReports.CreateTable(_detailTableLayout, 0);

                        AddBodyText(bodyTable, cropYear, fromDate.ToString(HEADER_DATE_FORMAT), toDate.ToString(HEADER_DATE_FORMAT), state.Payee);
                        AddDetailTable(detailTable, stateList, i, subTotalFirstNetTons, subTotalNinetySixPct, subTotalPayAmt);

                        PdfReports.AddTableNoSplit(document, pgEvent, bodyTable);
                        PdfReports.AddTableNoSplit(document, pgEvent, detailTable);
                    }


                    if (lastPayee != state.Payee)
                    {
                        //-------------------------------------------------------------------------------------
                        // When you change members, kick out the page and move on to the next member,
                        // and reset flags.
                        //-------------------------------------------------------------------------------------

                        lastPayee = state.Payee;

                        bodyTable   = PdfReports.CreateTable(_bodyTableLayout, 0);
                        detailTable = PdfReports.CreateTable(_detailTableLayout, 0);

                        CalcSubTotals(stateList, i, out subTotalFirstNetTons, out subTotalNinetySixPct, out subTotalPayAmt);

                        pgEvent.FillEvent(state.Shid, state.BusinessName, state.AddrLine1, state.AddrLine2, state.CSZ, subTotalPayAmt, 0, rptTitle, imgLogo);
                        document.NewPage();

                        AddBodyText(bodyTable, cropYear, fromDate.ToString(HEADER_DATE_FORMAT), toDate.ToString(HEADER_DATE_FORMAT), state.Payee);
                        AddDetailTable(detailTable, stateList, i, subTotalFirstNetTons, subTotalNinetySixPct, subTotalPayAmt);

                        PdfReports.AddTableNoSplit(document, pgEvent, bodyTable);
                        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();
                }
            }
        }