public static void printModel(string content, serialPort portPrinter) { if (string.IsNullOrEmpty(content) && portPrinter == null) { return; } List <PrintEntity> printEntities = JsonConvert.DeserializeObject <List <PrintEntity> >(content); if (printEntities != null && printEntities.Count > 0) { //portPrinter.initUSB(); for (int i = 0; i < printEntities.Count; i++) { //portPrinter.PrintString(printEntities[i].content); if (string.IsNullOrEmpty(printEntities[i].isQRCode) || printEntities[i].isQRCode == "0") { logger.Info("port print:" + printEntities[i].content); //add 2018年9月10日 增加换行 portPrinter.PrintString(printEntities[i].content + "\n"); } else { portPrinter.PrintQRCode(printEntities[i].content); } } } portPrinter.PrintString("\n\n\n\n\n\n"); //portPrinter.Write(content); }
internal static void PrintQRCode(string code, serialPort portPrinter) { if (string.IsNullOrEmpty(code) && portPrinter == null) { return; } portPrinter.PrintString(code); }
internal static void setSerialPort(PrinterConfigEntity printerConfigEntity, Action <object> webCallback) { ResponseEntity responseEntity = new ResponseEntity(); if (printerConfigEntity != null) { string port = printerConfigEntity.port; string intBaud = printerConfigEntity.intBaud; if (!String.IsNullOrEmpty(port) && !String.IsNullOrEmpty(intBaud)) { serialPort m_serialPort; if (PrinterManager.Instance.PortPrinter == null) { m_serialPort = new serialPort(port, intBaud); m_serialPort.pageWidth = printerConfigEntity.pageWidth; m_serialPort.brand = printerConfigEntity.printerBrand; m_serialPort.init(); } else { m_serialPort = PrinterManager.Instance.PortPrinter; m_serialPort.Close(); } if (m_serialPort.Open(port, int.Parse(intBaud))) { PrinterManager.Instance.Init = true; PrinterManager.Instance.PrinterTypeEnum = PrinterTypeEnum.port; PrinterManager.Instance.PortPrinter = m_serialPort; m_serialPort.PrintString("串口打印机连接成功!\n\n\n\n\n"); responseEntity.code = ResponseCode.SUCCESS; responseEntity.msg = "打印机设置成功"; } else { m_serialPort.Close(); responseEntity.code = ResponseCode.Failed; responseEntity.msg = "该端口不可用"; } } else { responseEntity.code = ResponseCode.Failed; responseEntity.msg = "端口或波特率参数不能为空"; } if (webCallback != null) { webCallback.Invoke(new object[] { "setPrinterCallBack", responseEntity }); } } }
internal static void printNote(StatisticsVM statisticsVM, serialPort mPrinter) { if (statisticsVM == null) { return; } if (mPrinter == null) { return; } if (mPrinter.pageWidth == "small") { mPrinter.PrintString(" 收银对账 \n"); } else { mPrinter.PrintString(" 收银对账 \n"); } StringBuilder sb = new StringBuilder(); if (mPrinter.pageWidth == "small") { 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.pageWidth == "small") { 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"); }