Ejemplo n.º 1
0
        private void FilterButton_Click(object sender, EventArgs e)
        {
            var filter = new SupplyFilter
            {
                ID                = FilterIDTextBox.Text.AsInt(),
                SupplierName      = FilterSupplierNameTextBox.Text,
                ComponentID       = (FilterComponentDropDown.SelectedValue.AsInt() == 0) ? null : FilterComponentDropDown.SelectedValue.AsInt(),
                DeliveredFrom     = (FilterDeliveredFromDatePicker.Format == DateTimePickerFormat.Custom) ? null : FilterDeliveredFromDatePicker.Value.Date.AsDateTime(),
                DeliveredTo       = (FilterDeliveredToDatePicker.Format == DateTimePickerFormat.Custom) ? null : FilterDeliveredToDatePicker.Value.Date.AsDateTime(),
                IsNotApprovedOnly = FilterIsNotApprovedOnlyCheckBox.Checked
            };

            using (var repository = new SupplyRepository())
            {
                SupplyGrid.DataSource = repository.GetSupplies(filter);
            }

            SupplyGrid.ClearSelection();
        }
Ejemplo n.º 2
0
        private void filterClicked(object obj)
        {
            ObservableCollection <Item> results = new ObservableCollection <Item>();

            // Null check for the combo box
            if (PetFilter != null)
            {
                // Only adds pets if the user did not specify supplies
                if (SupplyFilter.Contains("All Supplies"))
                {
                    foreach (Item product in Items)
                    {
                        // Adds animal to the results based on the pet filter combo box and object type
                        if (product.GetType().Equals(typeof(LandAnimal)) && (petFilter.Contains("Land Pet") || PetFilter.Contains("All Pets")))
                        {
                            results.Add(product);
                        }

                        if (product.GetType().Equals(typeof(AirAnimal)) && (petFilter.Contains("Air Pet") || PetFilter.Contains("All Pets")))
                        {
                            results.Add(product);
                        }

                        if (product.GetType().Equals(typeof(SeaAnimal)) && (petFilter.Contains("Sea Pet") || PetFilter.Contains("All Pets")))
                        {
                            results.Add(product);
                        }
                    }
                }
            }


            // Supply filter null check
            if (SupplyFilter != null)
            {
                foreach (Item product in Items)
                {
                    if (PetFilter.Contains("All Pets"))
                    {
                        if (SupplyFilter.Contains("All Supplies"))
                        {
                            // Adds every item in inventory to the results
                            if (product.GetType().Equals(typeof(Food)) || product.GetType().Equals(typeof(Clothing)))
                            {
                                results.Add(product);
                            }
                        }
                        else if (SupplyFilter.Contains("Food"))
                        {
                            // Adds all of the food in inventory to the results
                            if (product.GetType().Equals(typeof(Food)))
                            {
                                results.Add(product);
                            }
                        }
                        else if (SupplyFilter.Contains("Clothing"))
                        {
                            // Adds all of the clothing in invetory to results
                            if (product.GetType().Equals(typeof(Clothing)))
                            {
                                results.Add(product);
                            }
                        }
                    }
                    else if (PetFilter.Contains("Land Pet"))
                    {
                        // Adds all land pet food based on combo box and animalAttachment variable which establishes relationship between supply and animal
                        if (product.animalAttachment == Item.LandPet && product.GetType().Equals(typeof(Food)) && (SupplyFilter.Contains("Food") || SupplyFilter.Contains("All Supplies")))
                        {
                            results.Add(product);
                        }
                        // Adds all land pet clothing based on combo box and animalAttachment variable which establishes relationship between supply and animal
                        else if (product.animalAttachment == Item.LandPet && product.GetType().Equals(typeof(Clothing)) && SupplyFilter.Contains("Clothing"))
                        {
                            results.Add(product);
                        }
                    }
                    else if (PetFilter.Contains("Air Pet"))
                    {
                        // See land pet comments for explantion
                        if (product.animalAttachment == Item.AirPet && product.GetType().Equals(typeof(Food)) && (SupplyFilter.Contains("Food") || SupplyFilter.Contains("All Supplies")))
                        {
                            results.Add(product);
                        }
                        else if (product.animalAttachment == Item.AirPet && product.GetType().Equals(typeof(Clothing)) && SupplyFilter.Contains("Clothing"))
                        {
                            results.Add(product);
                        }
                    }
                    else if (PetFilter.Contains("Sea Pet"))
                    {
                        // See land pet comments for explantion
                        if (product.animalAttachment == Item.SeaPet && product.GetType().Equals(typeof(Food)) && (SupplyFilter.Contains("Food") || SupplyFilter.Contains("All Supplies")))
                        {
                            results.Add(product);
                        }
                        else if (product.animalAttachment == Item.SeaPet && product.GetType().Equals(typeof(Clothing)) && SupplyFilter.Contains("Clothing"))
                        {
                            results.Add(product);
                        }
                    }
                }
            }

            // Switches to view that diplays results
            // Passes the main window container, the results list, and the shopping window to return to
            MainView.ActiveView = new FilterWindowVM(MainView, results, this);
        }