I'm creating an application for a front end side of a database that allows users to log in and buy tickets/vouchers for special events. I've got everything done, but im having trouble on the search page.
Basically I have a few combo boxes that have options within them that allow the user to specify their search. the combo boxes are named like , category, genre, location, price range etc...
all of which have drop down menus for different options.
I want the user to chose these options then click the search button to narrow their search down.
I'm having trouble with this. I can get the search to narrow it down if the user picks an option for one combobox, but when they chose another option in another combobox it resets the search and primiarly searching for the combo box.
Do i keep creating Select statements for them, or do i just put the search criteria on the dataset.?
Here is the code for the search button, im sure most of you experience programmers will be able to understand it, as im a very simple way of working and naming.
public void searchButton_Click(object sender, RoutedEventArgs e)
{
using (SqlConnection _connection = SMUMomentsDB.GetConnection())
{
_connection.Open();
using (SqlDataAdapter _momentsTableAdapter = new SqlDataAdapter("Select * from SpecialMoment", _connection))
{
DataSet _ds = new DataSet();
_momentsTableAdapter.Fill(_ds);
momentsDataGrid.ItemsSource = _ds.Tables[0].DefaultView;
momentsDataGrid.IsReadOnly = true;
if (categoryComboBox.SelectedIndex == 0)
{
SqlDataAdapter _entertainmentCategory = new SqlDataAdapter("Select * from SpecialMoment WHERE GenreID in ('2', '3', '11', '14')", _connection);
_entertainmentCategory.Fill(_ds);
momentsDataGrid.ItemsSource = _ds.Tables[0].DefaultView;
momentsDataGrid.IsReadOnly = true;
}
if (locationComboBox.SelectedIndex == 0)
{
SqlDataAdapter locationAdapter = new SqlDataAdapter("Select * from SpecialMoment WHERE VenueLocation = 'Wales'", _connection);
{
_momentsTableAdapter.Fill(_ds);
momentsDataGrid.ItemsSource = _ds.Tables[0].DefaultView;
momentsDataGrid.IsReadOnly = true;
}
}
}
}
}
}
if (categoryComboBox.SelectedIndex == 0)
{
using (SqlConnection _connection = SMUMomentsDB.GetConnection())
{
_connection.Open();
using (SqlDataAdapter _momentsTableAdapter = new SqlDataAdapter("Select * from SpecialMoment WHERE GenreID in ( '2', '3', '11', '14')", _connection))
{
DataSet _ds = new DataSet();
_momentsTableAdapter.Fill(_ds);
momentsDataGrid.ItemsSource = _ds.Tables[0].DefaultView;
momentsDataGrid.IsReadOnly = true;
}
}
}
if (genreComboBox.SelectedIndex == 0)
{
using (SqlConnection _connection = SMUMomentsDB.GetConnection())
{
_connection.Open();
using (SqlDataAdapter _momentsTableAdapter = new SqlDataAdapter("Select * from SpecialMoment WHERE GenreID = '3'", _connection))
{
DataSet _ds = new DataSet();
_momentsTableAdapter.Fill(_ds);
momentsDataGrid.ItemsSource = _ds.Tables[0].DefaultView;
momentsDataGrid.IsReadOnly = true;
}
}
}
if (locationComboBox.SelectedIndex == 0)
{
using (SqlConnection _connection = SMUMomentsDB.GetConnection())
{
_connection.Open();
using (SqlDataAdapter _momentsTableAdapter = new SqlDataAdapter("Select * from SpecialMoment WHERE VenueLocation = 'Wales'", _connection))
{
DataSet _ds = new DataSet();
_momentsTableAdapter.Fill(_ds);
momentsDataGrid.ItemsSource = _ds.Tables[0].DefaultView;
momentsDataGrid.IsReadOnly = true;
}
}
}
if (categoryComboBox.SelectedIndex == 1)
{
MessageBox.Show("Food and Drink");
}