Ejemplo n.º 1
0
        private void MoviesForm_Load(object sender, System.EventArgs e)
        {
            try
            {
                checkBoxFilters = new List <CheckBox>();

                dataGridViewMovies.DataSource = defaultFilter.FilterDataMovies();

                filterDataLogic.FilterDataGrid("FilterValuesMovies", filtersGroupBox, out checkBoxFilters);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        public void FilterData(DataGridView dataGridView, string filterDataMethod, List <CheckBox> checkBoxFilters, object index = null)
        {
            Type[] types = Assembly.Load("MoviesLibrary").GetTypes()
                           .Where(t => typeof(DefaultFilter).IsAssignableFrom(t) && t != typeof(DefaultFilter)).ToArray();

            HashSet <U> filteredValues = new HashSet <U>();

            foreach (var checkBox in checkBoxFilters)
            {
                if (checkBox.Checked)
                {
                    foreach (Type t in types)
                    {
                        var instance = Activator.CreateInstance(t, checkBox);

                        var method = t.GetMethod(filterDataMethod);

                        if (instance != null && method != null && method.DeclaringType.IsSealed)
                        {
                            switch (index)
                            {
                            case null:
                                filteredValues.UnionWith((List <U>)method.Invoke(instance, null));
                                break;

                            default:
                                filteredValues.UnionWith((List <U>)method.Invoke(instance, new[] { index }));
                                break;
                            }
                        }
                    }
                }
                else
                {
                    if (index == null)
                    {
                        dataGridView.DataSource = defaultFilter.FilterDataMovies();
                    }
                    else
                    {
                        dataGridView.DataSource = defaultFilter.FilterDataActors()[(int)index];
                    }
                }
            }

            if (filteredValues.Count > 0)
            {
                dataGridView.DataSource = filteredValues.ToList();
            }
        }