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!");
            }
        }
示例#2
0
        public ApparelFilterMaterials(TabApparel tab)
        {
            InitializeComponent();

            DialogResult = DialogResult.Cancel;

            checkBox1.Checked = TabApparel.ShowDefStuff;
            // get materials list
            {
                var stuffs = tab.GetCachedList()
                             .Where(x => !String.IsNullOrEmpty(x.Material))
                             .Select(x => x.Material)
                             .OrderBy(x => x)
                             .Distinct();

                checkedListBox1.DataSource = stuffs.ToList();
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    string stuffName = (string)checkedListBox1.Items[i];
                    if (!TabApparel.StuffActiveState.TryGetValue(stuffName, out bool state))
                    {
                        TabApparel.StuffActiveState[stuffName] = state = true;
                    }
                    checkedListBox1.SetItemChecked(i, state);
                }
            }
        }
        public ApparelFilterForm(TabApparel tab)
        {
            InitializeComponent();
            this.tab = tab;

            comboBox2.DataSource = typeof(Apparel).GetProperties().Where(x => x.PropertyType == typeof(float?)).Select(x =>
            {
                var localized = (LocalizedDisplayNameAttribute)x
                                .GetCustomAttributes(true)
                                .Where(a => a is LocalizedDisplayNameAttribute)
                                .FirstOrDefault();

                return(new ComboBoxColumn
                {
                    Name = x.Name,
                    DisplayName = localized?.DisplayName
                });
            }).ToList();

            string langName     = File.Exists("Language") ? File.ReadAllText("Language") : "English";
            string langFileName = $"Languages\\{langName}.xml";

            if (!Localization.TryLoadFromFile(langFileName, out Exception ex))
            {
                MessageBox.Show($"Error: {ex.Message}", langFileName);
                Environment.Exit(1);
            }

            comboBox1.Items.Add("Combo1_Item_WithRecipe".Translate());
            comboBox1.Items.Add("Combo1_Item_All".Translate());

            comboBox3.Items.Add("Combo2_Item_SortByDescending".Translate());
            comboBox3.Items.Add("Combo2_Item_SortByAscending".Translate());

            label2.Text = "Label_HasRecipe".Translate();
            label3.Text = "Label_FilterByParam".Translate();
            label4.Text = "Label_SortOrder".Translate();
            label1.Text = "Label_Depth".Translate();

            button1.Text = "Button_ApplyFilter".Translate();

            Localization.Finalize();

            comboBox1.SelectedIndex = 0;
            comboBox2.SelectedIndex = 0;
            comboBox3.SelectedIndex = 0;

            // get materials list
            {
                var stuffs = tab.GetCachedList()
                             .Where(x => !String.IsNullOrEmpty(x.Material))
                             .Select(x => x.Material)
                             .OrderBy(x => x)
                             .Distinct();

                checkedListBox1.DataSource = stuffs.ToList();
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    string stuffName = (string)checkedListBox1.Items[i];
                    if (!TabApparel.StuffActiveState.TryGetValue(stuffName, out bool state))
                    {
                        TabApparel.StuffActiveState[stuffName] = state = true;
                    }
                    checkedListBox1.SetItemChecked(i, state);
                }
            }
        }