![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
Можно ли сделать фильтрацию 1 таблицы одновременно с 3 фильтров?
Тоесть, у меня в таблице 3 столбца, далее есть edit.text, чекбокс и комбобокс - у каждого из них есть условия фильтрации для каждого столбца. Так вот, можно ли сделать не прибегая к многочисленным условиям IF чтобы фильтры работали параллельно? Тоесть накладывались друг на друга. На данный момент для каждого из них у меян примерно такой код: Код:
if (edit2.Text='') and (checkbox9.Checked=false) and (combobox15.Text<>'') then
begin {if1}
ADOQuery1.Filter:=Format('(Район LIKE ''%s'')',[combobox15.Text]);
ADOQuery1.Filtered:=True;
exit;
end;{if1}
if (edit2.Text<>'') and (checkbox9.Checked=false) and (combobox15.Text<>'') then
begin {if2}
ADOQuery1.Filter:=Format('(Район LIKE ''%s'' and Комнат ''%s'')',[combobox15.Text,edit2.Text]);
ADOQuery1.Filtered:=True;
exit;
end;{if2}
if (edit2.Text='') and (checkbox9.Checked=true) and (combobox15.Text<>'') then
begin {if3}
ADOQuery1.Filter:=Format('(Район LIKE ''%s'' and Этаж<>1)',[combobox15.Text]);
ADOQuery1.Filtered:=True;
exit;
end;{if3}
if (edit2.Text<>'') and (checkbox9.Checked=true) and (combobox15.Text<>'') then
begin {if4}
ADOQuery1.Filter:=Format('(Район LIKE ''%s'' and Комнат ''%s'' and Этаж<>1)',[combobox15.Text,edit2.Text]);
ADOQuery1.Filtered:=True;
exit;
end;{if4} if (edit2.Text='') and (checkbox9.Checked=false) and (combobox15.Text<>'') then
begin {if1-1}
ADOQuery1.Filter:=Format('(Район LIKE ''%s'')',[combobox15.Text]);
ADOQuery1.Filtered:=True;
exit;
end;{if1-1}
if (edit2.Text<>'') and (checkbox9.Checked=false) and (combobox15.Text='Все') then
begin {if2-1}
ADOQuery1.Filter:=Format('(Комнат ''%s'')',[edit2.Text]);
ADOQuery1.Filtered:=True;
exit;
end;{if2-1}
if (edit2.Text='') and (checkbox9.Checked=true) and (combobox15.Text='') then
begin {if3-1}
ADOQuery1.Filter:='Этаж<>1';
ADOQuery1.Filtered:=True;
exit;
end;{if3-1}
if (edit2.Text<>'') and (checkbox9.Checked=true) and (combobox15.Text='Все') then
begin {if4-1}
ADOQuery1.Filter:=Format('(Комнат ''%s'' and Этаж<>1)',[edit2.Text]);
ADOQuery1.Filtered:=True;
exit;
end;{if4-1}Я думаю есть альтернатива этой грамосткости... Подскажите пожалуйста... |
|
#2
|
||||
|
||||
|
Цитата:
альтернатива IF - выбор готового текста запроса из, например, комбобокса) |
|
#3
|
|||
|
|||
|
А если подумать?
Код:
var
F,S:String;
.....
S:=''; F:='';
if (combobox15.Text<>'') then
begin
S:=Format('(Район LIKE ''%s'')',[combobox15.Text]);
if F= '' then F:= S else F:=F + 'and '+S;
end;{if1}
if (edit2.Text<>'')then
begin
S:=Format('(Комнат ''%s'')',[edit2.Text]);
if F= '' then F:= S else F:=F + 'and '+S;
end;{if2}
if (checkbox9.Checked) then
begin
S:='(Этаж<>1)';
if F= '' then F:= S else F:=F + 'and '+S;
end;{if3}
if F='' then begin
ADOQuery1.Filtered:=False;
end else begin
ADOQuery1.Filter:=F;
ADOQuery1.Filtered:=True;
end;Только условие с комнатами непонятное |