套打.二开案例.表单插件中获取默认打印机
<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
{
if (this.View != null)
this.View.Session["ProcessRateValue"] = 100;
}
}, (T) => { });
}
private OperateResultCollection GetPrinterResult()
{
if (printerQueryInfoResult == null)
{
OperateResult nullResult = new OperateResult()
{
Name = "获取打印机配置",
MessageType = MessageType.FatalError,
SuccessStatus = false,
Message = "获取打印机配置",
};
return new OperateResultCollection() { nullResult };
}
OperateResultCollection collection = new OperateResultCollection();
OperateResult successResult = new OperateResult()
{
Name = "获取打印机配置",
MessageType = MessageType.Normal,
SuccessStatus = true,
Message = "获取打印机配置成功",
};
collection.Add(successResult);
var defaultPrinter = printerQueryInfoResult.Printer;
if (defaultPrinter == null)
return collection;
//输出部分常规打印机信息
foreach (var prop in defaultPrinter.GetType().GetProperties())
{
if (!prop.CanRead)
continue;
OperateResult propResult = new OperateResult()
{
Name = prop.Name,
MessageType = MessageType.Normal,
SuccessStatus = true,
Message = ObjectUtils.Object2String(prop.GetValue(defaultPrinter, null)),
};
collection.Add(propResult);
}
return collection;
}
}
套打.二开案例.表单插件中获取默认打印机
本文2024-09-23 04:12:43发表“云星空知识”栏目。
本文链接:https://wenku.my7c.com/article/kingdee-k3cloud-163844.html