📄 ufrmfiltersql.pas
字号:
if Str = '' then FM.FxGrid.RemoveItem(I);
if Str = '无' then FM.FxGrid.RemoveItem(I);
end;
MemoFilter.Lines.Clear;
for I:=1 to FM.FxGrid.Rows-2 do begin
Str:=FM.FxGrid.TextMatrix[I,0]+' '+FM.FxGrid.TextMatrix[I,1]+' '+
FM.FxGrid.TextMatrix[I,2];
MemoFilter.Lines.Add(Str);
if FM.FxGrid.TextMatrix[I,3] = '' then FM.FxGrid.TextMatrix[I,3]:='并且';
Str:=FM.FxGrid.TextMatrix[I,3];
MemoFilter.Lines.Add(Str);
end;
{***最后一行*********}
Str:=MemoFilter.Lines.Strings[MemoFilter.Lines.Count-1];
if (Str = '并且') or (Str = '或者') then
MemoFilter.Lines.Strings[MemoFilter.Lines.Count-1]:='';
bCount:=True; K:=0;
{oooo括号问题 更加 直观ooooooooo} {ooooo And or 的关键oooooooooooo}
for I:=1 to MemoFilter.Lines.Count-1 do begin
if MemoFilter.Lines.Strings[I] = '或者' then begin
bCount:=not bCount;
K:=K+1;
if not bCount then MemoFilter.Lines.Strings[I]:='或者 【'
else MemoFilter.Lines.Strings[I]:='或者 】';
end;
end;
//只有一个或者 关键
MemoFilter.Text:=Trim(MemoFilter.Text);
if (K mod 2) = 1 then MemoFilter.Lines.Add('】');
end;
{*******************************************************************************
* 把过滤SQL的条件添加到 左边
* 只能用双引号
* iFieldType:Integer; // 1 数子 2 时间 3 字符
*ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
* PAddFilterToREdt 已经做了很多初始话 工作
* 这儿就可以 不做了
*******************************************************************************}
procedure TFrmFilterSQL.PAddFilterSQLToREdt;
var
StrVlu1,sOpator,Str:String;
I,iCol:Integer;
begin
MemoFilterSQL.Lines.Clear;
for I:=1 to FM.FxGrid.Rows-2 do begin
Str:=FM.FxGrid.TextMatrix[I,0];
PGetFieldType(Str);
iCol:=FM.CmbStrA.Items.IndexOf(Str);
sOpator:=FM.FxGrid.TextMatrix[I,1];
if sOpator = '包含' then sOpator:='Like';
StrVlu1:=saFieldName[iCol]+' '+sOpator+' ';
Str:=FM.FxGrid.TextMatrix[I,2];
if iFieldType = 1 then ;//数字
if iFieldType = 2 then ;//时间 暂时空
if (iFieldType = 3) and (sOpator = 'Like') then Str:='"%'+Str+'%'+'"'
else if (iFieldType = 3) then Str:='"'+Str+'"';
StrVlu1:=StrVlu1+Str;
if I <> FM.FxGrid.Rows-2 then begin
if FM.FxGrid.TextMatrix[I,3] = '并且' then StrVlu1:=StrVlu1+' And ';
if FM.FxGrid.TextMatrix[I,3] = '或者' then StrVlu1:=StrVlu1+' Or ';
end;
MemoFilterSQL.Lines.Append(StrVlu1);
end;
{oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo}
end;
{*******************************************************************************
* 得到数组的种类 iFieldType // 1 数子 2 时间 3 字符
*******************************************************************************}
procedure TFrmFilterSQL.PGetFieldType(sCmbTxt:String);
var
K:integer;
begin
K:=FM.CmbStrA.Items.IndexOf(sCmbTxt);
if (saFieldType[K] = ftMemo) or (saFieldType[K] = ftWideString) or
(saFieldType[K] = ftString) or (saFieldType[K] = ftFmtMemo) then
begin
iFieldType:=3; //字符
end else if
(saFieldType[K] = ftInteger) or (saFieldType[K] = ftWord) or
(saFieldType[K] = ftSmallint) or (saFieldType[K] = ftFloat) or
(saFieldType[K] = ftCurrency) or (saFieldType[K] = ftFloat) then
begin
iFieldType:=1; //数字
end else iFieldType:=2; //时间
end;
procedure TFrmFilterSQL.MemoFilterSQLChange(Sender: TObject);
begin
if Pos('''',MemoFilterSQL.Text) > 0 then begin
MemoFilterSQL.Text:=MyReplaceStrA(MemoFilterSQL.Text,'''','"');
Exit;
end;
end;
procedure TFrmFilterSQL.SpeedButton1Click(Sender: TObject);
begin
FM.PSetControlInGridVisible(False);
MemoFilter.Text:='';
MemoFilterSQL.Text:='';
FM.FxGrid.Rows:=1;
FM.FxGrid.Rows:=3;
end;
{ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
* 初始话
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo}
procedure TFrmFilterSQL.PInitFilterGrid;
begin
FM.PFillCaption(['列名','条件','取值','关系']);
FM.PBingDingCtrlB([FM.CmbStrA ,FM.CmbStrB,FM.EdtBtnA,FM.CmbInt]);
end;
procedure TFrmFilterSQL.FMCmbIntKeyPress(Sender: TObject; var Key: Char);
begin
Key:=#0;
end;
procedure TFrmFilterSQL.FMEdtBtnAKeyPress(Sender: TObject; var Key: Char);
begin
{oo当为数字型 不能输入整数ooooooooooooooooooooooooooooooooo}
if iFieldType = 1 then Key:=MyEnterNumberA(FM.EdtBtnA,Key,6);
end;
procedure TFrmFilterSQL.FMCmbStrAChange(Sender: TObject);
begin
FM.CmbStrAChange(Sender);
PSetFilterChar(FM.CmbStrA.Text);
FM.FxGrid.TextMatrix[FM.FxGrid.Row,1]:='无';
FM.FxGrid.TextMatrix[FM.FxGrid.Row,2]:='';
FM.EdtBtnA.Text:='';
end;
{ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
* 要根据左边的 条件来判断 该输入的数字 还是 字符
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo}
procedure TFrmFilterSQL.FMEdtBtnAEnter(Sender: TObject);
var
Str:String;
begin
FM.EdtBtnAEnter(Sender);
Str:=FM.FxGrid.TextMatrix[FM.FxGrid.Row,0];
if Str = '' then Exit;
PSetFilterChar(Str);
end;
procedure TFrmFilterSQL.FMCmbStrBEnter(Sender: TObject);
begin
FM.CmbStrBEnter(Sender);
if FM.FxGrid.TextMatrix[FM.FxGrid.Row,0] <> '' then
PSetFilterChar(FM.FxGrid.TextMatrix[FM.FxGrid.Row,0]);
end;
{ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
* 把过滤条件 添加到 表格中 AddGridRow();
ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo}
procedure TFrmFilterSQL.PSetFilterToGrid;
var
I,iBiaoShi:Integer;
Str,S0,S1,S2,S3:String;
begin
iBiaoShi:=100;
for I:=0 to MemoFilter.Lines.Count-1 do begin
Str:=MemoFilter.Lines.Strings[I];
if (Pos('并且',Str) <=0 ) and (Pos('或者',Str) <=0 ) and (Str <>'】') then begin
S0:=MyCutString(True,Str);
Str:=MyCutString(False,Str);
S1:=MyCutString(True,Str);
S2:=MyCutString(False,Str);
end;
S3:='';iBiaoShi:=100;
Str:=MemoFilter.Lines.Strings[I];
if (Pos('并且',Str) >0 ) then S3:='并且';
if (Pos('或者',Str) >0 ) then S3:='或者';
if S3 <> '' then begin
AddGridRow([S0,S1,S2,S3],FM.fxGrid);
iBiaoShi:=0;
end;
end;
if (iBiaoShi = 100) then AddGridRow([S0,S1,S2,S3],FM.fxGrid);
end;
{*******************************************************************************
* F7 选择的快接见
*******************************************************************************}
procedure TFrmFilterSQL.FMEdtBtnAKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
FM.EdtBtnAKeyDown(Sender, Key, Shift);
if Key = VK_F7 then FM.SBtnEdtA.OnClick(Sender);
end;
procedure TFrmFilterSQL.FMSBtnEdtAClick(Sender: TObject);
var
Str:String;
I:Integer;
begin
FrmFilterSQLQ:=TFrmFilterSQLQ.Create(Self);
FrmFilterSQLQ.sCurSQL:=FrmQueryTop.sQueryFZIDSQL;
DeBebugSpy(nil,'FMSBtnEdtAClick sQueryFZIDSQL=',FrmQueryTop.sQueryFZIDSQL);
FrmFilterSQLQ.sCurStr:=FM.EdtBtnA.Text;
DeBebugSpy(nil,'FMSBtnEdtAClick sQueryFZIDSQL=',FM.EdtBtnA.Text);
Str:=FM.FxGrid.TextMatrix[FM.FxGrid.Row,0];
I:=FM.CmbStrA.Items.IndexOf(Str);
//网格序号 不可设置 是假列
if I <= 0 then Exit; //曾经 出现 I = -1 暂时还不知道什么原因 以后出现 就弹不出选择对话筐
Str:=saFieldName[I];
DeBebugSpy(nil,'FMSBtnEdtAClick sQueryFZIDSQL=',Str);
FrmFilterSQLQ.sCurField:=Str;
FrmFilterSQLQ.PFillListBox();
sTempSQL:='';
FrmFilterSQLQ.ShowModal;
if sTempSQL <> '' then FM.EdtBtnA.Text:=sTempSQL;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -