Exemple #1
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);
        }
Exemple #2
0
 ///<summary>Whenever we are printing we should eventually go through this method.</summary>
 public static bool TryPrint(ODprintout printout)
 {
     if (!TrySetPrinter(printout))
     {
         return(false);
     }
     return(printout.TryPrint());
 }
Exemple #3
0
 ///<summary>This method is designed to be called every single time we print.  It helps figure out which printer to use, handles displaying dialogs if necessary,
 ///and tests to see if the selected printer is valid, and if not then it gives user the option to print to an available printer.
 ///Also creates an audit trail entry with the AuditDescription text that is set within printDocument.
 ///Debug mode will not display the print dialog but will instead prefer the default printer.</summary>
 public static bool TrySetPrinter(ODprintout printout)
 {
     if (printout.SettingsErrorCode != PrintoutErrorCode.Success)
     {
         ShowError(printout);
         return(false);
     }
     return(SetPrinter(printout.PrintDoc.PrinterSettings, printout.Situation, printout.AuditPatNum, printout.AuditDescription));
 }
 ///<summary></summary>
 public FormRpPrintPreview(ODprintout printout) : this()
 {
     if (printout.SettingsErrorCode != PrintoutErrorCode.Success)
     {
         PrinterL.ShowError(printout);
         this.DialogResult = DialogResult.Cancel;
         return;
     }
     _printPreviewControl2.Document = printout.PrintDoc;
 }
Exemple #5
0
 private static bool IsControlPreviewOverrideValid(ODprintout printout)
 {
     if (printout.SettingsErrorCode != PrintoutErrorCode.Success)           //Mimics how preview form handles errors.
     {
         ShowError(printout);
         return(false);
     }
     ControlPreviewOverride.Document = printout.PrintDoc;
     ControlPreviewOverride          = null;
     return(true);
 }
Exemple #6
0
        ///<summary>Launches FormPrintPreview for the given printDoc.  Returns true if dialog result was OK; Otherwise false.</returns>
        private static bool PreviewClassic(ODprintout printout)
        {
            if (ControlPreviewOverride != null)
            {
                return(IsControlPreviewOverrideValid(printout));
            }
            FormPrintPreview formPreview = new FormPrintPreview(printout);          //This form is self validating.

            formPreview.ShowDialog();
            formPreview.BringToFront();
            return(formPreview.DialogResult == DialogResult.OK);
        }
Exemple #7
0
        ///<summary>Launches FormRpPrintPreview for the given printDoc.  Returns true if dialog result was OK; Otherwise false.</returns>
        private static bool RpPreview(ODprintout printout)
        {
            if (ControlPreviewOverride != null)
            {
                return(IsControlPreviewOverrideValid(printout));
            }
            FormRpPrintPreview formPreview = new FormRpPrintPreview(printout);

            formPreview.ShowDialog();
            formPreview.BringToFront();
            return(formPreview.DialogResult == DialogResult.OK);
        }
Exemple #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));
        }
Exemple #9
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));
        }
        private void PrintReceipt(string receiptStr)
        {
            string[] receiptLines = receiptStr.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            MigraDoc.DocumentObjectModel.Document doc = new MigraDoc.DocumentObjectModel.Document();
            doc.DefaultPageSetup.PageWidth   = Unit.FromInch(3.0);
            doc.DefaultPageSetup.PageHeight  = Unit.FromInch(0.181 * receiptLines.Length + 0.56);     //enough to print receipt text plus 9/16 inch (0.56) extra space at bottom.
            doc.DefaultPageSetup.TopMargin   = Unit.FromInch(0.25);
            doc.DefaultPageSetup.LeftMargin  = Unit.FromInch(0.25);
            doc.DefaultPageSetup.RightMargin = Unit.FromInch(0.25);
            MigraDoc.DocumentObjectModel.Font bodyFontx = MigraDocHelper.CreateFont(8, false);
            bodyFontx.Name = FontFamily.GenericMonospace.Name;
            MigraDoc.DocumentObjectModel.Section section = doc.AddSection();
            Paragraph       par       = section.AddParagraph();
            ParagraphFormat parformat = new ParagraphFormat();

            parformat.Alignment = ParagraphAlignment.Left;
            parformat.Font      = bodyFontx;
            par.Format          = parformat;
            par.AddFormattedText(receiptStr, bodyFontx);
            MigraDoc.Rendering.Printing.MigraDocPrintDocument printdoc = new MigraDoc.Rendering.Printing.MigraDocPrintDocument();
            MigraDoc.Rendering.DocumentRenderer renderer = new MigraDoc.Rendering.DocumentRenderer(doc);
            renderer.PrepareDocument();
            printdoc.Renderer = renderer;
#if DEBUG
            FormRpPrintPreview pView = new FormRpPrintPreview(printdoc);
            pView.ShowDialog();
#else
            try {
                ODprintout printout = PrinterL.CreateODprintout(
                    printSit: PrintSituation.Receipt,
                    auditPatNum: _patCur.PatNum,
                    auditDescription: Lans.g(this, "PayConnect receipt printed")
                    );
                if (PrinterL.TrySetPrinter(printout))
                {
                    printdoc.PrinterSettings = printout.PrintDoc.PrinterSettings;
                    printdoc.Print();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(Lan.g(this, "Printer not available.") + "\r\n" + Lan.g(this, "Original error") + ": " + ex.Message);
            }
#endif
        }
Exemple #11
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));
        }
Exemple #12
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));
        }
Exemple #13
0
 ///<summary>Shows a translated error message in a MessageBox for the given printDoc.</summary>
 public static void ShowError(ODprintout printout)
 {
     ShowError(GetErrorStringFromCode(printout.SettingsErrorCode), printout.ErrorEx);
 }
 ///<summary>Uses the following ODprintout fields: Situation, TotalPages, AuditPatNum, AuditDescription.</summary>
 public FormPrintPreview(ODprintout printout)
 {
     InitializeComponent();            // Required for Windows Form Designer support
     _printout  = printout;
     TotalPages = printout.TotalPages;
 }