Пример #1
0
        /// <summary>
        /// 后台打印
        /// </summary>
        /// <param name="order"></param>
        /// <param name="socket"></param>
        private void Backstage <T>(T order, Socket socket, PrintOption option = null) where T : class
        {
            var printSign = string.Empty;

            if (order is TangOrder)
            {
                printSign = "Tang";
            }
            else if (order is ThirdOrder)
            {
                printSign = "Third";
            }
            var enumName = System.Enum.GetName(typeof(PrinterMode), Device.Mode);
            var type     = System.Type.GetType($"Jiandanmao.Code.{printSign}{enumName}Print");

            if (order is Order)
            {
                ((BackstagePrint)Activator.CreateInstance(type, order, this, socket)).Print();
            }
            else if (order is TangOrder)
            {
                ((TangBackstagePrint)Activator.CreateInstance(type, order, this, socket, option)).Print();
            }
            else
            {
                ((ThirdBackstagePrint)Activator.CreateInstance(type, order, this, socket)).Print();
            }
        }
Пример #2
0
 public TangOrderPrint(TangOrder order, Printer printer, Socket socket, PrintOption option) : base(order, printer, socket, option)
 {
     if (option.Mode == Enum.PrintMode.PreOrder)
     {
         Title = "厨房总单";
     }
     else
     {
         Title = $"厨房总单({option.Title})";
     }
 }
Пример #3
0
 /// <summary>
 /// 打印订单(堂食)
 /// </summary>
 /// <param name="order"></param>
 /// <param name="socket"></param>
 private void PrintOrder(TangOrder order, Socket socket, PrintOption option)
 {
     if (Device.Type == 1)
     {
         ReceptionPrint(order, socket, option);
     }
     else if (Device.Type == 2)
     {
         Backstage(order, socket, option);
     }
 }
Пример #4
0
 public TangBackstagePrint(TangOrder order, Printer printer, Socket socket, PrintOption option)
 {
     Order    = order;
     Printer  = printer;
     _socket  = socket;
     Option   = option;
     Title    = option.Title;
     Products = Option.Products?.Where(a => a.Feature == ProductFeature.SetMeal || Printer.Device.Foods.Contains(a.ProductId)).ToList();
     if (option.Mode == PrintMode.PreOrder)
     {
         Title = "点菜单";
     }
 }
Пример #5
0
 /// <summary>
 /// 打印堂食订单
 /// </summary>
 /// <param name="order"></param>
 public void Print(TangOrder order, PrintOption option)
 {
     lock (GetLock(Device.IP))
     {
         try
         {
             var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
             socket.Connect(new IPEndPoint(IPAddress.Parse(Device.IP), Device.Port));
             PrintOrder(order, socket, option);
             socket.Close();
         }
         catch (SocketException ex)
         {
             LogHelper.AddLog($"堂食订单打印异常:{ex.Message}");
             throw new Exception($"打印机[{Device.Name}]连接异常");
         }
         Thread.Sleep(10);
     }
 }
Пример #6
0
        /// <summary>
        /// 打印订单
        /// </summary>
        /// <param name="order"></param>
        public static void Print <T>(T order, int type = 0, PrintOption option = null) where T : class
        {
            var printers = App.Printers.Where(a => a.Device.State == 1);

            if (type != 0)
            {
                printers = printers.Where(a => a.Device.Type == type);
            }
            foreach (var printer in printers)
            {
                for (int i = 0; i < printer.Device.Quantity; i++)
                {
                    if (order is Order entity)
                    {
                        if ((printer.Device.Scope & ActionScope.Takeout) > 0)
                        {
                            printer.Print(entity);
                        }
                    }
                    else if (order is TangOrder tang)
                    {
                        if (printer.Device.Type == 1 &&                                                 // 前台小票机
                            !string.IsNullOrEmpty(printer.Device.CashierName) &&                        // 打印机有设置关联收银台
                            !printer.Device.CashierName.Trim().Equals(tang.CashierName?.Trim() ?? ""))  // 打印机关联收银台与订单不匹配
                        {
                            continue;                                                                   // 不进行打印
                        }
                        if ((printer.Device.Scope & ActionScope.Store) > 0)
                        {
                            printer.Print(tang, option);
                        }
                    }
                    else if (order is ThirdOrder thirdOrder)
                    {
                        if ((printer.Device.Scope & ActionScope.Takeout) > 0)
                        {
                            printer.Print(thirdOrder);
                        }
                    }
                }
            }
        }
Пример #7
0
        /// <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));
        }
Пример #8
0
 public TangFoodPrint(TangOrder order, Printer printer, Socket socket, PrintOption option) : base(order, printer, socket, option)
 {
 }