Exemple #1
0
        public static bool SendStringToPrinter(string szString)
        {
            IntPtr pBytes;
            Int32  dwCount;
            IntPtr hPrinter = new IntPtr(0);

            var strPrintName = ConfigRegistryHelper.GetConfiguredPrinter("PrintMealTicket");

            if (string.IsNullOrEmpty(strPrintName))
            {
                UIHelper.ShowMessage("The meal ticket printer is not configured.");
                return(false);
            }
            var lreturn = OpenPrinter(strPrintName, out hPrinter, new IntPtr());

            if (!lreturn)
            {
                UIHelper.ShowMessage("The Printer name you typed wasn't recognized.");
                return(false);
            }
            // How many characters are in the string?
            dwCount = szString.Length;
            // Assume that the printer is expecting ANSI text, and then convert
            // the string to ANSI text.
            pBytes = Marshal.StringToCoTaskMemAnsi(szString);
            // Send the converted ANSI string to the printer.
            SendBytesToPrinter(strPrintName, pBytes, dwCount);
            Marshal.FreeCoTaskMem(pBytes);
            ClosePrinter(hPrinter);
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Muestra el reporte en un mediante el visor de Crystal Reports o
        /// manda a imprimir el reporte directamente a la impresora configurada.
        /// </summary>
        /// <param name="report"> Documento .rpt </param>
        /// <param name="reportName"> Nombre del reporte. </param>
        /// <param name="isDialog"> Se mostrará en una ventana tipo Dialogo. </param>
        /// <param name="owner"> Ventana Principal que utiliza el visor. </param>
        /// <param name="isDirectPrint"> Bandera de impresion directa. </param>
        /// <history>
        /// [edgrodriguez] 16/Jul/2016 Created
        /// </history>
        public static void ShowReport(ReportDocument report, string reportName = "", bool isDialog = false, Window owner = null, EnumPrintDevice PrintDevice = EnumPrintDevice.pdScreen, bool IsInvitation = false, int numCopies = 1)
        {
            switch (PrintDevice)
            {
            case EnumPrintDevice.pdPrinter:
                var boPrintReportOptions = new PrintReportOptions();
                boPrintReportOptions.PrinterName = (IsInvitation) ? ConfigRegistryHelper.GetConfiguredPrinter("PrintInvit") : boPrintReportOptions.PrinterName;
                if (IsInvitation && string.IsNullOrEmpty(boPrintReportOptions.PrinterName))
                {
                    UIHelper.ShowMessage($"The printer is not configured, please configure your printer.");
                    return;
                }
                var boReportClientDocument  = report.ReportClientDocument;
                var boPrintOutputController = boReportClientDocument.PrintOutputController;

                boPrintReportOptions.JobTitle       = reportName;
                boPrintReportOptions.NumberOfCopies = numCopies;
                boPrintOutputController.PrintReport(boPrintReportOptions);
                break;

            case EnumPrintDevice.pdScreen:
                var crViewer = new frmViewer(report, reportName);
                crViewer.Owner = owner;
                if (isDialog)
                {
                    crViewer.ShowDialog();
                    break;
                }
                crViewer.Show();
                break;
            }
        }