private async Task <bool> PrintLine(string message, ClaimedPosPrinter claimedPrinter)
        {
            if (claimedPrinter == null)
            {
                rootPage.NotifyUser("Claimed printer object is null. Cannot print.", NotifyType.ErrorMessage);
                return(false);
            }

            if (claimedPrinter.Receipt == null)
            {
                rootPage.NotifyUser("No receipt printer object in claimed printer.", NotifyType.ErrorMessage);
                return(false);
            }

            ReceiptPrintJob job = claimedPrinter.Receipt.CreateJob();

            job.PrintLine(message);
            if (await job.ExecuteAsync())
            {
                rootPage.NotifyUser("Printed line", NotifyType.StatusMessage);
                return(true);
            }
            rootPage.NotifyUser("Was not able to print line", NotifyType.StatusMessage);
            return(false);
        }
コード例 #2
0
        /// <summary>
        /// Prints a sample receipt.
        /// </summary>
        private async Task <bool> PrintReceipt(Dictionary <string, double> receiptItems)
        {
            if (!IsPrinterClaimed())
            {
                return(false);
            }

            ReceiptPrintJob job = claimedPrinter.Receipt.CreateJob();

            job.PrintLine("======================");
            job.PrintLine("|   Sample Header    |");
            job.PrintLine("======================");

            job.PrintLine("Item             Price");
            job.PrintLine("----------------------");
            double total = 0.0;

            foreach (KeyValuePair <string, double> item in receiptItems)
            {
                job.PrintLine(string.Format("{0,-15} {1,6:##0.00}", item.Key, item.Value));
                total += item.Value;
            }
            job.PrintLine("----------------------");
            job.PrintLine(string.Format("Total-----------{0,6:##0.00}", total));

            ReceiptPrintJob merchantFooter = GetMerchantFooter(claimedPrinter);
            ReceiptPrintJob customerFooter = GetCustomerFooter(claimedPrinter);

            // execute print jobs
            // Note that we actually execute "job" twice in order to print
            // the statement for both the customer as well as the merchant.

            if (!await job.ExecuteAsync() ||
                !await customerFooter.ExecuteAsync() ||
                !await job.ExecuteAsync() ||
                !await merchantFooter.ExecuteAsync())
            {
                rootPage.NotifyUser("Failed to print receipts.", NotifyType.ErrorMessage);
                return(false);
            }
            rootPage.NotifyUser("Printed receipts.", NotifyType.StatusMessage);
            return(true);
        }
        /// <summary>
        /// Prints a sample receipt.
        /// </summary>
        private async Task <bool> PrintReceipt(Dictionary <string, double> receiptItems)
        {
            if (!IsPrinterClaimed())
            {
                return(false);
            }

            string receiptString = "======================\n" +
                                   "|   Sample Header    |\n" +
                                   "======================\n" +
                                   "Item             Price\n" +
                                   "----------------------\n";

            double total = 0.0;

            foreach (KeyValuePair <string, double> item in receiptItems)
            {
                receiptString += string.Format("{0,-15} {1,6:##0.00}\n", item.Key, item.Value);
                total         += item.Value;
            }
            receiptString += "----------------------\n";
            receiptString += string.Format("Total-----------{0,6:##0.00}\n", total);

            ReceiptPrintJob merchantJob    = claimedPrinter.Receipt.CreateJob();
            string          merchantFooter = GetMerchantFooter();

            PrintLineFeedAndCutPaper(merchantJob, receiptString + merchantFooter);

            ReceiptPrintJob customerJob    = claimedPrinter.Receipt.CreateJob();
            string          customerFooter = GetCustomerFooter();

            PrintLineFeedAndCutPaper(customerJob, receiptString + customerFooter);

            // execute print jobs
            // Note that we actually execute "job" twice in order to print
            // the statement for both the customer as well as the merchant.
            if (!(await merchantJob.ExecuteAsync()) ||
                !(await customerJob.ExecuteAsync()))
            {
                rootPage.NotifyUser("Failed to print receipts.", NotifyType.ErrorMessage);
                return(false);
            }
            rootPage.NotifyUser("Printed receipts.", NotifyType.StatusMessage);
            return(true);
        }
        private async Task <bool> PrintLine()
        {
            if (!IsPrinterClaimed())
            {
                return(false);
            }
            ReceiptPrintJob job = claimedPrinter.Receipt.CreateJob();

            job.PrintLine(txtPrintLine.Text);

            if (await job.ExecuteAsync())
            {
                rootPage.NotifyUser("Printed line", NotifyType.StatusMessage);
                return(true);
            }
            rootPage.NotifyUser("Was not able to print line", NotifyType.StatusMessage);
            return(false);
        }
        /// <summary>
        /// Prints the line that is in the textbox. Then checks for any error conditions and reports the same to user.
        /// </summary>
        private async Task <bool> PrintLineAndCheckForErrors()
        {
            if (!IsPrinterClaimed())
            {
                return(false);
            }
            ReceiptPrintJob job = claimedPrinter.Receipt.CreateJob();

            job.PrintLine(txtPrintLine.Text);

            if (await job.ExecuteAsync())
            {
                rootPage.NotifyUser("Printed line", NotifyType.StatusMessage);
                return(true);
            }
            else
            {
                if (claimedPrinter.Receipt.IsCartridgeEmpty)
                {
                    rootPage.NotifyUser("Printer is out of ink. Please replace cartridge.", NotifyType.StatusMessage);
                }
                else if (claimedPrinter.Receipt.IsCartridgeRemoved)
                {
                    rootPage.NotifyUser("Printer cartridge is missing. Please replace cartridge.", NotifyType.StatusMessage);
                }
                else if (claimedPrinter.Receipt.IsCoverOpen)
                {
                    rootPage.NotifyUser("Printer cover is open. Please close it.", NotifyType.StatusMessage);
                }
                else if (claimedPrinter.Receipt.IsHeadCleaning)
                {
                    rootPage.NotifyUser("Printer is currently cleaning the cartridge. Please wait until cleaning has completed.", NotifyType.StatusMessage);
                }
                else if (claimedPrinter.Receipt.IsPaperEmpty)
                {
                    rootPage.NotifyUser("Printer is out of paper. Please insert a new roll.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("Was not able to print line", NotifyType.StatusMessage);
                }
            }
            return(false);
        }
コード例 #6
0
        private async Task <bool> PrintBitmap()
        {
            if (!IsPrinterClaimed())
            {
                return(false);
            }
            claimedPrinter.Receipt.IsLetterQuality = true;
            ReceiptPrintJob job       = claimedPrinter.Receipt.CreateJob();
            BitmapFrame     logoFrame = await LoadLogoBitmapAsync();

            job.PrintBitmap(logoFrame, PosPrinterAlignment.Center);
            if (await job.ExecuteAsync())
            {
                rootPage.NotifyUser("Bitmap printed successfully", NotifyType.StatusMessage);
                return(true);
            }
            rootPage.NotifyUser("Was not able to print bitmap", NotifyType.ErrorMessage);
            return(false);
        }
コード例 #7
0
        async Task <bool> ExecuteJobAndReportResultAsync(ReceiptPrintJob job)
        {
            bool success = await job.ExecuteAsync();

            if (success)
            {
                rootPage.NotifyUser("Printing complete.", NotifyType.StatusMessage);
            }
            else
            {
                ClaimedReceiptPrinter receiptPrinter = rootPage.ClaimedPrinter.Receipt;
                string reason;
                if (receiptPrinter.IsCartridgeEmpty)
                {
                    reason = "Printer is out of ink. Please replace cartridge.";
                }
                else if (receiptPrinter.IsCartridgeRemoved)
                {
                    reason = "Printer cartridge is missing. Please replace cartridge.";
                }
                else if (receiptPrinter.IsCoverOpen)
                {
                    reason = "Printer cover is open. Please close it.";
                }
                else if (receiptPrinter.IsHeadCleaning)
                {
                    reason = "Printer is currently cleaning the cartridge. Please wait until cleaning has completed.";
                }
                else if (receiptPrinter.IsPaperEmpty)
                {
                    reason = "Printer is out of paper. Please insert a new roll.";
                }
                else
                {
                    reason = "Unable to print.";
                }
                rootPage.NotifyUser(reason, NotifyType.ErrorMessage);
            }
            return(success);
        }