【问题标题】:Printer fails to receive job from DeviceHub打印机无法从 DeviceHub 接收作业
【发布时间】:2019-10-24 22:55:48
【问题描述】:

我有这个问题中描述的确切情况: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* 行。

【问题讨论】:

    标签: c# acumatica


    【解决方案1】:

    如果我理解正确,那么您需要通过Automation Steps 屏幕添加报告并将其与DeviceHub 关联。
    示例是为 Invoices 编写的,当流程将在需要打印 Invoice 的情况下工作时,将使用这些设置:

    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

    【讨论】:

    • 任何澄清的cmets?这与 DeviceHub 有什么关系,或者我将如何“将其与 DeviceHub 关联”?
    • 这看起来更像我的预期!不过我有点困惑。有好几次你将"ZRCRADDR"reportID 都传递给了一个方法。 "ZRCRADDR" 是我的报告。您是在这种假设下操作,还是您认为那是我的打印机?在我的代码中,"DYMOLABEL" 是我的打印机。
    • 使用这个字符串值 Acumatica Create Primary Graph 将打印("Customer"=&gt; CustomerMaint,"Vendor"=&gt;VendorMaint),你可以输入null
    • 您的更新代码现已到达 DeviceHub。但很可惜,同样的问题也存在。从 Acumatica 开始的作业会成功,而从代码开始的作业则不会。我用详细信息更新了我的问题。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-05
      • 2018-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-03
      • 2012-06-24
      • 1970-01-01
      相关资源
      最近更新 更多