打印机无法从DeviceHub接收作业

时间:2019-06-10 14:11:50

标签: c# acumatica

我对这个问题有确切的描述:Device Hub communication with printer queue

由于该问题既没有接受也没有可接受的答案,所以我再次提出问题。

我已经用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");
}

有人可以指出我的帮助方向吗?

编辑:

进一步测试后,我发现了以下内容:

Acumatica将使用内置的打印过程成功打印到我的DeviceHub打印机。但是,当打印这些作业之一时,DeviceHub日志显示一个POLL事件。尝试从我的代码打印时,DeviceHub会记录一个NT事件,该事件永远不会进入打印机队列。

在进一步测试中,2019 R1中的日志略有变化。从Acumatica打印发票也会导致NT事件。但是,与在Acumatica中创建的作业和在代码中创建的作业相比,只有一行不同。

绿色= Acumatica的工作

橙色=代码中的工作

代码发送的作业中缺少行Printer DYMOLABEL - printing PDF to \\*printer*

2 个答案:

答案 0 :(得分:3)

如果我的理解正确,那么您需要通过Automation Steps屏幕添加报告,并将其与DeviceHub关联。
发票编写了示例,当该过程将在需要打印发票的情况下进行,然后将使用以下设置:

public class CustomEntry : PXGraph<CustomEntry>
{
 [PXQuickProcess.Step.IsBoundToAttribute(typeof(UsrPath.SO303000.Balanced.Report.PrintLabelReport), false)][PXQuickProcess.Step.RequiresStepsAttribute(typeof(SOQuickProcessParameters.prepareInvoice))]
 [PXQuickProcess.Step.IsInsertedJustAfterAttribute(typeof(SOQuickProcessParameters.prepareInvoice))]
 [PXQuickProcess.Step.IsApplicableAttribute(typeof(Where<Current<SOOrderType.behavior>, In3<SOOrderTypeConstants.salesOrder, SOOrderTypeConstants.invoiceOrder, SOOrderTypeConstants.creditMemo>, And<Current<SOOrderType.aRDocType>, NotEqual<ARDocType.noUpdate>>>))]
 protected virtual void SOQuickProcessParameters_PrintInvoice_CacheAttached(PXCache sender)
 {
 }
}
public static class UsrPath
{
 public static class SO303000
 {
    public static readonly Type GroupGraph = typeof(SOInvoiceEntry);
    public static class Balanced
    {
        public const string GroupStepID = "Balanced";
        public static class Report
        {
            public const string GroupActionID = "Report";
            public class PrintLabelReport : PXQuickProcess.Step.IDefinition
            {
                public Type Graph
                {
                    get
                    {
                        return UsrPath.SO303000.GroupGraph;
                    }
                }
                public string StepID
                {
                    get
                    {
                        return "Balanced";
                    }
                }
                public string ActionID
                {
                    get
                    {
                        return "Report";
                    }
                }
                public string MenuID
                {
                    get
                    {
                        return "Print Label";
                    }
                }
                public string OnSuccessMessage
                {
                    get
                    {
                        return "<Invoice form> is prepared";
                    }
                }
                public string OnFailureMessage
                {
                    get
                    {
                        return "Preparing Invoice form";
                    }
                }
            }
        }
     }
  }
}  

更新的答案

 public PXAction<BAccount> PrintAddressLabel;
    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Print Label")]
    protected virtual IEnumerable printAddressLabel(PXAdapter adapter)
    {
        List<BAccount> list = adapter.Get<BAccount>().ToList<BAccount>();
        int? branchID = this.Base.Accessinfo.BranchID;
        const string reportID = "YOUR_REPORT_ID";
        Dictionary<string, string> dictionary = new Dictionary<string, string>();
        Dictionary<string, PXReportRequiredException> dictionary2 = new Dictionary<string, PXReportRequiredException>();
        PXReportRequiredException ex = null;
        foreach (BAccount account in list)
        {
            dictionary["BAccountID"] = account.AcctCD;
            ex = PXReportRequiredException.CombineReport(ex, null, dictionary);
            object row = PXSelectorAttribute.Select<BAccount.bAccountID>(this.Base.BAccount.Cache, account);
            string text = new NotificationUtility(this.Base).SearchReport(null, row, reportID, branchID);
            //I think you get this problem due to absence of this line
            PrintParameters printParams = new PrintParameters
            {
                PrintWithDeviceHub = true,
                DefinePrinterManually = true,
                PrinterName = "DYMOLABEL"
            };
            dictionary2 = SMPrintJobMaint.AssignPrintJobToPrinter(dictionary2, dictionary, printParams, new NotificationUtility(this.Base).SearchPrinter, null, reportID, reportID, this.Base.Accessinfo.BranchID);
        }
        if (ex != null)
        {
            SMPrintJobMaint.CreatePrintJobGroups(dictionary2);
            throw ex;
        }
        return adapter.Get();
    }

    [Serializable]
    [PXCacheName("Print Parameters")]
    public partial class PrintParameters : IBqlTable, IPrintable
    {
        #region PrintWithDeviceHub
        [PXDBBool]
        [PXDefault(typeof(FeatureInstalled<FeaturesSet.deviceHub>))]
        public virtual bool? PrintWithDeviceHub { get; set; }
        public abstract class printWithDeviceHub : IBqlField { }
        #endregion

        #region DefinePrinterManually
        [PXDBBool]
        [PXDefault(true)]
        public virtual bool? DefinePrinterManually { get; set; }
        public abstract class definePrinterManually : IBqlField { }
        #endregion

        #region PrinterName
        [PXPrinterSelector]
        public virtual string PrinterName { get; set; }
        public abstract class printerName : IBqlField { }
        #endregion
    }  

Configuration of the Device Hub

答案 1 :(得分:0)

我不愿意将此作为答案发布,因为代码与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);
    }
  }
}

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