Mark,
Thanks so much for your reply–it is pointing me in the right direction and I very much appreciate it. I do need a bit more assistance as I am a novice with C# and Epicor (as you will see).
Remember that I am attempting to apply the rules to multiple rows. To begin with, I have applied the rule to two rows as follows:
private void CreateRowRule_Part()
{
// Description: Part
// **** begin autogenerated code ****
RuleAction disabledPart_RowAction = RuleAction.AddRowSettings(this.oTrans, "Part", false, SettingStyle.Disabled);
RuleAction[] ruleActions = new RuleAction[] {
disabledPart_RowAction};
// Create RowRule and add to the EpiDataView.
RowRule rrCreateRowRule_Part = new RowRule("Part.PartNum", new RowRuleConditionDelegate2(this.Engineer_CustomRuleCondition), "Part.PartNum", ruleActions);
((EpiDataView)(this.oTrans.EpiDataViews["Part"])).AddRowRule(rrCreateRowRule_Part);
// **** end autogenerated code ****
}
private void CreateRowRule_PartRev()
{
// Description: PartRev
// **** begin autogenerated code ****
RuleAction disabledPartRev_RowAction = RuleAction.AddRowSettings(this.oTrans, "PartRev", false, SettingStyle.Disabled);
RuleAction[] ruleActions = new RuleAction[] {
disabledPartRev_RowAction};
// Create RowRule and add to the EpiDataView.
RowRule rrCreateRowRule_PartRev = new RowRule("Part.PartNum", new RowRuleConditionDelegate2(this.Engineer_CustomRuleCondition), "Part.PartNum", ruleActions);
((EpiDataView)(this.oTrans.EpiDataViews["PartRev"])).AddRowRule(rrCreateRowRule_PartRev);
// **** end autogenerated code ****
}
private bool Engineer_CustomRuleCondition(Ice.Lib.ExtendedProps.RowRuleDelegateArgs args)
{
EpiDataView edv = (EpiDataView) this.oTrans.EpiDataViews["CallContextClientData"];
string userID = edv.dataView[0]["CurrentUserId"].ToString();
try
{
UserFileAdapter adapterUserFile = new UserFileAdapter(this.oTrans);
adapterUserFile.BOConnect();
bool result = adapterUserFile.GetByID(userID);
if (result)
{
if (adapterUserFile.UserFileData.UserFile[0]["GroupList"].ToString().IndexOf("Engineering 1") != -1)
{
MessageBox.Show("User belongs to Engineering 1 Group");
return false;
}
}
adapterUserFile.Dispose();
}
catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}
MessageBox.Show("User does NOT belong to Engineering 1 Group");
return true;
}
While this works as needed, it seems to be a bit sloppy and inefficient.
I say its sloppy, because in creating my row rules I reference the Part.PartNum value to be equal to itself as part of the rule. I don’t really need that as I can rely solely on the return value of the delegate. [I am following the example created by the Rule Wizard, which requires at least one conditional value.]
It is inefficient as the MessageBox appears 4 times for every Part Row and 2 or three times (I lost count) for every PartRev row. I just need it to evaluate once per Part row–actually, once per session, but it is my understanding that row rules fire on row change.
Finally, rather than have the Delegate and the Row Rule use a boolean value, is it possible to use a string? I’d have the Delegate produce a concatenated string based on one or more security groups i.e. “~Engineer~Planner” then have the row rules evaluate the existence of substrings in the returned value.
Any help on this would also be appreciated.
Michael