Fórum Accent Insensitive ACCESS? #393485
07/01/2011
0
Pessoal, estou fazendo um codigo para ignorar acentos no access, funciona quando INICIA COM usando o like e o %, porém quero um form que faça varias coisas, QUE INICIA COM, CONTENDO e BUSCAR POR LETRAS cfre o button A..B, C..D etc...
Ja criei o começo, mais não consigo aplicar o resto da regra para este procedimento, segue o que ja foi feito.
Obrigado...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids, StdCtrls, Tabs,
ExtCtrls, ComCtrls, Buttons, XPMan;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
pnlFiltro: TPanel;
lblFiltrar: TLabel;
bttFiltrar: TButton;
EdtPesquisa: TEdit;
pButton: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
SpeedButton9: TSpeedButton;
SpeedButton10: TSpeedButton;
SpeedButton11: TSpeedButton;
SpeedButton12: TSpeedButton;
SpeedButton13: TSpeedButton;
SpeedButton14: TSpeedButton;
StatusBar1: TStatusBar;
procedure EdtPesquisaChange(Sender: TObject);
procedure bttFiltrarClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
procedure AccessInsensitive(qQuery: TADOQuery; sEdtPesquisa: TEdit; TipoFilter: Integer);
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.AccessInsensitive(qQuery: TADOQuery; sEdtPesquisa: TEdit; TipoFilter: Integer);
var
i: Integer;
str: String;
begin
str := EmptyStr;
for i := 1 to Length(sEdtPesquisa.Text) do
str := str + '_';
if TipoFilter = 0 then // Então o filter é pelo texto no change do Edit (INICIA COM)
begin
if sEdtPesquisa.Text <> EmptyStr then
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add('Select * From crdUf WHERE (crdUf.descricao BETWEEN :BUSCA_INI AND :BUSCA_FIN) ');
qQuery.SQL.Add(' AND (crdUf.descricao LIKE :LIMITESPACO) ');
qQuery.Parameters.ParamByName('BUSCA_INI').Value := EdtPesquisa.Text;
qQuery.Parameters.ParamByName('BUSCA_FIN').Value := EdtPesquisa.Text + 'Z'; // Este Z significa um delimitador de caracteres
// para ser contado 1 char a mais depois do STR
qQuery.Parameters.ParamByName('LIMITESPACO').Value := str +'%';
qQuery.Open;
end else
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add('Select * From crdUf order by descricao ');
qQuery.Open;
end;
end else
if TipoFilter = 1 then // Então o filter é o texto do Edit pelo button (CONTENDO)
begin
if sEdtPesquisa.Text <> EmptyStr then
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add('Select * From crdUf WHERE (crdUf.descricao BETWEEN :BUSCA_INI AND :BUSCA_FIN) ');
qQuery.SQL.Add(' AND (crdUf.descricao LIKE :LIMITESPACO) ');
qQuery.Parameters.ParamByName('BUSCA_INI').Value := EdtPesquisa.Text;
qQuery.Parameters.ParamByName('BUSCA_FIN').Value := EdtPesquisa.Text + 'Z'; // Este Z significa um delimitador de caracteres
// para ser contado 1 char a mais depois do STR
qQuery.Parameters.ParamByName('LIMITESPACO').Value := '%'+ str +'%';
qQuery.Open;
end else
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add('Select * From crdUf order by descricao ');
qQuery.Open;
end;
end;
end;
procedure TForm1.EdtPesquisaChange(Sender: TObject);
begin
AccessInsensitive(ADOQuery1,EdtPesquisa,0);
end;
procedure TForm1.bttFiltrarClick(Sender: TObject);
begin
Tag := 1;
AccessInsensitive(ADOQuery1,EdtPesquisa,Tag);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
AccessInsensitive(ADOQuery1,EdtPesquisa,0);
end;
end.
Adriano Dolce
Curtir tópico
+ 0
Responder
Posts
07/01/2011
Adriano Dolce
Resolvido a parte do CONTENDO, agora falta apenas os buttons
Código:
Código:
procedure TForm1.AccessInsensitive(qQuery: TADOQuery; sEdtPesquisa: TEdit; TipoFilter: Integer);
var
i: Integer;
str: String;
begin
str := EmptyStr;
for i := 1 to Length(sEdtPesquisa.Text) do
str := str + '_';
if TipoFilter = 0 then // Então o filter é pelo texto no change do Edit (INICIA COM)
begin
if sEdtPesquisa.Text <> EmptyStr then
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add(' SELECT * from tabla WHERE (campo BETWEEN :BUSCA_INI AND :BUSCA_FIN) ');
qQuery.SQL.Add(' AND (campo LIKE :LIMITESPACO) ');
qQuery.SQL.Add(' OR (campo like :ESCRITEDIT) ');
qQuery.Parameters.ParamByName('BUSCA_INI').Value := EdtPesquisa.Text;
qQuery.Parameters.ParamByName('BUSCA_FIN').Value := EdtPesquisa.Text + 'Z';
qQuery.Parameters.ParamByName('LIMITESPACO').Value := str +'%';
qQuery.Parameters.ParamByName('ESCRITEDIT').Value := EdtPesquisa.Text + '%';
qQuery.Open;
end else
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add('Select * From tabla order by campo ');
qQuery.Open;
end;
end else
if TipoFilter = 1 then // Então o filter é o texto do Edit pelo button (CONTENDO)
begin
if sEdtPesquisa.Text <> EmptyStr then
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add(' SELECT * from tabla WHERE (campo BETWEEN :BUSCA_INI AND :BUSCA_FIN) ');
qQuery.SQL.Add(' AND (campo LIKE :LIMITESPACO) ');
qQuery.SQL.Add(' OR (campo like :ESCRITEDIT) ');
qQuery.Parameters.ParamByName('BUSCA_INI').Value := EdtPesquisa.Text;
qQuery.Parameters.ParamByName('BUSCA_FIN').Value := EdtPesquisa.Text + 'Z';
qQuery.Parameters.ParamByName('LIMITESPACO').Value := '%'+ str +'%';
qQuery.Parameters.ParamByName('ESCRITEDIT').Value := '%'+ EdtPesquisa.Text + '%';
qQuery.Open;
end else
begin
qQuery.Close;
qQuery.SQL.Clear;
qQuery.SQL.Add('select * from tabla order by campo ');
qQuery.Open;
end;
end;
end;
Responder
Gostei + 0
08/01/2011
Adriano Dolce
Resolvido
os buttons
uso
Valeu pessoal
os buttons
procedure TForm1.FilterLetras(qQuery: TADOQuery; sLetraIni, sLetraFin: String); var s: String; begin with qQuery do begin Filtered := False; s := 'campo like ' + QuotedStr(sLetraIni+'*') + 'or campo like ' + QuotedStr(sLetraFin+'*'); Filter := s; Filtered := True; end; end;
uso
procedure TForm1.SpeedButton1Click(Sender: TObject); begin FilterLetras( ADOQuery1, (Sender as TSpeedButton).Caption[1], (Sender as TSpeedButton).Caption[2] ); end;
Valeu pessoal
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)