我有此问题中描述的确切情况:设备中心与打印机队列的通信
由于这个问题既没有接受也没有可接受的答案,因此我再次提出这个问题。
我已经使用Acumatica配置了DeviceHub,并且显示了我的打印机。我正在通过PXAction发送打印作业。执行该操作后,DeviceHub会记录作业的成功接收,但是打印机队列从未接收到该作业。
这是我的代码,因为这是StackOverflow:
public PXAction<PX.Objects.CR.BAccount> PrintAddressLabel;
[PXButton(CommitChanges=true)]
[PXUIField(DisplayName = "Print Label")]
protected void printAddressLabel()
{
BAccount baccount = Base.Caches[typeof(BAccount)].Current as BAccount;
string bAccountID = baccount.BAccountID.ToString();
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["BAccountID"] = bAccountID;
PXReportRequiredException ex = null;
ex = PXReportRequiredException.CombineReport(ex, "ZRCRADDR", parameters);
SMPrintJobMaint.CreatePrintJobGroup("DYMOLABEL", ex, "Address Label");
}
Run Code Online (Sandbox Code Playgroud)
有人可以指出我的帮助方向吗?
编辑:
经过进一步测试,我发现:
Acumatica将使用内置的打印过程成功打印到我的DeviceHub打印机。但是,当打印这些作业之一时,DeviceHub日志会显示一个POLL事件。尝试从我的代码打印时,DeviceHub会记录一个NT事件,该事件永远不会进入打印机队列。
经过进一步测试,2019 R1中的日志略有变化。从Acumatica打印发票NT也会导致事件。但是,与在Acumatica中创建的作业和在代码中创建的作业相比,有一行不同。
绿色= Acumatica的工作
橙色=代码中的工作
Printer DYMOLABEL - printing PDF to \\*printer*从代码发送的作业中缺少该行。
我犹豫是否将其作为答案发布,因为该代码与 Vardan 发布的代码非常相似。但该代码对我不起作用,而这段代码对我有用。它实际上来自他引用的同一个链接,但它来自最后链接的源代码,这是因为我对他的帖子的评论而添加的。我稍微修改了代码,因为我不需要它来完成他所做的一切。
希望它可以帮助别人。
定制类:
[System.SerializableAttribute]
public partial class PrintParameters : IBqlTable, PX.SM.IPrintable
{
#region PrintWithDeviceHub
public abstract class printWithDeviceHub : IBqlField { }
[PXDBBool]
[PXDefault(typeof(FeatureInstalled<FeaturesSet.deviceHub>))]
[PXUIField(DisplayName = "Print with DeviceHub")]
public virtual bool? PrintWithDeviceHub { get; set; }
#endregion
#region DefinePrinterManually
public abstract class definePrinterManually : IBqlField { }
[PXDBBool]
[PXDefault(true)]
[PXUIField(DisplayName = "Define Printer Manually")]
public virtual bool? DefinePrinterManually { get; set; }
#endregion
#region Printer
public abstract class printerName : PX.Data.IBqlField { }
[PX.SM.PXPrinterSelector]
public virtual string PrinterName { get; set; }
#endregion
}
public class CsPrintMaint : PXGraph<CsPrintMaint>
{
public void PrintReportInDeviceHub(string reportID, Dictionary<string, string> parametersDictionary, string printerName, int? branchID)
{
Dictionary<string, PXReportRequiredException> reportsToPrint = new Dictionary<string, PXReportRequiredException>();
PrintParameters filter = new PrintParameters();
filter.PrintWithDeviceHub = true;
filter.DefinePrinterManually = true;
filter.PrinterName = printerName;
reportsToPrint = PX.SM.SMPrintJobMaint.AssignPrintJobToPrinter(reportsToPrint, parametersDictionary, filter,
new NotificationUtility(this).SearchPrinter, CRNotificationSource.BAccount, reportID, reportID, branchID);
if (reportsToPrint != null)
{
PX.SM.SMPrintJobMaint.CreatePrintJobGroups(reportsToPrint);
}
}
}
Run Code Online (Sandbox Code Playgroud)
BusinessAccountMaint 扩展:
public class BusinessAccountMaint_Extension : PXGraphExtension<BusinessAccountMaint>
{
public PXAction<BAccount> printAddressLabelNH;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Print Label (NH)")]
public virtual IEnumerable PrintAddressLabelNH(PXAdapter adapter)
{
int? branchID = this.Base.Accessinfo.BranchID;
Dictionary<string, string> parametersDictionary = new Dictionary<string, string>();
BAccount bAccount = this.Base.Caches[typeof(BAccount)].Current as BAccount;
parametersDictionary["BAccount.BAccountID"] = bAccount.BAccountID.ToString();
CsPrintMaint printMaintGraph = PXGraph.CreateInstance<CsPrintMaint>();
printMaintGraph.PrintReportInDeviceHub("ZRADDRBA", parametersDictionary, "DYMOLBLNH", branchID);
return adapter.Get();
}
}
Run Code Online (Sandbox Code Playgroud)