本文主要是介绍bartender打印脚本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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();
}
}
}
这篇关于bartender打印脚本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!