Reordering header buttons

2019-08-17 08:02发布

I have added a custom save button in Sales Order screen in place of my current one. How do I reorder the main toolbar so that new save button is in place of the old one? You can do this easily for grid buttons, but for header ones it is not so obvious.

标签: acumatica
1条回答
够拽才男人
2楼-- · 2019-08-17 08:38

The order of the buttons is based on the order of the PXActions in the graph.

(1) In this example my save button is first, then cancel button second.

enter image description here

public class MyGraph : PXGraph<MyGraph>
{
    public PXSave<MyPrimaryDac> Save;
    public PXCancel<MyPrimaryDac> Cancel;
}

(2) In this example my cancel button is first, then save button second.

enter image description here

public class MyGraph : PXGraph<MyGraph>
{
    public PXCancel<MyPrimaryDac> Cancel;
    public PXSave<MyPrimaryDac> Save;
}

Note that PXSave and PXCancel are PXActions.

Edit: from comments and question edits if you are extending another graph you should be able to use a new class inherited from PXSave and set the property name the same ("Save" in the example of sales order). Here is something that should work for an override to the save button and asking the user a question and keeps the save button in the same button location...

public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
    public SalesPXSave<SOOrder> Save;

    public class SalesPXSave<TNode> : PXSave<TNode> where TNode : class, IBqlTable, new()
    {
        public SalesPXSave(PXGraph graph, string name) : base(graph, name)
        {
        }

        public SalesPXSave(PXGraph graph, Delegate handler) : base(graph, handler)
        {
        }

        [PXSaveButton]
        [PXUIField(DisplayName = "Save", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
        protected override IEnumerable Handler(PXAdapter adapter)
        {
            bool someCondition = true;
            if (someCondition)
            {
                if (adapter.View.Ask(adapter.View.Graph.Caches[typeof(TNode)].Current, "Hi User",
                    MessageButtons.YesNo) != WebDialogResult.Yes)
                {
                    return adapter.Get();
                }
            }

            return base.Handler(adapter);
        }
    }
}

Edit: For reference here are some quick untested examples of extending RowPersisting or the Persist in an extension if this is preferred vs extending the buttons...

[PXOverride]
public virtual void Persist(Action del)
{
    if (Base.Document.Ask(Base.Document.Current, "Question", "Continue?",
            MessageButtons.YesNo) != WebDialogResult.Yes)
    {
        return;
    }

    del?.Invoke();
}


protected virtual void SOOrder_RowPersisting(PXCache cache, PXRowPersistingEventArgs e, PXRowPersisting del)
{
    var row = (SOOrder)e.Row;
    if (row == null)
    {
        return;
    }

    if ((e.Operation == PXDBOperation.Insert || e.Operation == PXDBOperation.Update || e.Operation == PXDBOperation.Delete) &&
        Base.Document.Ask(row, "Question", "Continue ?", MessageButtons.YesNo, true) != WebDialogResult.Yes)
    {
        e.Cancel = true;
        return;
    }

    del?.Invoke(cache, e);
}
查看更多
登录 后发表回答