Acumatica处理屏幕更新ARTran自定义字段需要还更新自定义表字段

时间:2017-12-31 23:46:47

标签: acumatica

我们有一个自定义处理屏幕,它正在更新ARTran表中名为UsrDateNotified的自定义字段,其中UsrDateNotified位于自定义表ItemBaseDocument中的RevisionDateReceived之前。我们还需要更新表ItemBaseDocument中的UsrDateNotified字段,该字段链接到ARTran中的InventoryID。我们当前的代码验证了更新ARTran表,但我们正在努力解决如何更新所选ARTran记录的相关ItemBaseDocument。这种情况的正确方法是什么?

using System;
using System.Collections;
using System.Linq;
using PX.Data;
using PX.SM;
using PX.Objects.AR;
using PX.Objects.CR;
using PX.Objects.IN;

namespace DocCenter
{
  public class UpdateLastNotified : PXGraph<UpdateLastNotified>
  {
    public PXFilter<UpdateLastNotifiedFilter> MasterView;
    public PXCancel<UpdateLastNotifiedFilter> Cancel;


    [PXFilterable]

    public PXSelect<ARTran> DetailsView;

 public UpdateLastNotified() 
    {
   Cancel.SetCaption("Clear Filter");
   this.DetailsView.Cache.AllowInsert = false;
   this.DetailsView.Cache.AllowDelete = false;
   this.DetailsView.Cache.AllowUpdate = true; 
    }



protected virtual IEnumerable detailsView()
{
UpdateLastNotifiedFilter filter = MasterView.Current as UpdateLastNotifiedFilter;
PXSelectBase<ARTran> cmd = new PXSelectJoinOrderBy<ARTran, 
  InnerJoin<InventoryItem, On<ARTran.inventoryID, Equal <InventoryItem.inventoryID>>, 
  InnerJoin<ItemBaseDocument, On<InventoryItemExt.usrDocumentNumber, Equal<ItemBaseDocument.baseDocumentCode>>,
  InnerJoin<Contact, On<ARTranExt.usrContactID, Equal<Contact.contactID>>>>>,  
  OrderBy<Asc<ARTran.tranDate>>>(this);    

cmd.WhereAnd<Where<ContactExt.usrNotificationPriority,
Equal<Current<UpdateLastNotifiedFilter.notificationPriority>>>>();   


cmd.WhereAnd<Where<ARTranExt.usrDateNotified,
Less<ItemBaseDocument.revisionDateReceived>>>();     


 if (filter.BaseDocumentCode != null)
{
 cmd.WhereAnd<Where<InventoryItemExt.usrDocumentNumber,
Equal<Current<UpdateLastNotifiedFilter.baseDocumentCode>>>>(); 
}  

   return cmd.Select();
} 

public PXAction<UpdateLastNotifiedFilter> Process;
[PXProcessButton]
[PXButton(CommitChanges=true)]
[PXUIField(DisplayName = "Process")]
protected virtual IEnumerable process(PXAdapter adapter)
{

  PXLongOperation.StartOperation(this, delegate() 
  {
  foreach(ARTran tran in DetailsView.Select())
    {
    if (tran.Selected==true)
      {
      ARTranExt tranExt = tran.GetExtension<ARTranExt>();
      ARInvoiceEntry tranEntry = new ARInvoiceEntry();
      tranExt.UsrDateNotified = MasterView.Current.DateNotified;
      tranEntry.Transactions.Update(tran);
      tranEntry.Save.PressButton();



      }

    }


  }

        );
 return adapter.Get();
}




    [Serializable]
    public class UpdateLastNotifiedFilter : IBqlTable
    {

public static class NotificationPriority
{
    public const string None = "N";
    public const string Alert = "A";
    public const string Express = "E";
    public const string Shipment = "P";
    public const string Subscription = "S";
}   


      #region NotificationPriority
      public abstract class notificationPriority : PX.Data.IBqlField
      {
      }  

      [PXDBString(1, IsFixed = true)]
      [PXDefault(NotificationPriority.None)]
      [PXUIField(DisplayName = "Notification Type")]
      [PXStringList(
          new string[]
      {
      NotificationPriority.None,
      NotificationPriority.Alert,
      NotificationPriority.Express,
      NotificationPriority.Shipment,
      NotificationPriority.Subscription
      },
      new string[]
      {
      "None",
      "Alert",
      "Express",
      "Shipment",
      "Subscription"
      })]  


      #endregion    





      #region BaseDocumentID
      public abstract class baseDocumentCode : PX.Data.IBqlField
      {
      }  

 [PXString(50)]
[PXUIField(DisplayName="Document Number")]
[PXSelector(typeof(DocCenter.ItemBaseDocument.baseDocumentCode))]    

      public virtual String BaseDocumentCode
      {
        get;

        set;

      }
      #endregion      



      #region DateNotified
      public abstract class dateNotified : PX.Data.IBqlField
      {
      } 
      [PXDBDate()]
      [PXDefault(typeof(AccessInfo.businessDate))]
      [PXUIField(DisplayName = "Date Notified")]
      public DateTime? DateNotified { get; set; }
      #endregion 




    }




  }
}

1 个答案:

答案 0 :(得分:0)

您最好的选择是创建一个选择ItemBaseDocument的视图。

PXSelect<ItemBaseDocument> ViewName;

在for循环的操作按钮中,您将需要创建一个新的ItemBaseDocument对象并将其设置为相应的ItemBaseDocument行条目。然后,您可以更新此对象的日期,以及执行Save.PressButton()操作时,该操作也应保存对该条目的更新。

foreach(ARTran tran in DetailsView.Select())
{
if (tran.Selected==true)
  {
  ARTranExt tranExt = tran.GetExtension<ARTranExt>();
  ARInvoiceEntry tranEntry = new ARInvoiceEntry();
  tranExt.UsrDateNotified = MasterView.Current.DateNotified;
  tranEntry.Transactions.Update(tran);
  tranEntry.Save.PressButton();

  //Target Added Code
  ItemBaseDocument doc = PXSelect<ItemBaseDocument, Where<ItemBaseDocument.inventoryID, 
     Equal<Required<ARTran.inventoryID>>>>.Select(tran.InventoryID);
  doc.UsrDateNotified = MasterView.Current.DateNotified;

  }

}

免责声明:上面添加的代码中可能存在语法错误。如果有,请告诉我,我会解决它。