【分享】单据查询时对单据体特定字段做不同颜色处理
金蝶云社区-_Tmp
_Tmp
7人赞赏了该文章 1,493次浏览 未经作者许可,禁止转载编辑于2019年03月16日 14:24:53

原始反馈:制单人凭证录入的时候金额为负值时显示是红色,但是其他用户查询这张凭证的时候点击凭证后,不显示红色。
这个问题可以参照了论坛的相关帖子:
Python脚本实现单据体背景色及字段前景色设置【分享】

实现效果:


Python代码:


[code]clr.AddReference('Kingdee.BOS.Core')
clr.AddReference('Kingdee.BOS.DataEntity')
from Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel import *
from Kingdee.BOS.Orm.DataEntity import *
def AfterBindData(e):
entity = this.View.BillBusinessInfo.GetEntity('FEntity');
objCollection =this.View.Model.GetEntityDataObject(entity);
grid =this.View.GetControl('FEntity');
for index in range(len(objCollection)):
obj = objCollection[index];
valDebit = obj["Debit"];
valCredit = obj['FCredit'];
if valDebit is not None and valDebit <0:
grid.SetForecolor("FDebit","#FF0000", index);#需要设置字段标识Key
if valCredit is not None and valCredit <0:
grid.SetForecolor("FCredit","#FF0000", index);#需要设置字段标识Key[/code]C#插件代码(C#插件这里用的是采购订单,不过大同小异):


[code] public override void AfterBindData(EventArgs e)
{
base.AfterBindData(e);

Entity entityPOOrder = this.View.BillBusinessInfo.GetEntity("FPOOrderEntry");
DynamicObjectCollection objCollection = this.View.Model.GetEntityDataObject(entityPOOrder);
var grid = this.View.GetControl("FPOOrderEntry");
for (int i = 0; i < objCollection.Count; i++)
{
if (objCollection[i]["Qty"] != null)
{
object objQty = objCollection[i]["Qty"];
decimal decimalQty;
if (decimal.TryParse(objQty.ToString(), out decimalQty))
{
if (decimalQty > 50)
{
grid.SetForecolor("FQty", "#FF0000", i);
}
else
{
grid.SetForecolor("FQty", "#000000", i);
}
}
}
}

}[/code]