/// <summary> /// Get a list of property states for the given property using current descriptions. /// </summary> /// <param name="property">The data property to get the states for.</param> /// <param name="states">The combination of property states to return.</param> /// <param name="row">Specific data row for list objects, or null for regular data objects.</param> public virtual IEnumerable <string> GetStates(DataProperty property, PropertyChange states, DataRow row) { var state = new HashSet <string>(); if (property.Visible) { if (property.Editable) { if (property.Required && states.IncludesRequired()) { state.Add(Required); } if (property.Modified == true && states.IncludesValue()) { state.Add(Modified); } if (states.IncludesValidation()) { var err = property.GetValidationErrors(row); if (err?.Errors != null) { if (err.HasErrors()) { state.Add(Invalid); } else if (err.Errors.Any(e => e.Severity == ErrorSeverity.Warning)) { state.Add(Warning); } else if (err.Errors.Any() || // info? // don't mark as valid blank or enum and bool properties, since it's not helpful !property.IsNull(row) && !(property is EnumProperty) && !(property is BooleanProperty)) { state.Add(Valid); } } } } else if (states.IncludesEditable()) { state.Add(Readonly); } } else if (states.IncludesVisible()) { state.Add(Hidden); } return(state); }
/// <summary> /// Returns a list of current field criteria settings. /// </summary> public List <FieldCriteriaSetting> GetFieldCriteriaSettings() { // get a map of properties Dictionary <string, DataProperty> map = new Dictionary <string, DataProperty>(); foreach (DataProperty p in Properties) { map.Add(p.Name, p); } // clear the map from properties that are associated with operators OperatorProperty op; foreach (DataProperty p in Properties) { if ((op = p as OperatorProperty) == null) { continue; } if (op.AdditionalPropertyName != null) { map.Remove(op.AdditionalPropertyName); } if (op.AdditionalPropertyName2 != null) { map.Remove(op.AdditionalPropertyName2); } } // export visible non-null settings List <FieldCriteriaSetting> res = new List <FieldCriteriaSetting>(); foreach (DataProperty p in map.Values) { if (p.IsNull() || !p.Visible) { continue; } if ((op = p as OperatorProperty) != null) { List <string> value = new List <string>(); foreach (var apn in new string[] { op.AdditionalPropertyName, op.AdditionalPropertyName2 }) { DataProperty v = apn != null ? this[apn] : null; if (v != null && !v.IsNull() && v.Visible) { value.Add(v.DisplayStringValue); } } res.Add(new FieldCriteriaSetting { Label = p.Label, Operator = op.DisplayStringValue, Value = value.ToArray() }); } else { res.Add(new FieldCriteriaSetting { Label = p.Label, Operator = null, Value = new string[] { p.DisplayStringValue } }); } } return(res); }