I want to have a DBGrid showing products filtered based on 4 dbLookupCombobox'es
If I select a Manufacturer, the Category1-3 will update/filter and only show existing categories for products for the selected manufacturer.
If I then select a Category1, then Category2-3 will update/filter and only show existing categories for products for the selected manufacturer and Category1.
Same with Category2 as category1 but includes choice of Category1.
Also I want to be able to only choose from Category1+2 with no Manufacturer selected.
Whatever I choose from these 4 Combos, I want the DBGrid to update and show the filtered products.
When done filtering, I want a Reset filter Button to start over.
Scenario:
1x FDConnection, Firebird.
5x FDQuery and Datasources
1x DBGrid
4x dbLookupComboBox
1x Button
The Queries:
FDQuery1: FDQ_Manufacturers:
select distinct MANUFACTURERNAME from Products where
upper (CATEGORYTEXT1) like upper(:CATEGORYTEXT1)
and upper(CATEGORYTEXT2) like upper(:CATEGORYTEXT2)
and upper(CATEGORYTEXT3) like upper(:CATEGORYTEXT3)
FDQuery2: FDQ_Category1
select distinct CATEGORYTEXT1 from Products where
upper(MANUFACTURERNAME) like upper(:MANUFACTURERNAME)
FDQuery3: FDQ_Category2
select distinct CATEGORYTEXT2 from Products where
upper(MANUFACTURERNAME) like upper(:MANUFACTURERNAME)
and upper(CATEGORYTEXT1) like upper(:CATEGORYTEXT1)
FDQuery4: FDQ_Category3
select distinct CATEGORYTEXT3 from Products where
upper(MANUFACTURERNAME) like upper(:MANUFACTURERNAME)
and upper(CATEGORYTEXT1) like upper(:CATEGORYTEXT1)
and upper(CATEGORYTEXT2) like upper(:CATEGORYTEXT2)
FDQuery5: FDQ_Products
select first 100 * from Products where
and upper(MANUFACTURERNAME) like upper(:MANUFACTURERNAME)
and upper(CATEGORYTEXT1) like upper(:CATEGORYTEXT1)
and upper(CATEGORYTEXT2) like upper(:CATEGORYTEXT2)
and upper(CATEGORYTEXT3) like upper(:CATEGORYTEXT3)
and upper(DESCRIPTION) like upper(:DESCRIPTION)
ORDER BY PRICE
The dbLookupComboBox'es:
dbLookupComboBox1: LCB_Manufacturers: OnSelect: FilterProducts('MANUFACTURERNAME', LCB_Manufacturers.Text);
dbLookupComboBox2: LCB_Category1: OnSelect: FilterProducts('CATEGORYTEXT1', LCB_Category1.Text);
dbLookupComboBox3: LCB_Category2: Onselect: FilterProducts('CATEGORYTEXT2', LCB_Category2.Text);
dbLookupComboBox4: LCB_Category3: OnSelect: FilterProducts('CATEGORYTEXT3', LCB_Category3.Text);
ListSource is the DataSources for each FDQuery.
ListField and KeyField is respectively the MANUFACTURERNAME, CATEGORYTEXT1, CATEGORYTEXT2, CATEGORYTEXT3
- I initialize the all Params with '%%'
- I run FDQuery1-4 and now have all Manufacturers and categories filled in the Combos.
- I run FDQuery5 and have a unfiltered result of products in the DBGrid.
- Now we are ready to do the SQL Filtering.
Questions:
Is the dbLookupComboBoxes the right choice of component for this task?
Is it the right way to handle this kind of filtering?
I can't figure out the FilterProducts procedure. I can show my code, but I it is really no good, living its own life..
Sorry for bringing such long post. I have spend alot of time in this, and really need an advice now.