示例#1
0
        static string convert(string pData)
        {
            //#barcode,12345678#
            //#cut#
            //#clean#
            //#center#

            char xchar = '#';

            StringReader  sr = new StringReader(pData);
            StringBuilder sb = new StringBuilder();

            string line = null;

            while ((line = sr.ReadLine()) != null)
            {
                if (line.StartsWith(xchar.ToString()) && line.EndsWith(xchar.ToString()))
                {
                    line = line.Trim(xchar);
                    var arr = ToolString.explodeList(line);
                    if (arr.Length > 0)
                    {
                        string cmd  = arr.Length > 0 ? arr[0] : null;
                        string arg1 = arr.Length > 1 ? arr[1] : null;
                        string arg2 = arr.Length > 2 ? arr[2] : null;
                        string arg3 = arr.Length > 3 ? arr[3] : null;

                        MemoryStream ms = new MemoryStream();
                        BinaryWriter bw = new BinaryWriter(ms);
                        switch (cmd)
                        {
                        case "barcode":
                            if (arg1 != null)
                            {
                                PosPrinter.Reinit(bw);
                                PosPrinter.OutCenter(bw);
                                PosPrinter.OutHeight(bw, 60);
                                PosPrinter.Barcode(bw, arg1);
                                PosPrinter.Text(bw, arg1);
                                PosPrinter.Reinit(bw);
                            }
                            else
                            {
                                sb.AppendLine("error");
                            }
                            break;

                        case "cut":
                        {
                            PosPrinter.Cut(bw);
                        }
                        break;

                        case "clean":
                        {
                            PosPrinter.Reinit(bw);
                        }
                        break;

                        case "center":
                        {
                            PosPrinter.OutCenter(bw);
                        }
                        break;
                        }

                        bw.Flush();
                        var newdata = ms.ToArray();

                        var newline = Encoding.ASCII.GetString(newdata);

                        sb.AppendLine(newline);
                    }
                }
                else
                {
                    sb.AppendLine(line);
                }
            }



            return(sb.ToString());
        }