public void FilterBy(SongFilter filter) { FilteredMediaList.Clear(); foreach (Song s in MediaList) { FilteredMediaList.Add(s); } for (int i = 0; i < FilteredMediaList.Count; i++) { Song s = FilteredMediaList[i]; int minYear; int maxYear; int minRating; int maxRating; if (s.SongName.Contains(filter.SongName)) { FilteredMediaList.Remove(s); i--; continue; } bool shouldFilter = int.TryParse(filter.MinYear, out minYear); if (shouldFilter == true && s.YearReleased < minYear) { FilteredMediaList.Remove(s); i--; continue; } shouldFilter = int.TryParse(filter.MaxYear, out maxYear); if (shouldFilter == true && s.YearReleased > maxYear) { FilteredMediaList.Remove(s); i--; continue; } shouldFilter = int.TryParse(filter.MinRating, out minRating); if (shouldFilter == true && s.MyRating < minRating) { FilteredMediaList.Remove(s); i--; continue; } shouldFilter = int.TryParse(filter.MaxRating, out maxRating); if (shouldFilter == true && s.MyRating > maxRating) { FilteredMediaList.Remove(s); i--; continue; } } }
public FormSongFilter(SongFilter filter) { InitializeComponent(); textBoxSongName.Text = filter.SongName; textBoxMinYear.Text = filter.MinYear; textBoxMaxYear.Text = filter.MaxYear; textBoxMinRating.Text = filter.MinRating; textBoxMaxRating.Text = filter.MaxRating; _SongFilter = filter; }
private void buttonFilter_Click(object sender, EventArgs e) { SongFilter S = new SongFilter(); FormSongFilter SongFormFilter = new FormSongFilter(S); DialogResult Result = SongFormFilter.ShowDialog(); if (Result == DialogResult.OK) { _MediaCollection.FilterBy(S); listBox1.DataSource = _MediaCollection.FilteredMediaList; } else { listBox1.DataSource = _MediaCollection.MediaList; } }