private void button1_Click(object sender, EventArgs e) { if (int.TryParse(textBox1.Text, out int bodyResultsCount)) { List <string> allowedStuff = checkedListBox1.CheckedItems .Cast <string>() .ToList(); List <Apparel> allItems = tab.GetCachedList() .Where(x => String.IsNullOrEmpty(x.Material) || allowedStuff.Contains(x.Material)) .ToList(); string fieldName = (comboBox2.SelectedItem as ComboBoxColumn)?.Name; List <Apparel> filtered = ApparelFilter.FilterApparels(allItems, fieldName, comboBox3.SelectedIndex == 0, comboBox1.SelectedIndex == 0, bodyResultsCount); if (checkBox1.Checked) { tab.ClearCart(); } tab.AddInToCart(filtered); tab.ActivateCart(true, true); this.Close(); } else { MessageBox.Show("Invalid number!"); } }
public static List <Apparel> FilterApparels(List <Apparel> list, string fieldName, bool orderByDescending, bool onlyCraftable, int bodyResultsCount) { ApparelFilter filter = new ApparelFilter(list, fieldName); if (orderByDescending) { filter.SortApparelsByDescending(); } else { filter.SortApparels(); } return(filter.Filter(onlyCraftable, bodyResultsCount)); }