public bool TestPrintOrder()
        {
            Double id = printOrder.id;

            pd = new PrintDocument();
            this.setPageSize();
            Model.PrintRe printRe = new Model.PrintRe();
            printRe.id = id;
            try
            {
                Pixel              = pd.DefaultPageSettings.PrinterResolution.X; // 获取分辨率
                pd.PrintPage      += pd_PrintPage;
                pd.PrintController = new StandardPrintController();              //去掉打印弹出框
                pd.Print();
                printRe.code = 0;
                new Utils.Notification().Open("打印通知", "打印完成");
                printRe.msg = "打印成功";
            }
            catch (Exception ex)
            {
                printRe.code = 1;
                printRe.msg  = ex.Message;
                MyLogService.Error("解析打印指令出错", ex);
                new Utils.Notification().Open("打印通知", "解析打印指令出错");
                return(false);
            }
            finally {
                this.msg = DynamicJson.Serialize(printRe);
                MyLogService.Print(this.msg);
            }

            return(true);
        }
 public bool SetPrintOrder(string printOrder)
 {
     try
     {
         new Utils.Notification().Open("打印通知", "已接到打印指令,正在打印");
         this.printOrder = DynamicJson.Parse(printOrder);
         MyLogService.Print(printOrder);
         return(true);
     }
     catch (Exception ex)
     {
         this.msg = ex.Message;
         MyLogService.Error("反序列化打印指令出错", ex);
         new Utils.Notification().Open("打印通知", "反序列化打印指令出错");
         return(false);
     }
 }
        void pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            Graphics g       = e.Graphics;
            var      content = printOrder.content;

            foreach (var item in content)
            {
                string type = item.type;
                switch (type.ToLower())
                {
                case "text":
                    printText(g, item);
                    break;

                case "line":
                    printLine(g, item);
                    break;

                case "qrcode":
                    printBarCode(g, item, BarcodeFormat.QR_CODE);
                    break;

                case "datamatrix":
                    printBarCode(g, item, BarcodeFormat.DATA_MATRIX);
                    break;

                case "barcode":
                    printBarCode(g, item, BarcodeFormat.CODE_128);
                    break;

                case "image":
                    printImage(g, item);
                    break;

                default:
                    MyLogService.Print("无法识别的打印命令:" + type);
                    break;
                }
            }
        }