套打.二开案例.表单插件中获取默认打印机

<0>效果

<1>实现
通过前端QueryPrinterInfo指令获取打印机信息。


[Kingdee.BOS.Util.HotUpdate]
[Description("获取打印机信息")]
public class PrinterSamplePlugIn : AbstractListPlugIn
{
//超时时间
private int timeoutMilliseconds = 10000;
//默认打印机线程同步开关
private ManualResetEvent manualEvent = new ManualResetEvent(false);
//打印机查询信息结果
private KDPrinterQueryInfoResult printerQueryInfoResult;
//打印机查询信息请求
private KDPrinterQueryInfoArg printerQueryInfoArg;
private static readonly string QueryPrinterInfo = "QueryPrinterInfo";
public override void CustomEvents(CustomEventsArgs e)
{
if (e == null)
return;
if (e.EventName == QueryPrinterInfo)
{
try
{
KDPrinterQueryInfoResult result = JSONObject.Parse(e.EventArgs).ConvertToObject<KDPrinterQueryInfoResult>();
//命令区分
if (result.JobId == printerQueryInfoArg.JobId)
printerQueryInfoResult = result;
}
catch
{
//代码跑到这个位置代表着转换失败,考虑是否插件没有升级,打印服务有没有升级的兼容
}
finally
{
manualEvent.Set();
}
}
}
public override void BarItemClick(BarItemClickEventArgs e)
{
if (e.BarItemKey.EqualsIgnoreCase("GetDefPrinter"))
if (printerQueryInfoArg != null)
{
return;
}
manualEvent.Reset();
printerQueryInfoResult = null;
printerQueryInfoArg = new KDPrinterQueryInfoArg()
{
IsDialog = false,
IsDefaultInfo = true,
IncludeAll = false,
JobId = Guid.NewGuid().ToString(),
PrintAddress = string.Empty,
};
this.View.AddAction(QueryPrinterInfo, printerQueryInfoArg);
this.View.ShowProcessForm((x) =>
{
var result = GetPrinterResult();
this.View.ShowOperateResult(result);
printerQueryInfoResult = null;
printerQueryInfoArg = null;
}, "获取默认打印机配置...");
MainWorker.QuequeTask(this.View.Context, () =>
{
try
{
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
manualEvent.WaitOne(timeoutMilliseconds);
}
catch (Exception ex)
{
}
finally
套打.二开案例.表单插件中获取默认打印机
声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。



