Beispiel #1
0
        public static bool SmartFieldRequired(object target, RuleArgs e)
        {
            ISmartField value = (ISmartField)Utilities.CallByName(target, e.PropertyName, CallType.Get);

            if (value.HasNullValue() == true)
            {
                e.Description = Resources.ruleSmartFieldRequired.Replace("{rulePropertyName}", e.PropertyName);
                return(false);
            }
            return(true);
        }
Beispiel #2
0
        /// <summary>
        /// Implements a rule that only allows one field out of the specified set of fields to have a non-null value.
        /// Example: A gentleman can record his girlfriend's name, or his wife's name, but not both.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="e"></param>
        /// <returns></returns>
        public static bool AOrBValue(object target, RuleArgs e)
        {
            AOrBValueRuleArgs ee = (AOrBValueRuleArgs)e;
            int nonBlankCount    = 0;

            for (int i = 0; i < ee.PropertyList.Count; i++)
            {
                // Get object type of property.
                // Check the value assigned to each property in a manner appropriate to its object type, and count
                //   how many have a non-blank value.
                Object o = Utilities.CallByName(target, ee.PropertyList[i].ToString(), CallType.Get);
                Type   t = o.GetType();
                // string
                if (t.FullName == "System.String")
                {
                    String s = (String)o;
                    if (!(s == null ||
                          s == String.Empty
                          )
                        )
                    {
                        nonBlankCount++;
                    }
                }
                // char
                else if (t.FullName == "System.Char")
                {
                    Char c = (Char)o;
                    if (!(c == ' '
                          )
                        )
                    {
                        nonBlankCount++;
                    }
                }
                // SmartDate
                else if (t.FullName == "Csla.SmartDate")
                {
                    SmartDate d = (SmartDate)o;
                    if (!(d == null ||
                          d.IsEmpty
                          )
                        )
                    {
                        nonBlankCount++;
                    }
                }
                // SmartField
                else if (t.FullName == "CslaSrd.SmartInt16" ||
                         t.FullName == "CslaSrd.SmartInt32" ||
                         t.FullName == "CslaSrd.SmartInt64" ||
                         t.FullName == "CslaSrd.SmartFloat" ||
                         t.FullName == "CslaSrd.SmartDecimal" ||
                         t.FullName == "CslaSrd.SmartBool"
                         )
                {
                    ISmartField f = (ISmartField)o;
                    if (!(f == null ||
                          f.HasNullValue()
                          )
                        )
                    {
                        nonBlankCount++;
                    }
                }
                // other - error.
                else
                {
                }
            }
            if (nonBlankCount > 1)
            {
                String csvPropertyList = String.Empty;
                for (int i = 0; i < ee.PropertyList.Count; i++)
                {
                    csvPropertyList += "," + ee.PropertyList[i].ToString();
                }
                if (csvPropertyList.Length > 0)
                {
                    csvPropertyList = csvPropertyList.Substring(1);
                }

                ee.Description = Resources.ruleAOrBValue.Replace("{propertyList}", csvPropertyList);
                return(false);
            }
            else
            {
                return(true);
            }
        }