采购订单打开单据时表格行设置颜色

 列表根据条件设置背景色
import clr 
clr.AddReference('System')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('System.Drawing')
clr.AddReference('System.Collections')

from System import *
from System.Collections import *
from System.Collections.Generic import *
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Metadata import FormatCondition
from System.Drawing import *

def OnFormatRowConditions(args):
  if(args.DataRow.ColumnContains('F_Krystal_PriceStatus') and args.DataRow['F_Krystal_PriceStatus'] is not None):
    if(args.DataRow['F_Krystal_PriceStatus']!='B'):
      fc = FormatCondition()
      fc.ApplayRow = True
      fc.BackColor = "#FF0000"
      args.FormatConditions.Add(fc)
View Code

 

 Python实现

import clr 
clr.AddReference('System')
clr.AddReference('Kingdee.BOS')
clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('System.Drawing')
clr.AddReference('System.Collections')

from System import *
from System.Collections import *
from System.Collections.Generic import *
from Kingdee.BOS import *
from Kingdee.BOS.Core import *
from Kingdee.BOS.Core.Metadata import FormatCondition
from System.Drawing import *

def OnFormatRowConditions(args):
  if(args.DataRow.ColumnContains('F_Krystal_PriceStatus') and args.DataRow['F_Krystal_PriceStatus'] is not None):
    if(args.DataRow['F_Krystal_PriceStatus']!='B'):
      fc = FormatCondition()
      fc.ApplayRow = True
      fc.BackColor = "#FF0000"
      args.FormatConditions.Add(fc)
View Code

 

 
插件实现

 

 

 

 

 

 

 

using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;


namespace Krystal.K3.SCM.Business.PlugIn.PUR
{
    /// <summary>
    /// 功能描述    :PurchaseOrderEdit  
    /// 创 建 者    :Administrator
    /// 创建日期    :2024/7/11 10:01:51 
    /// 最后修改者  :Krystal
    /// 最后修改日期:2024/7/11 10:01:51 
    /// </summary>
    [Description("采购订单-表单插件")]
    [HotUpdate]
    public class PurchaseOrderEdit: AbstractBillPlugIn
    {
        #region <常量>
        #endregion <常量>

        #region <变量>
        #endregion <变量>

        #region <属性>
        #endregion <属性>

        #region <构造方法和析构方法>
        #endregion <构造方法和析构方法>

        #region <方法>
        #endregion <方法>

        #region <事件>
        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
            var entityKey = "FPOOrderEntry";

            var backColor = "#FF0000";

            var backColor0 =  "#cfe2f3";

            var backColor1 = "#ead1dc";
          


            var rowCount = this.View.Model.GetEntryRowCount(entityKey);


            // 常规操作是直接使用grid.SetRowBackcolor函数,已过时,目前只有客户端生效

            #region 设置某一行整行背景色 客户端生效 已过时 
            //var grid = this.View.GetControl<EntryGrid>(entityKey);


            ////价格状态不等于最低价,唯一价,标红
            //for (var x = 0; x < rowCount; ++x)
            //{
            //    var ps = this.View.Model.GetValue("F_Krystal_PriceStatus", x) + "";
            //    if (ps != "A" && ps != "B")
            //    {
            //        grid.SetRowBackcolor(backColor, x);//第x+1行
            //        //grid.SetBackcolor(backColor, 1);//第二行
            //    }
            //}
            #endregion


            #region  批量设置某一行整行背景色  客户端网页都生效
            var grid = this.View.GetControl<EntryGrid>(entityKey);
            var colors = new List<KeyValuePair<int, string>>();

            for (var x = 0; x < rowCount; ++x)
            {
                var ps = this.View.Model.GetValue("F_Krystal_PriceStatus", x) + "";
                if (ps != "A" && ps != "B")
                {
                    //var backColor3 = x % 2 == 0 ? backColor0 : backColor1;
                    colors.Add(new KeyValuePair<int, string>(x, backColor));
                }

            }

            grid.SetRowBackcolor(colors);


            #endregion


            #region 客户端网页都生效 设置价格状态字段的某一行的背景色
            //var grid = this.View.GetControl<EntryGrid>(entityKey);

            ////grid.SetBackcolor("FPrice", backColor, 1);
            //////价格状态不等于最低价,唯一价,标红
            //for (var x = 0; x < rowCount; ++x)
            //{
            //    var ps = this.View.Model.GetValue("F_Krystal_PriceStatus", x) + "";
            //    if (ps != "A" && ps != "B")
            //    {
            //        grid.SetBackcolor("F_Krystal_PriceStatus", backColor, x);//第x+1行
            //        //grid.SetBackcolor(backColor, 1);//第二行
            //    }
            //}

            #endregion


            #region 批量设置价格状态字段的某一行的背景色 客户端网页都生效




            //var grid = this.View.GetControl<EntryGrid>(entityKey);
            //var colors = new List<KeyValuePair<int, string>>();

            //for (var x = 0; x < rowCount; ++x)
            //{
            //    var ps = this.View.Model.GetValue("F_Krystal_PriceStatus", x) + "";
            //    if (ps != "A" && ps != "B")
            //    {
            //        colors.Add(new KeyValuePair<int, string>(x, backColor));
            //    }
            //    //var backColor3 = x % 2 == 0 ? backColor0 : backColor1;

            //}
            //grid.SetCellsBackcolor("F_Krystal_PriceStatus", colors);


            #endregion




            #region 客户端生效,网页端不生效
            //GridSetRowBackcolor(this.View, entityKey, backColor, 1);
            #endregion


        }

        private void GridSetRowBackcolor(IDynamicFormView view, string entityKey, string color, int rowIndex)
        {
            var value = new JSONObject();

            value[rowIndex.ToString()] = color;

            var jo = new JSONObject();

            jo["backcolor"] = value;

            var grid = view.GetControl<EntryGrid>(entityKey);

            var formState = view.GetService<IDynamicFormState>();

            formState.AftInvokeControlMethod(grid.ControlAppearance, "UpdateFieldStates", jo);
 

        }
        #endregion <事件>
    }
}
完整代码

 

 

 

 

 

 

posted @ 2024-08-06 13:54  lanrenka  阅读(29)  评论(0编辑  收藏  举报