protected virtual void BeforePrint() { BufferList = new List <byte[]>(); // 打印当日序号 BufferList.Add(PrinterCmdUtils.AlignCenter()); BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2)); BufferList.Add(TextToByte(Title)); BufferList.Add(PrinterCmdUtils.NextLine()); BufferList.Add(PrinterCmdUtils.AlignLeft()); BufferList.Add(PrinterCmdUtils.PrintLineLeftRight($"餐桌:{Order.DeskName}", $"单号:{Order.Identifier}", fontSize: 2)); BufferList.Add(PrinterCmdUtils.NextLine()); if (!string.IsNullOrEmpty(Order.Remark)) { BufferList.Add(PrinterCmdUtils.BoldOn()); BufferList.Add(TextToByte($"备注:{Order.Remark}")); BufferList.Add(PrinterCmdUtils.NextLine()); BufferList.Add(PrinterCmdUtils.BoldOff()); BufferList.Add(PrinterCmdUtils.NextLine()); } BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1)); BufferList.Add(TextToByte($"服务员:{Order.StaffName}")); BufferList.Add(PrinterCmdUtils.NextLine()); BufferList.Add(TextToByte($"打印时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}")); BufferList.Add(PrinterCmdUtils.NextLine()); BufferList.Add(PrinterCmdUtils.SplitLine("-", Printer.Device.Format)); BufferList.Add(PrinterCmdUtils.NextLine()); BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2)); }
private void Format(string name, string description) { BeforePrint(); if (!string.IsNullOrEmpty(description)) { name += $"({description})"; } BufferList.Add(PrinterCmdUtils.FontSizeSetBig(3)); BufferList.Add(PrinterCmdUtils.AlignLeft()); BufferList.Add(PrinterCmdUtils.PrintLineLeftRight(name, "*1", Printer.FormatLen, 3)); BufferList.Add(PrinterCmdUtils.NextLine()); AfterPrint(); Send(); }
protected override void Printing() { BufferList.Add(PrinterCmdUtils.FontSizeSetBig(3)); BufferList.Add(PrinterCmdUtils.AlignLeft()); foreach (var product in Products) { var name = product.Name; if (!string.IsNullOrEmpty(product.Description)) { name += $"({product.Description})"; } BufferList.Add(PrinterCmdUtils.PrintLineLeftRight(name, "*" + double.Parse(product.Quantity + "").ToString(), Printer.FormatLen, 3)); BufferList.Add(PrinterCmdUtils.NextLine()); } }
private void Format(string name, string description, string remark) { BeforePrint(); if (!string.IsNullOrEmpty(description)) { name += $"({description})"; } BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2)); BufferList.Add(PrinterCmdUtils.AlignLeft()); BufferList.Add(PrinterCmdUtils.PrintLineLeftRight("*1", name, Printer.FormatLen, 2)); BufferList.Add(PrinterCmdUtils.NextLine()); if (remark != null) { BufferList.Add(TextToByte($"备注:{remark}")); BufferList.Add(PrinterCmdUtils.NextLine()); } AfterPrint(); Send(); }
/// <summary> /// 打印订单商品 /// </summary> /// <param name="product"></param> /// <returns></returns> private List <byte[]> ProductLine(ThirdOrderProduct product, int fontSize = 1) { var left = product.Name; if (!string.IsNullOrEmpty(product.GetDesc())) { left += "(" + product.GetDesc() + ")"; } var middle = "*" + Convert.ToDouble(product.Quantity); var right = Convert.ToDouble(product.Price * product.Quantity) + ""; var place = string.Empty; for (int i = 0; i < maxRightLen - middle.Length - right.Length; i++) { place += " "; } right = middle + place + right; var buffer = PrinterCmdUtils.PrintLineLeftRight(left, right, fontSize: fontSize); return(new List <byte[]> { buffer }); }
/// <summary> /// 前台打印(堂食订单) /// </summary> /// <param name="order"></param> /// <param name="socket"></param> private void ReceptionPrint(TangOrder order, Socket socket, PrintOption option) { var bufferArr = new List <byte[]> { // 打印当日序号 PrinterCmdUtils.AlignCenter(), PrinterCmdUtils.FontSizeSetBig(2), TextToByte(ApplicationObject.App.Business.Name), PrinterCmdUtils.NextLine(), TextToByte($"当日流水:{order.Identifier}"), PrinterCmdUtils.NextLine(), TextToByte(option.Title ?? "结账单"), PrinterCmdUtils.NextLine() }; // 餐桌 if (order.DeskId != null) { bufferArr.Add(PrinterCmdUtils.AlignLeft()); bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(2)); bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight($"餐桌:{order.DeskName}", $"人数:{order.PeopleNumber}", fontSize: 2)); bufferArr.Add(PrinterCmdUtils.NextLine()); } bufferArr.Add(PrinterCmdUtils.FontSizeSetBig(1)); // 订单编号 bufferArr.Add(TextToByte($"订单编号:{order.Code}")); bufferArr.Add(PrinterCmdUtils.NextLine()); // 下单 bufferArr.Add(TextToByte($"下单时间:{order.CreateTime:yyyy-MM-dd HH:mm:ss}")); bufferArr.Add(PrinterCmdUtils.NextLine()); // 服务员 bufferArr.Add(TextToByte($"收银员:{order.StaffName}")); bufferArr.Add(PrinterCmdUtils.NextLine()); // 备注 if (!string.IsNullOrEmpty(order.Remark)) { bufferArr.Add(TextToByte($"备注:{order.Remark}")); bufferArr.Add(PrinterCmdUtils.NextLine()); } // 商品分隔 bufferArr.Add(PrinterCmdUtils.SplitText("-", "购买商品", Device.Format)); bufferArr.Add(PrinterCmdUtils.NextLine()); // 打印商品 foreach (var product in option.Products) { var buffer = ProductLine(product); buffer.ForEach(a => { bufferArr.Add(a); bufferArr.Add(PrinterCmdUtils.NextLine()); }); } // 分隔 bufferArr.Add(PrinterCmdUtils.SplitLine("-", Device.Format)); bufferArr.Add(PrinterCmdUtils.NextLine()); // 金额 bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("餐位费:", order.MealFee.ToString())); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("原价:", order.OriginalAmount.ToString())); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("优惠:", (order.OriginalAmount - order.Amount + order.PreferentialAmount).ToString())); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("实收:", order.ActualAmount.ToString())); bufferArr.Add(PrinterCmdUtils.NextLine()); //if (!string.IsNullOrEmpty(order.PaymentTypeName)) //{ // bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("付款方式:", order.PaymentTypeName)); // bufferArr.Add(PrinterCmdUtils.NextLine()); //} if (order.TangOrderPayments != null && order.TangOrderPayments.Count > 0) { if (order.TangOrderPayments.Count == 1) { var first = order.TangOrderPayments.First(); bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("付款方式:", first.Name)); bufferArr.Add(PrinterCmdUtils.NextLine()); } else { var first = order.TangOrderPayments.First(); bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("付款方式:", $"{first.Name}:{first.Amount}")); bufferArr.Add(PrinterCmdUtils.NextLine()); for (int i = 1; i < order.TangOrderPayments.Count; i++) { bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("", $"{order.TangOrderPayments[i].Name}:{order.TangOrderPayments[i].Amount}")); bufferArr.Add(PrinterCmdUtils.NextLine()); } } } if (!string.IsNullOrEmpty(order.PaymentRemark)) { bufferArr.Add(PrinterCmdUtils.PrintLineLeftRight("支付备注:", order.PaymentRemark)); bufferArr.Add(PrinterCmdUtils.NextLine()); } // 分隔 bufferArr.Add(PrinterCmdUtils.SplitText("-", "其他", Device.Format)); bufferArr.Add(PrinterCmdUtils.NextLine()); // 打印时间 bufferArr.Add(TextToByte($"打印时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}")); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(TextToByte(ApplicationObject.App.Business.Name)); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(TextToByte($"电话:{ApplicationObject.App.Business.Mobile}")); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(TextToByte($"地址:{ApplicationObject.App.Business.Address}")); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(PrinterCmdUtils.AlignCenter()); bufferArr.Add(TextToByte($"谢谢您的惠顾")); bufferArr.Add(PrinterCmdUtils.NextLine()); bufferArr.Add(PrinterCmdUtils.AlignLeft()); bufferArr.Add(PrinterCmdUtils.NextLine()); // 切割 bufferArr.Add(PrinterCmdUtils.FeedPaperCutAll()); // 打印 bufferArr.ForEach(a => socket.Send(a)); }