acumatica - 使用 IEnumerable 函数向数据视图添加过滤器
问题描述
我正在定制以向现有数据视图添加一些过滤器。员工时间活动页面上
的活动数据视图。
我已将 Customer 属性添加到PMTimeActivity
和OwnedFilter
。现在我需要修改activity
方法以考虑客户过滤器。这样做的唯一方法是使用以下场景之一覆盖该方法:
无需调用基本方法并复制代码并添加过滤器部分
调用基本方法并检查每个返回记录的条件。
第一种情况是使这部分自定义非常有问题,因为每次将自定义升级到任何其他构建时都需要查看此代码。
从性能的角度来看,第二种情况并不好。
有没有人遇到过这个问题,如何以可接受的方式做到这一点?
下面是该activity
方法的代码:
protected virtual IEnumerable activity()
{
List<object> args = new List<object>();
EmployeeActivitiesEntry.PMTimeActivityFilter filterRow = this.Filter.Current;
if (filterRow == null)
{
return null;
}
BqlCommand cmd = BqlCommand.CreateInstance(new Type[]
{
typeof(Select2<EPActivityApprove, LeftJoin<EPEarningType, On<EPEarningType.typeCD, Equal<PMTimeActivity.earningTypeID>>, LeftJoin<CRActivityLink, On<CRActivityLink.noteID, Equal<PMTimeActivity.refNoteID>>, LeftJoin<CRCase, On<CRCase.noteID, Equal<CRActivityLink.refNoteID>>, LeftJoin<ContractEx, On<CRCase.contractID, Equal<ContractEx.contractID>>>>>>, Where<EPActivityApprove.ownerID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.ownerID>>, And<EPActivityApprove.trackTime, Equal<True>, And<PMTimeActivity.isCorrected, Equal<False>>>>, OrderBy<Desc<EPActivityApprove.date>>>)
});
if (filterRow.ProjectID != null)
{
cmd = cmd.WhereAnd<Where<EPActivityApprove.projectID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.projectID>>>>();
}
if (filterRow.ProjectTaskID != null)
{
cmd = cmd.WhereAnd<Where<EPActivityApprove.projectTaskID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.projectTaskID>>>>();
}
if (filterRow.FromWeek != null || filterRow.TillWeek != null)
{
List<Type> cmdList = new List<Type>();
bool? includeReject = filterRow.IncludeReject;
bool flag = true;
if (includeReject.GetValueOrDefault() == flag & includeReject != null)
{
cmdList.Add(typeof(Where<, , >));
cmdList.Add(typeof(EPActivityApprove.approvalStatus));
cmdList.Add(typeof(Equal<ActivityStatusListAttribute.rejected>));
cmdList.Add(typeof(Or<>));
}
if (filterRow.FromWeek != null)
{
if (filterRow.TillWeek != null)
{
cmdList.Add(typeof(Where<, , >));
}
else
{
cmdList.Add(typeof(Where<, >));
}
cmdList.Add(typeof(EPActivityApprove.weekID));
cmdList.Add(typeof(GreaterEqual<Required<EmployeeActivitiesEntry.PMTimeActivityFilter.fromWeek>>));
args.Add(filterRow.FromWeek);
if (filterRow.TillWeek != null)
{
cmdList.Add(typeof(And<>));
}
}
if (filterRow.TillWeek != null)
{
cmdList.Add(typeof(Where<EPActivityApprove.weekID, LessEqual<Required<EmployeeActivitiesEntry.PMTimeActivityFilter.tillWeek>>>));
args.Add(filterRow.TillWeek);
}
cmd = cmd.WhereAnd(BqlCommand.Compose(cmdList.ToArray()));
}
return new PXView(this, false, cmd).SelectMultiBound(new object[]
{
this.Filter.Current
}, args.ToArray());
}
解决方案
我会考虑尝试使用 PXView,这是 Sergey在这里描述的。
如果是员工活动时间卡,它可能如下所示:
public class EmployeeExt : PXGraphExtension<EmployeeActivitiesEntry>
{
protected virtual IEnumerable activity()
{
var sel = new PXView(Base, true, Base.Activity.View.BqlSelect);
if(true)
{
sel.WhereAnd<Where<EPActivityApprove.projectID, Equal<Current<EmployeeActivitiesEntry.PMTimeActivityFilter.projectID>>>>();
}
int totalRow = 0;
int startRow = PXView.StartRow;
return sel.Select(PXView.Currents, PXView.Parameters,
PXView.Searches, PXView.SortColumns, PXView.Descendings,
PXView.Filters, ref startRow, PXView.MaximumRows, ref totalRow);
}
}
推荐阅读
- python - 如果不满足 Pandas 中新列的条件,请使用上述值
- python-3.x - 添加的层必须是类层的实例
- memory - 关于ceph内核客户端与物理内存的关系?
- javascript - 如何使用 findIndex() 在 JS 中查找所选项目的索引?
- javascript - 如何使用 IONIC ion-select 选择列表中的所有选项
- azure - 错误:删除 ID 为 XXX 的用户时出错 graphrbac.UsersClient#Delete Authorization_RequestDenied - 权限不足,无法完成操作
- javascript - 使用 Nestjs 监听多个 RabbitMQ 队列
- c++ - 类中方法的受保护问题
- ruby-on-rails - 如何通知 React 从 Ruby on Rails 后端更新页面?
- javascript - React:为什么它会跳过我的“获取”功能?