Acumatica 在 PXView 中设置特定 column/cell 的样式?

Acumatica Styling a specific column/cell in PXView?

我对 Acumatica 的编码非常陌生。我正在尝试更改 AR303000 header 页面上单元格的颜色。 (见下面的代码)。显然这是行不通的。我收到 PXFormViewEventArgs 的错误消息在命名空间 PX.Web.UI.
中不存在 任何人都可以指导我应该使用什么名称空间并更正我的代码以使其正常工作吗? 谢谢,

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using PX.Common;
using PX.Data;
using PX.SM;
using PX.Objects.AR.CCPaymentProcessing;
using PX.Objects.AR.Repositories;
using PX.Objects.Common;
using PX.Objects.Common.Discount;
using PX.Objects.CA;
using PX.Objects.CM;
using PX.Objects.CR;
using PX.Objects.CR.Extensions;
using PX.Objects.CS;
using PX.Objects.SO;
using PX.Objects.AR.CCPaymentProcessing.Helpers;
using PX.Data.BQL.Fluent;
using PX.Data.BQL;
using PX.Data.Descriptor;
using CashAccountAttribute = PX.Objects.GL.CashAccountAttribute;
using PX.Objects.GL.Helpers;
using PX.Objects.TX;
using PX.Objects.IN;
using PX.Objects.CR.Extensions.Relational;
using PX.Objects.CR.Extensions.CRCreateActions;
using PX.Objects.GDPR;
using PX.Objects.GraphExtensions.ExtendBAccount;
using PX.Data.ReferentialIntegrity.Attributes;
using CRLocation = PX.Objects.CR.Standalone.Location;
using PX.Objects;
using PX.Objects.AR;

namespace PX.Objects.AR
{
  public class CustomerMaint_Extension : PXGraphExtension<CustomerMaint>
  {
  

    protected void Page_Load(object sender, EventArgs e)
    {
      Style escalated = new Style();
      escalated.ForeColor = System.Drawing.Color.Red;
      this.Page.Header.StyleSheet.CreateStyleRule(escalated, this, ".CssEscalated");

      Style rowStyle = new Style();
      rowStyle.BackColor = System.Drawing.Color.Red;
      this.Page.Header.StyleSheet.CreateStyleRule(rowStyle, this, ".CssRowStyle");

      Style cellStyle = new Style();
      cellStyle.BackColor = System.Drawing.Color.Aqua;
      this.Page.Header.StyleSheet.CreateStyleRule(cellStyle, this, ".CssCellStyle");

      Style highlightStyle = new Style();
      highlightStyle.BackColor = System.Drawing.Color.Yellow;
      this.Page.Header.StyleSheet.CreateStyleRule(highlightStyle, this, ".CssHighlightStyle");
  
    }
    
    protected void Customer_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PX.Web.UI.PXFormViewEventArgs f)
      {
        var customer = (CR.BAccount)e.Row;
        var customerExt = customer.GetExtension<CR.BAccountExt>();
        if (customerExt != null)
          {
            /*I want to change the color of this cell in the form*/
            customerExt.UsrReadOnlyAcctName = customer.AcctName;
          }
      }
  
    #region Event Handlers

    #endregion
  }
}```

我认为你可以检测到UsrReadonlyAcctName 的Form 和控件,然后在Page_Load 期间应用Css 样式;下面是一个示例,但在我的例子中,我找到了一个网格,然后在 RowDataBound:

期间检测了一个单元格的值
     public override void Initialize()
    {
        //Access page via http context current handler
        Page page = HttpContext.Current?.Handler as PXPage;
        if (page != null)
        {
            page.Load += Page_Load;
        }
    }

    private void Page_Load(object sender, EventArgs e)
    {
        Page page = (Page)sender;

        RegisterStyle(page, "MyCssRed", "#FD9999 !important", null, false);

        PX.Web.UI.PXGrid grdMyGridControl = (PX.Web.UI.PXGrid)ControlHelper.FindControl("grid2", page);  // Allocations popup

        if (grdMyGridControl != null)
        {
            grdMyGridControl.RowDataBound += (object grdsender, PXGridRowEventArgs erdb) =>
            {
                var data = erdb.Row;
                if (data == null) { return; }
                bool isRed = false;

                PXGridCell cell = data.Cells["INItemLotSerialKvExt__ValueString"];
                if (cell == null) return;
                Object value = cell.Value;
                if (value != null && (String)value == "R")
                {
                    isRed = true;
                }
                
                ...
                                
                if (isRed)
                        data.Style.CssClass = "MyCssRed";
                

Patrick Chen 提供了有用的参考。

编辑答案:

下面是销售订单页面 SO301000 上的示例,它找到“客户订单编号”文本框并在其文本为空时添加颜色:

    private void Page_Load(object sender, EventArgs e)
    {
        Page page = (Page)sender;

        RegisterStyle(page, "MyCssRed", "#FD9999 !important", null, false);

        PX.Web.UI.PXTextEdit myBox = (PX.Web.UI.PXTextEdit)ControlHelper.FindControl("edCustomerOrderNbr", page);

        if (myBox != null)
        {
            myBox.DataBinding += (object boxsender, EventArgs boxargs) =>
            {
                PX.Web.UI.PXTextEdit box = boxsender as PX.Web.UI.PXTextEdit;
                string cellText = box.Text;
                box.CssClass = string.IsNullOrEmpty(cellText) ? "MyCssRed" : "editor";
            };
        }