我正在为员工时间活动屏幕(EP307000)制作表单模型。我正在构建一个额外的网格来显示给定月份的所有数据。为此,我需要一个允许用户选择月/年组合的字段。我已经构建了自定义PXSelector并获取了所有数据来填充它,但我遇到的问题是每当焦点转移到该字段时,描述字段都被隐藏,并且只显示自然键。例如,如果用户选择2017年6月,则该字段中存储的值应为“20170630”,但显示给用户的值应为“2017年6月”。
“From Week”和“Until Week”PXSelector字段具有我想要的功能,但我似乎无法复制它。这就是宣布“直到周”的方式:
#region TillWeek
public abstract class tillWeek : IBqlField
{
}
[PXDBInt]
[PXWeekSelector2(DescriptionField = typeof(EPWeekRaw.shortDescription))]
[PXUIField(DisplayName = "Until Week", Visibility = PXUIVisibility.Visible)]
public virtual int? TillWeek { set; get; }
#endregion
下面的图片显示了字段之间的差异。 “From Week”字段看起来不同,因为我从PXWeekSelector2中删除了“DescriptionField = typeof(EPWeekRaw.shortDescription)”。
这是自定义选择器的代码:
public class MonthYearSelectorAttribute : PXCustomSelectorAttribute
{
public MonthYearSelectorAttribute()
: base(typeof(DateInfoExt.dateInt), new Type[]{ typeof (DateInfoExt.monthName), typeof (DateInfoExt.year)})
{
DescriptionField = typeof(DateInfoExt.description);
}
public override void FieldVerifying(PXCache sender, PXFieldVerifyingEventArgs e)
{
}
protected virtual IEnumerable GetRecords()
{
DateTime currentDate = DateTime.Now;
PX.SM.DateInfo dateInfo = PXSelect<PX.SM.DateInfo, Where<PX.SM.DateInfo.month, Equal<Required<PX.SM.DateInfo.month>>, And<PX.SM.DateInfo.year, Equal<Required<PX.SM.DateInfo.year>>>>>.Select(this._Graph, currentDate.Month, currentDate.Year);
int? currentDateInt = dateInfo.DateInt;
int? pastDateInt = dateInfo.DateInt - 50000;
foreach(PX.SM.DateInfo result in PXSelectGroupBy<PX.SM.DateInfo, Where<PX.SM.DateInfo.dateInt, LessEqual<Required<PX.SM.DateInfo.year>>, And<PX.SM.DateInfo.dateInt, GreaterEqual<Required<PX.SM.DateInfo.dateInt>>>>, Aggregate<GroupBy<PX.SM.DateInfo.month, GroupBy<PX.SM.DateInfo.year>>>, OrderBy<Asc<PX.SM.DateInfo.year, Asc<PX.SM.DateInfo.month>>>>.Select(this._Graph, currentDateInt, pastDateInt))
{
DateInfoExt ext = new DateInfoExt();
ext.Year = result.Year;
ext.MonthName = result.MonthName;
ext.DateInt = result.DateInt;
ext.Description = result.MonthName + "-" + result.Year.ToString();
yield return ext;
}
}
}
public class DateInfoExt : IBqlTable
{
public DateInfoExt()
{
}
[PXString]
[PXUIField(DisplayName = "Description")]
public virtual string Description { get; set; }
public abstract class description : IBqlField
{
}
[PXDBString]
[PXUIField(DisplayName = "MonthYear", IsReadOnly = true)]
public virtual string MonthYear { get; set; }
public abstract class monthYear : IBqlField
{
}
[PXDBString]
[PXUIField(DisplayName = "Month Name", IsReadOnly = true)]
public virtual string MonthName { get; set; }
public abstract class monthName : IBqlField
{
}
[PXDBInt]
[PXUIField(DisplayName = "Year", IsReadOnly = true)]
public virtual int? Year { get; set; }
public abstract class year : IBqlField
{
}
[PXDBInt(IsKey = true)]
[PXUIField(DisplayName = "Date (Integer)", IsReadOnly = true, Visible = false)]
public virtual int? DateInt { get; set; }
public abstract class dateInt : IBqlField
{
}
}
public class PMTimeActivityFilterExt : PXCacheExtension<PX.Objects.EP.EmployeeActivitiesEntry.PMTimeActivityFilter>
{
public abstract class month : IBqlField
{
}
[PXDBInt]
[MonthYearSelector]
[PXUIField(DisplayName = "Month", Visibility = PXUIVisibility.Visible)]
public virtual int Month
{
get; set;
}
}
提前致谢
答案 0 :(得分:0)
尝试#1 :这可能是您在PXSelector控件上设置为 文本 的 DisplayMode 属性ASPX?
<px:PXSelector runat="server" DataField="Month" ID="edMonth" ... DisplayMode="Text"/>
尝试#2:以下是框架支持的唯一可实现的结果 - Year-Month 组合,后跟 MonthName Year 描述在括号内:
将无法显示Month选择器内的一个字段的值,并通过其他字段在下拉网格中排序记录 - 框架根本不支持此类行为。
要获得上述结果,您应将DateInfoExt描述字段中使用的PXUIFieldAttribute的Visible设置为false:
public class DateInfoExt : IBqlTable
{
...
public abstract class description : IBqlField { }
[PXString()]
[PXUIField(DisplayName = "Description", Visible = false)]
public virtual string Description { get; set; }
...
}
稍微改变DateInfoExt DAC的Description字段如何填充delagate中的值:
foreach (PX.SM.DateInfo result in PXSelectGroupBy<PX.SM.DateInfo,
Where<PX.SM.DateInfo.dateInt, LessEqual<Required<PX.SM.DateInfo.year>>,
And<PX.SM.DateInfo.dateInt, GreaterEqual<Required<PX.SM.DateInfo.dateInt>>>>,
Aggregate<GroupBy<PX.SM.DateInfo.month, GroupBy<PX.SM.DateInfo.year>>>,
OrderBy<Asc<PX.SM.DateInfo.year, Asc<PX.SM.DateInfo.month>>>>.Select(this._Graph, currentDateInt, pastDateInt))
{
DateInfoExt ext = new DateInfoExt();
ext.DateInt = result.DateInt;
ext.Year = result.Year;
ext.MonthName = result.MonthName;
ext.Description = string.Format("{0}-{1} ({2} {0})", result.Year, result.Month, result.MonthName);
yield return ext;
}
这就是我在Aspx中声明 Month 选择器的方式:
<px:PXSelector runat="server" DataField="Month" ID="edMonth" CommitChanges="True" TextMode="Search" ValueField="DateInt" DisplayMode="Text"/>