目录
RowRule示例
1.根据行字段值对字段进行样式设置
//高亮显示
RowRule rr1 = new RowRule("UD103.ShortChar02", RuleCondition.Equals, "");//如果UD103.ShortChar02=""
//高亮显示该行的UD103.ShortChar02字段
rr1.AddAction(RuleAction.AddControlSettings(this.oTrans, "UD103.ShortChar02", SettingStyle.Highlight));
((EpiDataView)(this.oTrans.EpiDataViews["UD103"])).AddRowRule(rr1);//将RowRule添加到EpiDataView实例化对象中
//自定义背景颜色
RowRule rr1 = new RowRule("UD103.ShortChar02", RuleCondition.Equals, "");//如果UD103.ShortChar02=""
ControlSettings controlSettings = new ControlSettings();
controlSettings.BackColor = Color.Red;//设置自定义背景颜色
controlSettings.StyleSetName = "MyStyle001";//设置该样式的名称,样式名称不能为空,也不能使用已有样式名,否则背景颜色将优先从该样式名对应的样式中获取,导致自定义背景色无效
rr1.AddAction(RuleAction.AddControlSettings(this.oTrans, "UD103.ShortChar02", controlSettings));
((EpiDataView)(this.oTrans.EpiDataViews["UD103"])).AddRowRule(rr1);
2.根据自定义方法返回值控制字段只读
private bool IsApproved(RowRuleDelegateArgs args)
{
string shortChar01= Convert.ToString(args.Row["ShortChar01"]);
if (shortChar01== "Approved") return true;
else return false;
}
RowRule rr1 = new RowRule(null, new RowRuleConditionDelegate2(this.IsApproved), null);//如果IsApproved方法返回true
//该行的UD103.ShortChar02字段设置为只读,控制数据输入
rr1.AddAction(RuleAction.AddControlSettings(this.oTrans, "UD103.ShortChar02", SettingStyle.ReadOnly));
((EpiDataView)(this.oTrans.EpiDataViews["UD103"])).AddRowRule(rr1);//将RowRule添加到EpiDataView实例化对象中
3.根据自定义方法返回值控制整行只读
private bool IsApproved(RowRuleDelegateArgs args)
{
string shortChar01= Convert.ToString(args.Row["ShortChar01"]);
if (shortChar01== "Approved") return true;
else return false;
}
RowRule rr1 = new RowRule(null, new RowRuleConditionDelegate2(this.IsApproved), null);//如果IsApproved方法返回true
rr1.AddAction(RuleAction.DisableRow(this.oTrans, "UD103A"));//控制整行数据输入
((EpiDataView)(this.oTrans.EpiDataViews["UD103"])).AddRowRule(rr1);//将RowRule添加到EpiDataView实例化对象中
4.SettingStyle
除了高亮显示和只读样式,还可以设置加粗,强制输入等,具体可以查看SettingStyle枚举:
public enum SettingStyle
{
Bold = 0,
Error = 1,
Warning = 2,
OK = 3,
Highlight = 4,
Disabled = 5,
Mandatory = 6,
Invisible = 7,
ReadOnly = 8
}
5.根据自定义方法返回值执行自定义行为
除SettingStyle枚举中的行为外,我们也可以自定义行为:
private bool IsApproved(RowRuleDelegateArgs args)
{
string shortChar01= Convert.ToString(args.Row["ShortChar01"]);
if (shortChar01== "Approved") return true;
else return false;
}
private void DoSomeThings(RowRuleDelegateArgs args){
epiBt1.ReadOnly = true;
}
//根据IsApproved方法返回值,执行DoSomeThings方法
RowRule rr1 = new RowRule(null, new RowRuleConditionDelegate2(this.IsApproved), null, new RowRuleActionDelegate2(this.DoSomeThings),null);
((EpiDataView)(this.oTrans.EpiDataViews["UD103"])).AddRowRule(rr1);
6.RowRule失效情况
暂时发现调用了oTrans.Clear()时RowRule会失效,需改为调用oTrans.ClearDataSets()。