📄 fssearch.~pas
字号:
var
f:double;
Error:integer;
begin
val(s,f,Error);
result:=(Error=0);
end;
procedure TfSearchDlg.FormCreate(Sender: TObject);
begin
IniWindow();
SearchSuccess:=true;
QueryList:=TList.Create();
self.FormStyle:=fsStayOnTop;
end;
function TfSearchDlg.DoQuery(IsAnd:boolean):boolean;
procedure GetLogic(var aFieldLogic:string;var aDispLogic:string);
begin
if QueryList.Count<1 then
begin
aFieldLogic:='';
aDispLogic:='';
end
else begin
if IsAnd then
begin
aFieldLogic:='and';
aDispLogic:='并且';
end
else begin
aFieldLogic:='or';
aDispLogic:='或者';
end;
end;
end; //end procedure
var
DataType:TFieldType;
FieldName,left,right,Condition:string;
p:pQueryItem;
FieldLogic,DispLogic,value,s:string;
begin
result:=true;
DataType:=Fields[cbCompItem.itemIndex].DataType;
FieldName:=Fields[cbCompItem.itemIndex].FieldName;
Condition:=GetCondition(left,right);
case GetFieldType(DataType) of
1:begin
//字符串类型
if IsRange() then
begin
s:=' ('+FieldName+' >= '''+dtRange1.Text+''') and ('+FieldName
+' <= '''+dtRange2.Text+''')';
Value:='在 '+dtRange1.Text+' 与 '+dtRange2.Text+' 之间';
end
else begin
s:='('+FieldName+Condition+''''+left+dtCompare.Text+right+''') ';
Value:=dtCompare.Text;
end;
end;
2:begin
//整型
if IsRange() then
begin
if IsInteger(dtRange1.Text) and IsInteger(dtRange2.Text) then
begin
s:=' ('+FieldName+' >= '+dtRange1.Text+') and ('+FieldName
+' <= '+dtRange2.Text+')';
Value:='在 '+dtRange1.Text+' 与 '+dtRange2.Text+' 之间';
end
else begin
MessageBox(self.Handle,'输入数据不是有效整数值','数据类型转错误',MB_OK);
result:=false;
end;
end
else begin
if IsInteger(dtCompare.Text) then
begin
s:='('+FieldName+Condition+dtCompare.Text+')';
Value:=dtCompare.Text;
end
else begin
MessageBox(self.Handle,'输入数据不是有效整数值','数据类型转错误',MB_OK);
result:=false;
end;
end;
end;
3:begin
//浮点型(含货币型)
if IsRange() then
begin
if IsReal(dtRange1.Text) and IsReal(dtRange2.Text) then
begin
s:=' ('+FieldName+' >= '+dtRange1.Text+') and ('+FieldName
+' <= '+dtRange2.Text+')';
Value:='在 '+dtRange1.Text+' 与 '+dtRange2.Text+' 之间';
end
else begin
MessageBox(self.Handle,'输入数据不是有效的小数值','数据类型转错误',MB_OK);
result:=false;
end;
end
else begin
if IsReal(dtCompare.Text) then
begin
s:='('+FieldName+Condition+dtCompare.Text+')';
Value:=dtCompare.Text;
end
else begin
MessageBox(self.Handle,'输入数据不是有效的小数值','数据类型转错误',MB_OK);
result:=false;
end;
end;
end;
4:begin
//日期时间型
if IsRange() then
begin
if IsDateTime(dtRange1.Text) and IsDateTime(dtRange2.Text) then
begin
s:=' ('+FieldName+' between '+DateSeparator+dtRange1.Text+DateSeparator
+' and '+DateSeparator+dtRange2.Text+DateSeparator+')';
Value:='在 '+dtRange1.Text+' 与 '+dtRange2.Text+' 之间';
end
else begin
MessageBox(self.Handle,'输入数据不是有效的时间值','数据类型转错误',MB_OK);
result:=false;
end;
end
else begin
if IsDateTime(dtCompare.Text) then
begin
s:='('+FieldName+Condition+DateSeparator+dtCompare.Text+DateSeparator+')';
Value:=dtCompare.Text;
end
else begin
MessageBox(self.Handle,'输入数据不是有效的时间值','数据类型转错误',MB_OK);
result:=false;
end;
end;
end; //end 4
else result:=false;
end; //end case
if result then
begin
p:=new(pQueryItem);
GetLogic(FieldLogic,DispLogic);
p.QueryStr:=' '+FieldLogic+' '+s;
p.DispCondition.Logic:=DispLogic;
p.DispCondition.CompItem:=cbCompItem.Text;
p.DispCondition.Condition:=cbCondition.Text;
p.DispCondition.Value:=Value;
QueryList.Add(p);
end;
end;
procedure TfSearchDlg.lvDisp();
var
li:TListItem;
i:integer;
p:pQueryItem;
begin
ListView1.Clear;
for i:=0 to QueryList.Count-1 do
begin
li:=ListView1.Items.Add;
p:=QueryList.Items[i];
li.Caption:=p.DispCondition.Logic;
li.SubItems.Add(p.DispCondition.CompItem);
li.SubItems.Add(p.DispCondition.Condition);
li.SubItems.Add(p.DispCondition.Value);
end; //end for
ListView1.ItemIndex:=ListView1.Items.Count-1;
end;
procedure TfSearchDlg.bbOkClick(Sender: TObject);
var
s:string;
i:integer;
p:pQueryItem;
begin
{if cbCompItem.Text='' then
begin
messageBox(self.Handle,'你忘记选择比较项','查询错误',MB_OK);
exit;
end;
if cbCondition.ItemIndex<0 then
begin
messageBox(self.Handle,'你忘记选择比较条件','查询错误',MB_OK);
exit;
end;
}
if cbMultiCondition.Checked then
begin
if QueryList.Count<1 then
begin
ShowMessage('没有要查询的条件');
exit;
end
end
else begin
if not DoQuery(false) then exit;
end;
s:=' ';
for i:=0 to QueryList.Count-1 do
begin
p:=QueryList.Items[i];
s:=s+p.QueryStr+' ';
end;
QueryStr:=s;
close;
end;
procedure TfSearchDlg.cbConditionCloseUp(Sender: TObject);
begin
if IsRange() then
begin
SetCompareEdit(false);
//self.SetFocusedControl(dtRange1);
end
else begin
SetCompareEdit(true);
//self.SetFocusedControl(dtCompare);
end;
end;
procedure TfSearchDlg.SetCompareEdit(Simple:boolean);
begin
if Simple then
begin
dtRange1.Visible:=false;
dtRange2.Visible:=false;
dtCompare.Visible:=true;
end
else begin
dtRange1.Visible:=true;
dtRange2.Visible:=true;
dtCompare.Visible:=false;
end;
end;
function TfSearchDlg.GetCompareState():boolean;
begin
result:=dtCompare.Visible;
end;
procedure TfSearchDlg.bbCancelClick(Sender: TObject);
begin
SearchSuccess:=false;
end;
procedure TfSearchDlg.FormShow(Sender: TObject);
var
i,DropCount:integer;
begin
//加载fields
for i:=0 to Fields.Count-1 do
begin
if Fields[i].FieldKind=fkData then
begin
cbCompItem.Items.Add(Fields[i].DisplayName);
end;
end; //end for
DropCount:=Fields.Count;
if Fields.Count>20 then
DropCount:=20;
cbCompItem.DropDownCount:=DropCount;
LoadStatus();
end;
procedure TfSearchDlg.LoadStatus();
var
s:string;
begin
if SaveCondition then
begin
if cbCompItem.Items.Count>0 then
begin
if cbCompItem.Items.Count>CompItemIndex then
begin
cbCompItem.ItemIndex:=CompItemIndex;
end
else
cbCompItem.ItemIndex:=0;
end;
SetCondition();
s:=Conditions[ConditionIndex].Display;
cbCondition.ItemIndex:=cbCondition.Items.IndexOf(s);
cbCondition.OnChange(cbCondition);
dtCompare.Text:=CompareValue;
dtRange1.Text:=CompareRange1;
dtRange2.Text:=CompareRange2;
cbMultiCondition.Checked:=MultiCondition;
cbMultiCondition.OnClick(cbMultiCondition);
lvDisp();
end
else begin
if cbCompItem.Items.Count>0 then
cbCompItem.ItemIndex:=0;
SetCondition();
cbCondition.ItemIndex:=0;
cbCondition.OnChange(cbCondition);
dtCompare.Text:='';
dtRange1.Text:='';
dtRange2.Text:='';
cbMultiCondition.Checked:=MultiCondition;
cbMultiCondition.OnClick(cbMultiCondition);
end;
end;
procedure TfSearchDlg.SaveStatus();
begin
if SaveCondition then
begin
CompItemIndex:=cbCompItem.ItemIndex;
ConditionIndex:=GetConditionIndex();
CompareValue:=dtCompare.Text;
CompareRange1:=dtRange1.Text;
CompareRange2:=dtRange2.Text;
MultiCondition:=cbMultiCondition.Checked;
end;
end;
procedure TfSearchDlg.cbCompItemChange(Sender: TObject);
begin
SetCondition();
end;
procedure TfSearchDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
SaveStatus();
end;
procedure TfSearchDlg.cbMultiConditionClick(Sender: TObject);
begin
SetWindow(not cbMultiCondition.Checked);
end;
procedure TfSearchDlg.SpeedButton2Click(Sender: TObject);
begin
if DoQuery(true) then
lvDisp();
end;
procedure TfSearchDlg.SpeedButton1Click(Sender: TObject);
begin
if DoQuery(false) then
lvDisp();
end;
procedure TfSearchDlg.SpeedButton3Click(Sender: TObject);
var
index:integer;
p:pQueryItem;
begin
if ListView1.SelCount>0 then
begin
index:=ListView1.Selected.Index;
p:=QueryList.Items[index];
QueryList.Delete(index);
dispose(p);
lvDisp();
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -