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

采购订单打开单据时表格行根据条件显示背景色

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)

插件实现

创建项目

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

创建类,实现接口

在这里插入图片描述

重写方法

完整代码

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 <事件>
    }
}

编译后挂载插件到表单插件

在这里插入图片描述

启动开发环境进行测试

单元格设置背景色

在这里插入图片描述

行背景色

在这里插入图片描述

  • 6
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值