bartender打印脚本

发布时间:2024年01月09日

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();
? ? ? ? }
? ? }

}
?

文章来源:https://blog.csdn.net/abcmaopao/article/details/135480889
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。