public static void printModel(string content, USBPrinter usbPrinter) { if (string.IsNullOrEmpty(content) && usbPrinter == null) { return; } List <PrintEntity> printEntities = JsonConvert.DeserializeObject <List <PrintEntity> >(content); if (printEntities != null && printEntities.Count > 0) { usbPrinter.initUSB(); for (int i = 0; i < printEntities.Count; i++) { if (string.IsNullOrEmpty(printEntities[i].isQRCode) || printEntities[i].isQRCode == "0") { logger.Info("usb print:" + printEntities[i].content); //add 2018年9月10日 增加一个换行 usbPrinter.PrintString(printEntities[i].content + "\n"); } else { //usb打印二维码可能会出现问题 所以直接不打印 //usbPrinter.printQRCode(printEntities[i].content); } } } usbPrinter.PrintString("\n\n\n\n\n\n"); //usbPrinter.PrintString(content); }
internal static void printNote(StatisticsVM statisticsVM, USBPrinter mPrinter) { if (statisticsVM == null) { return; } if (mPrinter == null) { return; } if (mPrinter.CurrentPrintType == PrinterType.TIII || mPrinter.CurrentPrintType == PrinterType.T5) { mPrinter.PrintString(" 收银对账 \n"); } else { mPrinter.PrintString(" 收银对账 \n"); } StringBuilder sb = new StringBuilder(); if (mPrinter.CurrentPrintType == PrinterType.TIII || mPrinter.CurrentPrintType == PrinterType.T5) { sb.Append("------------------------------\n"); } else { sb.Append("----------------------------------------------\n"); } sb.Append(Resources.R.branch_name + statisticsVM.branchname + "\n"); sb.Append(Resources.R.time + DateTime.Now.ToString("D") + "\n"); sb.Append(Resources.R.date_time + statisticsVM.starttime + "至" + statisticsVM.endtime + "\n"); sb.Append(Resources.R.shop_cashier_num + statisticsVM.cashiername + "\n"); sb.Append(Resources.R.ticketnums + statisticsVM.ticketnums + "\n"); sb.Append(Resources.R.ticketamount + statisticsVM.ticketamount + "\n"); sb.Append(Resources.R.returnnums + statisticsVM.returnnums + "\n"); sb.Append(Resources.R.returnamount + statisticsVM.returnamount + "\n"); sb.Append(Resources.R.rechargeamount + statisticsVM.rechargeamount + "\n"); sb.Append(Resources.R.subtotal + statisticsVM.subtotal + "\n"); if (mPrinter.CurrentPrintType == PrinterType.TIII || mPrinter.CurrentPrintType == PrinterType.T5) { sb.Append("------------------------------\n"); } else { sb.Append("----------------------------------------------\n"); } mPrinter.PrintString(sb.ToString()); StringBuilder sbtb = new StringBuilder(); sbtb.Append(tableFormat(Resources.R.payType, true, 15, false)); sbtb.Append(tableFormat(Resources.R.mumber, false, 8, false)); sbtb.Append(tableFormat(Resources.R.money, false, 8, false)); sbtb.Append("\n"); sbtb.Append(tableFormat("现金", true, 15, false)); sbtb.Append(tableFormat(statisticsVM.cashnums, false, 8, true)); sbtb.Append(tableFormat(statisticsVM.cashamount, false, 8, true)); sbtb.Append("\n"); sbtb.Append(tableFormat("支付宝", true, 15, false)); sbtb.Append(tableFormat(statisticsVM.alinums, false, 8, true)); sbtb.Append(tableFormat(statisticsVM.aliamount, false, 8, true)); sbtb.Append("\n"); sbtb.Append(tableFormat("微信", true, 15, false)); sbtb.Append(tableFormat(statisticsVM.wxnums, false, 8, true)); sbtb.Append(tableFormat(statisticsVM.wxamount, false, 8, true)); sbtb.Append("\n"); foreach (ZidingyizhifuBean zidingyizhifuBean in statisticsVM.zidingyizhifu) { sbtb.Append(tableFormat(zidingyizhifuBean.zidingyiname, true, 15, false)); sbtb.Append(tableFormat(zidingyizhifuBean.zidingyinums, false, 8, true)); sbtb.Append(tableFormat(zidingyizhifuBean.zidingyiamount, false, 8, true)); sbtb.Append("\n"); } sbtb.Append(tableFormat("合计", true, 15, false)); sbtb.Append(tableFormat("", false, 8, true)); sbtb.Append(tableFormat(statisticsVM.subtotal, false, 8, true)); sbtb.Append("\n\n\n"); mPrinter.PrintString(sbtb.ToString()); mPrinter.PrintString("\n\n\n\n\n"); }
//internal void setUSBPrinter(PrinterConfigEntity printerConfigEntity, JSBridge.JsCallbackHandle webCallback) internal void setUSBPrinter(PrinterConfigEntity printerConfigEntity, Action <object> webCallback) { IntPtr hUsb; if (printerConfigEntity != null) { listener = webCallback; responseEntity = new ResponseEntity(); PrinterManager.Instance.PrinterConfigEntity = printerConfigEntity; //edit by sven 2018年5月14日 不管USBprint是否已经init 都重新初始化一次 //if (PrinterManager.Instance.UsbPrinter == null) { USBPrinter usbPrinter = new USBPrinter(); //if (!usbPrinter.Init) { hUsb = usbPrinter.open(); if ((int)hUsb == -1) { responseEntity.code = ResponseCode.Failed; responseEntity.msg = "USB打印机打开失败"; listener?.Invoke(new object[] { "setPrinterCallBack", responseEntity }); return; } usbPrinter.HDevice = hUsb; } usbPrinter.pageWidth = printerConfigEntity.pageWidth; PrinterManager.Instance.Init = true; PrinterManager.Instance.PrinterTypeEnum = PrinterTypeEnum.usb; PrinterManager.Instance.UsbPrinter = usbPrinter; PrinterManager.Instance.PrinterConfigEntity = printerConfigEntity; usbPrinter.PrintString("USB打印机连接成功\n\n\n\n\n"); responseEntity.code = ResponseCode.SUCCESS; responseEntity.msg = "打印机设置成功"; //if (listener != null) //{ // listener.Invoke(new object[] { "setPrinterCallBack", responseEntity }); //} } //else //{ // if (PrinterManager.Instance.Init) // { // PrinterManager.Instance.UsbPrinter.PrintString("usb打印机测试成功\r\n\r\n\r\n\r\n"); // responseEntity.code = ResponseCode.SUCCESS; // responseEntity.msg = "打印机设置成功"; // } //} //getUsbDevices(); //debug //PrintServices.USBPrinterService upt = new PrintServices.USBPrinterService(); //upt.TestPrint(); //responseEntity.code = ResponseCode.SUCCESS; } else { responseEntity.code = ResponseCode.Failed; responseEntity.msg = "参数不能为空"; } if (listener != null) { listener.Invoke(new object[] { "setPrinterCallBack", responseEntity }); } }