一.效果图:
备注:只适用于只读列
二.代码案例:
自定义单据提附加背景色方法:
///
/// 设置单据体背景颜色
///
/// 实体
/// 行
/// 字段
/// 颜色代码
private void SetEntityBackgoundColor(string entityKey, int row, string fieldKey = “”, string backgroundColor = “#FA8072”)
{
EntryGrid grid = this.View.GetControl(entityKey);
List<KeyValuePair<int, string>> backgroundList = new List<KeyValuePair<int, string>>();
backgroundList.Add(new KeyValuePair<int, string>(row, backgroundColor));
if (fieldKey.IsEmpty())
{
grid.SetRowBackcolor(backgroundList);
IDynamicFormState formState = this.View.GetService<IDynamicFormState>();
formState.AftInvokeControlMethod(grid.ControlAppearance, "UpdateFieldStates",
new JSONObject() {
{
"backcolor", new JSONObject() {
{ row.ToString(), backgroundColor }
}
}
});
}
else
{
grid.SetCellsBackcolor(fieldKey, backgroundList);//设置单元格背景颜色
}
}
项目代码调用案例:
//加载事件
public override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Entity entity = this.View.BillBusinessInfo.GetEntity(“FTreeEntity”);
DynamicObjectCollection rows = this.Model.GetEntityDataObject(entity);
for (int i = 0; i < rows.Count - 1; i++)
{
//行标识一致,则是变更前和变更后 替代物料
if (rows[i][“RowId”].ToString() == rows[i + 1][“RowId”].ToString())
{
string MATERIALID1 = ((DynamicObject)rows[i][“MATERIALIDCHILD”])[“Id”].ToString();
string MATERIALID2 = ((DynamicObject)rows[i+1][“MATERIALIDCHILD”])[“Id”].ToString();
//替换前数据行
string sql = $"/*dialect*/ select FHeight from t_BD_MaterialBase where FMATERIALID = '{MATERIALID1}'";
DynamicObjectCollection data1 = DBUtils.ExecuteDynamicObject(this.Context, sql);
//替换后数据行
string sql2 = $"/*dialect*/ select FHeight from t_BD_MaterialBase where FMATERIALID = '{MATERIALID2}'";
DynamicObjectCollection data2 = DBUtils.ExecuteDynamicObject(this.Context, sql2);
if (data1.Count > 0 && data2.Count > 0)
{
//如果替换后物料行高 大于 替换前物料行高,两行数据变色
if (Convert.ToDouble(data1[0]["FHeight"]) < Convert.ToDouble(data2[0]["FHeight"]))
{
//单据体标识,行,颜色
SetEntityBackgoundColor("FTreeEntity", i, "", "#FF0000");
SetEntityBackgoundColor("FTreeEntity", i + 1, "", "#FF0000");
}
}
}
}
}