public void Setup()
 {
     pfiMailerDocument = new PFIMailerDocument(PdfLauncher.Instance);
     reportObject      = new ReportObject
     {
         ReportTempFileFullName = Path.Combine(Environment.CurrentDirectory, "PFIMailer.pdf")
     };
     pfiMailerDocument.ReportObject = reportObject;
 }
        private void PrintPFIMailers(PFIMailerOption pfiMailerOption)
        {
            //Create output variables
            string errorCode;
            string errorText;

            var businessRulesProcedures = new BusinessRulesProcedures(GlobalDataAccessor.Instance.DesktopSession);
            var pfiMailerAdjustmentDays = businessRulesProcedures.GetNumberOfDaysToAddForPFIMailer(GlobalDataAccessor.Instance.CurrentSiteId);

            var pfiMailerList = new List <ReportObject.PFIMailer>();
            var pfiMailerFilesToDeleteList = new List <String>();

            var retVal = false;

            switch (pfiMailerOption)
            {
            case PFIMailerOption.PrintPFIMailers:
                retVal = PawnProcedures.ExecuteGetPFIMailerData(GlobalDataAccessor.Instance.OracleDA,
                                                                pfiMailerOption,
                                                                out pfiMailerList,
                                                                out errorCode,
                                                                out errorText,
                                                                pfiMailerAdjustmentDays,
                                                                pfiDate: ShopDateTime.Instance.ShopDate);
                break;

            case PFIMailerOption.ReprintMailbook:
                retVal = PawnProcedures.ExecuteGetPFIMailerData(GlobalDataAccessor.Instance.OracleDA,
                                                                pfiMailerOption,
                                                                out pfiMailerList,
                                                                out errorCode,
                                                                out errorText,
                                                                pfiDate: Utilities.GetDateTimeValue(this.dateReprintMailbook.SelectedDate));
                break;

            case PFIMailerOption.ReprintPFIMailersByDate:
                retVal = PawnProcedures.ExecuteGetPFIMailerData(GlobalDataAccessor.Instance.OracleDA,
                                                                pfiMailerOption,
                                                                out pfiMailerList,
                                                                out errorCode,
                                                                out errorText,
                                                                pfiDate: Utilities.GetDateTimeValue(this.dateReprintMailers.SelectedDate));
                break;

            case PFIMailerOption.ReprintPFIMailersByTicket:
                retVal = PawnProcedures.ExecuteGetPFIMailerData(GlobalDataAccessor.Instance.OracleDA,
                                                                pfiMailerOption,
                                                                out pfiMailerList,
                                                                out errorCode,
                                                                out errorText,
                                                                startTicketNumber: Utilities.GetIntegerValue(this.txtBeginTicket.Text),
                                                                endTicketNumber: Utilities.GetIntegerValue(this.txtEndTicket.Text),
                                                                pfiDate: Utilities.GetDateTimeValue(this.dateTicketRange.SelectedDate));
                break;

            case PFIMailerOption.GetTodaysPrintedPFIMailerTickets:
                retVal = PawnProcedures.ExecuteGetPFIMailerData(
                    GlobalDataAccessor.Instance.OracleDA,
                    pfiMailerOption,
                    out pfiMailerList,
                    out errorCode,
                    out errorText,
                    pfiDate: Utilities.GetDateTimeValue(this.dateTicketRange.SelectedDate));
                break;

            default:
                System.Diagnostics.Debug.Assert(false, "Unexpected Default case. Forget to add handler?");
                break;
            }

            if (retVal)
            {
                if (pfiMailerOption == PFIMailerOption.GetTodaysPrintedPFIMailerTickets)
                {
                    if (pfiMailerList.Count > 0)
                    {
                        txtBeginTicket.Text = pfiMailerList[0].ticketNumber.ToString();
                        txtEndTicket.Text   = pfiMailerList[pfiMailerList.Count - 1].ticketNumber.ToString();
                    }
                }
                else if (pfiMailerOption == PFIMailerOption.ReprintMailbook)
                {
                    PrintMailingBook(pfiMailerFilesToDeleteList, pfiMailerList);
                    MessageBox.Show(@"PFI Mailbook Printing Complete");
                }
                else
                {
                    if (DisplayPrintPFIMailersConfirmationBox(pfiMailerList.Count, PFIMailerOption.ReprintPFIMailersByTicket == pfiMailerOption))
                    {
                        if (pfiMailerList.Count > 0)
                        {
                            var mailFee = businessRulesProcedures.GetPFIMailerFee(GlobalDataAccessor.Instance.CurrentSiteId);

                            var ticketNumberList    = new List <int>();
                            var originalPFINoteList = new List <DateTime>();
                            var pfiEligibleDateList = new List <DateTime>();

                            var pfiMailerFileNamesToMerge = new List <String>();
                            var recordCount = 1;
                            foreach (var pfiMailer in pfiMailerList)
                            {
                                var pfiMailerLocal = pfiMailer;

                                if (pfiMailerOption == PFIMailerOption.PrintPFIMailers)
                                // Spec Change
                                //pfiMailerOption == PFIMailerOption.ReprintPFIMailersByTicket ||
                                //pfiMailerOption == PFIMailerOption.ReprintPFIMailersByDate)
                                {
                                    //
                                    pfiMailerLocal.pfiEligibleDate = GetPFIEligibleDate();

                                    //process pfi eligible date adjustment
                                    if (ShopDateTime.Instance.ShopDate > pfiMailerLocal.originalPFINote)
                                    {
                                        // Special Rule PWN_BR-33 Adjustment
                                        pfiMailerLocal.pfiEligibleDate = GetPFIDateAdjustmentRule33(pfiMailerLocal.pfiEligibleDate);
                                    }

                                    //PawnProcedures.ExecuteUpdatePFIMailerData(
                                    //    GlobalDataAccessor.Instance.OracleDA,
                                    //    out errorCode,
                                    //    out errorText,
                                    //    pfiMailerLocal.storeNumber,
                                    //    pfiMailerLocal.ticketNumber,
                                    //    mailFee,
                                    //    pfiMailerLocal.originalPFINote,
                                    //    "Y",
                                    //    pfiEligibleDate);

                                    ticketNumberList.Add(pfiMailerLocal.ticketNumber);
                                    originalPFINoteList.Add(pfiMailerLocal.originalPFINote);
                                    pfiEligibleDateList.Add(pfiMailerLocal.pfiEligibleDate);
                                }

                                var pfiMailerDocument = new PFIMailerDocument(PdfLauncher.Instance);
                                var pfiMailerFileName = "PFIMailer" + recordCount + ".pdf";

                                var reportObject = new ReportObject
                                {
                                    ReportTempFileFullName =
                                        Path.Combine(
                                            SecurityAccessor.Instance.EncryptConfig.ClientConfig.GlobalConfiguration.BaseLogPath,
                                            pfiMailerFileName)
                                };

                                pfiMailerDocument.ReportObject = reportObject;

                                pfiMailerDocument.CreateReport(pfiMailerLocal);

                                if (FileLogger.Instance.IsLogInfo)
                                {
                                    FileLogger.Instance.logMessage(
                                        LogLevel.INFO, "PFI_Mailers", "Creating PFI Mailer {0}, Ticket Number {1}",
                                        pfiMailerFileName, pfiMailer.ticketNumber);
                                }

                                //var strReturnMessage =
                                //    PrintingUtilities.printDocument(
                                //        reportObject.ReportTempFileFullName,
                                //        GlobalDataAccessor.Instance.DesktopSession.LaserPrinter.IPAddress,
                                //        GlobalDataAccessor.Instance.DesktopSession.LaserPrinter.Port, 1);
                                //
                                //if (!strReturnMessage.Contains("SUCCESS"))
                                //{
                                //    FileLogger.Instance.logMessage(LogLevel.ERROR, this, "PFI Mailer : " + strReturnMessage);
                                //}

                                pfiMailerFileNamesToMerge.Add(Path.Combine(SecurityAccessor.Instance.EncryptConfig.ClientConfig.GlobalConfiguration.BaseLogPath, pfiMailerFileName));
                                recordCount++;
                            } // foreach (var pfiMailer in pfiMailerList)

                            // Merge PFIMailerX.pdf doc's
                            var mergedOutputFile      = Path.Combine(SecurityAccessor.Instance.EncryptConfig.ClientConfig.GlobalConfiguration.BaseLogPath, "PFIMailer.pdf");
                            var wasPDFMergeSuccessful = PDFITextSharpUtilities.MergePDFFiles(mergedOutputFile, pfiMailerFileNamesToMerge.ToArray());

                            if (wasPDFMergeSuccessful)
                            {
                                var strReturnMessage =
                                    PrintingUtilities.printDocument(
                                        mergedOutputFile,
                                        GlobalDataAccessor.Instance.DesktopSession.LaserPrinter.IPAddress,
                                        GlobalDataAccessor.Instance.DesktopSession.LaserPrinter.Port, 1);

                                if (FileLogger.Instance.IsLogInfo)
                                {
                                    FileLogger.Instance.logMessage(
                                        LogLevel.INFO, "PFI_Mailers", "Printing PFI Mailer {0}",
                                        mergedOutputFile);
                                }

                                if (!strReturnMessage.Contains("SUCCESS"))
                                {
                                    FileLogger.Instance.logMessage(LogLevel.ERROR, this, "PFI Mailer : " + strReturnMessage);
                                }
                            }

                            if (pfiMailerOption == PFIMailerOption.PrintPFIMailers)
                            {
                                PawnProcedures.ExecuteAddPFIMailerDataArray(
                                    GlobalDataAccessor.Instance.OracleDA,
                                    out errorCode,
                                    out errorText,
                                    int.Parse(GlobalDataAccessor.Instance.DesktopSession.CurrentSiteId.StoreNumber),
                                    ticketNumberList,
                                    originalPFINoteList,
                                    pfiEligibleDateList,
                                    mailFee);
                            }

                            // Spec Change
                            //else if (pfiMailerOption == PFIMailerOption.ReprintPFIMailersByDate ||
                            //         pfiMailerOption == PFIMailerOption.ReprintPFIMailersByTicket)
                            //{
                            //    PawnProcedures.ExecuteAddPFIMailerDataArray(
                            //        GlobalDataAccessor.Instance.OracleDA,
                            //        out errorCode,
                            //        out errorText,
                            //        int.Parse(GlobalDataAccessor.Instance.DesktopSession.CurrentSiteId.StoreNumber),
                            //        ticketNumberList,
                            //        originalPFINoteList,
                            //        pfiEligibleDateList,
                            //        mailFee);
                            //}

                            // Spec Change
                            //if (pfiMailerOption != PFIMailerOption.ReprintPFIMailersByTicket)
                            {
                                PrintMailingBook(pfiMailerFilesToDeleteList, pfiMailerList);
                            }
                        }
                    }
                }
            }
            else
            {
                if (pfiMailerOption == PFIMailerOption.ReprintMailbook)
                {
                    MessageBox.Show(@"There is no Mail Book for this date.");
                }
                //else if (pfiMailerOption == PFIMailerOption.GetTodaysPrintedPFIMailerTickets)
                //{
                //    MessageBox.Show(@"There are no PFI Mailers to be printed for this ticket range.");
                //}
                else
                {
                    MessageBox.Show(@"There are no PFI Mailers to be printed for this date.");
                }
            }
        }