Exemplo n.º 1
0
        private void butPostcards_Click(object sender, EventArgs e)
        {
            if (!validDateFrom.IsValid || !validDateTo.IsValid)
            {
                MsgBox.Show(this, "Please fix data entry errors first.");
                return;
            }
            DateTime dateFrom = PIn.Date(validDateFrom.Text);
            DateTime dateTo   = PIn.Date(validDateTo.Text);

            if (dateTo < dateFrom)
            {
                MsgBox.Show(this, "To date cannot be before From date.");
                return;
            }
            if (dateFrom.AddYears(1) <= dateTo)
            {
                MsgBox.Show(this, "Date range must not exceed 1 year.");
                return;
            }
            BirthdayTable = RpBirthday.GetBirthdayTable(dateFrom, dateTo);
            if (BirthdayTable.Rows.Count == 0)
            {
                MsgBox.Show(this, "No postcards to preview.");
                return;
            }
            pagesPrinted    = 0;
            patientsPrinted = 0;
            PaperSize           paperSize;
            PrintoutOrientation orient = PrintoutOrientation.Default;

            if (PrefC.GetLong(PrefName.RecallPostcardsPerSheet) == 1)
            {
                paperSize = new PaperSize("Postcard", 400, 600);
                orient    = PrintoutOrientation.Landscape;
            }
            else if (PrefC.GetLong(PrefName.RecallPostcardsPerSheet) == 3)
            {
                paperSize = new PaperSize("Postcard", 850, 1100);
            }
            else              //4
            {
                paperSize = new PaperSize("Postcard", 850, 1100);
                orient    = PrintoutOrientation.Landscape;
            }
            int totalPages = (int)Math.Ceiling((double)BirthdayTable.Rows.Count / (double)PrefC.GetLong(PrefName.RecallPostcardsPerSheet));

            PrinterL.TryPreview(pdCards_PrintPage,
                                Lan.g(this, "Birthday report postcards printed"),
                                PrintSituation.Postcard,
                                new Margins(0, 0, 0, 0),
                                PrintoutOrigin.AtMargin,
                                paperSize,
                                orient,
                                totalPages
                                );
        }
Exemplo n.º 2
0
        private void butPrint_Click(object sender, EventArgs e)
        {
            curPrintPage = 0;
            PrintoutOrientation orient = (landscape?PrintoutOrientation.Landscape:PrintoutOrientation.Portrait);

            if (PrinterL.TryPrint(pd1_PrintPage, printoutOrigin: PrintoutOrigin.AtMargin, printoutOrientation: orient))
            {
                numTimesPrinted++;
            }
            printerGraph = null;
            Display();
        }
Exemplo n.º 3
0
        ///<summary>Attempts to print a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
        ///<param name="printPageEventHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditPatNum">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<param name="duplex">Use default unless double-sided printing is required.</param>
        ///<returns>Returns true if succesfully printed.</returns>
        public static bool TryPrint(PrintPageEventHandler printPageEventHandler, string auditDescription = "", long auditPatNum = 0
                                    , PrintSituation printSit = PrintSituation.Default, Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default
                                    , PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, Duplex duplex = Duplex.Default)
        {
            ODprintout printout = new ODprintout(
                printPageEventHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                printoutOrientation: printoutOrientation,
                duplex: duplex
                );

            return(TryPrint(printout));
        }
Exemplo n.º 4
0
        private void Print_Click()
        {
            _pagesPrinted   = 0;
            _headingPrinted = false;
            gridMainPrint   = new ODGrid()
            {
                Width = 1050, TranslationName = "", HideScrollBars = true
            };
            FillGrid(isPrinting: true);           //not nessecary to explicity name parameter but makes code easier to read.
            PrintoutOrientation orient = PrintoutOrientation.Default;

            if (gridMainPrint.WidthAllColumns > 800)
            {
                orient = PrintoutOrientation.Landscape;
            }
            PrinterL.TryPrintOrDebugRpPreview(pd2_PrintPage,
                                              Lan.g(this, "Accounting transaction history for") + " " + _acctCur.Description + " " + Lan.g(this, "printed"),
                                              printoutOrientation: orient
                                              );
        }
Exemplo n.º 5
0
        ///<summary>Attempts to print if in RELEASE mode or if in DEBUG mode will open ODprintout in FormRpPrintPreview.</summary>
        ///<param name="printPageHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditPatNum">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<returns>Returns true if succesfully printed, or if preview is shown and OK is clicked.</returns>
        public static bool TryPrintOrDebugRpPreview(PrintPageEventHandler printPageHandler, string auditDescription
                                                    , PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, PrintSituation printSit = PrintSituation.Default, long auditPatNum = 0
                                                    , Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default, bool isForcedPreview = false)
        {
            ODprintout printout = new ODprintout(
                printPageHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                printoutOrientation: printoutOrientation,
                duplex: Duplex.Default
                );

            if (ODBuild.IsDebug() || isForcedPreview)
            {
                return(RpPreview(printout));
            }
            return(TryPrint(printout));
        }
Exemplo n.º 6
0
        ///<summary>Attempts to print if in RELEASE mode or if in DEBUG mode will open ODprintout in FormPrintPreview.</summary>
        ///<param name="printPageEventHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<returns>Returns true if succesfully printed, or if preview is shown and OK is clicked.</returns>
        public static bool TryPrintOrDebugClassicPreview(PrintPageEventHandler printPageEventHandler, string auditDescription, Margins margins = null
                                                         , int totalPages = 1, PrintSituation printSit = PrintSituation.Default, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default
                                                         , PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, bool isForcedPreview = false, long auditPatNum = 0, PaperSize paperSize = null)
        {
            ODprintout printout = new ODprintout(
                printPageEventHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                paperSize,
                printoutOrientation,
                totalPages: totalPages
                );

            if (ODBuild.IsDebug() || isForcedPreview)
            {
                return(PreviewClassic(printout));
            }
            return(TryPrint(printout));
        }
Exemplo n.º 7
0
        ///<summary>Gets a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
        ///<param name="printPageHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditPatNum">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="paperSize">When set, this will override the default paperSize of "new PaperSize("default",850,1100)".</param>
        ///<param name="totalPages">When creating an ODprintout for print previewing, this defines the total number of pages.  Required if multiple pages needed when using Classic printing in FormPrintPreview.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<param name="duplex">Use default unless double-sided printing is required.</param>
        ///<param name="copies">Gets or sets the number of copies of the document to print.</param>
        ///<returns>A new ODprintout with the given args that serves as a conduit for centralized printing and previewing methods with nice error messages.</returns>
        public static ODprintout CreateODprintout(PrintPageEventHandler printPageHandler = null, string auditDescription = ""
                                                  , PrintSituation printSit = PrintSituation.Default, long auditPatNum   = 0, Margins margins   = null, PrintoutOrigin printoutOrigin        = PrintoutOrigin.Default
                                                  , PaperSize paperSize     = null, int totalPages = 1, PrintoutOrientation printoutOrientation = PrintoutOrientation.Default, Duplex duplex = Duplex.Default, short copies = 1
                                                  , bool isErrorSuppressed  = false)
        {
            ODprintout printout = new ODprintout(
                printPageHandler,
                printSit,
                auditPatNum,
                auditDescription,
                margins,
                printoutOrigin,
                paperSize,
                printoutOrientation,
                duplex,
                copies,
                totalPages
                );

            if (!isErrorSuppressed && printout.SettingsErrorCode != PrintoutErrorCode.Success)
            {
                ShowError(printout);
            }
            return(printout);
        }
Exemplo n.º 8
0
        ///<summary>Attempts to preview (FormPrintPreview) a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
        ///<param name="printPageHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
        ///<param name="auditDescription">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="printSit">ODprintout does not do anything with this field.  But when PrinterL.TrySetPrinter() is invoked we will provide the information if needed.</param>
        ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
        ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
        ///<param name="paperSize">When set, this will override the default paperSize of "new PaperSize("default",850,1100)".</param>
        ///<param name="totalPages">When creating an ODprintout for print previewing, this defines the total number of pages.</param>
        ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
        ///<returns>Returns true if preview is shown and OK is clicked.</returns>
        public static bool TryPreview(PrintPageEventHandler printPageHandler, string auditDescription, PrintSituation printSit = PrintSituation.Default
                                      , Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default, PaperSize paperSize = null, PrintoutOrientation printoutOrientation = PrintoutOrientation.Default
                                      , int totalPages  = 1)
        {
            ODprintout printout = new ODprintout(
                printPageHandler,
                printSit,
                auditDescription: auditDescription,
                margins: margins,
                printoutOrigin: printoutOrigin,
                paperSize: paperSize,
                printoutOrientation: printoutOrientation,
                totalPages: totalPages
                );

            return(PreviewClassic(printout));
        }
Exemplo n.º 9
0
 ///<summary>Gets a PrintDocument that has some added functionality.  All printing in Open Dental should use this method (or an ODprintout object) for printing.</summary>
 ///<param name="printPageEventHandler">The handler that will get invoked when printing.  This defines how to draw each page.</param>
 ///<param name="printSit">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed.</param>
 ///<param name="auditPatNum">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed.</param>
 ///<param name="auditDescription">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed.</param>
 ///<param name="margins">When set, this will override the default margins of "new Margins(25,25,40,40)".</param>
 ///<param name="printoutOrigin">Defaults to printer default.  Set to AtMargin if the graphics origin starts at the page margins; AtZero if the graphics origin is at the top-left corner of the printable page.</param>
 ///<param name="paperSize">When set, this will override the default paperSize of "new PaperSize("default",850,1100)".</param>
 ///<param name="totalPages">When creating an ODprintout for print previewing, this defines the total number of pages.</param>
 ///<param name="printoutOrientation">Defaults to printers default value.  Otherwise specify a value for either landscape or portrait.</param>
 ///<param name="duplex">Typically set when performing double-sided printing.</param>
 ///<param name="copies">Gets or sets the number of copies of the document to print.</param>
 ///<param name="totalPages">ODprintout does not do anything with this field. But when ValidationDelegate is invoked we will provide the information if needed. Defaults to 1.</param>
 ///<param name="printOrPreviewExceptionDelegate">Any custom delegate that the calling method wants to happen when printing or previewing throws an exception.</param>
 ///<param name="tryPreviewDelegate">Required to be implemented if the calling method needs the ability to preview.</param>
 ///<param name="tryPrintOrDebugPreviewDelegate">Same as tryPreviewDelegate, but defines isPreview based on if program is in DEBUG mode.</param>
 ///<returns>A new ODprintout with the given args that serves as a conduit safe printing and previewing methods.</returns>
 public ODprintout(PrintPageEventHandler printPageEventHandler = null, PrintSituation printSit = PrintSituation.Default, long auditPatNum = 0, string auditDescription   = ""
                   , Margins margins = null, PrintoutOrigin printoutOrigin = PrintoutOrigin.Default, PaperSize paperSize = null, PrintoutOrientation printoutOrientation = PrintoutOrientation.Default
                   , Duplex duplex   = Duplex.Default, short copies        = 1, int totalPages = 1) : base()
 {
     CurPrintout = this;
     _printDoc   = new PrintDocument();
     //if(InitPrintSettings!=null) {
     //	_printDoc.PrinterSettings=InitPrintSettings;
     //	InitPrintSettings=null;
     //}
     Situation        = printSit;
     AuditPatNum      = auditPatNum;
     AuditDescription = auditDescription;
     TotalPages       = totalPages;
     if (!HasValidSettings)
     {
         return;
     }
     _printDoc.PrintPage += printPageEventHandler;
     if (printoutOrientation != PrintoutOrientation.Default)
     {
         _printDoc.DefaultPageSettings.Landscape = (printoutOrientation == PrintoutOrientation.Landscape)?true:false;
     }
     if (printoutOrigin != PrintoutOrigin.Default)
     {
         _printDoc.OriginAtMargins = (printoutOrigin == PrintoutOrigin.AtMargin)?true:false;
     }
     _printDoc.DefaultPageSettings.Margins = (margins ?? new Margins(25, 25, 40, 40));
     if (paperSize == null)
     {
         //This prevents a bug caused by some printer drivers not reporting their papersize.
         //But remember that other countries use A4 paper instead of 8 1/2 x 11.
         if ((InvalidMinDefaultPageWidth != -1 && _printDoc.DefaultPageSettings.PrintableArea.Width <= InvalidMinDefaultPageWidth) ||
             (InvalidMinDefaultPageHeight != -1 && _printDoc.DefaultPageSettings.PrintableArea.Height <= InvalidMinDefaultPageHeight))
         {
             _printDoc.DefaultPageSettings.PaperSize = new PaperSize("default", 850, 1100);
         }
         InvalidMinDefaultPageHeight = 0;
         InvalidMinDefaultPageWidth  = -1;
     }
     else
     {
         _printDoc.DefaultPageSettings.PaperSize = paperSize;
     }
     _printDoc.PrinterSettings.Copies = copies;
     if (duplex != Duplex.Default)
     {
         _printDoc.PrinterSettings.Duplex = duplex;
     }
     if (ODBuild.IsWeb())
     {
         //https://referencesource.microsoft.com/#System.Drawing/commonui/System/Drawing/Printing/PrintDocument.cs,3f3c2622b65be86a
         //The PrintController property will create a PrintControllerWithStatusDialog if no print controller is explictly set.
         _printDoc.PrintController = new StandardPrintController();              //Default PrintController shows a dialog that locks up web.
     }
 }