Beispiel #1
0
        public override CompareResult Compare(string fragmentText)
        {
            double similarity = 0;
            if (ignoreCase)
            {
                if (ItemKey.StartsWith(fragmentText, StringComparison.InvariantCultureIgnoreCase))
                {
                    this.SortIndex = LevenshteinDistance(ItemKey, fragmentText, out similarity, ignoreCase) * Math.Pow(10, FilterColumns.Length + 1);
                    return CompareResult.VisibleAndSelected;
                }
                if (ItemValue.StartsWith(fragmentText, StringComparison.InvariantCultureIgnoreCase))
                {
                    this.SortIndex = LevenshteinDistance(ItemValue, fragmentText, out similarity, ignoreCase) * Math.Pow(10, FilterColumns.Length);
                    return CompareResult.VisibleAndSelected;
                }

                if (FilterColumns != null)
                {
                    int i = 1;
                    foreach (string strCol in FilterColumns)
                    {
                        if (strCol.StartsWith(fragmentText, StringComparison.InvariantCultureIgnoreCase))
                        {
                            this.SortIndex = LevenshteinDistance(strCol, fragmentText, out similarity, ignoreCase) * Math.Pow(10, FilterColumns.Length - i);
                            return CompareResult.VisibleAndSelected;
                        }
                        i++;
                    }
                }
            }
            else
            {
                if (ItemKey.Contains(fragmentText))
                {
                    this.SortIndex = LevenshteinDistance(ItemKey, fragmentText, out similarity, ignoreCase) * Math.Pow(10, FilterColumns.Length + 1);
                    return CompareResult.VisibleAndSelected;
                }
                if (ItemValue.Contains(fragmentText))
                {
                    this.SortIndex = LevenshteinDistance(ItemValue, fragmentText, out similarity, ignoreCase) * Math.Pow(10, FilterColumns.Length);
                    return CompareResult.VisibleAndSelected;
                }

                if (FilterColumns != null)
                {
                    int i = 1;
                    foreach (string strCol in FilterColumns)
                    {
                        if (strCol.ToLower().Contains(fragmentText))
                        {
                            this.SortIndex = LevenshteinDistance(strCol, fragmentText, out similarity, ignoreCase) * Math.Pow(10, FilterColumns.Length - i);
                            return CompareResult.VisibleAndSelected;
                        }
                        i++;
                    }
                }
            }
            return CompareResult.Hidden;
        }