Example #1
0
        public static SearchingType ProcessSearchValue(string searchValue, out string actualSearchValue)
        {
            SearchingType searchingType      = SearchingType.Exact;
            bool          isStartWithStar    = searchValue.StartsWith("*");
            bool          isEndWithStar      = searchValue.EndsWith("*");
            bool          containsVaildValue = searchValue.Any(c => !c.Equals('*') && !c.Equals(' ')); // make sure the value contains character other than '*' only

            if ((isStartWithStar || isEndWithStar) && containsVaildValue)
            {
                if (isStartWithStar && isEndWithStar)
                {
                    actualSearchValue = searchValue.Substring(1, searchValue.Length - 2);
                    return(SearchingType.BothSideFuzzyMatching);
                }
                else if (isStartWithStar)
                {
                    actualSearchValue = searchValue.Substring(1);
                    return(SearchingType.LeftFuzzyMatching);
                }
                else if (isEndWithStar)
                {
                    actualSearchValue = searchValue.Substring(0, searchValue.Length - 1);
                    return(SearchingType.RightFuzzyMatching);
                }
            }
            actualSearchValue = searchValue;
            return(searchingType);
        }
Example #2
0
        void _mf_FilterComputerByProp(List <SearchingCriteria> arg)
        {
            if (_cDescriptions == null)
            {
                return;
            }

            List <string> filterComp = new List <string>();

            foreach (SearchingCriteria sc in arg)
            {
                string        targetProp = sc.nameElement.Substring(sc.nameElement.LastIndexOf('_') + 1);
                string        targetElem = sc.nameElement.Substring(0, sc.nameElement.LastIndexOf('_'));
                SearchingType st         = sc.searchingType;


                foreach (var item0 in _cDescriptions)
                {
                    string compName = item0.Key;

                    foreach (KeyValuePair <string, List <Dictionary <string, string> > > item1 in item0.Value.Values)
                    {
                        if (item1.Key != targetElem)
                        {
                            continue;
                        }

                        foreach (Dictionary <string, string> item2 in item1.Value)
                        {
                            string val;
                            if (st == SearchingType.Contains)
                            {
                                if (item2.TryGetValue(targetProp, out val))
                                {
                                    if (val.Contains(sc.value))
                                    {
                                        filterComp.Add(compName);
                                    }
                                }
                            }
                            else if (st == SearchingType.Gt)
                            {
                                if (item2.TryGetValue(targetProp, out val))
                                {
                                    double curVal   = double.Parse(val);
                                    double checkVal = double.Parse(sc.value);
                                    if (curVal >= checkVal)
                                    {
                                        filterComp.Add(compName);
                                    }
                                }
                            }
                            else if (st == SearchingType.Lt)
                            {
                                if (item2.TryGetValue(targetProp, out val))
                                {
                                    double curVal   = double.Parse(val);
                                    double checkVal = double.Parse(sc.value);
                                    if (curVal <= checkVal)
                                    {
                                        filterComp.Add(compName);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            filterComp = filterComp.Distinct().ToList();
            _mf.HighlightComputers(filterComp);
        }