📄 search.pas
字号:
//产生查询语句
function TForm_search.GetQueryStr() :string;
var
SearchSql:string;
begin
//从树型控件中得到sql语句
SearchSql:=GenerateSql(myNode);
//showmessage(SearchSql);
if trim(SearchSql)='' then
result:=''
else
result:=unit_wxp.SearchSql +SearchSql ;
end;
//////////////////////////////////////////////////////////////////
//根据不同的字段类型,添加不通的操作符
procedure TForm_search.AddOperator(FieldType:string);
begin
//showmessage(FieldType);
if (FieldType='number') or (FieldType='money') then
begin
with combo_operator do
begin
clear;
text:= '等于(=)';
Items.Add('等于(=)');
Items.Add('不等于(<>)');
Items.Add('大于(>)');
Items.Add('小于(<)');
Items.Add('大于等于(>=)');
Items.Add('小于等于(<=)');
end;
end
else if FieldType='date' then
begin
with combo_operator do
begin
clear;
text:= '等于(=)';
Items.Add('等于(=)');
Items.Add('不等于(<>)');
Items.Add('大于(>)');
Items.Add('小于(<)');
Items.Add('大于等于(>=)');
Items.Add('小于等于(<=)');
end;
edit_value.text:=datetostr(today);
end
else if FieldType='boolean' then
begin
with combo_operator do
begin
Clear ;
text:='等于(=)';
Items.Add('等于(=)');
end;
end
else
begin
with combo_operator do
begin
Clear ;
text:='等于(=)';
Items.Add('等于(=)');
Items.Add('不等于(<>)');
Items.Add('相似(like)');
end;
end;
end;
//////////////////////////////////////////////////////////////////
function TForm_search.GenerateSql(tempNode:Ttreenode) :string;
var
tempSql:string;
begin
if tempNode=nil then
begin
Result:='';
exit;
end;
if tempNode=myNode then
begin
tempSql:=GenerateSql(tempNode.getFirstChild );
Result:=tempsql;
exit;
end;
if tempNode.getNextSibling <>nil then
begin
tempSql:=GenerateSql(tempNode.getNextSibling );
if copy(tempNode.text,1,6)='子条件' then
begin
if (GenerateSql(tempNode.getFirstChild )<>'') and (tempSql<>'') then
tempSql:='('+GenerateSql(tempNode.getFirstChild )+')'+' '
+Getrelation(tempNode.Text )+ ' '+tempSql
else if (GenerateSql(tempNode.getFirstChild )<>'') and (tempSql='') then
tempSql:='('+GenerateSql(tempNode.getFirstChild )+')';
//tempSql:=tempSql+ ' '; //+ Getrelation(tempNode.Text );
Result:= tempSql;
end
else if copy(tempNode.text,1,6)<>'子条件' then
begin
if tempSql<>'' then
tempSql:=GetOneSql(tempNode.Text ) + ' ' +Getrelation2(tempNode.Text)
+' '+ tempSql
else
tempSql:=GetOneSql(tempNode.Text );
Result:=tempSql;
end;
exit;
end;
if tempNode.getNextSibling =nil then
begin
if copy(tempNode.text,1,6)='子条件' then
begin
if GenerateSql(tempNode.getFirstChild )<>'' then
tempSql:='('+GenerateSql(tempNode.getFirstChild )+')'+' ';
//+Getrelation(tempNode.Text );
//tempSql:=tempSql+ ' '; //+ Getrelation(tempNode.Text );
Result:= tempSql;
end
else if copy(tempNode.text,1,6)<>'子条件' then
begin
tempSql:=GetOneSql(tempNode.Text );
Result:=tempSql;
end;
exit;
end;
end;
///////////////////////////////////////////////////////////
//判断是or还是and
//如'子条件(or),分离出or'
function TForm_search.Getrelation(tempStr:string):string;
begin
if copy(tempStr,8,2)='or' then
Result:='or'
else
Result:='and';
end;
//另一个判断是or或者and的函数
//如'名称=1(and),分离出and'
function TForm_search.Getrelation2(tempStr:string) :string;
var
tempPos:integer;
begin
tempPos:=pos('(',TempStr)-1;
if copy(TempStr,tempPos+2,2)='or' then
Result:='or'
else
Result:='and';
end;
//自定义函数过程结束
//定义函数获得具体查询部分
function TForm_search.GetOneSql(tempStr:string) :string;
var
tempPos:integer;
begin
tempPos:=pos('(',TempStr)-1;
Result:=copy(TempStr,1,tempPos);
end;
procedure TForm_search.list_fieldsClickCheck(Sender: TObject);
var
tempIndex:integer;
begin
//tempIndex:=list_delete.Items.IndexOf(list_fields.Items.Strings[list_fields.itemindex]);
//if tempIndex<0 then
// list_delete.Items.Add (list_fields.Items.Strings[list_fields.itemindex])
// else
// list_delete.Items.Delete(tempIndex);
end;
procedure TForm_search.HideColumn(i:integer;ifShow:boolean);
var
tempIndex:integer;
begin
tempIndex:=i;
//showmessage(inttostr(tempIndex));
case unit_wxp.WhichForm of
1:form_partinfo.DBGrid1.Columns[tempIndex].Visible :=ifshow;
2:form_partorder.DBGrid1.Columns[tempIndex].Visible :=ifshow;
3:form_partout.DBGrid1.Columns[tempIndex].Visible :=ifshow;
4:form_partin.DBGrid1.Columns[tempIndex].Visible :=ifshow;
5:form_partsell.DBGrid1.Columns[tempIndex].Visible :=ifshow;
6:form_machinetest.DBGrid1.Columns[tempIndex].Visible :=ifshow;
7:form_maintain.DBGrid1.Columns[tempIndex].Visible :=ifshow;
//jin
//200:Form_machine_in.DBGrid1.Columns[tempIndex].Visible :=ifshow;
300:Form_machine_out.DBGrid1.Columns[tempIndex].Visible :=ifshow;
400:Form_contract.DBGrid2.Columns[tempIndex].Visible :=ifshow;
500:Form_contract_order.DBGrid7.Columns[tempIndex].Visible :=ifshow;
600:Form_zx_cjd.DBGrid4.Columns[tempIndex].Visible :=ifshow;
700:Form_ys_cjd.DBGrid4.Columns[tempIndex].Visible :=ifshow;
800:Form_contract_tract.DBGrid3.Columns[tempIndex].Visible :=ifshow;
900:Form_transit_proxy.DBGrid1.Columns[tempIndex].Visible :=ifshow;
201:Form_hkhs.DBGrid1.Columns[tempIndex].Visible :=ifshow; //TForm_cjqk
202:Form_cjqk.DBGrid1.Columns[tempIndex].Visible :=ifshow; //TForm_cjqk
203:Form_thqk.DBGrid1.Columns[tempIndex].Visible :=ifshow; //TForm_cjqk
204:Form_cjyfk.DBGrid1.Columns[tempIndex].Visible :=ifshow; //TForm_cjqk
end;
end;
//根据字段的属性来决定一些查询语句的格式
function TForm_search.DealSearchText(tempStr:string):string;
begin
if (unit_wxp.GetFieldType(list_fields.ItemIndex )= 'string') or (unit_wxp.GetFieldType(list_fields.ItemIndex )= 'date') then
if unit_wxp.GetOperator(combo_operator.Text )=' like ' then
Result:='''%' + tempstr +'%'''
else
Result:='''' + tempstr +''''
else
Result:=tempStr;
end;
procedure TForm_search.AddValues(FieldName:string);
begin
edit_value.Clear ;
if FieldName='办事处' then
begin
if unit_wxp.myOffice <>'总部' then
edit_value.Items.Add (unit_wxp.myOffice )
else
begin
dm_wxp.ADOQuery1.Active :=false;
dm_wxp.ADOQuery1.SQL.Clear ;
dm_wxp.ADOQuery1.SQL.Add('select * from pub_z_office');
dm_wxp.ADOQuery1.Active :=true;
while not dm_wxp.ADOQuery1.Eof do
begin
//showmessage(ADOQuery2.FieldValues['办事处名称'] );
edit_value.Items.Add(dm_wxp.ADOQuery1.Fields.Fields[1].AsString );
dm_wxp.ADOQuery1.Next ;
end;
dm_wxp.ADOQuery1.Active :=false;
end;
edit_value.ItemIndex :=0;
exit;
end;
if (pos('时间',FieldName)<>0) or (pos('日期',FieldName)<>0) then
begin
edit_value.Text :=datetostr(today);
exit;
end;
//if FieldName='编号' then
if unit_wxp.GetFieldType(list_fields.ItemIndex )='boolean' then
begin
edit_value.Items.Add('false');
edit_value.Items.Add ('true');
edit_value.ItemIndex :=0;
exit;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -