public virtual void CRSetup_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
 {
     if (!sender.ObjectsEqual <CRSetup.contactEmailUnique, CRSetup.leadValidationThreshold>(e.Row, e.OldRow))
     {
         CRSetup row = (CRSetup)e.Row;
         LeadContactValidationRules rule = LeadContactValidationRules.Search <CRValidationRules.matchingField>(typeof(Contact.eMail).Name);
         if (row.ContactEmailUnique == true)
         {
             var emailRule = (LeadContactValidationRules)(LeadContactValidationRules.Cache.CreateCopy(rule ?? LeadContactValidationRules.Cache.CreateInstance()));
             emailRule.ValidationType     = ValidationTypesAttribute.LeadContact;
             emailRule.MatchingField      = this.Caches[typeof(Contact)].GetField(typeof(Contact.eMail));
             emailRule.TransformationRule = TransformationRulesAttribute.None;
             emailRule.ScoreWeight        = row.LeadValidationThreshold;
             LeadContactValidationRules.Update(emailRule);
         }
         else
         {
             if (rule != null)
             {
                 LeadContactValidationRules.Cache.SetDefaultExt <CRValidationRules.scoreWeight>(rule);
                 LeadContactValidationRules.Cache.SetDefaultExt <CRValidationRules.transformationRule>(rule);
                 LeadContactValidationRules.Update(rule);
             }
         }
     }
 }
        public virtual void LeadContactValidationRules_RowDeleting(PXCache sender, PXRowDeletingEventArgs e)
        {
            LeadContactValidationRules rule = e.Row as LeadContactValidationRules;

            if (rule != null && CRSetupRecord.Current.ContactEmailUnique == true &&
                rule.MatchingField == this.Caches[typeof(Contact)].GetField(typeof(Contact.eMail)))
            {
                throw new PXException(Messages.EmailsRuleOnDuplicate);
            }
        }
        public virtual void LeadContactValidationRules_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            LeadContactValidationRules rule = e.Row as LeadContactValidationRules;

            if (rule == null)
            {
                return;
            }
            PXUIFieldAttribute.SetEnabled(sender, rule,
                                          !(CRSetupRecord.Current.ContactEmailUnique == true && rule.MatchingField == this.Caches[typeof(Contact)].GetField(typeof(Contact.eMail))));
        }