Ejemplo n.º 1
0
        /// <summary>
        /// Compares this row with the other row provided using specified sort criteria.
        /// </summary>
        /// <param name="other">The other data row to compare this row to.</param>
        /// <param name="criteria">Sort criteria to use.</param>
        /// <returns>A 32-bit signed integer that indicates the relative order of the objects
        /// being compared. The return value has the following meanings: Value Meaning
        /// Less than zero This object is less than the other parameter. Zero This object
        /// is equal to other. Greater than zero This object is greater than other.</returns>
        public int CompareTo(DataRow other, ListSortCriteria criteria)
        {
            int res = 0;

            if (criteria == null || other == null || List != other.List)
            {
                return(res);
            }

            foreach (ListSortField sortFld in criteria)
            {
                DataProperty p = List[sortFld.PropertyName];
                if (p != null)
                {
                    object val1 = this[p.Column];
                    object val2 = other[p.Column];
                    if (val1 == val2)
                    {
                        res = 0;
                    }
                    else if (val1 == null && val2 != null)
                    {
                        res = -1;
                    }
                    else if (val1 != null && val2 == null)
                    {
                        res = 1;
                    }
                    else if (val1 is IComparable)
                    {
                        res = ((IComparable)val1).CompareTo(val2);
                    }
                    else if (val2 is IComparable)
                    {
                        res = -((IComparable)val2).CompareTo(val1);
                    }
                    else
                    {
                        res = string.Compare(
                            "" + p.ResolveValue(val1, ValueFormat.DisplayString),
                            "" + p.ResolveValue(val2, ValueFormat.DisplayString));
                    }
                    if (sortFld.SortDirection == ListSortDirection.Descending)
                    {
                        res *= -1;
                    }
                }
                if (res != 0)
                {
                    return(res);
                }
            }
            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// A filtering function that determines if the value of the specified property in the given row
        /// matches the specified criteria value using supplied operator.
        /// </summary>
        /// <param name="property">The data property of the object to match.</param>
        /// <param name="row">The data row to get the value from.</param>
        /// <param name="oper">Comparison operator to use.</param>
        /// <param name="criteria">The value to compare to.</param>
        /// <param name="caseSensitive">True to perform case-sensitive string matching, false otherwise.</param>
        /// <returns>True if the property value in the given row matches the specified criteria, false otherwise.</returns>
        public virtual bool PropertyValueMatches(DataProperty property, DataRow row, Operator oper, object criteria, bool caseSensitive)
        {
            ValueFormat format = criteria?.GetType() == typeof(string) ? ValueFormat.DisplayString : ValueFormat.Internal;
            object      value  = property.GetValue(format, row);

            criteria = property.ResolveValue(criteria, format);
            if (format.IsString() && !caseSensitive)
            {
                value    = value?.ToString()?.ToLower();
                criteria = criteria?.ToString()?.ToLower();
            }
            return(oper.Matches(value, criteria));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a value of the specified property from the given data row.
        /// </summary>
        /// <param name="dataItem">data row to get the data from.</param>
        /// <param name="property">proprety name to retrieve.</param>
        /// <param name="format">value format to return.</param>
        /// <returns></returns>
        public static object Get(object dataItem, string property, ValueFormat format)
        {
            DataRow dr = dataItem as DataRow;

            if (dr == null)
            {
                return(null);
            }
            DataProperty dp = dr.List[property];

            if (dp == null || dp.Column < 0 || dp.Column >= dr.Count)
            {
                return(null);
            }
            return(dp.ResolveValue(dr[dp.Column], format));
        }