Ejemplo n.º 1
0
        protected virtual void BeforePrint()
        {
            BufferList = new List <byte[]>();
            // 打印当日序号
            BufferList.Add(PrinterCmdUtils.AlignCenter());
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
            BufferList.Add(Encoding.GetEncoding("gbk").GetBytes("#" + Order.Identifier + " 简单猫"));
            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.AlignLeft());
            // 备注
            if (!string.IsNullOrEmpty(Order.Remark))
            {
                BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
                BufferList.Add(PrinterCmdUtils.BoldOn());
                BufferList.Add(Encoding.GetEncoding("gbk").GetBytes($"备注:{Order.Remark}"));
                BufferList.Add(PrinterCmdUtils.NextLine());
                BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1));
                BufferList.Add(PrinterCmdUtils.BoldOff());
                BufferList.Add(PrinterCmdUtils.NextLine());
            }
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(1));

            BufferList.Add(Encoding.GetEncoding("gbk").GetBytes("下单时间:" + Order.CreateTime.Value.ToString("yyyy-MM-dd HH:mm:ss")));

            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.SplitLine("-", Printer.Format));
            BufferList.Add(PrinterCmdUtils.NextLine());
            BufferList.Add(PrinterCmdUtils.FontSizeSetBig(2));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 打印订单
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static bool Print(Order order)
        {
            Socket     mySocket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress  ipAddress  = IPAddress.Parse("192.168.0.87");
            IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 9100);

            mySocket.Connect(ipEndPoint);
            mySocket.Send(PrinterCmdUtils.AlignCenter());
            mySocket.Send(PrinterCmdUtils.FontSizeSetBig(3));
            mySocket.Send(TextToByte("#3"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.AlignLeft());
            mySocket.Send(PrinterCmdUtils.FontSizeSetBig(1));
            mySocket.Send(TextToByte("商家小票"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.SplitLine("-"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.AlignCenter());
            mySocket.Send(PrinterCmdUtils.FontSizeSetBig(2));
            mySocket.Send(TextToByte("简单猫科技"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.AlignLeft());
            mySocket.Send(PrinterCmdUtils.FontSizeSetBig(1));
            mySocket.Send(TextToByte($"下单时间:{DateTime.Now:yyyy-MM-dd HH:mm:ss}"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(TextToByte("订单编号:201807283486948349"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(TextToByte("--------------------购买商品--------------------"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(TextToByte("劲爆花甲"));
            mySocket.Send(PrinterCmdUtils.AlignCenter());
            mySocket.Send(TextToByte("* 1"));
            mySocket.Send(PrinterCmdUtils.AlignRight());
            mySocket.Send(TextToByte("12"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.AlignLeft());
            mySocket.Send(TextToByte("麻辣虾球"));
            mySocket.Send(PrinterCmdUtils.AlignCenter());
            mySocket.Send(TextToByte("* 2"));
            mySocket.Send(PrinterCmdUtils.AlignRight());
            mySocket.Send(TextToByte("36"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(TextToByte("----------------------其他----------------------"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.AlignLeft());
            mySocket.Send(TextToByte("配送费"));
            mySocket.Send(PrinterCmdUtils.AlignRight());
            mySocket.Send(TextToByte("5"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(TextToByte("------------------------------------------------"));
            mySocket.Send(PrinterCmdUtils.NextLine());
            mySocket.Send(PrinterCmdUtils.FeedPaperCutAll());
            mySocket.Close();
            return(true);
        }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
 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());
     }
 }
Ejemplo n.º 5
0
 protected virtual void AfterPrint()
 {
     BufferList.Add(PrinterCmdUtils.NextLine(2));
     BufferList.Add(PrinterCmdUtils.FeedPaperCutAll());
 }