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

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

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

以下是翻译好的代码部分:

  1. protected virtual void xTACProjectMaster_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
  2. {
  3. Decimal? totPctComplete = 0;
  4. int rowCount = 0;
  5. var pj = e.Row as xTACProjectMaster;
  6. if (pj != null)
  7. {
  8. PXResultset<xTACProjectTask> res = PXSelect<xTACProjectTask,
  9. Where<xTACProjectTask.projectID, Equal<Required<xTACProjectTask.projectID>>>>.Select(this, pj.ProjectID);
  10. foreach (PXResult<xTACProjectTask> rec in res)
  11. {
  12. xTACProjectTask pt = rec;
  13. totPctComplete += pt.PctComplete;
  14. rowCount++;
  15. }
  16. if(rowCount > 0)
  17. pj.PctComplete = totPctComplete / rowCount;
  18. }
  19. }
英文:

I did it this way:

  1. protected virtual void xTACProjectMaster_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
  2. {
  3. Decimal? totPctComplete = 0;
  4. int rowCount = 0;
  5. var pj = e.Row as xTACProjectMaster;
  6. if (pj != null)
  7. {
  8. PXResultset&lt;xTACProjectTask&gt; res = PXSelect&lt;xTACProjectTask,
  9. Where&lt;xTACProjectTask.projectID, Equal&lt;Required&lt;xTACProjectTask.projectID&gt;&gt;&gt;&gt;.Select(this, pj.ProjectID);
  10. foreach (PXResult&lt;xTACProjectTask&gt; rec in res)
  11. {
  12. xTACProjectTask pt = rec;
  13. totPctComplete += pt.PctComplete;
  14. rowCount++;
  15. }
  16. if(rowCount &gt; 0)
  17. pj.PctComplete = totPctComplete / rowCount;
  18. }
  19. }

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:

确定