如何修改现有属性的基本代码

问题描述 投票:0回答:1

在时间表代码中,有一个名为PXWeekSelector2的属性:

enter image description here

我需要知道的是如何在定制项目中修改此属性的代码,以将weekListCount变量增加到超过1000(我们实际上是800,从2005年开始-这就是我们达到极限的原因) 。

不确定如何覆盖或修改现有属性。任何帮助,将不胜感激。

更新4/28:如果我查看源代码中的PXWeekSelector2Attribute,这就是我所看到的。我没有看到任何类似“ Prefetch”的方法:

namespace PX.Objects.EP
{
public class PXWeekSelector2Attribute : PXWeekSelectorAttribute
{
    public PXWeekSelector2Attribute();

    public static int GetNextWeekID(PXGraph graph, int weekID);
    public static int GetNextWeekID(PXGraph graph, DateTime date);
    public static DateTime GetWeekEndDate(PXGraph graph, int weekId);
    public static int GetWeekID(PXGraph graph, DateTime date);
    public static WeekInfo GetWeekInfo(PXGraph graph, int weekId);
    public static DateTime GetWeekStartDate(PXGraph graph, int weekId);
    public static bool IsCustomWeek(PXGraph graph);
    protected override IEnumerable GetAllRecords();

    public class FullWeekList
    {
        public FullWeekList();

        public static List<EPWeekRaw> Weeks();
    }
    public class WeekInfo
    {
        public WeekInfo();

        public DayInfo Mon { get; }
        public DayInfo Tue { get; }
        public DayInfo Wed { get; }
        public DayInfo Thu { get; }
        public DayInfo Fri { get; }
        public DayInfo Sat { get; }
        public DayInfo Sun { get; }
        public Dictionary<DayOfWeek, DayInfo> Days { get; }

        public void AddDayInfo(DateTime date);
        public bool IsValid(DateTime date);
    }
    public class DayInfo
    {
        public DayInfo(DateTime? date);

        public DateTime? Date { get; }
        public bool Enabled { get; }
    }
}

}

acumatica
1个回答
0
投票

一种方法是创建自己的PXWeekSelector2Attribute版本,在该版本中您将更改FullWeekList.Definition.Prefetch方法以读取所需数量的记录,如下所示

public void Prefetch()
{
    DateTime curentDay = this._stratDay;
    for (int i = 0; i < 1000; i++)
    {
        int year;
        if (curentDay.AddDays(-3.0).Year < curentDay.Year && PXDateTimeInfo.GetWeekNumber(curentDay) > 1)
        {
            year = curentDay.AddYears(-1).Year;
        }
        else
        {
            year = curentDay.Year;
        }
        EPWeekRaw rawWeek = EPWeekRaw.ToEPWeekRaw(new PXWeekSelectorAttribute.EPWeek
        {
            WeekID = new int?(year * 100 + PXDateTimeInfo.GetWeekNumber(curentDay))
        });
        this._weeks.Add(rawWeek);
        curentDay = curentDay.AddDays(7.0);
    }
}

复制几乎所有其他方法和PXWeekSelector2Attribute的成员,并更改它们以与您的属性的方法一起使用

    protected override IEnumerable GetAllRecords()
    {
        if (PXWeekSelectorCustomAttribute.IsCustomWeek(this._Graph))
        {
            return (from _ in (PXResultset<EPCustomWeek>)PXSelectBase<EPCustomWeek, PXSelect<EPCustomWeek>.Config>.Select(this._Graph, null).AsEnumerable<PXResult<EPCustomWeek>>()
            select EPWeekRaw.ToEPWeekRaw((EPCustomWeek)_)).ToList<EPWeekRaw>();
        }
        return PXWeekSelectorCustomAttribute.FullWeekList.Weeks();
    }

最后一件事是在需要时使用PXWeekSelector2AttributePXWeekSelectorCustomAttribute覆盖CacheAttached。>

© www.soinside.com 2019 - 2024. All rights reserved.