如何对详细字段值的总和求平均并将结果放在页眉中

huangapple go评论61阅读模式
英文:

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&lt;xTACProjectTask&gt; res = PXSelect&lt;xTACProjectTask,
											   Where&lt;xTACProjectTask.projectID, Equal&lt;Required&lt;xTACProjectTask.projectID&gt;&gt;&gt;&gt;.Select(this, pj.ProjectID);

			foreach (PXResult&lt;xTACProjectTask&gt; rec in res)
			{
				xTACProjectTask pt = rec;
				totPctComplete += pt.PctComplete;
				rowCount++;
			}

			if(rowCount &gt; 0)
				pj.PctComplete = totPctComplete / rowCount;
		}
	}

huangapple
  • 本文由 发表于 2020年1月7日 02:31:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/59617186.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定