如何检查删除是否被按下,因为删除项目

时间:2015-06-18 07:50:49

标签: acumatica

有没有办法检查Acumatica屏幕中是否按下了删除操作?这是因为我有一个用于重新加载StockItems屏幕的代码,每当我删除一个项目时,它都会给我一个movenext错误,但该项目正在被成功删除。以下是我的重装代码:

[PXOverride]
  public void Persist(Action persist)
  {
   persist();// this will call base Persist();
   InventoryItemMaint grp = PXGraph.CreateInstance<InventoryItemMaint>();
   InventoryItem inv = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>.Select(grp, this.Base.Item.Current.InventoryCD.Trim());
   if (inv != null && inv.InventoryID.HasValue)
   {
      grp.Item.Current = grp.Item.Search<InventoryItem.inventoryID>(inv.InventoryID);
      throw new PXRedirectRequiredException(grp, "Reloading Item");
   }
  }

2 个答案:

答案 0 :(得分:1)

作为我建议你添加到DAC字段IsDeleted的方法之一,如下所示:

[PXBool]
[PXDefault(false)]
public bool? IsDeleted { get; set; }

然后附加到RowDeleting()。例如:

protected virtual void ShipmentLine_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
{
    ShipmentLine line = (ShipmentLine)e.Row;
    line.IsDeleted = true;
}

最后将代码修改为以下场景:

[PXOverride]
public void Persist(Action persist)
{
  ShipmentLine  line = ViewShipmentLine.Current;
  if(line.IsDeleted)
  {
      //do some logic which you consider as nesessary
  }
  persist();// this will call base Persist();
  InventoryItemMaint grp = PXGraph.CreateInstance<InventoryItemMaint>();
  InventoryItem inv = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD,Equal<Required<InventoryItem.inventoryCD>>>>.Select(grp, this.Base.Item.Current.InventoryCD.Trim());
  if (inv != null && inv.InventoryID.HasValue)
        {
              grp.Item.Current = grp.Item.Search<InventoryItem.inventoryID>(inv.InventoryID);
  throw new PXRedirectRequiredException(grp, "Reloading Item");
        }
  }

希望它有所帮助。

答案 1 :(得分:0)

你可以按照Yura建议的方法,或者你可以用其他方式来实现它。

您可以在调用base persist之前检查记录的缓存状态,如果缓存状态显示已删除,则不要进行重定向。

代码可能如下[未测试]

[PXOverride]
  public void Persist(Action persist)
  {
    bool isDeletion = false;
    InventoryItem  CurrentItem = this.Base.Item.Cache.Current as InventoryItem ;
    if(this.Base.Item.Cache.GetStatus(CurrentItem) == PXEntryStatus.Deleted) // Helps to check whether the operation is deletion
       isDeletion = true;
   persist();// this will call base Persist();
    if(!isDeletion)
    {
      InventoryItemMaint grp = PXGraph.CreateInstance<InventoryItemMaint>();
      InventoryItem inv = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>.Select(grp, this.Base.Item.Current.InventoryCD.Trim());
      if (inv != null && inv.InventoryID.HasValue)
      {
      grp.Item.Current = grp.Item.Search<InventoryItem.inventoryID>(inv.InventoryID);
      throw new PXRedirectRequiredException(grp, "Reloading Item");
      }
    }
  }

编辑:

我发现上面的代码不能用作InventoryItem

this.Base.Item.Current // is returning null

这是移动文本错误的基本问题,因此我建议您按如下方式更新代码

[PXOverride]
        public void Persist(Action persist)
        {            
            persist();// this will call base Persist();
            InventoryItem CurrentItem = this.Base.Item.Current as InventoryItem;
            if (CurrentItem != null)
            {
                InventoryItemMaint grp = PXGraph.CreateInstance<InventoryItemMaint>();
                InventoryItem inv = PXSelect<InventoryItem, Where<InventoryItem.inventoryCD, Equal<Required<InventoryItem.inventoryCD>>>>.Select(grp, CurrentItem.InventoryCD.Trim());
                if (inv != null && inv.InventoryID.HasValue)
                {
                    grp.Item.Current = grp.Item.Search<InventoryItem.inventoryID>(inv.InventoryID);
                    throw new PXRedirectRequiredException(grp, "Reloading Item");
                }
            }
        }