bartender打印脚本

该代码片段展示了如何在C#程序中使用BarTender库,通过获取传入的参数(如IMEI、日期和二维码),更新模板中的值,然后进行一次序列化标签的打印操作,防止重复打印。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;

namespace print
{
    class Program
    {

        private static void Main(string[] args)
        {

            //1.获取MES账户信息
            String did = "did";
            String password = "password";
            String imei = "imei";
            String date = "date";
            String qrcode = "%7B%22did%22%3A701184104%2C%22password%22%3A%22716888%22%2C%22authkey%22%3Anull%2C%22keyId%22%3A%22861213050793238%22%7D";
            if (args.Length > 0)
            {
                String urlArg = args[0];
                String right = urlArg.Split("://")[1].Split("/")[0];
                String[] urlArgs = right.Split(';');
                if (urlArgs.Length == 5) {
                    did = urlArgs[0];
                    password = urlArgs[1];
                    imei = urlArgs[2];
                    date = urlArgs[3];
                    qrcode = urlArgs[4];
                }
            }
            Console.WriteLine(did);
            Console.WriteLine(password);
            Console.WriteLine(imei);
            Console.WriteLine(date);
            Console.WriteLine(qrcode);
            //1.打开bartender
            BarTender.Application btapp = new BarTender.Application();
            //2.选择模板
            BarTender.Format btformat = btapp.Formats.Open(@"C:\bartender\print.btw", false, "");
            String oldDid = btformat.GetNamedSubStringValue("did");
            if (oldDid.Contains(did))
            {
                //本次打印的和上次相同,拒绝打印
                Console.WriteLine("系统拦截重复打印");
                btformat.Close();
                btapp.Quit();
                Thread.Sleep(5000);
                return;
            }
            //传递参数
            btformat.SetNamedSubStringValue("did", did);
            btformat.SetNamedSubStringValue("password", password);
            btformat.SetNamedSubStringValue("imei", imei);
            btformat.SetNamedSubStringValue("date", date);
            String code = System.Web.HttpUtility.UrlDecode(qrcode);
            btformat.SetNamedSubStringValue("qrcode", code);
            //3.打印一份
            btformat.PrintSetup.NumberSerializedLabels = 1;
            //4.执行打印
            btformat.PrintOut(true, false);
            //5.关闭模板
            btformat.Save();
            btformat.Close();
            //6.退出bartender
            btapp.Quit();
        }
    }

}
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值