internal void SetDrivePrinterSetter(PrinterConfigEntity printerConfigEntity, Action <object> webCallback) { responseEntity = new ResponseEntity(); if (printerConfigEntity != null) { PrinterManager.Instance.PrinterConfigEntity = printerConfigEntity; try { //DrivePrinter最好还是采用单例比较好 DrivePrinter drivePrinter = DrivePrinter.Instance; drivePrinter.printerName = printerConfigEntity.printerName; //"GP-5890X Series"; drivePrinter.SetPrinterName(); drivePrinter.Print("驱动连接打印机成功\r\n\r\n\r\n"); drivePrinter.pageWidth = printerConfigEntity.pageWidth; PrinterManager.Instance.Init = true; PrinterManager.Instance.PrinterTypeEnum = Enums.PrinterTypeEnum.drive; PrinterManager.Instance.DrivePrinter = drivePrinter; PrinterManager.Instance.PrinterConfigEntity = printerConfigEntity; responseEntity.code = ResponseCode.SUCCESS; responseEntity.msg = "打印机设置成功"; } catch (Exception e) { responseEntity.code = ResponseCode.Failed; responseEntity.msg = "驱动打印出错"; logger.Error("drive print err", e); } } else { responseEntity.code = ResponseCode.Failed; responseEntity.msg = "参数不能为空"; } if (webCallback != null) { webCallback.Invoke(new object[] { "setPrinterCallBack", responseEntity }); } }
internal static void printModel(string content, DrivePrinter drivePrinter) { if (string.IsNullOrEmpty(content) && drivePrinter == null) { return; } //content = content.Replace("\\r", " "); //content = content.Replace("\\n", "\n"); List <PrintEntity> printEntities = JsonConvert.DeserializeObject <List <PrintEntity> >(content); if (printEntities != null && printEntities.Count > 0) { StringBuilder sb = new StringBuilder(); //portPrinter.initUSB(); for (int i = 0; i < printEntities.Count; i++) { logger.Info("lpt print:" + printEntities[i].content); //判断如果是头尾 16个(32个英文)中文字符换行 if (!string.IsNullOrEmpty(printEntities[i].needAutoNewLine) && printEntities[i].needAutoNewLine == "1") { string cont = printEntities[i].content.Replace("\\n", ""); sb.Append(ProcessNewlineString(cont) + Environment.NewLine); } else { if (string.IsNullOrEmpty(printEntities[i].isQRCode) || printEntities[i].isQRCode == "0") { //add 2018年9月10日 增加换行 string cont = printEntities[i].content.Replace("\\n", ""); sb.Append(cont + Environment.NewLine); } else { //并口没有二维码 //portPrinter.PrintQRCode(printEntities[i].content); } } } drivePrinter.PrintString(sb.ToString() + "\r\n\r\n\r\n\r\n\r\n"); } }
internal static void printNote(StatisticsVM statisticsVM, DrivePrinter 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"); //驱动打印改为一次性打印 sb.Append(sbtb); mPrinter.PrintString(sb.ToString() + "\\n\\n\\n\\n\\n"); //mPrinter.PrintString("\n\n\n\n\n"); }