英文:
How can I average the sum of detail field values and put the result in the header
问题
我在自定义屏幕的详细/网格部分有一个字段,我想要基本上求平均值(总和除以行数),然后在页眉部分显示这个值。我似乎找不到如何在PXFormula字段中完成这个操作的示例。如果我需要使用RowSelected事件(或FieldUpdating事件),那就这样吧,但我希望能够使用PXFormula字段完成这个操作。
英文:
I have a field in the detail / grid section of a custom screen that I want to essentially average (sum divided by row count), and then display this value in the header section. I can't seem to find any examples of how to do this with a PXFormula field. If I need to use the RowSelected event (or FieldUpdating event) then so be it, but I was hoping to do this with the PXFormula field.
答案1
得分: 0
以下是翻译好的代码部分:
protected virtual void xTACProjectMaster_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
Decimal? totPctComplete = 0;
int rowCount = 0;
var pj = e.Row as xTACProjectMaster;
if (pj != null)
{
PXResultset<xTACProjectTask> res = PXSelect<xTACProjectTask,
Where<xTACProjectTask.projectID, Equal<Required<xTACProjectTask.projectID>>>>.Select(this, pj.ProjectID);
foreach (PXResult<xTACProjectTask> rec in res)
{
xTACProjectTask pt = rec;
totPctComplete += pt.PctComplete;
rowCount++;
}
if(rowCount > 0)
pj.PctComplete = totPctComplete / rowCount;
}
}
英文:
I did it this way:
protected virtual void xTACProjectMaster_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
{
Decimal? totPctComplete = 0;
int rowCount = 0;
var pj = e.Row as xTACProjectMaster;
if (pj != null)
{
PXResultset<xTACProjectTask> res = PXSelect<xTACProjectTask,
Where<xTACProjectTask.projectID, Equal<Required<xTACProjectTask.projectID>>>>.Select(this, pj.ProjectID);
foreach (PXResult<xTACProjectTask> rec in res)
{
xTACProjectTask pt = rec;
totPctComplete += pt.PctComplete;
rowCount++;
}
if(rowCount > 0)
pj.PctComplete = totPctComplete / rowCount;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论