コード例 #1
0
        //loading the screen
        private void ViewVehiclesScreen_Load(object sender, EventArgs e)
        {
            List <string> searchableAttrs = new List <string> {
                "VID", "Type", "Make", "Model", "Colour", "Price-Range", "Kilometers", "Load-Rating", "Sold Status"
            };

            foreach (string item in searchableAttrs)
            {
                SearchAttrTypeBox.Items.Add(item);
            }

            SortedDictionary <int, Entity> allCars = VehicleManagement.GetSortedDictionary();

            loadSearchResults(allCars);
        }//end ViewVehiclesScreen_Load()
コード例 #2
0
        }//end ViewVehiclesScreen_Load()

        /// <summary>
        /// Click event handler for search button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SearchVehiclesBtn_Click(object sender, EventArgs e)
        {
            //make sure we have an attribute to search by
            if (SearchAttrTypeBox.SelectedIndex < 0)
            {
                MessageBox.Show("You need to enter an attribute to search by");
            }
            else if (SearchVehiclesInput.Text == "")
            {
                MessageBox.Show("You need to enter an search term");
            }
            else
            {
                //all the cars we have
                SortedDictionary <int, Entity> allCars = VehicleManagement.GetSortedDictionary();
                //the cars to show
                SortedDictionary <int, Entity> resultSet = new SortedDictionary <int, Entity>();
                //the string we are searching on
                string searchOn = SearchVehiclesInput.Text;

                foreach (KeyValuePair <int, Entity> entry in allCars)
                {
                    Vehicle vehicle = (Vehicle)entry.Value;
                    if (vehicle.FindAttribute(SearchAttrTypeBox.SelectedItem.ToString(), searchOn))
                    {
                        resultSet.Add(entry.Key, vehicle);
                    }
                }

                if (resultSet.Count() > 0)
                {
                    loadSearchResults(resultSet);
                }
                else
                {
                    MessageBox.Show("Sorry, no vehicles matched your search terms");
                }
            } //end if
        }     //end SearchVehiclesBtn_Click()