async void PrintReceipt_Click() { if (!IsPrinterClaimed()) { return; } string receiptString = "======================\n" + "| Sample Header |\n" + "======================\n" + "Item Price\n" + "----------------------\n" + "Books 10.40\n" + "Games 9.60\n" + "----------------------\n" + "Total 20.00\n"; rootPage.NotifyUser("Printing receipt...", NotifyType.StatusMessage); // The job consists of two receipts, one for the merchant and one // for the customer. ReceiptPrintJob job = rootPage.ClaimedPrinter.Receipt.CreateJob(); PrintLineFeedAndCutPaper(job, receiptString + GetMerchantFooter()); PrintLineFeedAndCutPaper(job, receiptString + GetCustomerFooter()); await ExecuteJobAndReportResultAsync(job); }
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); }
/// <summary> /// Prints the line that is in the textbox. /// </summary> async void PrintLine_Click() { if (!IsPrinterClaimed()) { return; } ReceiptPrintJob job = rootPage.ClaimedPrinter.Receipt.CreateJob(); job.PrintLine(PrintLineTextBox.Text); await ExecuteJobAndReportResultAsync(job); }
private async void PrintBarcode_Click() { if (!IsPrinterClaimed()) { return; } rootPage.ClaimedPrinter.Receipt.IsLetterQuality = true; ReceiptPrintJob job = rootPage.ClaimedPrinter.Receipt.CreateJob(); job.PrintBarcode(BarcodeText.Text, BarcodeSymbologies.Upca, 60, 3, PosPrinterBarcodeTextPosition.Below, PosPrinterAlignment.Center); await ExecuteJobAndReportResultAsync(job); }
private async void PrintBitmap_Click() { if (!IsPrinterClaimed()) { return; } rootPage.ClaimedPrinter.Receipt.IsLetterQuality = true; ReceiptPrintJob job = rootPage.ClaimedPrinter.Receipt.CreateJob(); BitmapFrame logoFrame = await LoadLogoBitmapAsync(); job.PrintBitmap(logoFrame, PosPrinterAlignment.Center); await ExecuteJobAndReportResultAsync(job); }
private ReceiptPrintJob GetCustomerFooter(ClaimedPosPrinter printer) { ReceiptPrintJob customerFooter = printer.Receipt.CreateJob(); customerFooter.PrintLine(); customerFooter.PrintLine("______________________"); customerFooter.PrintLine("Tip"); customerFooter.PrintLine(); customerFooter.PrintLine("Customer Copy"); LineFeedAndCutPaper(customerFooter); return(customerFooter); }
// Cut the paper after printing enough blank lines to clear the paper cutter. private void LineFeedAndCutPaper(ReceiptPrintJob job) { if (IsPrinterClaimed()) { for (uint n = 0; n < claimedPrinter.Receipt.LinesToPaperCut; n++) { job.PrintLine(); } if (printer.Capabilities.Receipt.CanCutPaper) { job.CutPaper(); } } }
private ReceiptPrintJob GetMerchantFooter(ClaimedPosPrinter printer) { ReceiptPrintJob merchantFooter = printer.Receipt.CreateJob(); merchantFooter.PrintLine(); merchantFooter.PrintLine("______________________"); merchantFooter.PrintLine("Tip"); merchantFooter.PrintLine(); merchantFooter.PrintLine("______________________"); merchantFooter.PrintLine("Signature"); merchantFooter.PrintLine(); merchantFooter.PrintLine("Merchant Copy"); LineFeedAndCutPaper(merchantFooter); return(merchantFooter); }
// Cut the paper after printing enough blank lines to clear the paper cutter. private void PrintLineFeedAndCutPaper(ReceiptPrintJob job, string receipt) { // Passing a multi-line string to the Print method results in // smoother paper feeding than sending multiple single-line strings // to PrintLine. string feedString = ""; for (uint n = 0; n < rootPage.ClaimedPrinter.Receipt.LinesToPaperCut; n++) { feedString += "\n"; } job.Print(receipt + feedString); if (rootPage.Printer.Capabilities.Receipt.CanCutPaper) { job.CutPaper(); } }
/// <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); }
/// <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); }
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); }
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); }