Beispiel #1
0
        public static void xPrint(int printCount, bool isHighResolution)
        {
            if (doc.Printer.IsPrinterOnline(_printer))
            {
                var mediaID   = doc.GetMediaId();
                var mediaName = doc.GetMediaName();

                for (int i = 0; i < printCount; i++)
                {
                    doc.DoPrint(isHighResolution ? PrintOptionConstants.bpoHighResolution : PrintOptionConstants.bpoAutoCut, "0");
                }


                return;
            }

            throw new Exception("No supported printer detected.");
        }
        private ToPrint PrinterErrorCheck(string Location)
        {
            var           error    = -1;
            DocumentClass document = new DocumentClass();

            try
            {
                document.Open(Location);

                object[] printers = (object[])document.Printer.GetInstalledPrinters();
                Console.WriteLine("Printers Found");
                foreach (var printer in printers)
                {
                    Console.WriteLine(printer);
                }
                Console.WriteLine("End Printers Found");
                string TemplateMedia = document.GetMediaName();
                string PrinterMedia  = document.Printer.GetMediaName();
                Console.WriteLine("Template Media: " + TemplateMedia + ", Printer Media: " + PrinterMedia);

                if (printers.Length == 0)
                {
                    error = 4258;
                    document.Close();
                    var result = (DialogResult)PMessageBox.Show("Error: e" + error + "No printer aviliable" + ": refer wiki > e" + error,
                                                                "fault in Printers", MessageBoxButtons.RetryCancel);
                    if (result == DialogResult.Retry)
                    {
                        return(ToPrint.Retry);
                    }
                    return(ToPrint.No);
                }
                else if (printers.Length > 0)
                {
                    if (!document.Printer.IsPrinterOnline(printers[0].ToString()))
                    {
                        error = 4261;
                        document.Close();
                        var result = (DialogResult)PMessageBox.Show("Error: e" + error + "\nTheres printer connected" +
                                                                    "\nRefer wiki > e" + error, "No printer connection", MessageBoxButtons.RetryCancel);
                        if (result == DialogResult.Retry)
                        {
                            return(ToPrint.Retry);
                        }
                        return(ToPrint.No);
                    }
                    else if (TemplateMedia != PrinterMedia)
                    {
                        if (PrinterMedia == "")
                        {
                            error = 3465;
                            document.Close();
                            var result = (DialogResult)PMessageBox.Show("Error: e" + error + "No media installed in connected printer" + ": refer wiki > e" + error,
                                                                        "Check Printers", MessageBoxButtons.RetryCancel);
                            if (result == DialogResult.Retry)
                            {
                                return(ToPrint.Retry);
                            }
                            return(ToPrint.No);
                        }
                        else
                        {
                            error = 3461;
                            document.Close();
                            var result = (DialogResult)PMessageBox.Show("Error: e" + error + "\nMedia installed in printer: " + PrinterMedia +
                                                                        "\nIs not equal to document media: " + TemplateMedia + "\nMake sure media in printer is: " + TemplateMedia + "\nRefer wiki > e" + error,
                                                                        "Check Media", MessageBoxButtons.RetryCancel);
                            if (result == DialogResult.Retry)
                            {
                                return(ToPrint.Retry);
                            }
                            return(ToPrint.No);
                        }
                    }
                    error = -1;
                    document.Close();
                    return(ToPrint.Yes);
                }
                return(ToPrint.No);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                error = 4261;
                document.Close();
                var result = (DialogResult)PMessageBox.Show("Error: e" + error + "No Brother printer connected found" + ": refer wiki > e" + error,
                                                            "Check Printers", MessageBoxButtons.RetryCancel);
                if (result == DialogResult.Retry)
                {
                    return(ToPrint.Retry);
                }
                return(ToPrint.No);
            }
        }