在委托中排序视图

时间:2017-10-11 08:30:33

标签: acumatica

我试图通过添加这样的视图委托来对视图进行排序:

public class AppointmentEntry_Extension:PXGraphExtension<AppointmentEntry>
  {
    protected virtual IEnumerable appointmentRecords()
    {
        PXView select = new PXView(Base, true, Base.AppointmentRecords.View.BqlSelect);
        int totalrow = 0;
        int startrow = PXView.StartRow;
        select.OrderByNew<OrderBy<Desc<FSAppointment.createdDateTime>>>();
        List<object> result = select.Select(PXView.Currents, PXView.Parameters, PXView.Searches, PXView.SortColumns, PXView.Descendings, PXView.Filters, ref startrow, PXView.MaximumRows, ref totalrow);
        PXView.StartRow = 0;
        return result;
    }
}

它加载最新记录(按日期),但是当我导航到下一条记录时,它会显示相同的记录。当我点击Last Record时,它只显示不同的一个。

enter image description here

2 个答案:

答案 0 :(得分:0)

如果使用相同的名称,则只需在扩展中添加所需的视图(无需使用视图委托)。例如,如果基本图表视图具有类似的内容......

public PXSelect<SomeDac> AppointmentRecords;

在您的扩展程序图中,您可以为该视图执行此操作...

public PXSelect<SomeDac, OrderBy<SomeNewOrder>> AppointmentRecords;

编辑:覆盖视图委托或使用视图覆盖不会更改主视图的顺序。留下这个答案,以防其他人试图做同样的事情。这样做可能会更改链接到网格的视图的顺序。

答案 1 :(得分:0)

实现所需行为的最简单方法是使用通用查询替换约会数据输入页面,该通用查询配置为按任何给定顺序对记录进行排序: enter image description here enter image description here

如果用通用查询替换约会数据输入页面不是一个选项,则必须覆盖下面代码片段后面的所有4个导航按钮(插入和删除按钮不应该像以前的代码那样有任何问题样品)。另外,请记住,约会Nbr选择器仍然会通过约会Nbr字段按降序排序FSAppointment记录。这是由于PXSelectorAttribute允许仅通过其外键或替换键对记录进行排序(如果已定义)。

using PX.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace FieldService.ServiceDispatch
{
    public class AppointmentEntryExt : PXGraphExtension<AppointmentEntry>
    {
        public PXFirstCst<FSAppointment> First;
        public PXPreviousCst<FSAppointment> Previous;
        public PXNextCst<FSAppointment> Next;
        public PXLastCst<FSAppointment> Last;

        public class PXFirstCst<TNode> : PXFirst<TNode>
            where TNode : class, IBqlTable, new()
        {
            public PXFirstCst(PXGraph graph, string name)
                : base(graph, name)
            {
            }
            public PXFirstCst(PXGraph graph, Delegate handler)
                : base(graph, handler)
            {
            }

            [PXUIField(DisplayName = ActionsMessages.First, MapEnableRights = PXCacheRights.Select)]
            [PXFirstButton]
            protected override IEnumerable Handler(PXAdapter adapter)
            {
                adapter = PrepareCustomNavAdapter(this, adapter);
                return base.Handler(adapter);
            }
        }

        public class PXPreviousCst<TNode> : PXPrevious<TNode>
            where TNode : class, IBqlTable, new()
        {
            public PXPreviousCst(PXGraph graph, string name)
                : base(graph, name)
            {
            }
            public PXPreviousCst(PXGraph graph, Delegate handler)
                : base(graph, handler)
            {
            }

            private PXAdapter origAdapter;

            [PXUIField(DisplayName = ActionsMessages.Previous, MapEnableRights = PXCacheRights.Select)]
            [PXPreviousButton]
            protected override IEnumerable Handler(PXAdapter adapter)
            {
                origAdapter = adapter;
                adapter = PrepareCustomNavAdapter(this, adapter, true);
                return base.Handler(adapter);
            }

            protected override IEnumerable InsertAndGet(PXAdapter adapter)
            {
                if (!_inserted)
                {
                    return base.InsertAndGet(origAdapter);
                }
                else
                {
                    return base.InsertAndGet(adapter);
                }
            }
        }

        public class PXNextCst<TNode> : PXNext<TNode>
            where TNode : class, IBqlTable, new()
        {
            public PXNextCst(PXGraph graph, string name)
                : base(graph, name)
            {
            }
            public PXNextCst(PXGraph graph, Delegate handler)
                : base(graph, handler)
            {
            }

            private PXAdapter origAdapter;

            [PXUIField(DisplayName = ActionsMessages.Next, MapEnableRights = PXCacheRights.Select)]
            [PXNextButton]
            protected override IEnumerable Handler(PXAdapter adapter)
            {
                origAdapter = adapter;
                adapter = PrepareCustomNavAdapter(this, adapter, true);

                var primaryCache = Graph.Views[Graph.PrimaryView].Cache;
                object current = primaryCache.Current;
                if (current != null && primaryCache.GetStatus(current) == PXEntryStatus.Inserted)
                {
                    adapter.StartRow--;
                }
                return base.Handler(adapter);
            }

            protected override IEnumerable InsertAndGet(PXAdapter adapter)
            {
                if (!_inserted)
                {
                    return base.InsertAndGet(origAdapter);
                }
                else
                {
                    return base.InsertAndGet(adapter);
                }
            }
        }

        public class PXLastCst<TNode> : PXLast<TNode>
            where TNode : class, IBqlTable, new()
        {
            public PXLastCst(PXGraph graph, string name)
                : base(graph, name)
            {
            }
            public PXLastCst(PXGraph graph, Delegate handler)
                : base(graph, handler)
            {
            }
            [PXUIField(DisplayName = ActionsMessages.Last, MapEnableRights = PXCacheRights.Select)]
            [PXLastButton]
            protected override IEnumerable Handler(PXAdapter adapter)
            {
                adapter = PrepareCustomNavAdapter(this, adapter);
                return base.Handler(adapter);
            }
        }

        public static PXAdapter PrepareCustomNavAdapter(PXAction action, 
            PXAdapter adapter, bool prevNextAction = false)
        {
            var select = adapter.View.BqlSelect;
            select = select.OrderByNew<OrderBy<
                Desc<FSAppointment.createdDateTime,
                Desc<FSAppointment.srvOrdType,
                Desc<FSAppointment.refNbr>>>>>();

            var newAdapter = new PXAdapter(new PXView(action.Graph, true, select))
            {
                MaximumRows = adapter.MaximumRows
            };

            object current = action.Graph.Views[action.Graph.PrimaryView].Cache.Current;
            if (prevNextAction)
            {
                var sortColumns = new string[adapter.SortColumns.Count() + 1];
                adapter.SortColumns.CopyTo(sortColumns, 1);
                sortColumns[0] = "CreatedDateTime";
                newAdapter.SortColumns = sortColumns;

                var descendings = new bool[adapter.Descendings.Count() + 1];
                adapter.Descendings.CopyTo(descendings, 1);
                descendings[0] = true;
                newAdapter.Descendings = descendings;

                var searches = new object[adapter.Searches.Count() + 1];
                adapter.Searches.CopyTo(searches, 1);
                if (current != null && current is FSAppointment)
                    searches[0] = ((FSAppointment)current).CreatedDateTime;
                newAdapter.Searches = searches;
            }
            else if (current != null)
            {
                adapter.Currents = new object[] { current };
            }

            return newAdapter;
        }
    }
}