I’m attempting to create a customization to validate an email address in the Person / Contact Entry screen. I duplicated the c# code in the following thread (BPM to validate email address format in UD Fields - #9 by system), adapting it to the PerCon table instead of the Customer table.
However, I am getting a compilation error on only one row. I am not sure what is meant by:
Error: CS0123 - line 63 (175) - No overload for ‘PerConEMailAddress123_CustomRuleCondition’ matches delegate ‘Ice.Lib.ExtendedProps.RowRuleConditionDelegate2’
Here is the script:
// **************************************************
// Custom code for PerConForm
// Created: 9/9/2020 10:51:55 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using System.Text.RegularExpressions;
public static class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
public static void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
CreateRowRulePerConEMailAddressCustomCondition_123();;
// End Wizard Added Custom Method Calls
}
public static void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private static void CreateRowRulePerConEMailAddressCustomCondition_123()
{
// Description: InvalidEmail
// **** begin autogenerated code ****
RuleAction[] ruleActions = new RuleAction[0];
// Create RowRule and add to the EpiDataView.
// Dummy Context Object
object contextObject = null;
//Begin row 63 (compilation error row)
RowRule rrCreateRowRulePerConEMailAddressCustomCondition_123 = new RowRule("PerCon.EMailAddress", new RowRuleConditionDelegate2(Script.PerConEMailAddress123_CustomRuleCondition), 123, new RowRuleActionDelegate2(Script.PerConEMailAddressDelegate123_CustomRuleAction), contextObject);
// End row 63
((EpiDataView)(Script.oTrans.EpiDataViews["PerCon"])).AddRowRule(rrCreateRowRulePerConEMailAddressCustomCondition_123);
// **** end autogenerated code ****
}
private static bool PerConEMailAddress123_CustomRuleCondition(object Arg1, object Arg2)
{
bool result = false;
// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
try
{
// ** put Row Rule condition evaluation logic here
if(!String.IsNullOrEmpty(Arg1.ToString()))
{
result = !isValidEmail(Arg1.ToString());
}
}
catch(Exception ex)
{
MessageBox.Show("Error: "+ex.Message);
}
return result;
}
private static void PerConEMailAddressDelegate123_CustomRuleAction(object UserObject)
{
// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
// ** put custom Rule Action logic here
try
{
EpiDataView edV = (EpiDataView)oTrans.EpiDataViews["PerCon"];
edV.dataView[edV.Row]["EMailAddress"]="";
edV.Notify(new EpiNotifyArgs("PerConEntryForm", edV.Row, edV.Column));
}
catch(Exception ex)
{
MessageBox.Show("Error: "+ex.Message);
}
finally
{
MessageBox.Show("The Email address is invalid","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
public static bool isValidEmail(string inputEmail)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
}
Thank you for the response. Quite frankly, I am well in over my head as I am a neophyte when it comes to c# programming. I have replaced (object UserObject) with (object Arg1, object Arg2) but this change now raises two compilation errors instead of the one I was receiving.
Compiling Custom Code ...
----------errors and warnings------------
Error: CS0123 - line 63 (175) - No overload for 'PerConEMailAddress123_CustomRuleCondition' matches delegate 'Ice.Lib.ExtendedProps.RowRuleConditionDelegate2'
Error: CS0123 - line 63 (175) - No overload for 'PerConEMailAddressDelegate123_CustomRuleAction' matches delegate 'Ice.Lib.ExtendedProps.RowRuleActionDelegate2'
** Compile Failed. **
If you did the first, then all you have to do is update the function <rulename>_CustomRuleCondition() to return true when the Rule Action should be applied.
Here’s one that did on ABC Code’s CountFreq field to highlight if it is a multiple of 7.
Code
// **************************************************
// Custom code for AbcCodeForm
// Created: 9/10/2020 1:12:36 PM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Erp.Adapters;
using Erp.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
public class Script
{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **
// End Wizard Added Module Level Variables **
// Add Custom Module Level Variables Here **
public void InitializeCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
// Begin Wizard Added Variable Initialization
// End Wizard Added Variable Initialization
// Begin Wizard Added Custom Method Calls
CreateRowRuleAbcCodeCountFreqCustomCondition_7();;
// End Wizard Added Custom Method Calls
}
public void DestroyCustomCode()
{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
// Begin Wizard Added Object Disposal
// End Wizard Added Object Disposal
// Begin Custom Code Disposal
// End Custom Code Disposal
}
private void CreateRowRuleAbcCodeCountFreqCustomCondition_7()
{
// Description: CountFreqMultOf7
// **** begin autogenerated code ****
RuleAction errorAbcCode_CountFreq = RuleAction.AddControlSettings(this.oTrans, "AbcCode.CountFreq", SettingStyle.Error);
RuleAction[] ruleActions = new RuleAction[] {
errorAbcCode_CountFreq};
// Create RowRule and add to the EpiDataView.
RowRule rrCreateRowRuleAbcCodeCountFreqCustomCondition_7 = new RowRule("AbcCode.CountFreq", new RowRuleConditionDelegate2(this.AbcCodeCountFreq7_CustomRuleCondition), 7, ruleActions);
((EpiDataView)(this.oTrans.EpiDataViews["AbcCode"])).AddRowRule(rrCreateRowRuleAbcCodeCountFreqCustomCondition_7);
// **** end autogenerated code ****
}
private bool AbcCodeCountFreq7_CustomRuleCondition(Ice.Lib.ExtendedProps.RowRuleDelegateArgs args)
{
bool result = false;
// ** RowRuleDelegateArgs Properties: args.Arg1, args.Arg2, args.Context, args.Row
// ** put Row Rule condition evaluation logic here
result = (Int32.Parse(args.Arg1.ToString()) % 7 == 0 ? true : false);
return result;
}
}
The only line I had to add or modify was the one that sets the value of the result to return in the ...CustomRuleCondition() function.
Why are you making this a customization and not a BPM? Server side code will work for any interface, but a customization will only work for this screen. Just a thought…
I’m of the same opinion.
Coincidentally I had been playing with RegEx recently so fiddled around with a form customization for a bit, I was able to get it working… sort of (message pops up multiple times).
When I finally switched to a BPM things became much simpler, easier.
Attached a copy of BPM if your interested in trying that out.
Note that I did very little testing on this one, I was just playing around today. PerCon_RegEx_Email_Validate.bpm (31.4 KB)