/// <summary> /// /// </summary> /// <param name="bitmatNumber">1~20の値</param> /// <param name="strFilePath">Bitmapのファイルパス</param> /// <returns></returns> public bool SetBitmap(int bitmatNumber, string strFilePath) { if (bitmatNumber > 0 && 21 > bitmatNumber) { bool bSetBitmapSuccess = false; for (int iRetryCount = 0; iRetryCount < 5; iRetryCount++) { try { m_Printer.SetBitmap(bitmatNumber, PrinterStation.Receipt, strFilePath, m_Printer.RecLineWidth / 2, PosPrinter.PrinterBitmapCenter); bSetBitmapSuccess = true; break; } catch (PosControlException pce) { if (pce.ErrorCode == ErrorCode.Failure && pce.ErrorCodeExtended == 0 && pce.Message == "デバイスが初期化されていません。") { System.Threading.Thread.Sleep(1000); } } } return(bSetBitmapSuccess); } return(false); }
private void PrintReceipt(PosEventSignResult result) { StringBuilder sb = new StringBuilder(); try { p.RecLetterQuality = true; p.SetBitmap(1, PrinterStation.Receipt, "..\\..\\Resources\\outpost_logo_receipt.bmp", p.RecLineWidth, PosPrinter.PrinterBitmapCenter); sb.Append(PrintCommands.bitmap_1); sb.Append(PrintCommands.center); // TODO: Address + VAT number. sb.Append(PrintCommands.double_size + "VAT RECEIPT\n"); sb.Append(PrintCommands.reset); sb.Append(string.Concat(Enumerable.Repeat("-", p.RecLineChars))); // TODO sb.Append(PrintCommands.feed_cut); p.PrintNormal(PrinterStation.Receipt, sb.ToString()); } catch (PosControlException e) { Debug.WriteLine("Point of sale control exception: {0}", e); if (e.ErrorCode == ErrorCode.Extended) { Debug.WriteLine("Extended: ", e.ErrorCodeExtended); } } }
private void test_printer(PosPrinter p) { try { Debug.WriteLine("CapRecPresent: {0}", p.CapRecPresent); Debug.WriteLine("CapRecPageMode: {0}", p.CapRecPageMode); Debug.WriteLine("CapRecMarkFeed: {0}", p.CapRecMarkFeed); Debug.WriteLine("CapRuledLine: {0}", p.CapRecRuledLine); Debug.WriteLine("CapRecDWideDHigh: {0}", p.CapRecDWideDHigh); Debug.WriteLine("CapRecBitmap: {0}", p.CapRecBitmap); Debug.WriteLine("CapTransaction: {0}", p.CapTransaction); Debug.WriteLine("High quality?: {0}", p.RecLetterQuality); Debug.WriteLine("Receipt paper low?: {0}", p.RecNearEnd); Debug.WriteLine("Lines to paper cut: {0}", p.RecLinesToPaperCut); Debug.WriteLine("Line width: {0}", p.RecLineWidth); Debug.WriteLine(Directory.GetCurrentDirectory()); p.RecLetterQuality = true; p.SetBitmap(1, PrinterStation.Receipt, Resources.outpost_logo_receipt.ToString(), p.RecLineWidth, PosPrinter.PrinterBitmapCenter); //p.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Transaction); p.PrintNormal(PrinterStation.Receipt, PrintCommands.bitmap_1 + "Hello world!" + PrintCommands.bold + PrintCommands.double_size + "Hello world!" + PrintCommands.feed_cut); //p.TransactionPrint(PrinterStation.Receipt, PrinterTransactionControl.Normal); } catch (PosControlException e) { Debug.WriteLine("Point of sale control exception: {0}", e); if (e.ErrorCode == ErrorCode.Extended) { Debug.WriteLine("Extended: ", e.ErrorCodeExtended); } } }
void PrintReceipt(PosEventSignResult pesr) { string tab = " "; // Necessary since the receipt printer doesn't seem to support normal tab characters. string total_label = "Total: "; StringBuilder sb = new StringBuilder(); try { // Initialization. PosPrinter.RecLetterQuality = true; PosPrinter.SetBitmap(1, PrinterStation.Receipt, "..\\..\\Resources\\outpost_logo_black.bmp", PosPrinter.RecLineWidth, PosPrinter.PrinterBitmapCenter); // Header logo. sb.Append(PrintCommands.bitmap_1); // Establishment data. Dispatcher.Invoke(() => { sb.Append( PrintCommands.center + CompanyNameLabel.Content + "\n" + CompanyStreetLabel.Content + "\n" + CompanyCityLabel.Content + "\n" + CompanyVATLabel.Content + "\n\n" ); }); // Receipt title. sb.Append(PrintCommands.double_size); if (pesr.Event.IsTrainingMode) { sb.Append("TRAINING RECEIPT\n"); } else { sb.Append("VAT RECEIPT\n"); } if (pesr.Event.IsRefund) { sb.Append("REFUND\n"); } sb.Append(PrintCommands.reset); decimal receipt_total = 0.0m; int space_count; // Product lines & total. sb.Append(PrintCommands.bold + "Products & Services:\n" + PrintCommands.reset); foreach (ProductLine l in pesr.Event.Products) { space_count = PosPrinter.RecLineChars - l.Quantity.ToString().Length - l.ProductName.ToString().Length - l.SellingPrice.ToString().Length - l.PrintVatRateId.ToString().Length - tab.Length - 3; // TODO: Handle (space_count <= 0) case. Debug.Assert(0 < space_count); sb.Append( string.Format(tab + "{0}x {1}", l.Quantity, l.ProductName) + string.Concat(Enumerable.Repeat(" ", space_count)) + string.Format("{0} {1}\n", l.SellingPrice, l.PrintVatRateId) ); receipt_total += l.SellingPrice; } sb.Append(tab + string.Concat(Enumerable.Repeat("-", PosPrinter.RecLineChars - tab.Length)) + "\n"); space_count = PosPrinter.RecLineChars - total_label.Length - receipt_total.ToString().Length - tab.Length - 2; sb.Append(tab + total_label + string.Concat(Enumerable.Repeat(" ", space_count)) + receipt_total.ToString() + "\n\n"); // Payment lines. // TODO: Add support for change & refund. sb.Append(PrintCommands.bold + "Payment:\n" + PrintCommands.reset); foreach (PaymentLine l in pesr.Event.Payments) { space_count = PosPrinter.RecLineChars - l.PaymentName.ToString().Length - l.PayAmount.ToString().Length - tab.Length - 2; sb.Append(tab + l.PaymentName + string.Concat(Enumerable.Repeat(" ", space_count)) + l.PayAmount + "\n"); } sb.Append("\n"); // VAT data. int len, taxable_max_char_count = 0, rate_max_char_count = 0, amount_max_char_count = 0; sb.Append(PrintCommands.bold + "VAT:\n" + PrintCommands.reset); // TODO: Multilingual support. foreach (VATSplit v in pesr.VATSplit) { // Calculate spacing for alignment. len = v.TaxableAmount.ToString().Length; if (taxable_max_char_count < len) { taxable_max_char_count = len; } len = v.VATRate.ToString().Length; if (rate_max_char_count < len) { rate_max_char_count = len; } len = v.VATAmount.ToString().Length; if (amount_max_char_count < len) { amount_max_char_count = len; } } foreach (VATSplit v in pesr.VATSplit) { sb.Append( tab + v.PrintVatRateId + ": " + string.Concat(Enumerable.Repeat(" ", taxable_max_char_count - v.TaxableAmount.ToString().Length)) + v.TaxableAmount + " @ " + string.Concat(Enumerable.Repeat(" ", rate_max_char_count - v.VATRate.ToString().Length)) + v.VATRate + "% = " + string.Concat(Enumerable.Repeat(" ", amount_max_char_count - v.VATAmount.ToString().Length)) + +v.VATAmount + "\n" ); } sb.Append(tab + total_label + string.Concat( Enumerable.Repeat(" ", taxable_max_char_count + rate_max_char_count + amount_max_char_count + 10 - total_label.Length - pesr.GetTotalVATAmount().ToString().Length ) ) + pesr.GetTotalVATAmount() + "\n\n" ); // Other mandatory data. sb.Append( PrintCommands.bold + "Cash Register Data:\n" + PrintCommands.reset + tab + "PLU hash: " + pesr.Signature.PrintPluHash + "\n" + tab + "POS: " + pesr.Event.POSSerialNumber + "\n" + tab + "Version: " + "~TODO~" + "\n" + // TODO tab + "Terminal: " + pesr.Event.TerminalId + "\n" + tab + "Transaction: " + pesr.Event.TransactionNumber.ToString() + "\n" + tab + "Date & time: " + pesr.Event.TransactionDateTime.ToString("dd/MM/yyyy HH:mm:ss") + "\n" + tab + "User: "******"\n" + "\n" ); // FDM control data. // Must follow specific naming conventions as dictated by the law! // See circular no. E.T. 124.747, chapter 5, points 44 & 45! sb.Append( PrintCommands.bold + "Control Data:\n" + PrintCommands.reset + tab + pesr.Signature.SignDateTime + "\n" + tab + string.Format("Receipt counter: {0}/{1} {2}\n", pesr.Signature.TicketNumber, pesr.Signature.TicketCount, pesr.Signature.EventType ) + tab + "Receipt signature:\n" + tab + tab + pesr.Signature.Signature + "\n" + tab + "Control module ID: " + pesr.Signature.FDMSerialNumber + "\n" + tab + "VAT signing card ID: " + pesr.Signature.VSCIdentificationNumber + "\n\n" ); // Invalidity footer. if (pesr.Event.IsTrainingMode) { sb.Append(PrintCommands.center + PrintCommands.double_size + "THIS IS NOT A\nVALID VAT RECEIPT\n" + PrintCommands.reset ); } sb.Append(PrintCommands.feed_cut); PosPrinter.PrintNormal(PrinterStation.Receipt, sb.ToString()); } catch (PosControlException e) { Debug.WriteLine("Point of sale control exception: {0}", e); if (e.ErrorCode == ErrorCode.Extended) { Debug.WriteLine("Extended: ", e.ErrorCodeExtended); } } }