Пример #1
0
        /// <summary>
        /// 会员充值小票
        /// </summary>
        /// <param name="shop"></param>
        /// <param name="num"></param>
        /// <param name="count"></param>
        /// <param name="way"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public static byte[] charge(String shop, String num, String count, String way, String time)
        {
            String shop_f  = "   会员充值(" + shop + ")";
            String num_f   = "   会员号码:" + num;
            String count_f = "   充值金额:" + count;
            String way_f   = "   充值方式:" + way;
            String time_f  = "   充值时间:" + time;

            try
            {
                byte[] b_title        = System.Text.Encoding.GetEncoding("gbk").GetBytes(shop_f);
                byte[] b_num          = System.Text.Encoding.GetEncoding("gbk").GetBytes(num_f);
                byte[] b_count        = System.Text.Encoding.GetEncoding("gbk").GetBytes(count_f);
                byte[] b_way          = System.Text.Encoding.GetEncoding("gbk").GetBytes(way_f);
                byte[] b_time         = System.Text.Encoding.GetEncoding("gbk").GetBytes(time_f);
                byte[] b_no           = System.Text.Encoding.GetEncoding("gbk").GetBytes("   ----------------------------------------");
                byte[] b_breakPartial = PrinterCmdUtils.feedPaperCutPartial();

                byte[][] charge_0 =
                {
                    b_init,
                    b_center,      b_title,     b_next2Line,
                    b_left,        b_count,     b_nextLine,
                    b_way,         b_nextLine,
                    b_time,        b_nextLine,
                    b_no,          b_nextLine,
                    b_breakPartial,
                    PrinterCmdUtils.open_money()
                };

                byte[][] charge_1 =
                {
                    b_init,
                    b_center,      b_title,     b_next2Line,
                    b_left,        b_num,       b_nextLine,
                    b_count,       b_nextLine,
                    b_way,         b_nextLine,
                    b_time,        b_nextLine,
                    b_no,          b_nextLine,
                    b_breakPartial,
                    PrinterCmdUtils.open_money()
                };

                if (String.IsNullOrEmpty(num))
                {
                    return(PrinterCmdUtils.byteMerger(charge_0));
                }
                else
                {
                    return(PrinterCmdUtils.byteMerger(charge_1));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #2
0
        public static byte[] bmpToByte(Bitmap bmp)
        {
            int h = bmp.Height / 24 + 1;
            int w = bmp.Width;

            byte[][] all = new byte[4 + 2 * h + h * w][];

            all[0] = new byte[] { 0x1B, 0x33, 0x00 };

            Color pixelColor;

            // ESC * m nL nH 点阵图
            byte[] escBmp = new byte[] { 0x1B, 0x2A, 0x21, (byte)(w % 256), (byte)(w / 256) };

            // 每行进行打印
            for (int i = 0; i < h; i++)
            {
                all[i * (w + 2) + 1] = escBmp;
                for (int j = 0; j < w; j++)
                {
                    byte[] data = new byte[] { 0x00, 0x00, 0x00 };
                    for (int k = 0; k < 24; k++)
                    {
                        if (((i * 24) + k) < bmp.Height)
                        {
                            pixelColor = bmp.GetPixel(j, (i * 24) + k);
                            if (pixelColor.R == 0)
                            {
                                data[k / 8] += (byte)(128 >> (k % 8));
                            }
                        }
                    }
                    all[i * (w + 2) + j + 2] = data;
                }
                //换行
                all[(i + 1) * (w + 2)] = PrinterCmdUtils.nextLine(1);
            }
            all[h * (w + 2) + 1] = PrinterCmdUtils.nextLine(2);
            all[h * (w + 2) + 2] = PrinterCmdUtils.feedPaperCutAll();
            all[h * (w + 2) + 3] = PrinterCmdUtils.open_money();

            return(PrinterCmdUtils.byteMerger(all));
        }
Пример #3
0
        public void SendSocketMsg(String ip, int port, int times, byte[] data)
        {
            try
            {
                byte[] mData;
                if (times == 1)
                {
                    mData = new byte[data.Length];
                    Array.Copy(data, 0, mData, 0, data.Length);
                }
                else
                {
                    mData = new byte[data.Length * times];
                    byte[][] m = new byte[times][];
                    for (int i = 0; i < times; i++)
                    {
                        m[i] = data;
                    }
                    Array.Copy(PrinterCmdUtils.byteMerger(m), 0, mData, 0, PrinterCmdUtils.byteMerger(m).Length);
                }

                #region  步 Socket
                Socket     mySocket   = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                IPAddress  ipAddress  = IPAddress.Parse(ip);
                IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, port);

                mySocket.Connect(ipEndPoint);
                //mySocket.Send(data);
                mySocket.Send(mData);
                mySocket.Close();
                #endregion
            }
            catch (Exception ex)
            {
                Logger.Trace(ex.Message);
                Logger.Trace(ex.StackTrace);
            }
        }
Пример #4
0
        /// <summary>
        /// 收银小票  Json对象拼接
        /// </summary>
        /// <param name="head"></param>
        /// <param name="recv"></param>
        /// <param name="foot"></param>
        /// <returns></returns>
        public static byte[] jsonParse(String head, String recv, String foot, String url)
        {
            try
            {
                //二维码生成
                EscCommand esc = new EscCommand();
                esc.addSelectErrorCorrectionLevelForQRCode((byte)0x31);
                esc.addSelectSizeOfModuleForQRCode((byte)8);
                esc.addStoreQRCodeData(url);
                esc.addPrintQRCode();

                ArrayList datas = esc.getCommand();
                Byte[]    Bytes = new Byte[datas.Count];
                for (int i = 0; i < datas.Count; i++)
                {
                    Bytes[i] = (Byte)datas[i];
                }

                byte[] bytes = EscCommand.toPrimitive(Bytes);

                //打印小票头部
                List <String>     headString = new List <String>();
                List <TicketHead> mHeads     = JsonConvert.DeserializeObject <List <TicketHead> >(head);

                headString.Add("  " + mHeads[0].Ordertime);
                headString.Add("  NO." + mHeads[0].Shopno);
                headString.Add(FileUtils.getFixedWidthString("  当班人员:" + mHeads[0].Shopuser, 36) + "餐牌号:" + mHeads[0].Card);
                headString.Add("  ---------------------------------------------");

                List <String> newString = new List <String>();
                List <Ticket> mTickets  = JsonConvert.DeserializeObject <List <Ticket> >(recv);

                String nameTitle = "  名称              数量 售价    优惠    总额";
                newString.Add(nameTitle);

                for (int i = 0; i < mTickets.Count; i++)
                {
                    StringBuilder item = new StringBuilder();

                    if (("1".Equals(mTickets[i].Type) || "2".Equals(mTickets[i].Type)))
                    {
                        if ("".Equals(mTickets[i].Parentid))
                        {
                            if (mTickets[i].Name.Length > 8)
                            {
                                item.Append(FileUtils.getFixedWidthString(mTickets[i].Name.Substring(0, 8), 19));
                                item.Append(mTickets[i].Num.PadRight(4));
                                item.Append(String.Format("{0:F2}", mTickets[i].Price).PadRight(8));
                                item.Append(String.Format("{0:F2}", mTickets[i].Rebetmoney).PadRight(8));
                                item.Append(String.Format("{0:F2}", mTickets[i].Money).PadRight(6));

                                newString.Add("  " + item.ToString());
                                newString.Add("  " + mTickets[i].Name.Substring(8, mTickets[i].Name.Length - 8));
                            }
                            else
                            {
                                item.Append(FileUtils.getFixedWidthString(mTickets[i].Name, 19));
                                item.Append(mTickets[i].Num.PadRight(4));
                                item.Append(String.Format("{0:F2}", mTickets[i].Price).PadRight(8));
                                item.Append(String.Format("{0:F2}", mTickets[i].Rebetmoney).PadRight(8));
                                item.Append(String.Format("{0:F2}", mTickets[i].Money).PadRight(6));

                                newString.Add("  " + item.ToString());
                            }
                        }
                        else
                        {
                            newString.Add("  " + mTickets[i].Name);
                        }
                    }
                }

                newString.Add("  ---------------------------------------------");

                List <String>     footString = new List <String>();
                List <TicketFoot> mFoots     = JsonConvert.DeserializeObject <List <TicketFoot> >(foot);

                String moneytotal = ((float.Parse(mFoots[0].DecAmmBalance) + float.Parse(mFoots[0].DecGroupBuyMoney))).ToString("f2");
                String money      = ((float.Parse(mFoots[0].DecRebeatBalance) + float.Parse(mFoots[0].DecGroupBuyMoney))).ToString("f2");

                footString.Add(FileUtils.getFixedWidthString("  餐品数量:", 20) + FileUtils.getFixedWidthString(mFoots[0].Counts, 10) + "点餐金额: " + moneytotal.PadRight(4));

                if (float.Parse(mFoots[0].DecWipeMoney) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  抹零优惠:", 40) + mFoots[0].DecWipeMoney);
                }

                if (float.Parse(mFoots[0].DecMemberCoupon) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  会员优惠:", 40) + mFoots[0].DecMemberCoupon);
                }

                if (float.Parse(money) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  券类优惠:", 40) + money.PadRight(4));

                    for (int i = 0; i < mTickets.Count; i++)
                    {
                        if (!"1".Equals(mTickets[i].Type) && !"2".Equals(mTickets[i].Type))
                        {
                            footString.Add(FileUtils.getFixedWidthString("    " + mTickets[i].Name, 20) + mTickets[i].Num);
                        }
                        else
                        {
                            if (!string.IsNullOrEmpty(mTickets[i].RebetName))
                            {
                                footString.Add(FileUtils.getFixedWidthString("    " + mTickets[i].RebetName, 20) + 1);
                            }
                        }
                    }
                }

                footString.Add("  ---------------------------------------------");
                if (float.Parse(mFoots[0].DecPaidBalance) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  折后支付:", 40) + mFoots[0].DecPaidBalance);
                }

                if (float.Parse(mFoots[0].Membermoney) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  会员支付:", 40) + mFoots[0].Membermoney);
                }

                if (float.Parse(mFoots[0].Cashmoney) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  现金支付:", 40) + mFoots[0].Cashmoney);
                }

                if (!string.IsNullOrEmpty(mFoots[0].Bankmoney))
                {
                    footString.Add(FileUtils.getFixedWidthString("  " + mFoots[0].Bankmoney.Split(':')[0], 40) + mFoots[0].Bankmoney.Split(':')[1]);
                }

                if (float.Parse(mFoots[0].Givechange) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  现金找零:", 40) + mFoots[0].Givechange);
                }

                if (float.Parse(mFoots[0].RechMoney) != 0.0f)
                {
                    footString.Add(FileUtils.getFixedWidthString("  充值金额:", 40) + mFoots[0].RechMoney);
                }

                /////////////////////////////////////////////////////////////////////////////////////////


                byte[][] headByte = new byte[15][];                                    //头部数组
                headByte[0] = b_init;
                headByte[1] = b_center;
                headByte[2] = System.Text.Encoding.GetEncoding("gbk").GetBytes("欢迎光临");
                headByte[3] = b_nextLine;
                headByte[4] = System.Text.Encoding.GetEncoding("gbk").GetBytes(mHeads[0].Shopbrand);
                headByte[5] = b_next2Line;
                headByte[6] = b_left;
                for (int i = 0; i < 8; i += 2)
                {
                    headByte[i + 7] = System.Text.Encoding.GetEncoding("gbk").GetBytes(headString[i / 2]);
                    headByte[i + 8] = b_nextLine;
                }

                byte[][] contentByte = new byte[newString.Count * 2][];            //中间体
                for (int i = 0; i < newString.Count * 2; i += 2)
                {
                    contentByte[i]     = System.Text.Encoding.GetEncoding("gbk").GetBytes(newString[i / 2]);
                    contentByte[i + 1] = b_nextLine;
                }

                byte[][] footByte = new byte[footString.Count * 2 + 23][];            //底部数组
                for (int i = 0; i < footString.Count * 2; i += 2)
                {
                    footByte[i]     = System.Text.Encoding.GetEncoding("gbk").GetBytes(footString[i / 2]);
                    footByte[i + 1] = b_nextLine;
                }

                footByte[footString.Count * 2] = System.Text.Encoding.GetEncoding("gbk").GetBytes("  ---------------------------------------------");
                if (string.IsNullOrEmpty(mHeads[0].Memberid))
                {
                    footByte[footString.Count * 2 + 1] = b_center;
                    footByte[footString.Count * 2 + 2] = b_center;
                }
                else
                {
                    footByte[footString.Count * 2 + 1] = b_nextLine;
                    footByte[footString.Count * 2 + 2] = System.Text.Encoding.GetEncoding("gbk").GetBytes("  会员号:" + mHeads[0].Memberid);
                }

                footByte[footString.Count * 2 + 3] = b_next2Line;
                footByte[footString.Count * 2 + 4] = b_center;
                footByte[footString.Count * 2 + 5] = System.Text.Encoding.GetEncoding("gbk").GetBytes("谢谢惠顾!欢迎再次光临!");
                footByte[footString.Count * 2 + 6] = b_nextLine;
                footByte[footString.Count * 2 + 7] = System.Text.Encoding.GetEncoding("gbk").GetBytes("如需开发票,请凭小票在一周内到门店开取");
                footByte[footString.Count * 2 + 8] = b_next2Line;

                footByte[footString.Count * 2 + 9]  = b_left;
                footByte[footString.Count * 2 + 10] = System.Text.Encoding.GetEncoding("gbk").GetBytes("  门店地址:" + mHeads[0].Shopaddress);
                footByte[footString.Count * 2 + 11] = b_nextLine;
                footByte[footString.Count * 2 + 12] = System.Text.Encoding.GetEncoding("gbk").GetBytes("  联系电话:" + mHeads[0].Shoptel);
                footByte[footString.Count * 2 + 13] = b_nextLine;
                footByte[footString.Count * 2 + 14] = System.Text.Encoding.GetEncoding("gbk").GetBytes("  品牌网址:" + mHeads[0].Url);
                footByte[footString.Count * 2 + 15] = b_next2Line;
                footByte[footString.Count * 2 + 16] = b_center;

                footByte[footString.Count * 2 + 17] = b_next2Line;
                footByte[footString.Count * 2 + 18] = System.Text.Encoding.GetEncoding("gbk").GetBytes("微信扫一扫    畅享免费WiFi");
                footByte[footString.Count * 2 + 19] = b_next2Line;

                footByte[footString.Count * 2 + 20] = bytes;
                footByte[footString.Count * 2 + 21] = b_breakPartial;
                footByte[footString.Count * 2 + 22] = PrinterCmdUtils.open_money();

                byte[][] totalByte = new byte[38 + newString.Count * 2 + footString.Count * 2][];

                Array.Copy(headByte, totalByte, headByte.Length);
                Array.Copy(contentByte, 0, totalByte, headByte.Length, contentByte.Length);
                Array.Copy(footByte, 0, totalByte, headByte.Length + contentByte.Length, footByte.Length);

                return(PrinterCmdUtils.byteMerger(totalByte));
            }
            catch (Exception)
            {
                throw;
            }
        }