备注:只适用于只读列
自定义单据提附加背景色方法:
///
/// 设置单据体背景颜色
///
/// 实体
/// 行
/// 字段
/// 颜色代码
private void SetEntityBackgoundColor(string entityKey, int row, string fieldKey = “”, string backgroundColor = “#FA8072”)
{
EntryGrid grid = this.View.GetControl(entityKey);
List
backgroundList.Add(new KeyValuePair
if (fieldKey.IsEmpty())
{
grid.SetRowBackcolor(backgroundList);
IDynamicFormState formState = this.View.GetService();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");}}}}}
下一篇:c++中的this指针