public static void printModel(string content, BluetoothPrinter bluetoothPrinter) { if (string.IsNullOrEmpty(content) && bluetoothPrinter == null) { return; } List <PrintEntity> printEntities = JsonConvert.DeserializeObject <List <PrintEntity> >(content); if (printEntities != null && printEntities.Count > 0) { if (!bluetoothPrinter.isConnected()) { bluetoothPrinter.openConnection(); } for (int i = 0; i < printEntities.Count; i++) { if (string.IsNullOrEmpty(printEntities[i].isQRCode) || printEntities[i].isQRCode == "0") { logger.Info("bluetooth print:" + printEntities[i].content); //add 2018年9月10日 增加换行 bluetoothPrinter.PrintString(printEntities[i].content + "\n"); } else { //usb打印二维码可能会出现问题 所以直接不打印 //usbPrinter.printQRCode(printEntities[i].content); } } } bluetoothPrinter.PrintString("\n\n\n\n\n\n"); //bluetoothPrinter.PrintString(content); }
private bool setBluetooth(PrinterConfigEntity printerConfigEntity) { List <BluetoothDeviceInfo> bluetoothDeviceArrayList = PrinterManager.Instance.BluetoothDeviceArrayList; foreach (BluetoothDeviceInfo bluetoothDevice in bluetoothDeviceArrayList) { if (bluetoothDevice.DeviceName.Equals(printerConfigEntity.deviceId)) { BluetoothPrinter bluetoothPrinter; if (PrinterManager.Instance.Init && PrinterManager.Instance.BluetoothPrinter != null) { if (bluetoothDevice.DeviceAddress.Equals(PrinterManager.Instance.BluetoothPrinter.MacAddress)) { bluetoothPrinter = PrinterManager.Instance.BluetoothPrinter; } else { PrinterManager.Instance.BluetoothPrinter.closeConnection(); //关闭之前的蓝牙打印机 bluetoothPrinter = new BluetoothPrinter(bluetoothDevice); //创建新的蓝牙打印机实例 bluetoothPrinter.pageWidth = printerConfigEntity.pageWidth; } } else { bluetoothPrinter = new BluetoothPrinter(bluetoothDevice); } bluetoothPrinter.Encoding = "GBK"; if (printerConfigEntity.pageWidth == "small") { bluetoothPrinter.CurrentPrintType = PrinterType.T8; } else { bluetoothPrinter.CurrentPrintType = PrinterType.T5; } //bluetoothPrinter.Handler(bluetoothHandler); if (!bluetoothPrinter.isConnected()) { bluetoothPrinter.openConnection(); } else { // savePrinterConfig(printerConfigEntity); // PrintUtils.printText(bluetoothPrinter); } PrinterManager.Instance.Init = true; PrinterManager.Instance.PrinterTypeEnum = PrinterTypeEnum.bluetooth; PrinterManager.Instance.BluetoothPrinter = bluetoothPrinter; PrinterManager.Instance.PrinterConfigEntity = printerConfigEntity; bluetoothPrinter.PrintString("蓝牙打印机连接成功\n\n\n\n\n"); responseEntity.code = ResponseCode.SUCCESS; responseEntity.msg = "打印机设置成功"; if (listener != null) { listener.Invoke(new object[] { "setPrinterCallBack", responseEntity }); } return(true); } } return(false); }
internal static void printNote(StatisticsVM statisticsVM, BluetoothPrinter 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"); }