Exemple #1
0
        public BindingList<EventEntry> Search()
        {
            FormStorage<bool> storage = new FormStorage<bool>(false);
            Dictionary<string, string> searchTerms = new Dictionary<string, string>();
            Search search = new Search(searchTerms, typeof(EventEntry), storage);

            search.ShowDialog();

            if (storage.Value && searchTerms.Count != 0)
            {
                BindingList<EventEntry> searchList = new BindingList<EventEntry>();
                foreach(EventEntry entry in _events)
                {
                    searchList.Add(entry);
                }

                foreach (KeyValuePair<string, string> pair in searchTerms)
                {
                    for (int i = 0; i < searchList.Count; i++)
                    {
                        object property = typeof(EventEntry).GetProperty(pair.Value).GetValue(searchList[i]);
                        if (property != null && !property.ToString().Contains(pair.Key))
                        {
                            i--;
                            searchList.Remove(searchList[i + 1]);
                        }
                    }
                }

                return searchList;
            }

            return _events;
        }
Exemple #2
0
        public BindingList<DatabaseEntry> Search()
        {
            FormStorage<bool> storage = new FormStorage<bool>(false);
            Dictionary<string, string> searchTerms = new Dictionary<string,string>();
            Search search = new Search(searchTerms, typeof(DatabaseEntry), storage);

            search.ShowDialog();

            if (storage.Value && searchTerms.Count != 0)
            {
                BindingList<DatabaseEntry> searchList = new BindingList<DatabaseEntry>();
                foreach (DatabaseEntry entry in _availableEntries)
                {
                    searchList.Add(entry);
                }

                foreach (KeyValuePair<string, string> pair in searchTerms)
                {
                    for(int i = 0; i < searchList.Count; i++)
                    {
                        if (pair.Value == "Majors" || pair.Value == "Minors")
                        {
                            bool contains = false;

                            BindingList<string> keyList = (BindingList<string>)typeof(DatabaseEntry).GetProperty(pair.Value).GetValue(searchList[i]);

                            foreach (string major in keyList)
                            {
                                if (major.Contains(pair.Key))
                                {
                                    contains = true;
                                }
                            }
                            if(!contains)
                            {
                                i--;
                                searchList.Remove(searchList[i + 1]);
                            }
                        }
                        else
                        {
                            object property = typeof(DatabaseEntry).GetProperty(pair.Value).GetValue(searchList[i]);
                            if (property != null && !property.ToString().Contains(pair.Key))
                            {
                                i--;
                                searchList.Remove(searchList[i + 1]);
                            }
                        }
                    }
                }

                return searchList;
            }

            return _availableEntries;
        }